Skip to content

fix: prevent MCP guideline tools from returning homepage content - #8784

Merged
joshblack merged 2 commits into
mainfrom
copilot/fix-mcp-guideline-tools-homepage-return
Nov 19, 2026
Merged

joshblack merged 2 commits into
mainfrom
copilot/fix-mcp-guideline-tools-homepage-return

Conversation

@joshblack

@joshblack joshblack commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

When a component has no guidelines page, Primer’s redirect to the homepage can make the MCP tools present homepage content as component guidance. The tools now detect redirects away from the requested page and return a clear no-guidelines response.

Changelog

New

  • Regression coverage for redirects in both guideline tools.

Changed

  • Return a no-guidelines response when a request redirects away from its requested page.
  • Correct the usage-guidelines tool’s missing-page message.

Removed

  • None.

Rollout strategy

  • No changes needed in github/github-ui

Testing & Reviewing

Review the redirect behavior for Card in both guideline tools and confirm components with published guidance still return it.

@changeset-bot

changeset-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1ec9763

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/mcp Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@joshblack joshblack changed the title [WIP] Fix MCP guideline tools returning homepage for missing guidance Prevent MCP guideline tools from returning homepage content Nov 17, 2026
@joshblack joshblack changed the title Prevent MCP guideline tools from returning homepage content fix: prevent MCP guideline tools from returning homepage content Nov 17, 2026
@joshblack
joshblack marked this pull request as ready for review November 17, 2026 16:19
@joshblack
joshblack requested a review from a team as a code owner November 17, 2026 16:19
@joshblack
joshblack requested review from llastflowers and a balanced review from Copilot November 17, 2026 16:19

Copilot AI 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.

🟢 Approval recommended

No active review issues were identified for the fix preventing redirected homepage content from being presented as component guidance.

No open issues 🎉

What changed in this PR

Prevents Primer’s MCP guideline tools from presenting homepage content as component guidance when a requested page redirects elsewhere, addressing #8782.

Changes:

  • Detect redirects away from the requested page in both guideline tools and return a no-guidelines response.
  • Correct the usage-guidelines missing-page message and add redirect regression tests.
  • Include a patch changeset for @primer/mcp.
File Description
packages/​mcp/​src/​server.ts Adds shared redirect detection and corrects the usage-guidelines response.
packages/​mcp/​src/​server.test.ts Adds homepage-redirect regression coverage for both guideline tools.
.changeset/​mcp-guideline-redirects.md Records the fix for an @primer/mcp patch release.

Review effort: Balanced

@github-actions
github-actions Bot temporarily deployed to storybook-preview-8784 November 17, 2026 16:30 Inactive
@joshblack joshblack added the integration-tests: skipped manually Changes in this PR do not require an integration test label Nov 17, 2026
@joshblack
joshblack enabled auto-merge November 17, 2026 16:39

@Ultroncn Ultroncn 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.

Thanks for fixing this — the redirect check reads well, and I verified the new test really exercises it (new Response(body) defaults to ok: true, so the test would fail without the fix).

Two small notes:

  1. The test only pins the redirect-to-homepage case. Since the helper's contract is "any different page", I left a suggestion below to also cover a redirect to a different non-homepage URL (the component page itself), so a future change that only special-cased / couldn't silently pass.

  2. Not part of this PR, but the same pattern exists elsewhere in server.ts: get_component_examples (/product/components/<slug>), get_pattern (/product/<scenario-patterns|ui-patterns>/<id>) and get_icon (/octicons/icon/<name>-<size>) fetch user-controlled primer.style URLs and only check response.ok before returning <main> content. If primer.style ever redirects one of those to the homepage with a 200, they'd return homepage content as docs. Might be worth applying this helper there in a follow-up — leaving that to you.

Comment on lines +535 to +548
it.each([
{
tool: 'get_component_usage_guidelines',
expectedPath: '/product/components/card/guidelines',
expectedMessage: 'There are no usage guidelines for the `Card` component',
},
{
tool: 'get_component_accessibility_guidelines',
expectedPath: '/product/components/card/accessibility',
expectedMessage: 'There are no accessibility guidelines for the `Card` component',
},
])('$tool does not return homepage content after a redirect', async ({tool, expectedPath, expectedMessage}) => {
const fetchMock = vi.mocked(fetch)
fetchMock.mockResolvedValue(responseWithFinalUrl('<main><h1>Primer homepage</h1></main>', 'https://primer.style/'))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice test — one small suggestion: the helper's contract is "any different page", but this only pins the redirect-to-homepage case. Adding a redirect to a different non-homepage URL (here, the component page itself) would also guard against a future change that only special-cased /:

Suggested change
it.each([
{
tool: 'get_component_usage_guidelines',
expectedPath: '/product/components/card/guidelines',
expectedMessage: 'There are no usage guidelines for the `Card` component',
},
{
tool: 'get_component_accessibility_guidelines',
expectedPath: '/product/components/card/accessibility',
expectedMessage: 'There are no accessibility guidelines for the `Card` component',
},
])('$tool does not return homepage content after a redirect', async ({tool, expectedPath, expectedMessage}) => {
const fetchMock = vi.mocked(fetch)
fetchMock.mockResolvedValue(responseWithFinalUrl('<main><h1>Primer homepage</h1></main>', 'https://primer.style/'))
it.each([
{
tool: 'get_component_usage_guidelines',
expectedPath: '/product/components/card/guidelines',
expectedMessage: 'There are no usage guidelines for the `Card` component',
finalUrl: 'https://primer.style/',
},
{
tool: 'get_component_accessibility_guidelines',
expectedPath: '/product/components/card/accessibility',
expectedMessage: 'There are no accessibility guidelines for the `Card` component',
finalUrl: 'https://primer.style/',
},
{
tool: 'get_component_accessibility_guidelines',
expectedPath: '/product/components/card/accessibility',
expectedMessage: 'There are no accessibility guidelines for the `Card` component',
finalUrl: 'https://primer.style/product/components/card',
},
])('$tool does not return content from a different page after a redirect', async ({tool, expectedPath, expectedMessage, finalUrl}) => {
const fetchMock = vi.mocked(fetch)
fetchMock.mockResolvedValue(responseWithFinalUrl('<main><h1>Primer homepage</h1></main>', finalUrl))

@joshblack
joshblack added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit 13d5ff6 Nov 19, 2026
66 checks passed
@joshblack
joshblack deleted the copilot/fix-mcp-guideline-tools-homepage-return branch November 19, 2026 19:39
@primer primer Bot mentioned this pull request Nov 19, 2026

This branch was successfully deployed

1 active and 1 inactive deployments
storybook-preview-8784 — 1ec97637 Deployed Nov 17, 2026 by github-actions[bot]
github-pages — 1ec97637 Deployed Nov 17, 2026 by joshblack via deploy-preview #34390
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: skipped manually Changes in this PR do not require an integration test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP guideline tools return the homepage for components without guidance

5 participants