Skip to content

fix(mcp): name the reason on MCP route 400 log lines - #10475

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/search-mcp-400-reason
Nov 28, 2026
Merged

waleedlatif1 merged 3 commits into
stagingfrom
fix/search-mcp-400-reason

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • MCP route 400s now say why on the existing Client error response line through describeResponseError, so client incompatibility can be told apart from noise. Response bodies are unchanged.
  • serveStatelessMcp reads the reason only when the SDK transport refuses a request (status >= 400):
    • errorCode is the JSON-RPC code.
    • errorReason is the SDK message with any dynamic tail dropped, e.g. Bad Request: Unsupported protocol version.
    • errorDetail is the mcp-protocol-version header capped at 40 chars, set only when that version was the cause.
  • Both MCP routes (Search MCP and /api/mcp) pass MCP_PARSE_ERROR_RESPONSES to parseRequest. A contract validation failure is logged with its field and issue kind (a JSON-RPC batch is body / invalid_type), and invalid JSON as invalid_json. Both still render the default 400 bodies.
  • v2ValidationError and the MCP renderer now share one describeValidationError, so the v2 summary is the same as before.

Type of Change

  • Bug fix

Testing

  • route-handler.protocol.test.ts drives the real route, SDK transport and Search MCP server. It checks the logged reason for an unsupported protocol version and for a batch body. Each test failed when its guard was reverted.
  • Ran lib/knowledge/mcp/route-handler.test.ts, lib/api/mcp/route-handler.test.ts, app/api/v2/lib/*.test.ts and lib/api/server/validation.test.ts; all pass. Biome is clean on the changed files.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
docs Ready Ready Preview Nov 28, 2026 11:49am UTC

Request Review

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 7 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues remain.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues remain.

Summary

Adds reasons to existing MCP error logs without changing response bodies.

  • MCP rejection logs now show why a request was refused.

No new actionable issues found. Tests were inspected but not run during this review.

Reviews (4) · Last reviewed commit: "fix(mcp): pass a route context in the te..." · Reviewed by Greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 7 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 force-pushed the fix/search-mcp-400-reason branch from 25f47dd to 908ee55 Compare November 28, 2026 11:44
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@waleedlatif1
waleedlatif1 merged commit e1d814a into staging Nov 28, 2026
7 of 8 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/search-mcp-400-reason branch November 28, 2026 11:44

This branch was successfully deployed

1 active deployment
Preview — 908ee556 Deployed Nov 28, 2026 by vercel[bot]
Sign up for free to 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