Skip to content

feat: update MCP SDK and monitoring - #227

Merged
dodeja merged 10 commits into
mainfrom
codex/mcp-sdk-sentry-audit
May 29, 2026
Merged

feat: update MCP SDK and monitoring#227
dodeja merged 10 commits into
mainfrom
codex/mcp-sdk-sentry-audit

Conversation

@dodeja

@dodejadodeja commented May 28, 2026

Copy link
Copy Markdown
Member

Summary

  • update the MCP package to @modelcontextprotocol/sdk@^1.29.0 and @terminal49/sdk@0.2.0
  • add optional Sentry MCP monitoring with env-based setup, input/output capture flags, and manual error capture for hosted errors
  • add optional intent input telemetry across all MCP tools for Sentry analysis
  • sync the local TypeScript SDK to the 0.2.0 structure and update MCP compatibility fixes
  • add /mcp Vercel routing/CORS support and refresh MCP docs/env examples
  • apply npm audit fixes, including a narrow Mintlify preview override to resolve the nested qs advisory

Verification

  • npm audit at repo root: 0 vulnerabilities
  • npm audit in packages/mcp: 0 vulnerabilities
  • npm audit in sdks/typescript-sdk: 0 vulnerabilities
  • npm run type-check --workspace @terminal49/mcp
  • npm run lint --workspace @terminal49/mcp
  • npm test --workspace @terminal49/mcp -- --run (41 passed)
  • npm run build --workspace @terminal49/mcp
  • npm run type-check --workspace @terminal49/sdk
  • npm run lint --workspace @terminal49/sdk
  • npm test --workspace @terminal49/sdk -- --run (50 passed, 2 skipped)
  • npm run build --workspace @terminal49/sdk
  • npm run build
  • cd docs && npx mintlify broken-links
  • MCP Inspector with real token: get_supported_shipping_lines for MAEU succeeded with intent argument
  • Sentry smoke test: local captureException flushed successfully

Greptile Summary

This PR upgrades the MCP SDK to @modelcontextprotocol/sdk@^1.29.0, adds optional Sentry MCP monitoring (@sentry/node@^10.55.0) with env-based init and PII-off defaults, introduces an optional intent telemetry field across all tool input schemas, adds a /mcp Vercel route with matching CORS headers, and applies a batch of npm audit overrides.

  • Sentry integration: instrument.ts bootstraps Sentry as the first import in both the STDIO and HTTP entry points; wrapMcpServerWithSentry wraps the server for span/trace capture; captureMcpException + flushMcpEvents handle tool-level error reporting.
  • intent telemetry: An optional 200-char intent string is appended to every tool's input schema for Sentry analysis; it is explicitly not forwarded to the Terminal49 API.
  • Flush strategy: The finally block in api/mcp.ts flushes Sentry unconditionally when initialized (fixing the previously flagged event-loss for tool errors); wrapToolWithContract also calls flushMcpEvents() in its catch, which is necessary for the STDIO transport but adds up to 2 seconds of blocking latency before the error response is delivered in the HTTP/serverless path.

Confidence Score: 4/5

Safe to merge with one latency concern in the error path worth addressing before or shortly after shipping.

Every tool error now triggers await flushMcpEvents() inside wrapToolWithContract before the error object is returned to the MCP transport layer. Because the transport writes the response only after the handler returns, this adds up to 2 seconds of wall-clock delay to every tool error response visible to the MCP client. In the HTTP/Vercel path the finally block in api/mcp.ts already handles flushing after the response is delivered, so this per-tool flush is redundant there. The safety risk is low (no data loss, no incorrect behaviour), but the latency impact is real and present on every validation or API error path.

packages/mcp/src/server.ts — the wrapToolWithContract catch block awaits flushMcpEvents() before returning, blocking error response delivery.

Important Files Changed

FilenameOverview
packages/mcp/src/sentry.tsNew Sentry integration module: env-based init, MCP server instrumentation, exception capture, and flush helpers. Logic is clean; parseBoolean/parseSampleRate helpers are well-guarded.
packages/mcp/src/server.tsAdds optional intent telemetry field to all tool schemas and Sentry error capture; wrapToolWithContract now awaits flushMcpEvents() in the catch block, blocking error responses for up to 2 seconds before the response is sent to the MCP client.
api/mcp.tsSentry initialization import added first (correct ordering); finally-block now flushes unconditionally when Sentry is initialized, addressing the previously flagged event-loss issue.
packages/mcp/src/instrument.tsSingle-purpose bootstrap module that calls initializeSentryFromEnv(); correctly placed as the first import in both entry points.
packages/mcp/src/mcp.test.tsTest coverage added for intent telemetry schema, Sentry exception capture on tool errors, and isError flag; Sentry module is properly mocked.
vercel.jsonAdds /mcp route (rewrite + CORS headers) mirroring the existing / route; updated allowed headers to include MCP-Protocol-Version and Mcp-Session-Id on both routes.
packages/mcp/package.jsonBumps MCP SDK to ^1.29.0, adds @sentry/node ^10.55.0, and adds several audit-fix overrides for nested transitive vulnerabilities.

Sequence Diagram

sequenceDiagram
participant Client as MCP Client
participant Vercel as Vercel Edge
participant Handler as api/mcp.ts handler
participant MCPServer as McpServer (Sentry-wrapped)
participant Tool as wrapToolWithContract
participant Sentry as Sentry SDK
Client->>Vercel: POST /mcp or POST /
Vercel->>Handler: forward request
Handler->>MCPServer: server.connect(transport) + handleRequest
MCPServer->>Tool: call tool handler(args)
alt Tool success
Tool-->>MCPServer: "{ content, structuredContent }"
MCPServer-->>Handler: response written to transport
Handler->>Sentry: flush(2000) [finally block]
Handler-->>Vercel: function complete
else Tool error
Tool->>Sentry: captureException(error)
Tool->>Sentry: flush(2000) blocks response up to 2s
Sentry-->>Tool: flushed
Tool-->>MCPServer: "{ content, isError: true }"
MCPServer-->>Handler: error response written to transport
Handler->>Sentry: flush(2000) [finally block, queue already empty]
Handler-->>Vercel: function complete
else Outer handler error
Handler->>Sentry: captureException(error)
Handler->>Sentry: flush(2000) [finally block]
Handler-->>Vercel: 500 response
end
Vercel-->>Client: response
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---### Issue 1 of 1
packages/mcp/src/server.ts:598-605
**`await flushMcpEvents()` blocks every tool error response for up to 2 seconds**`flushMcpEvents()` is awaited inside `wrapToolWithContract`'s catch block before returning the error object. Because the MCP SDK only writes the response to the HTTP transport *after* this function returns, every tool error (validation failure, API error, etc.) adds up to 2000 ms of wall-clock latency to the round-trip before the client receives anything. In the HTTP/serverless path, the `finally` block in `api/mcp.ts` already flushes after the response is delivered — so this per-tool flush is both redundant for Vercel and actively harmful for response time. For the STDIO transport there is no outer lifecycle flush, so the concern is real for that path, but the same 2-second blocking delay applies there too. Consider firing the flush without awaiting in the tool catch (fire-and-forget), or conditionally skipping it in HTTP mode, and relying on the `finally` block in the serverless handler.

Reviews (5): Last reviewed commit: "fix: capture handled mcp tool errors" | Re-trigger Greptile

@vercel

vercelBot commented May 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
apiReadyReadyPreview, CommentMay 29, 2026 7:19pm

Request Review

@mintlify

mintlifyBot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

ProjectStatusPreviewUpdated (UTC)
terminal49🟢 ReadyView PreviewMay 28, 2026, 10:47 PM

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:2c734171b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment threadsdks/typescript-sdk/README.md

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:270dbdbfcb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment threadvercel.json Outdated
@dodeja

Copy link
Copy Markdown
MemberAuthor

@greptile review

Comment threadpackages/mcp/src/sentry.ts
@dodeja

Copy link
Copy Markdown
MemberAuthor

@greptile review

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:24ccec0758

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment threadTerminal49-API.postman_collection.json Outdated
@dodeja

Copy link
Copy Markdown
MemberAuthor

@greptile review

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:62c461f4a6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment threadpackages/mcp/src/server.ts
@dodeja

Copy link
Copy Markdown
MemberAuthor

@greptile review

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:1393bf104f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment threadpackages/mcp/src/server.ts
Comment threadapi/mcp.ts
@dodeja

Copy link
Copy Markdown
MemberAuthor

@greptile review

@dodeja
dodeja merged commit 4be5b33 into mainMay 29, 2026
10 checks passed
@github-actionsgithub-actionsBot mentioned this pull request Aug 22, 2026
Sign up for freeto 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.

1 participant

@dodeja