Skip to content
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

feat(core): Add wrapMcpServerWithSentry to instrument MCP servers from @modelcontextprotocol/sdk #16032

Merged
merged 1 commit into from
Apr 14, 2025

Conversation

lforst
Copy link
Member

@lforst lforst commented Apr 11, 2025

Exposes an API from the core package to wrap MCP servers to have parameterized spans (actually transactions) for the common handlers that MCP servers have.

This is super basic instrumentation for now that has shortcomings:

  • no auto instrumentation yet (IITM has a bug outlined here Impossible to instrument @modelcontextprotocol/sdk nodejs/import-in-the-middle#187)
  • The server is a bit weird. LLMs connect to the server on an SSE endpoint (request number 1) and then they send POST requests to a different endpoint on the server. The problem is that the handlers run in the context of the SSE endpoint. This means that the traces aren't really connected yet because the http.client POST requests are not attached to the resource/prompt/tool handler spans in any way. I'll try to tackle this in a follow-up by patching underlying APIs and tring to connect things based on JSONRPC message.

Ref #16052

Copy link
Contributor

github-actions bot commented Apr 11, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.28 KB - -
@sentry/browser - with treeshaking flags 23.12 KB - -
@sentry/browser (incl. Tracing) 36.99 KB - -
@sentry/browser (incl. Tracing, Replay) 74.17 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.55 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 78.83 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 90.65 KB - -
@sentry/browser (incl. Feedback) 39.68 KB - -
@sentry/browser (incl. sendFeedback) 27.9 KB - -
@sentry/browser (incl. FeedbackAsync) 32.67 KB - -
@sentry/react 25.09 KB - -
@sentry/react (incl. Tracing) 38.91 KB - -
@sentry/vue 27.51 KB - -
@sentry/vue (incl. Tracing) 38.71 KB - -
@sentry/svelte 23.32 KB - -
CDN Bundle 24.51 KB - -
CDN Bundle (incl. Tracing) 36.98 KB - -
CDN Bundle (incl. Tracing, Replay) 72.03 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 77.18 KB - -
CDN Bundle - uncompressed 71.47 KB - -
CDN Bundle (incl. Tracing) - uncompressed 109.34 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 220.63 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 233.16 KB - -
@sentry/nextjs (client) 40.53 KB - -
@sentry/sveltekit (client) 37.44 KB - -
@sentry/node 143.23 KB - -
@sentry/node - without tracing 96.47 KB - -
@sentry/aws-serverless 120.77 KB +0.01% +1 B 🔺

View base workflow run

@lforst lforst force-pushed the lforst-mcp-server-instrumentation branch from fb6dcf4 to dccd668 Compare April 14, 2025 10:34
@lforst lforst force-pushed the lforst-mcp-server-instrumentation branch from 61556c4 to e0e9a2b Compare April 14, 2025 10:51
@lforst lforst changed the title feat(node): Add mcp server instrumentation feat(core): Add wrapMcpServerWithSentry to instrument MCP servers from @modelcontextprotocol/sdk Apr 14, 2025
@lforst lforst marked this pull request as ready for review April 14, 2025 10:51
@lforst lforst requested review from mydea, Lms24 and matejminar April 14, 2025 10:56
@lforst lforst self-assigned this Apr 14, 2025
@lforst lforst merged commit 6eb7366 into develop Apr 14, 2025
156 checks passed
@lforst lforst deleted the lforst-mcp-server-instrumentation branch April 14, 2025 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants