Skip to content

feat(core): MCP server instrumentation without breaking Miniflare #16817

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

Open
wants to merge 55 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
dff2080
feat(mcp-server): Enhance transport handling and request instrumentation
betegon Jun 27, 2025
cb28ccc
test transport layer
betegon Jul 1, 2025
1480b78
refactor(mcp-server.test): Simplify test setup by using beforeEach fo…
betegon Jul 1, 2025
5a97d69
test(mcp-server): Add tests for span creation and semantic convention…
betegon Jul 1, 2025
03077f8
test(mcp-server): Update tests to control transport connection in ind…
betegon Jul 2, 2025
cac9bd0
test(mcp-server): Refine span attributes and transport details
betegon Jul 2, 2025
37ef9a9
test(mcp-server): Replace direct tracing module calls with spies for …
betegon Jul 2, 2025
ac015ce
feat(mcp-server): Add TypeScript type definitions for MCP server inst…
betegon Jul 2, 2025
c2f3e82
feat(mcp-server): Introduce MCP attributes and methods for enhanced t…
betegon Jul 2, 2025
094574f
test(mcp-server): Add tests for span creation with various notificati…
betegon Jul 2, 2025
9972b09
test(mcp-server): Update test to use spy for startSpan
betegon Jul 2, 2025
ef52da5
refactor(mcp-server): improve span handling and attribute extraction
betegon Jul 2, 2025
aee709b
simplify attributes
betegon Jul 2, 2025
edc4e3c
refactor(mcp-server): improve types
betegon Jul 2, 2025
62ca0f3
refactor(mcp-server): refactor span handling and utility functions fo…
betegon Jul 2, 2025
08c39f1
remove unused import and comment legacy support
betegon Jul 3, 2025
fe2c865
refactor(mcp-server): improve notification span handling and set attr…
betegon Jul 3, 2025
ec3cb6f
refactor(mcp-server): span and attribute creation
betegon Jul 3, 2025
e193118
refactor(mcp-server): method configuration and argument extraction fo…
betegon Jul 3, 2025
347422c
refactor(mcp-server): improve transport type handling and add tests f…
betegon Jul 3, 2025
02cb799
Merge branch 'develop' into bete/mcp-server-semantic-convention
betegon Jul 3, 2025
9776402
fix lint
betegon Jul 3, 2025
d4c74a9
refactor(mcp-server): use fill for method wrapping for transport hand…
betegon Jul 4, 2025
25297f6
Merge branch 'develop' into bete/mcp-server-semantic-convention-fill
betegon Jul 4, 2025
7b5fd86
move files to intregations directory
betegon Jul 8, 2025
97990c6
use parseStringToURLObject for url handling and update test
betegon Jul 8, 2025
1efda74
(draft) fix span duration
betegon Jul 8, 2025
aa0a9fd
Add tool call results and MCP spans duration to cover their children …
betegon Jul 9, 2025
4973a60
Implement MCP server attribute extraction and correlation system. New…
betegon Jul 10, 2025
de1b87f
Refactor MCP server integration. improve attribute extraction and spa…
betegon Jul 10, 2025
7624a3e
fix lint
betegon Jul 10, 2025
d94a4d0
prettier
betegon Jul 10, 2025
6c67f51
Implement PII filtering for MCP server spans. Introduce a new utility…
betegon Jul 10, 2025
b305410
Merge branch 'develop' into bete/mcp-server-semantic-convention-fill
betegon Jul 11, 2025
24bff02
add debug logger
betegon Jul 11, 2025
670e6b1
feat(mcp-server): tool result handling and error capturing
betegon Jul 11, 2025
f73fdc6
add tests
betegon Jul 11, 2025
ff4823e
fix lint
betegon Jul 11, 2025
b62ba22
fix lint
betegon Jul 11, 2025
1f48e0d
Update MCP e2e tests to match new semantic conventions
betegon Jul 14, 2025
cdb920b
Merge branch 'develop' into bete/mcp-server-semantic-convention-fill
betegon Jul 14, 2025
4f7042a
fix (mcp-server): pass original context to createErrorCapturingHandler
betegon Jul 15, 2025
790f2b3
Merge branch 'develop' into bete/mcp-server-semantic-convention-fill
betegon Jul 15, 2025
8524991
refactor types
betegon Jul 16, 2025
477f1f2
Set span status to error when capturing errors and added MCP method n…
betegon Jul 17, 2025
0ea5876
fix: capture to only JSON-RPC server-side errors
betegon Jul 17, 2025
2d435ca
Merge branch 'develop' into bete/mcp-server-semantic-convention-fill
betegon Jul 17, 2025
284e763
update logger
betegon Jul 17, 2025
ec5d736
fix lint
betegon Jul 17, 2025
d5fcdc3
fix: create a map for each transport to identify different sessions t…
betegon Jul 17, 2025
612fc8c
lint fix
betegon Jul 18, 2025
1cd1048
ref: improve jsdoc and refactor attributes to be in a single file
betegon Jul 18, 2025
683a895
restore handlerArgs argument
betegon Jul 18, 2025
61587a9
use reduce to improve performance
betegon Jul 18, 2025
64bfeda
remove legacy test
betegon Jul 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('Should record transactions for mcp handlers', async ({ baseURL }) => {
return transactionEvent.transaction === 'POST /messages';
});
const toolTransactionPromise = waitForTransaction('node-express', transactionEvent => {
return transactionEvent.transaction === 'mcp-server/tool:echo';
return transactionEvent.transaction === 'tools/call echo';
});

const toolResult = await client.callTool({
Expand All @@ -39,19 +39,22 @@ test('Should record transactions for mcp handlers', async ({ baseURL }) => {

const postTransaction = await postTransactionPromise;
expect(postTransaction).toBeDefined();
expect(postTransaction.contexts?.trace?.op).toEqual('http.server');

const toolTransaction = await toolTransactionPromise;
expect(toolTransaction).toBeDefined();
expect(toolTransaction.contexts?.trace?.op).toEqual('mcp.server');
expect(toolTransaction.contexts?.trace?.data?.['mcp.method.name']).toEqual('tools/call');
// TODO: When https://github.com/modelcontextprotocol/typescript-sdk/pull/358 is released check for trace id equality between the post transaction and the handler transaction

// TODO: When https://github.com/modelcontextprotocol/typescript-sdk/pull/358 is released check for trace id equality between the post transaction and the handler transaction
});

await test.step('resource handler', async () => {
const postTransactionPromise = waitForTransaction('node-express', transactionEvent => {
return transactionEvent.transaction === 'POST /messages';
});
const resourceTransactionPromise = waitForTransaction('node-express', transactionEvent => {
return transactionEvent.transaction === 'mcp-server/resource:echo';
return transactionEvent.transaction === 'resources/read echo://foobar';
});

const resourceResult = await client.readResource({
Expand All @@ -64,10 +67,12 @@ test('Should record transactions for mcp handlers', async ({ baseURL }) => {

const postTransaction = await postTransactionPromise;
expect(postTransaction).toBeDefined();
expect(postTransaction.contexts?.trace?.op).toEqual('http.server');

const resourceTransaction = await resourceTransactionPromise;
expect(resourceTransaction).toBeDefined();

expect(resourceTransaction.contexts?.trace?.op).toEqual('mcp.server');
expect(resourceTransaction.contexts?.trace?.data?.['mcp.method.name']).toEqual('resources/read');
// TODO: When https://github.com/modelcontextprotocol/typescript-sdk/pull/358 is released check for trace id equality between the post transaction and the handler transaction
});

Expand All @@ -76,7 +81,7 @@ test('Should record transactions for mcp handlers', async ({ baseURL }) => {
return transactionEvent.transaction === 'POST /messages';
});
const promptTransactionPromise = waitForTransaction('node-express', transactionEvent => {
return transactionEvent.transaction === 'mcp-server/prompt:echo';
return transactionEvent.transaction === 'prompts/get echo';
});

const promptResult = await client.getPrompt({
Expand All @@ -100,10 +105,12 @@ test('Should record transactions for mcp handlers', async ({ baseURL }) => {

const postTransaction = await postTransactionPromise;
expect(postTransaction).toBeDefined();
expect(postTransaction.contexts?.trace?.op).toEqual('http.server');

const promptTransaction = await promptTransactionPromise;
expect(promptTransaction).toBeDefined();

expect(promptTransaction.contexts?.trace?.op).toEqual('mcp.server');
expect(promptTransaction.contexts?.trace?.data?.['mcp.method.name']).toEqual('prompts/get');
// TODO: When https://github.com/modelcontextprotocol/typescript-sdk/pull/358 is released check for trace id equality between the post transaction and the handler transaction
});
});
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export { featureFlagsIntegration, type FeatureFlagsIntegration } from './integra
export { profiler } from './profiling';
export { instrumentFetchRequest } from './fetch';
export { trpcMiddleware } from './trpc';
export { wrapMcpServerWithSentry } from './mcp-server';
export { wrapMcpServerWithSentry } from './integrations/mcp-server';
export { captureFeedback } from './feedback';
export type { ReportDialogOptions } from './report-dialog';
export { _INTERNAL_captureLog, _INTERNAL_flushLogsBuffer, _INTERNAL_captureSerializedLog } from './logs/exports';
Expand Down
Loading
Loading