Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Disable harbormaster metabot feedback & add appdb MCP feedback (#76932)

Tyler Pludeffdd62caaa5b
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.edn
index 6f6f9771d31..50a7908fece 100644
--- a/.clj-kondo/config/modules/config.edn
+++ b/.clj-kondo/config/modules/config.edn
@@ -1257,6 +1257,7 @@
app-db
config
llm
+ metabot
oauth-server
premium-features
request
@@ -1328,7 +1329,6 @@
settings
slackbot
sql-tools
- store-api
sync
system
task
diff --git a/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj b/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj
index 4013297ec01..7057f79086c 100644
--- a/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj
+++ b/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj
@@ -89,6 +89,7 @@
"HTTPAction"
"ImplicitAction"
"LoginHistory"
+ "McpFeedback"
"McpQueryHandle"
"McpSessionLog"
"McpToolCallLog"
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/models/entity_id_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/models/entity_id_test.clj
index c1506034e18..4f2f91a7480 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/models/entity_id_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/models/entity_id_test.clj
@@ -63,6 +63,7 @@
:model/CollectionPermissionGraphRevision
:model/DashboardCardSeries
:model/LoginHistory
+ :model/McpFeedback
:model/McpQueryHandle
:model/McpSessionLog
:model/McpToolCallLog
diff --git a/frontend/src/metabase-types/api/metabot.ts b/frontend/src/metabase-types/api/metabot.ts
index a6f67ba9758..4527b1ce5b9 100644
--- a/frontend/src/metabase-types/api/metabot.ts
+++ b/frontend/src/metabase-types/api/metabot.ts
@@ -302,17 +302,14 @@ export type MetabotSourceFeedback = {
/**
* Feedback payload for MCP Apps visualization results.
*
- * Sends the prompt and query context needed for Harbormaster
- * to understand the generated visualization.
+ * Sends the prompt and query context needed to understand
+ * the generated visualization.
*/
export type McpAppsFeedback = {
/** User's rating and optional comments about the generated visualization. */
feedback: {
positive: boolean;
- /** Client-generated id for feedback submission. */
- message_id: string;
-
/** Optional category for negative feedback. */
issue_type?: string;
@@ -320,7 +317,7 @@ export type McpAppsFeedback = {
freeform_feedback?: string;
};
- /** MCP-specific context that Harbormaster needs to evaluate the result. */
+ /** MCP-specific context stored alongside the rating. */
conversation_data: {
/** Identifies this submission as coming from the MCP Apps flow. */
source: "mcp";
diff --git a/frontend/src/metabase/embedding/mcp/hooks/useMcpFeedback.ts b/frontend/src/metabase/embedding/mcp/hooks/useMcpFeedback.ts
index dc63ad07b64..38b74abe0e8 100644
--- a/frontend/src/metabase/embedding/mcp/hooks/useMcpFeedback.ts
+++ b/frontend/src/metabase/embedding/mcp/hooks/useMcpFeedback.ts
@@ -62,7 +62,6 @@ export function useMcpFeedback({
const payload: McpAppsFeedback = {
feedback: {
positive,
- message_id: crypto.randomUUID(),
issue_type: values.issue_type || undefined,
freeform_feedback: values.freeform_feedback || undefined,
},
diff --git a/frontend/src/metabase/embedding/mcp/hooks/useMcpFeedback.unit.spec.ts b/frontend/src/metabase/embedding/mcp/hooks/useMcpFeedback.unit.spec.ts
index bb9f430cc73..96fc03484a6 100644
--- a/frontend/src/metabase/embedding/mcp/hooks/useMcpFeedback.unit.spec.ts
+++ b/frontend/src/metabase/embedding/mcp/hooks/useMcpFeedback.unit.spec.ts
@@ -6,18 +6,10 @@ import { renderHookWithProviders, waitFor } from "__support__/ui";
import { useMcpFeedback } from "./useMcpFeedback";
describe("useMcpFeedback", () => {
- const randomUuidSpy = jest.spyOn(crypto, "randomUUID");
- const feedbackMessageId = "11111111-1111-1111-1111-111111111111";
-
beforeEach(() => {
- randomUuidSpy.mockReturnValue(feedbackMessageId);
fetchMock.post("path:/api/embed-mcp/feedback", 200);
});
- afterEach(() => {
- randomUuidSpy.mockReset();
- });
-
it("submits the MCP feedback payload", async () => {
const { result } = renderHookWithProviders(
() =>
@@ -57,7 +49,6 @@ describe("useMcpFeedback", () => {
expect(JSON.parse(lastCall?.options?.body as string)).toEqual({
feedback: {
positive: false,
- message_id: feedbackMessageId,
issue_type: "wrong-visualization",
freeform_feedback: "Needs a different chart",
},
diff --git a/resources/migrations/064/20260706_mcp_feedback.yaml b/resources/migrations/064/20260706_mcp_feedback.yaml
new file mode 100644
index 00000000000..fd855b71633
--- /dev/null
+++ b/resources/migrations/064/20260706_mcp_feedback.yaml
@@ -0,0 +1,68 @@
+## Persist MCP Apps visualization feedback.
+##
+## MCP Apps feedback previously went only to Harbormaster; it is now stored
+## locally instead. MCP Apps have no metabot_conversation/metabot_message rows,
+## so the visualization context (prompt + query) is stored inline rather than
+## via a message FK.
+
+databaseChangeLog:
+ - changeSet:
+ id: v64.d7cqgl
+ author: tplude
+ comment: Create mcp_feedback table for MCP Apps visualization feedback
+ changes:
+ - createTable:
+ tableName: mcp_feedback
+ remarks: User feedback on MCP Apps visualizations - positive/negative w/ optional reason + comment
+ columns:
+ - column:
+ name: id
+ type: int
+ autoIncrement: true
+ constraints:
+ primaryKey: true
+ nullable: false
+ remarks: Surrogate PK
+ - column:
+ name: user_id
+ type: int
+ constraints:
+ nullable: false
+ remarks: 'The Metabase user who submitted the feedback. Unconstrained int (matches metabot_feedback precedent) so rows survive user deletion.'
+ - column:
+ name: positive
+ type: ${boolean.type}
+ constraints:
+ nullable: false
+ remarks: 'true = thumbs up, false = thumbs down'
+ - column:
+ name: issue_type
+ type: varchar(64)
+ constraints:
+ nullable: true
+ remarks: 'Optional structured issue category (e.g. "wrong-visualization")'
+ - column:
+ name: freeform_feedback
+ type: ${text.type}
+ constraints:
+ nullable: true
+ remarks: 'Optional freeform comment'
+ - column:
+ name: prompt
+ type: ${text.type}
+ constraints:
+ nullable: true
+ remarks: 'User prompt that produced the visualization, when available'
+ - column:
+ name: query
+ type: ${text.type}
+ constraints:
+ nullable: true
+ remarks: 'Encoded ad-hoc query that was being shown, when available'
+ - column:
+ name: created_at
+ type: ${timestamp_type}
+ defaultValueComputed: current_timestamp
+ constraints:
+ nullable: false
+ remarks: 'When the feedback was submitted'
diff --git a/src/metabase/agent_api/api.clj b/src/metabase/agent_api/api.clj
index f30f315760b..f7e071bb790 100644
--- a/src/metabase/agent_api/api.clj
+++ b/src/metabase/agent_api/api.clj
@@ -19,9 +19,7 @@
[metabase.events.core :as events]
[metabase.lib-be.core :as lib-be]
[metabase.lib.core :as lib]
- [metabase.metabot.config :as metabot.config]
[metabase.metabot.core :as metabot]
- [metabase.metabot.feedback :as metabot.feedback]
[metabase.metabot.tools.construct :as metabot-construct]
[metabase.metabot.tools.resources :as metabot-resources]
[metabase.metabot.tools.search :as metabot-search]
@@ -81,18 +79,6 @@
chain (collection/personal-collections-with-ui-details (conj (vec ancestors) coll))]
(str/join " / " (map :name chain)))))
-(defn submit-mcp-visualization-feedback!
- "Submit MCP Apps visualization feedback to Harbormaster.
-
- MCP Apps do not create `metabot_message` rows, so this intentionally skips
- local feedback persistence and forwards the MCP visualization context."
- [body]
- (let [metabot-id (api/check-500 (metabot.config/normalize-metabot-id metabot.config/embedded-metabot-id))
- body (assoc body :metabot_id metabot-id)]
- (metabot.config/check-metabot-enabled!)
- (metabot.feedback/submit-to-harbormaster!
- (metabot.feedback/mcp-harbormaster-payload body))))
-
;;; --------------------------------------------------- Schemas ------------------------------------------------------
;; Response schemas for the Agent API.
diff --git a/src/metabase/cmd/copy.clj b/src/metabase/cmd/copy.clj
index 56734a43496..f2aeb780e76 100644
--- a/src/metabase/cmd/copy.clj
+++ b/src/metabase/cmd/copy.clj
@@ -139,7 +139,9 @@
:model/MetabotSourceFeedback
:model/MetabotUsedTable
:model/MetabotPrompt
- :model/OsiAiContext]
+ :model/OsiAiContext
+ ;; 63+
+ :model/McpFeedback]
(when config/ee-available?
[:model/MetabotPermissions
:model/MetabotGroupLimit
diff --git a/src/metabase/mcp/callback_api.clj b/src/metabase/mcp/callback_api.clj
index cae00c0e883..21e783e5175 100644
--- a/src/metabase/mcp/callback_api.clj
+++ b/src/metabase/mcp/callback_api.clj
@@ -6,14 +6,14 @@
have to special-case non-protocol routes."
(:require
[clojure.string :as str]
- [metabase.agent-api.api :as agent-api]
[metabase.api.common :as api]
[metabase.api.macros :as api.macros]
[metabase.mcp.session :as mcp.session]
[metabase.mcp.validation :as mcp.validation]
+ [metabase.metabot.config :as metabot.config]
[metabase.util.i18n :refer [tru]]
- [metabase.util.log :as log]
- [metabase.util.malli.schema :as ms]))
+ [metabase.util.malli.schema :as ms]
+ [toucan2.core :as t2]))
(defn- mcp-session-id-from-headers
[request]
@@ -36,24 +36,15 @@
(def ^:private OptionalFeedbackText
[:maybe [:string {:max feedback-text-max-length}]])
-(defn- rethrow-api-check-exception
- [e]
- (when (:status-code (ex-data e))
- (throw e)))
-
-(defn- submit-mcp-feedback!
- [body]
- (let [submitted? (try
- (agent-api/submit-mcp-visualization-feedback! body)
- (catch clojure.lang.ExceptionInfo e
- (rethrow-api-check-exception e)
- (log/error e "Failed to submit MCP feedback to Harbormaster")
- (api/check false [502 (tru "Could not submit feedback.")]))
- (catch Exception e
- (log/error e "Failed to submit MCP feedback to Harbormaster")
- (api/check false [502 (tru "Could not submit feedback.")])))]
- (api/check-400 submitted?
- (tru "Cannot submit feedback. The license token and/or Store API URL are missing!"))))
+(defn- persist-mcp-feedback!
+ [{:keys [feedback conversation_data]}]
+ (t2/insert! :model/McpFeedback
+ {:user_id api/*current-user-id*
+ :positive (:positive feedback)
+ :issue_type (:issue_type feedback)
+ :freeform_feedback (:freeform_feedback feedback)
+ :prompt (:prompt conversation_data)
+ :query (:query conversation_data)}))
#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}
(api.macros/defendpoint :post "/drills"
@@ -71,14 +62,13 @@
(api.macros/defendpoint :post "/feedback" :- [:map
[:status [:= 204]]
[:body :nil]]
- "Proxy MCP Apps visualization feedback to Harbormaster."
+ "Persist MCP Apps visualization feedback."
[_route-params
_query-params
body :- [:map
[:feedback [:map
- [:message_id ms/NonBlankString]
[:positive :boolean]
- [:issue_type {:optional true} [:maybe :string]]
+ [:issue_type {:optional true} [:maybe [:string {:max 64}]]]
[:freeform_feedback {:optional true} OptionalFeedbackText]]]
[:conversation_data [:map
[:source [:= "mcp"]]
@@ -87,7 +77,8 @@
request]
(let [session-id (mcp-session-id-from-headers request)
_ (check-session-header! session-id api/*current-user-id*)]
- (submit-mcp-feedback! body))
+ (metabot.config/check-metabot-enabled!)
+ (persist-mcp-feedback! body))
api/generic-204-no-content)
(def ^{:arglists '([request respond raise])} routes
diff --git a/src/metabase/mcp/models/mcp_feedback.clj b/src/metabase/mcp/models/mcp_feedback.clj
new file mode 100644
index 00000000000..35df1f54f2a
--- /dev/null
+++ b/src/metabase/mcp/models/mcp_feedback.clj
@@ -0,0 +1,12 @@
+(ns metabase.mcp.models.mcp-feedback
+ "Persist MCP Apps visualization feedback. MCP Apps have no
+ metabot_conversation/metabot_message rows, so the visualization context
+ (prompt + query) is stored inline rather than via a message FK."
+ (:require
+ [methodical.core :as methodical]
+ [toucan2.core :as t2]))
+
+(methodical/defmethod t2/table-name :model/McpFeedback [_model] :mcp_feedback)
+
+(doto :model/McpFeedback
+ (derive :metabase/model))
diff --git a/src/metabase/metabot/api.clj b/src/metabase/metabot/api.clj
index 67bbd26fa11..5dd844a0ec5 100644
--- a/src/metabase/metabot/api.clj
+++ b/src/metabase/metabot/api.clj
@@ -279,13 +279,7 @@
[:issue_type {:optional true} [:maybe :string]]
[:freeform_feedback {:optional true} [:maybe :string]]]]
(metabot.config/check-metabot-enabled!)
- (let [message (metabot.feedback/persist-feedback! body)]
- (try
- (api/check-400 (metabot.feedback/submit-to-harbormaster!
- (metabot.feedback/harbormaster-payload body message))
- "Cannot submit feedback. The license token and/or Store API URL are missing!")
- (catch Exception e
- (log/error "Failed to submit feedback to Harbormaster: " (ex-message e)))))
+ (metabot.feedback/persist-feedback! body)
api/generic-204-no-content)
(api.macros/defendpoint :post "/source-feedback" :- [:map
diff --git a/src/metabase/metabot/feedback.clj b/src/metabase/metabot/feedback.clj
index 5621324e15d..1737549487c 100644
--- a/src/metabase/metabot/feedback.clj
+++ b/src/metabase/metabot/feedback.clj
@@ -1,72 +1,13 @@
(ns metabase.metabot.feedback
- "Local persistence of Metabot feedback, plus a Harbormaster submission path."
+ "Local persistence of Metabot feedback."
(:require
- [clj-http.client :as http]
- [clojure.string :as str]
[metabase.api.common :as api]
[metabase.app-db.core :as app-db]
- [metabase.config.core :as config]
- [metabase.metabot.persistence :as metabot.persistence]
[metabase.models.interface :as mi]
- [metabase.premium-features.core :as premium-features]
- [metabase.store-api.core :as store-api]
- [metabase.util.json :as json]
[toucan2.core :as t2]))
(set! *warn-on-reflection* true)
-(def ^:private harbormaster-conn-timeout-ms
- 2000)
-
-(def ^:private harbormaster-socket-timeout-ms
- 5000)
-
-(defn submit-to-harbormaster!
- "Submit metabot feedback to Harbormaster via the Store API.
- Returns the HTTP response on success, or nil if the token or Store API URL is missing."
- [feedback]
- (let [token (premium-features/premium-embedding-token)
- base-url (store-api/store-api-url)]
- (when-not (or (str/blank? token) (str/blank? base-url))
- (http/post (str base-url "/api/v2/metabot/feedback/" token)
- {:content-type :json
- :conn-timeout harbormaster-conn-timeout-ms
- :socket-timeout harbormaster-socket-timeout-ms
- :body (json/encode feedback)}))))
-
-(defn harbormaster-payload
- "Build the Harbormaster feedback payload from the request body, the resolved
- `metabot_message` row, and the submitter (defaults to the current user)."
- ([body message]
- (harbormaster-payload body message api/*current-user-id*))
- ([{:keys [metabot_id message_id positive issue_type freeform_feedback]}
- {:keys [conversation_id]}
- submitter-user-id]
- {:metabot_id metabot_id
- :feedback {:message_id message_id
- :positive positive
- :issue_type issue_type
- :freeform_feedback freeform_feedback}
- :conversation_data (metabot.persistence/conversation-detail conversation_id)
- :version config/mb-version-info
- :submission_time (str (java.time.OffsetDateTime/now))
- :submitter_user_id submitter-user-id
- :is_admin (boolean (t2/select-one-fn :is_superuser :model/User :id submitter-user-id))}))
-
-(defn mcp-harbormaster-payload
- "Build a Harbormaster feedback payload for MCP Apps visualization feedback.
- MCP Apps do not create `metabot_message` rows, so this path intentionally
- skips local `metabot_feedback` persistence and forwards the MCP context
- supplied by the client."
- ([body]
- (mcp-harbormaster-payload body api/*current-user-id*))
- ([body submitter-user-id]
- (assoc body
- :version config/mb-version-info
- :submission_time (str (java.time.OffsetDateTime/now))
- :submitter_user_id submitter-user-id
- :is_admin (boolean (t2/select-one-fn :is_superuser :model/User :id submitter-user-id)))))
-
(defn- resolve-rated-message
"Return the `metabot_message` row (`:id` + `:conversation_id`) identified by
`external-id`, plus the enclosing `:model/MetabotConversation` as `:conversation`.
diff --git a/src/metabase/models/resolution.clj b/src/metabase/models/resolution.clj
index 983756040c3..6e061488335 100644
--- a/src/metabase/models/resolution.clj
+++ b/src/metabase/models/resolution.clj
@@ -56,6 +56,7 @@
:model/HTTPAction metabase.actions.models
:model/ImplicitAction metabase.actions.models
:model/LoginHistory metabase.login-history.models.login-history
+ :model/McpFeedback metabase.mcp.models.mcp-feedback
:model/McpQueryHandle metabase.mcp.models.mcp-query-handle
:model/McpSessionLog metabase.mcp.models.mcp-session-log
:model/McpToolCallLog metabase.mcp.models.mcp-tool-call-log
diff --git a/test/metabase/mcp/callback_api_test.clj b/test/metabase/mcp/callback_api_test.clj
index 365cb2fb69c..e7af42923ec 100644
--- a/test/metabase/mcp/callback_api_test.clj
+++ b/test/metabase/mcp/callback_api_test.clj
@@ -1,15 +1,12 @@
(ns metabase.mcp.callback-api-test
(:require
- [clj-http.client :as http]
[clojure.test :refer :all]
[metabase.mcp.session :as mcp.session]
- [metabase.metabot.config :as metabot.config]
- [metabase.premium-features.core :as premium-features]
[metabase.test :as mt]
[metabase.test.data.users :as test.users]
[metabase.test.fixtures :as fixtures]
[metabase.test.http-client :as client]
- [metabase.util.json :as json]))
+ [toucan2.core :as t2]))
(set! *warn-on-reflection* true)
@@ -77,98 +74,74 @@
(client/client-full-response :post 401 "embed-mcp/drills"
{:encodedQuery "ZW5jb2RlZA=="})))))
-(deftest feedback-post-submits-mcp-visualization-context-test
- (testing "MCP feedback accepts visualization context without a Metabot message row"
- (let [store-url "http://hm.example"
- fake-token "test-fake-token-for-feedback"
- session-id (mcp.session/create! (mt/user->id :rasta))
- captured (atom nil)
- body {:feedback {:message_id (str (random-uuid))
- :positive false
+(deftest feedback-post-persists-mcp-visualization-feedback-test
+ (testing "MCP feedback is persisted to mcp_feedback with the visualization context inline"
+ (mt/with-model-cleanup [:model/McpFeedback]
+ (let [session-id (mcp.session/create! (mt/user->id :rasta))
+ body {:feedback {:positive false
:issue_type "wrong-visualization"
:freeform_feedback "wrong chart"}
:conversation_data {:source "mcp"
:prompt "show orders"
- :query "encoded-query"}}
- expected-url (str store-url "/api/v2/metabot/feedback/" fake-token)]
- (mt/with-temporary-setting-values [store-api-url store-url]
- (mt/with-dynamic-fn-redefs
- [premium-features/premium-embedding-token (constantly fake-token)
- http/post (fn [url opts]
- (reset! captured {:url url
- :opts opts
- :body (json/decode+kw (:body opts))}))]
- (post-mcp-feedback :rasta 204 body session-id)
- (is (=? {:url expected-url
- :opts {:conn-timeout pos-int?
- :socket-timeout pos-int?}
- :body {:metabot_id (metabot.config/normalize-metabot-id
- metabot.config/embedded-metabot-id)
- :feedback (:feedback body)
- :conversation_data (:conversation_data body)
- :version some?
- :submission_time some?
- :is_admin false}}
- @captured)))))))
+ :query "encoded-query"}}]
+ (post-mcp-feedback :rasta 204 body session-id)
+ (is (=? {:user_id (mt/user->id :rasta)
+ :positive false
+ :issue_type "wrong-visualization"
+ :freeform_feedback "wrong chart"
+ :prompt "show orders"
+ :query "encoded-query"
+ :created_at some?}
+ (t2/select-one :model/McpFeedback :user_id (mt/user->id :rasta)
+ {:order-by [[:id :desc]]})))))))
-(deftest feedback-post-returns-400-when-harbormaster-cannot-be-reached-test
- (testing "MCP feedback fails when there is no Harbormaster fallback"
- (let [store-url "http://hm.example"
- session-id (mcp.session/create! (mt/user->id :rasta))
- body {:feedback {:message_id (str (random-uuid))
- :positive true}
- :conversation_data {:source "mcp"
- :prompt "show orders"
- :query "encoded-query"}}
- posted? (atom false)]
- (mt/with-temporary-setting-values [store-api-url store-url]
- (mt/with-dynamic-fn-redefs
- [premium-features/premium-embedding-token (constantly nil)
- http/post (fn [& _] (reset! posted? true))]
- (is (=? {:status 400}
- (post-mcp-feedback :rasta 400 body session-id)))
- (is (false? @posted?)
- "Harbormaster must not be contacted when the premium token is missing"))))))
+(deftest feedback-post-persists-minimal-payload-test
+ (testing "MCP feedback with only a rating persists a row with the optional fields nil"
+ (mt/with-model-cleanup [:model/McpFeedback]
+ (let [session-id (mcp.session/create! (mt/user->id :rasta))
+ body {:feedback {:positive true}
+ :conversation_data {:source "mcp"}}]
+ (post-mcp-feedback :rasta 204 body session-id)
+ (is (=? {:user_id (mt/user->id :rasta)
+ :positive true
+ :issue_type nil
+ :freeform_feedback nil
+ :prompt nil
+ :query nil}
+ (t2/select-one :model/McpFeedback :user_id (mt/user->id :rasta)
+ {:order-by [[:id :desc]]})))))))
-(deftest feedback-post-returns-502-when-harbormaster-submission-fails-test
- (testing "MCP feedback surfaces Harbormaster submission failures without pretending the feedback was saved"
- (let [store-url "http://hm.example"
- session-id (mcp.session/create! (mt/user->id :rasta))
- body {:feedback {:message_id (str (random-uuid))
- :positive true}
- :conversation_data {:source "mcp"
- :prompt "show orders"
- :query "encoded-query"}}]
- (mt/with-temporary-setting-values [store-api-url store-url]
- (mt/with-dynamic-fn-redefs
- [premium-features/premium-embedding-token (constantly "test-fake-token-for-feedback")
- http/post (fn [& _] (throw (ex-info "Harbormaster unavailable" {})))]
- (is (=? {:status 502}
- (post-mcp-feedback :rasta 502 body session-id))))))))
+(deftest feedback-post-requires-metabot-enabled-test
+ (testing "MCP feedback returns 403 and persists nothing when no metabot instance is enabled"
+ (mt/with-model-cleanup [:model/McpFeedback]
+ (mt/with-temporary-setting-values [metabot-enabled? false
+ embedded-metabot-enabled? false]
+ (let [session-id (mcp.session/create! (mt/user->id :rasta))
+ body {:feedback {:positive true}
+ :conversation_data {:source "mcp"}}]
+ (is (=? {:status 403}
+ (post-mcp-feedback :rasta 403 body session-id)))
+ (is (zero? (t2/count :model/McpFeedback :user_id (mt/user->id :rasta)))))))))
(deftest feedback-post-rejects-oversized-free-text-test
- (testing "MCP feedback bounds user-controlled free text before proxying to Harbormaster"
- (let [session-id (mcp.session/create! (mt/user->id :rasta))
- too-large (apply str (repeat 10001 "x"))
- base-body {:feedback {:message_id (str (random-uuid))
- :positive true}
- :conversation_data {:source "mcp"}}
- posted? (atom false)]
- (mt/with-dynamic-fn-redefs
- [http/post (fn [& _] (reset! posted? true))]
+ (testing "MCP feedback bounds user-controlled free text before persisting"
+ (mt/with-model-cleanup [:model/McpFeedback]
+ (let [session-id (mcp.session/create! (mt/user->id :rasta))
+ too-large (apply str (repeat 10001 "x"))
+ base-body {:feedback {:positive true}
+ :conversation_data {:source "mcp"}}]
(doseq [[path label] [[[:feedback :freeform_feedback] "freeform feedback"]
[[:conversation_data :prompt] "prompt"]
[[:conversation_data :query] "query"]]]
(testing label
(is (=? {:status 400}
- (post-mcp-feedback :rasta 400 (assoc-in base-body path too-large) session-id))))))
- (is (false? @posted?)
- "Harbormaster must not be contacted for oversized feedback payloads"))))
+ (post-mcp-feedback :rasta 400 (assoc-in base-body path too-large) session-id)))))
+ (is (zero? (t2/count :model/McpFeedback :user_id (mt/user->id :rasta)))
+ "Oversized feedback payloads must not be persisted")))))
(deftest feedback-post-validates-session-header-test
(testing "MCP feedback validates the MCP session header"
- (let [body {:feedback {:message_id (str (random-uuid))
- :positive true}
+ (let [body {:feedback {:positive true}
:conversation_data {:source "mcp"
:prompt "show orders"
:query "encoded-query"}}]