Skip to content

fix(mcp): Restore sentry-mcp User-Agent on streamText provider calls - #2011

Merged
dcramer merged 2 commits into
mainfrom
fix/streamtext-user-agent
Nov 5, 2026
Merged

dcramer merged 2 commits into
mainfrom
fix/streamtext-user-agent

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

#1994 (d32e146) moved the embedded agent's User-Agent onto the generateText call and removed it from the four LLM providers. That fixed callEmbeddedAgent, where generateText's own call-level user-agent replaced the provider header.

It broke direct streamText callers. The chat playground's /api/chat route (packages/mcp-cloudflare/src/server/routes/chat.ts) calls streamText({ model: getOpenRouterModel(), … }). streamText adds no call-level user-agent, so since #1994 playground requests send only ai-sdk/openai/… ai-sdk/provider-utils/… runtime/… and no sentry-mcp/....

This puts "User-Agent": getUserAgent() back on all four providers: OpenAI, Anthropic, OpenRouter, and Azure OpenAI. The header is still computed when the model is built, not at module load. The call-level header on generateText in callEmbeddedAgent stays, because generateText would otherwise overwrite the provider's. Having both is harmless: the call-level value wins where it's set, and the provider value covers any direct streamText caller.

Tests:

  • provider-user-agent.test.ts builds each provider through the real setAgentProvider/setProviderBaseUrls factory, with a stubbed fetch and setServerVersion("1.2.3-x"). It calls streamText and asserts exactly one user-agent that starts with sentry-mcp/1.2.3-x (https://mcp.sentry.dev) . It covers OpenAI, Anthropic, OpenRouter, and both Azure URL shapes (/openai/v1 and /openai/deployments/<name>).
    • I deleted the header from each provider in turn, and each deletion fails exactly that provider's cases.
    • No network calls and no real keys.
  • bundle.test.mjs: the User-Agent test now drains the child's stderr into its failure messages. A non-JSON stdout line now fails the test cleanly instead of throwing an uncaught exception.

Review: a reviewer passed 9885b7b (the fix plus the bundle test change) with no must-fix findings. 00b74e0 came after that review. It replaces the OpenRouter-only test with the parametrized test for all four providers.

Checks: all scoped to the affected packages, with SENTRY_AUTH_TOKEN unset.

  • mcp-core builds, typechecks, and passes its tests (2103).
  • mcp-cloudflare typechecks.
  • mcp-server bundle builds and passes bundle.test.mjs (17).
  • Root pnpm run lint passes.
  • I skipped root pnpm run tsc/test/build: they build mcp-cloudflare, which uploads source maps.

via @dcramer.

--

View Session [Sentry]

sentry-junior Bot and others added 2 commits November 5, 2026 19:41
…llers

#1994 moved the embedded agent's User-Agent onto the generateText call
and dropped it from the providers. The chat playground calls streamText
with getOpenRouterModel() directly, and streamText adds no call-level
user-agent, so playground requests stopped sending sentry-mcp/... at
all. Restore the header on all four providers, still computed when the
model is built, and keep the call-level header in callEmbeddedAgent,
which generateText would otherwise overwrite. Add a streamText test.

In the bundle User-Agent test, drain the child's stderr into failure
messages and turn a non-JSON stdout line into a clean failure.
…ider

Replace the OpenRouter-only streamText test with one parametrized over
OpenAI, Anthropic, OpenRouter, and Azure OpenAI (v1 and deployment URLs),
built through the real provider factory. Removing the header from any
one provider fails its case.

Co-Authored-By: David Cramer <[email protected]>
@vercel

vercel Bot commented Nov 5, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 5, 2026 7:56pm UTC

Request Review

@github-actions github-actions Bot added the risk: low PR risk score: low label Nov 5, 2026
@dcramer
dcramer merged commit 159be6d into main Nov 5, 2026
33 checks passed
@dcramer
dcramer deleted the fix/streamtext-user-agent branch November 5, 2026 21:43

This branch was previously deployed

1 inactive deployment
Preview — 00b74e02 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: low PR risk score: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant