Skip to content

feat(mcp): Keep get_sentry_resource loaded in Claude Code - #1989

Closed
sentry-junior[bot] wants to merge 2 commits into
mainfrom
feat/mcp-always-load-resource
Closed

sentry-junior[bot] wants to merge 2 commits into
mainfrom
feat/mcp-always-load-resource

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Claude Code hides MCP tools behind tool search unless a tool sets _meta["anthropic/alwaysLoad"]. docs/mcp/harnesses.md already named get_sentry_resource as the tool to keep loaded, but none of our tools sent _meta.

  • ToolConfig gets an optional _meta field, which buildServer passes to registerTool.
  • get_sentry_resource is the only tool that sets {"anthropic/alwaysLoad": true}. A pasted Sentry URL then works without a tool search first. The key follows the current Claude Code docs ("Mark a tool to load upfront or stay deferred").
  • harnesses.md now says we set it. A user's server-level alwaysLoad setting can still override it.
  • measure-tokens now includes _meta, so its count matches the wire.

Impact

  • This only changes behavior in Claude Code. Other clients ignore the key.
  • Token cost: +11 against current main, which now includes the feat(mcp): Add a display title to every tool #1991 titles (47,553 → 47,564).
  • server.all-tools.test.ts checks that get_sentry_resource is the only tool in tools/list with _meta.

Checks: package-scoped tsc for @sentry/mcp-core and @sentry/mcp-cloudflare, root lint, and the mcp-core and mcp-cloudflare test suites. After rebasing onto main (with #1991), I re-ran mcp-core tsc, check:generated, root lint and the mcp-core tests. I didn't run the root tsc or test scripts, because they run the cloudflare build, which uploads source maps to Sentry.

via @dcramer.

--

View Session [Sentry]

@vercel

vercel Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
sentry-local Ready Ready Preview Nov 5, 2026 7:20pm UTC

Request Review

Claude Code defers MCP tools behind tool search unless a tool sets
`_meta["anthropic/alwaysLoad"]`. harnesses.md named get_sentry_resource
as the tool to keep loaded, but no tool sent `_meta`.

Add an optional `_meta` field to ToolConfig, pass it to registerTool,
and set `anthropic/alwaysLoad` on get_sentry_resource only. A test
checks that tools/list exports it on that tool and no other.

Co-Authored-By: David Cramer <[email protected]>
Resolve the ToolConfig conflict with #2035: keep the _meta field and the
outputSchema-typed handler.
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: low PR risk score: low labels Nov 5, 2026
@mehanig

mehanig commented Nov 6, 2026

Copy link
Copy Markdown

@getsentry-bot It looks like it's added to all clients? Can server not sent this field if User-Agent is not claude-code or maybe by looking at params.ClientInfo.name durin init event ?

@sentry-junior

sentry-junior Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Yes. As written, every client gets the key on get_sentry_resource. I left it ungated on purpose, but we could gate it.

Why it isn't gated now:

  • The MCP spec reserves _meta for implementation-defined metadata, and the key has a vendor prefix (anthropic/). Clients that don't know the key should ignore it.
  • It's one tool and costs about 11 tokens, so sending it everywhere costs very little.

What gating would take:

  • Hosted (/mcp): easy. mcp-handler.ts already puts clientFamily into ServerContext, using resolveClientFamily(user-agent) (claude-code/… → "claude-code"). buildServer runs for each request with that context. server.ts could send _meta only when context.clientFamily === "claude-code", and a test could check both cases.
  • stdio: harder. There's no User-Agent and no clientFamily. clientInfo.name arrives in initialize, but by then the tools are already registered, so we'd need a hook at tools/list time.
  • Risk: detecting by User-Agent can miss Claude Code builds that send a different UA, and those would quietly lose the always-load behavior.

We're keeping it ungated for now, because clients ignore unknown _meta keys and it costs about 11 tokens. If we decide we don't want vendor keys going to other clients, gating it on clientFamily for the hosted server is an easy follow-up.

@github-actions

Copy link
Copy Markdown
Contributor

This PR has had no activity for 3 days. It closes in 2 days unless someone pushes, comments, or adds the WIP label.

@github-actions github-actions Bot added the Stale label Nov 24, 2026
@sentry-junior
sentry-junior Bot requested a review from dcramer November 26, 2026 02:39
@dcramer dcramer closed this Nov 26, 2026

This branch was successfully deployed

1 active (outdated) and 1 inactive deployments
Actions — 58fb913c Deployed Nov 5, 2026 by sentry-junior[bot] via eval #1682
Preview — cd23ede0 Deployed Nov 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants