Skip to content

fix(docs-mcp): strip query strings and fragments from docs URLs - #1767

Merged
MathurAditya724 merged 4 commits into
getsentry:mainfrom
pcbeingused333:fix/docs-url-strip-query-fragment
Nov 15, 2026
Merged

MathurAditya724 merged 4 commits into
getsentry:mainfrom
pcbeingused333:fix/docs-url-strip-query-fragment

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Fixes #1618

Cause. normalizeDocPath in apps/docs-mcp/src/sentry-docs/fetcher.ts keeps ?query and #fragment, and fetchDocPage then appends .md to the whole string. https://docs.sentry.io/platforms/javascript/#tracing becomes a request for /platforms/javascript/ with fragment #tracing.md, so the server returns the HTML page, which is cached as Markdown for an hour.

Fix. Strip the query string and fragment first, before the origin, .md, trailing-slash and leading-slash steps. The exact-origin boundary is unchanged (https://docs.sentry.io.example.com/...?x=1 is still treated as a path, not as docs.sentry.io). Every caller of normalizeDocPath (fetchDocPage, the agent tools, the doctree and the citation URLs) gets the cleaned pathname.

Tests. apps/docs-mcp/src/__tests__/fetcher.test.ts gains cases for full URLs and relative paths with a query, a fragment or both, for the bare origin with ?/#, for the origin boundary with a query string, and a fetchDocPage test that checks the outbound request URL is https://docs.sentry.io/platforms/javascript.md.

This change was prepared with the assistance of an AI tool (Claude) and submitted by the account owner.

pcbeingused333 and others added 4 commits October 31, 2026 06:08
normalizeDocPath kept '?' and '#', so fetchDocPage appended '.md' to the whole
string and requested e.g. '#tracing.md' instead of '<pathname>.md'; the HTML
response was then cached as Markdown. Drop the query and fragment before the
other normalisation steps.

Fixes getsentry#1618

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@vercel

vercel Bot commented Oct 31, 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 Oct 31, 2026 12:44pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 31, 2026
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Friendly ping in case this slipped through — happy to adjust anything (scope, tests, style) if that makes review easier. Thanks for maintaining this!

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. Stripping ?/# at the top of normalizeDocPath fixes the cause described in #1618. Because the strip runs first, the .md suffix lands on the pathname, and every caller (fetchDocPage, buildDocsUrl, the agent tools, doctree) gets the same cleaned path. The exact-origin check still runs after the strip, so docs.sentry.io.example.com is still not treated as docs.sentry.io.

I ran fetcher.test.ts locally on this branch and all 20 tests pass, and tsc --noEmit for docs-mcp is clean. Against the old fetcher.ts, all 10 new cases fail, including the outbound-request assertion, so the tests lock in the fix.

@MathurAditya724
MathurAditya724 merged commit 2884bc6 into getsentry:main Nov 15, 2026
16 checks passed

This branch was previously deployed

1 inactive deployment
Preview — bb16f782 Deployed Oct 31, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs MCP URL normalization retains query strings and fragments

3 participants