From c67b635804ea06c9c0d49c85ae8ef729e6f08515 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 4 Aug 2026 02:30:32 +0000 Subject: [PATCH 1/2] fix(mcp): treat integration_save create gaps as caller errors Missing required fields when creating an integration (e.g. accessTokenSecretName) are agent-fixable; throw McpCallerError so they stay off Sentry (KODY-CLOUDFLARE-3N). --- .../integration-save.node.test.ts | 22 ++++++++++++++++++- .../integrations/integration-save.ts | 5 ++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/worker/src/mcp/capabilities/integrations/integration-save.node.test.ts b/packages/worker/src/mcp/capabilities/integrations/integration-save.node.test.ts index bc8250337f..f274f10faf 100644 --- a/packages/worker/src/mcp/capabilities/integrations/integration-save.node.test.ts +++ b/packages/worker/src/mcp/capabilities/integrations/integration-save.node.test.ts @@ -1,5 +1,6 @@ import { DatabaseSync } from 'node:sqlite' import { expect, test } from 'vitest' +import { McpCallerError } from '#mcp/caller-error.ts' import { createMcpCallerContext } from '#mcp/context.ts' import { createD1FromSqlite } from '#worker/test-support/create-d1-from-sqlite.ts' import { applyAllMigrations as applyRepositoryMigrations } from '#worker/test-support/apply-all-migrations.ts' @@ -164,7 +165,26 @@ test('mergeIntegrationConfig and integration_save create a new app + connection }, { env: createEnv().env, callerContext: caller('user-123') }, ), - ).rejects.toThrow(/missing or invalid required fields/i) + ).rejects.toThrow(McpCallerError) + + await expect( + integrationSaveCapability.handler( + { + name: 'slack', + tokenUrl: 'https://slack.com/api/oauth.v2.access', + flow: 'confidential', + clientId: 'slack-client-id', + // accessTokenSecretName omitted — create requires it + }, + { env: createEnv().env, callerContext: caller('user-123') }, + ), + ).rejects.toSatisfy( + (error: unknown) => + error instanceof McpCallerError && + /Cannot create integration "slack".*accessTokenSecretName/i.test( + error.message, + ), + ) }) test('integration_save reuses an existing app when credentials match and preserves unspecified fields on partial update', async () => { diff --git a/packages/worker/src/mcp/capabilities/integrations/integration-save.ts b/packages/worker/src/mcp/capabilities/integrations/integration-save.ts index 5d6e115ec7..afcb2d763f 100644 --- a/packages/worker/src/mcp/capabilities/integrations/integration-save.ts +++ b/packages/worker/src/mcp/capabilities/integrations/integration-save.ts @@ -3,6 +3,7 @@ import { defineDomainCapability } from '#mcp/capabilities/define-domain-capabili import { capabilityDomainNames } from '#mcp/capabilities/domain-metadata.ts' import { requireMcpUser } from '#mcp/capabilities/meta/require-user.ts' import { type CapabilityContext } from '#mcp/capabilities/types.ts' +import { McpCallerError } from '#mcp/caller-error.ts' import { getIntegration, upsertIntegration, @@ -90,7 +91,9 @@ function createNewIntegrationConfig( return `${field}: ${issue.message}` }) .join(', ') - throw new Error( + // Create-time field gaps are caller-fixable (agents omit required + // secrets names); keep them off Sentry via McpCallerError. + throw new McpCallerError( `Cannot create integration "${args.name}": missing or invalid required fields — ${details}`, ) } From 783c547928d4a4ff7dbc0c5e516b46d7dd335a2b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 4 Aug 2026 02:47:30 +0000 Subject: [PATCH 2/2] test(mcp): keep integration_save create-error message assertions Address CodeRabbit feedback so create-field gap tests still pin the caller-facing message alongside McpCallerError. --- .../capabilities/integrations/integration-save.node.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/worker/src/mcp/capabilities/integrations/integration-save.node.test.ts b/packages/worker/src/mcp/capabilities/integrations/integration-save.node.test.ts index f274f10faf..9c8aa156ea 100644 --- a/packages/worker/src/mcp/capabilities/integrations/integration-save.node.test.ts +++ b/packages/worker/src/mcp/capabilities/integrations/integration-save.node.test.ts @@ -165,7 +165,11 @@ test('mergeIntegrationConfig and integration_save create a new app + connection }, { env: createEnv().env, callerContext: caller('user-123') }, ), - ).rejects.toThrow(McpCallerError) + ).rejects.toSatisfy( + (error: unknown) => + error instanceof McpCallerError && + /missing or invalid required fields/i.test(error.message), + ) await expect( integrationSaveCapability.handler(