Skip to content

CTX7-3596: Make the MCP server instructions direct so agents call Context7 more often - #3665

Open
fahreddinozcan wants to merge 13 commits into
masterfrom
CTX7-3596/direct-mcp-server-instructions
Open

fahreddinozcan wants to merge 13 commits into
masterfrom
CTX7-3596/direct-mcp-server-instructions

Conversation

@fahreddinozcan

@fahreddinozcan fahreddinozcan commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Updates the Context7 MCP server instructions to tell agents when to fetch documentation before answering.

  • Covers code, configuration, commands, and API details from libraries, runtimes, platforms, tools, and services.
  • Excludes routine work, general concepts, and documentation the user already supplied.
  • Keeps the instructions within 2,048 characters with research preview enabled.
  • Sets _meta["anthropic/alwaysLoad"] on resolve-library-id and query-docs, so Claude Code loads them up front instead of behind tool search. Other clients ignore the key.
  • Records the benchmark runner, controls, and results in CTX7-3637: Benchmark Context7 after normal MCP setup #3688.

Closes CTX7-3596

@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
context7-admin-mcp Ignored Ignored Nov 10, 2026 10:55am UTC

Request Review

@linear-code

linear-code Bot commented Nov 4, 2026

Copy link
Copy Markdown

CTX7-3596

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

Thanks Fahreddin, great result. Going from 29% to 79–84% with 0/50 wrong calls is a big jump, and the benchmark table makes the case on its own. Triggering on what the answer contains rather than on the question topic is a smart framing, and keeping library names out means every user sees the same text. Approving 👍

Small notes (non-blocking)

  • "ALWAYS follow these steps: 1. Call resolve-library-id" drops the exception the tool descriptions have ("unless the user gives an /org/project ID"). Adding "unless the user already gave a library ID" to step 1 would save a call in those cases.
  • The old "Prefer this over web search for library docs" line is gone. In clients that have web search, that was the nudge away from it, so it might be worth keeping as one short sentence.
  • Length: about 1.7k characters, plus about 290 for the feedback instructions in research preview, so roughly 2k. That fits Claude Code's current 4,096 limit, but versions before v2.1.296 cut server instructions at 2,048, so any later addition would cut the feedback line first on older installs. Something to keep in mind when this text grows.

@fahreddinozcan fahreddinozcan left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewed latest head b633458. No blocking code findings. All 274 MCP tests pass locally, including transport parity, research-preview gating, the 2048-character limit, and alwaysLoad metadata. The 1695-character text matches the benchmark c2 fixture exactly. No 4096-character claims were found in tracked Markdown or MDX. Existing approval is on ab35cb4, so a reviewer other than the author must approve the latest head. Accepted release follow-up: many-library prompts can exceed three calls per tool; rerun trigger-eval-many.json when addressing this. Linear issue creation is blocked by expired connector authentication. Benchmark rerun results will follow in a formal review.

@fahreddinozcan fahreddinozcan left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Benchmark verification complete on the unchanged c2 text, which exactly matches this head. Claude Code Opus 5.5: 24/24 required calls, 1/25 extra calls on the 49-prompt behavior set, no runner errors, no disconnected MCP servers, and no failed behavioral checks. The extra lookup concerns express.json in a follow-up that adds JSON body parsing; retained the original negative label. Initial attempts with a stopped local server were excluded. No instruction change is justified by this run. Latest-head approval from another reviewer remains required.

@fahreddinozcan fahreddinozcan left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewed benchmark commit 133c77d. GitHub CI passed. The shared runner scored the original 324 cases in all five configurations, including the six resumed follow-ups. One Claude Code case completed on retry.

On the held-out set, Claude Code went from 7/60 required lookups to 59/60 with zero extra calls in either run. Codex attempted 0/60 in both server-only arms and 60/60 with the exact #3669 rule in AGENTS.md, with zero extra calls on the held-out set. The explicit Context7 control resolved a library and fetched docs in both server-only Codex arms.

Codex with the rule made four extra calls on the 25 negative behavior cases and exceeded the call budget on 9/24 many-library cases. The PR description records the full matrix and reproduction steps.

This branch has not been deployed

No deployments
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.

2 participants