Repository navigation
fix(mcp): keep repo regex/session and MCP-server tool noise out of Sentry #1333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kody-bot
merged 2 commits into
main
from
cursor/sentry-triage-batch-kody-cloudflare-kody-cloudflare-49-5bf9
Aug 8, 2026
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
packages/worker/src/mcp/capabilities/mcp-server/mcp-server-caller-error.node.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import { expect, test, vi } from 'vitest' | ||
| import { McpCallerError } from '#mcp/caller-error.ts' | ||
| import { createMcpCallerContext } from '#mcp/context.ts' | ||
| import { type McpServerSnapshot } from '#worker/mcp-client/types.ts' | ||
|
|
||
| const mocks = vi.hoisted(() => ({ | ||
| callTool: vi.fn(), | ||
| getMcpServerStatus: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock('#worker/mcp-client/hub-client.ts', () => ({ | ||
| createMcpClientHubClient: () => ({ | ||
| callTool: (...args: Array<unknown>) => mocks.callTool(...args), | ||
| }), | ||
| })) | ||
|
|
||
| vi.mock('#worker/mcp-client/status.ts', async () => { | ||
| const actual = await vi.importActual< | ||
| typeof import('#worker/mcp-client/status.ts') | ||
| >('#worker/mcp-client/status.ts') | ||
| return { | ||
| ...actual, | ||
| getMcpServerStatus: (...args: Array<unknown>) => | ||
| mocks.getMcpServerStatus(...args), | ||
| } | ||
| }) | ||
|
|
||
| const { synthesizeMcpServerToolDomain } = await import('./index.ts') | ||
|
|
||
| const ref = { serverId: 'server-1', name: 'supermemory' } | ||
|
|
||
| function createSnapshot(): McpServerSnapshot { | ||
| return { | ||
| serverId: 'server-1', | ||
| name: 'supermemory', | ||
| url: 'https://mcp.example.com/mcp', | ||
| state: 'ready', | ||
| authUrl: null, | ||
| error: null, | ||
| instructions: null, | ||
| tools: [ | ||
| { | ||
| name: 'listMemories', | ||
| description: 'List memories.', | ||
| inputSchema: { type: 'object', properties: {} }, | ||
| }, | ||
| ], | ||
| } | ||
| } | ||
|
|
||
| function createContext() { | ||
| return { | ||
| env: {} as Env, | ||
| callerContext: createMcpCallerContext({ | ||
| baseUrl: 'https://example.com', | ||
| user: { | ||
| userId: 'user-alice', | ||
| email: 'alice@example.com', | ||
| displayName: 'Alice', | ||
| }, | ||
| }), | ||
| } | ||
| } | ||
|
|
||
| test('mcp-server tool failures throw McpCallerError for downstream ProtocolError', async () => { | ||
| mocks.callTool.mockRejectedValueOnce( | ||
| new Error( | ||
| "ProtocolError: Structured content does not match the tool's output schema", | ||
| ), | ||
| ) | ||
| mocks.getMcpServerStatus.mockResolvedValueOnce({ | ||
| state: 'ready', | ||
| serverId: 'server-1', | ||
| name: 'supermemory', | ||
| ready: true, | ||
| toolCount: 1, | ||
| message: 'connected', | ||
| error: null, | ||
| }) | ||
|
|
||
| const synthesized = synthesizeMcpServerToolDomain({ | ||
| ref, | ||
| snapshot: createSnapshot(), | ||
| }) | ||
| const capability = synthesized?.domain.capabilities[0] | ||
| expect(capability).toBeDefined() | ||
|
|
||
| const error = await capability!.handler({}, createContext()).then( | ||
| () => null, | ||
| (thrown: unknown) => thrown, | ||
| ) | ||
|
|
||
| expect(error).toBeInstanceOf(McpCallerError) | ||
| expect((error as Error).message).toContain( | ||
| 'MCP server capability "supermemory:listMemories" failed:', | ||
| ) | ||
| expect((error as Error).message).toContain('Structured content') | ||
| }) | ||
|
|
||
| test('mcp-server unavailable servers throw McpCallerError', async () => { | ||
| mocks.callTool.mockRejectedValueOnce(new Error('fetch failed')) | ||
| mocks.getMcpServerStatus.mockResolvedValueOnce({ | ||
| state: 'disconnected', | ||
| serverId: 'server-1', | ||
| name: 'supermemory', | ||
| ready: false, | ||
| toolCount: 0, | ||
| message: 'The MCP server "supermemory" is not connected.', | ||
| error: null, | ||
| }) | ||
|
|
||
| const synthesized = synthesizeMcpServerToolDomain({ | ||
| ref, | ||
| snapshot: createSnapshot(), | ||
| }) | ||
| const capability = synthesized?.domain.capabilities[0] | ||
| expect(capability).toBeDefined() | ||
|
|
||
| const error = await capability!.handler({}, createContext()).then( | ||
| () => null, | ||
| (thrown: unknown) => thrown, | ||
| ) | ||
|
|
||
| expect(error).toBeInstanceOf(McpCallerError) | ||
| expect((error as Error).message).toMatch(/not connected/) | ||
| }) |
97 changes: 97 additions & 0 deletions
97
packages/worker/src/mcp/capabilities/repo/repo-search.node.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { expect, test, vi } from 'vitest' | ||
| import { McpCallerError } from '#mcp/caller-error.ts' | ||
| import { createMcpCallerContext } from '#mcp/context.ts' | ||
| import { buildRepoSearchInvalidRegexCallerMessage } from '#worker/repo/repo-session-caller-error.ts' | ||
|
|
||
| const mocks = vi.hoisted(() => ({ | ||
| repoSessionRpc: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock('#worker/repo/repo-session-do.ts', () => ({ | ||
| repoSessionRpc: (...args: Array<unknown>) => mocks.repoSessionRpc(...args), | ||
| })) | ||
|
|
||
| const { repoSearchCapability } = await import('./repo-search.ts') | ||
|
|
||
| function createContext() { | ||
| return { | ||
| env: {} as Env, | ||
| callerContext: createMcpCallerContext({ | ||
| baseUrl: 'https://example.com', | ||
| user: { | ||
| userId: 'user-alice', | ||
| email: 'alice@example.com', | ||
| displayName: 'Alice', | ||
| }, | ||
| }), | ||
| } | ||
| } | ||
|
|
||
| test('repo_search maps invalid regex DO errors to McpCallerError', async () => { | ||
| const compileMessage = | ||
| 'Invalid regular expression: /(?s).|^$/gi: Invalid group' | ||
| const search = vi | ||
| .fn() | ||
| .mockRejectedValue( | ||
| new Error(buildRepoSearchInvalidRegexCallerMessage(compileMessage)), | ||
| ) | ||
| mocks.repoSessionRpc.mockReturnValue({ search }) | ||
|
|
||
| const error = await repoSearchCapability | ||
| .handler( | ||
| { | ||
| session_id: 'session-1', | ||
| pattern: '(?s).|^$', | ||
| mode: 'regex', | ||
| }, | ||
| createContext(), | ||
| ) | ||
| .then( | ||
| () => null, | ||
| (thrown: unknown) => thrown, | ||
| ) | ||
|
|
||
| expect(error).toBeInstanceOf(McpCallerError) | ||
| expect((error as Error).message).toContain('invalid regex') | ||
| expect((error as Error).message).toContain('JavaScript RegExp') | ||
| }) | ||
|
|
||
| test('repo_search maps nested invalid regex causes to McpCallerError', async () => { | ||
| const search = vi.fn().mockRejectedValue( | ||
| new Error('Repo session search failed', { | ||
| cause: new Error( | ||
| buildRepoSearchInvalidRegexCallerMessage( | ||
| 'Invalid regular expression: /(?i)foo/: Invalid group', | ||
| ), | ||
| ), | ||
| }), | ||
| ) | ||
| mocks.repoSessionRpc.mockReturnValue({ search }) | ||
|
|
||
| await expect( | ||
| repoSearchCapability.handler( | ||
| { | ||
| session_id: 'session-1', | ||
| pattern: '(?i)foo', | ||
| mode: 'regex', | ||
| }, | ||
| createContext(), | ||
| ), | ||
| ).rejects.toBeInstanceOf(McpCallerError) | ||
| }) | ||
|
|
||
| test('repo_search rethrows non-regex failures unchanged', async () => { | ||
| const boom = new Error('Durable Object storage unavailable') | ||
| const search = vi.fn().mockRejectedValue(boom) | ||
| mocks.repoSessionRpc.mockReturnValue({ search }) | ||
|
|
||
| await expect( | ||
| repoSearchCapability.handler( | ||
| { | ||
| session_id: 'session-1', | ||
| pattern: 'hello', | ||
| }, | ||
| createContext(), | ||
| ), | ||
| ).rejects.toBe(boom) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.