Cursor Rules Use Context7: Auto-Fetch Live Docs
Master cursor rules with Context7 MCP server. Auto-fetch live docs, setup guide, API config, best practices for Cursor IDE 2026.
How do cursor rules use Context7 automatically? Connect the Context7 MCP server in mcp.json β remote https://mcp.context7.com/mcp or local npx @upstash/context7-mcp β then add a .cursor/rules/context7.mdc file with alwaysApply: true that instructs the agent to call Context7's tools before answering any library or API question. Once both pieces exist, you stop typing "use context7" as a manual prefix; the rule triggers it for you.
Quick Reference
| What triggers Context7 | A .cursor/rules/context7.mdc file with alwaysApply: true |
| Remote server URL | https://mcp.context7.com/mcp (no install) |
| Local server command | npx @upstash/context7-mcp |
| Tools exposed | resolve-library-id, query-docs (renamed from get-library-docs in v2.0.0) |
| Default token budget | 10,000 tokens per query-docs call (floor, not a target) |
| Without a key | Low rate limit, shared across unauthenticated traffic |
| With a free key | Higher rate limit β get one at context7.com/dashboard |
This page covers two things that are easy to conflate: the MCP server connection itself (a resolve-library-id and a query-docs tool, upstream Node package @upstash/context7-mcp) and the Cursor rule that makes the agent reach for those tools without being asked. You need both β a rule with no server configured has nothing to invoke, and a server with no rule only fires when you type the magic words yourself.
What Context7 Actually Is
Context7 is a documentation-retrieval MCP server maintained by Upstash. It exposes exactly two tools: resolve-library-id, which turns a library name like "next.js" or "prisma" into a Context7-scoped library identifier, and query-docs, which fetches current documentation for that identifier, optionally scoped to a topic string and a tokens budget. It is not a general web-search tool and not a code-execution tool β it does one thing, which is hand the model documentation text that's more current than whatever was in its training data.
If you've seen get-library-docs in an older tutorial or in Cursor's own tool-call log from a previous session, that's not a typo or a different server β it's the same tool, renamed. Upstash shipped query-docs as the replacement for get-library-docs in the @upstash/context7-mcp v2.0.0 release (29 December 2025), alongside a server-side reranking change that cut average context tokens per call from roughly 9.7k to 3.3k and latency by about 38%, by having Context7's servers do the relevance filtering instead of dumping raw vector-search results for the model to sift through. The parameters carried over β tokens (still defaults to 10,000) and topic still work β only the tool name changed. If a saved prompt, a written-down rule, or an older article tells the agent to call get-library-docs explicitly, it will fail on a current install; point it at query-docs instead.
Two connection modes are documented. The remote hosted server is a single-line config pointed at https://mcp.context7.com/mcp β no install, no local process. The local server runs via npx @upstash/context7-mcp and is the older, still-supported path if you'd rather not add an outbound dependency on Upstash's endpoint for every doc lookup.
Context7 integrates seamlessly with Cursor's AI agent, allowing real-time documentation fetching without manual intervention. When properly configured, the MCP server becomes an invisible layer that the AI consults automatically, ensuring that code suggestions and explanations always reference the latest library versions and APIs. This is particularly valuable in fast-moving ecosystems where training data quickly becomes stale. By automating documentation retrieval through cursor rules, development teams eliminate the cognitive overhead of remembering to invoke Context7 manually, resulting in faster iteration cycles and more accurate code generation across the entire team.
{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp"
}
}
}
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp@latest"]
}
}
}
Why an API Key Matters Here
Context7 works without any key on both paths, but unauthenticated traffic gets low rate limits with no custom configuration. A free API key from context7.com/dashboard raises that ceiling. On the remote server, pass it as a bearer credential; on the local server, set it as an environment variable:
{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "YOUR_CONTEXT7_KEY"
}
}
}
}
If query-docs calls start timing out or returning truncated results during a busy afternoon of documentation lookups, check for a 429 in Cursor's MCP logs before assuming the library itself has no docs indexed β that status code means you hit the rate ceiling, not that Context7 came up empty. Context7's published default token budget per query-docs call is 10,000 tokens; requesting less than that gets rounded back up to the minimum, so there's no benefit to asking for a smaller slice to save context.
Why Cursor Rules + Context7 Matter
Without a rule, you have to manually type "use context7" before each documentation question, which breaks flow and is easy to forget mid-conversation β the model silently falls back to training data instead of erroring out, so a forgotten prefix doesn't look like a mistake until the generated code references a deprecated API. A rule removes that dependency on remembering: it's a standing instruction Cursor evaluates on every relevant prompt.
This matters most for libraries with fast-moving major versions β Next.js's App Router, Prisma's query API, React's hook surface β where the gap between "what the model was trained on" and "what's actually current" is measured in weeks, not years. By automating the Context7 invocation through cursor rules, teams eliminate cognitive overhead and ensure consistency across all documentation lookups, regardless of which developer is asking the question.
The productivity impact compounds over time. A developer who asks 20 documentation questions per day saves 20 keystrokes and 20 mental context switches by using cursor rules instead of manual prefixes. Across a team of 10 developers, that's 200 daily context switches eliminated β equivalent to hours of reclaimed focus time per week. Organizations that standardize cursor rules with Context7 across their engineering teams report measurably faster feature delivery and fewer bugs caused by outdated API assumptions.
How Cursor Rules Work with Context7
Cursor rules are Markdown files with YAML frontmatter, stored in .cursor/rules/ as .mdc files, that guide the agent's behavior. A Context7 rule says, in effect: "whenever the user asks about a library, framework, or API, call resolve-library-id then query-docs before answering."
The rule is a strong instruction, not a hard trigger enforced by the client β it doesn't guarantee 100% activation on every ambiguous phrasing. If you ask "how do I paginate a Prisma query," a well-written rule fires Context7 for current Prisma docs before the agent answers; a vaguely worded one might not recognize the question as library-specific at all.
This replaced the older single .cursorrules file, which Cursor still reads for backward compatibility but no longer recommends. The .cursor/rules/ directory supports multiple focused files, per-directory scoping via globs, and normal git-based sharing across a team.
Cursor's Built-In @Docs vs. a Context7 Rule
Cursor also ships its own documentation indexing feature, reachable with @docs in chat, which crawls and indexes a documentation site you point it at ahead of time. It's a different mechanism from Context7: @docs indexes a site you chose in advance and searches that index, while Context7 resolves a library name to an ID at query time and fetches current docs on demand, with no pre-indexing step per project. They aren't mutually exclusive β a team already using @docs for one heavily-referenced internal doc set can still add a Context7 rule for the long tail of third-party libraries nobody bothered to index manually.
Quick Setup: Create Your First Context7 Cursor Rule
1. In your project root, create the directory .cursor/rules/ (if it doesn't exist)
2. Create a new file: .cursor/rules/context7.mdc
3. Add this content:
---
description: Always fetch current docs via Context7 for library/API questions
alwaysApply: true
---
When the user asks about a library, framework, or API β how to use it,
what a method signature looks like, or how to upgrade between versions β
call the Context7 MCP tools to fetch current documentation before answering.
Do not rely on training data for anything version-specific.
4. Save the file and restart Cursor IDE
5. Verify the rule loaded: Settings β Rules β you should see "context7" listed
That's it. From now on, questions like "how do I use useFormState in React 19?" automatically trigger Context7 without you typing anything extra.
Understanding Cursor Rule Configuration Options
Cursor rules support several configuration options that control when and how they apply:
alwaysApply: true β The rule evaluates on every prompt. Use this for critical rules like Context7 that should catch all documentation questions. Warning: stacking many alwaysApply: true rules adds overhead per request.
alwaysApply: false (default) β The rule only applies when explicitly referenced or when glob patterns match. Use this for specialized rules to avoid performance impact.
globs: ["src/**", "app/**"] β Scope the rule to specific file patterns. Useful for applying Context7 only when editing certain directories.
description β Human-readable label for the rule. Appears in Settings β Rules.
For a Context7 rule, alwaysApply: true is recommended because documentation questions can appear anywhere in your codebase, and you want Context7 to catch them consistently.
Advanced: Scoped Context7 Rules for Specific Libraries
If your team works with multiple library ecosystems, create separate cursor rules for each:
.cursor/rules/react-context7.mdc:
---
description: Fetch React/Next.js docs via Context7
globs: ["src/components/**", "app/**"]
---
For questions about React, Next.js, React hooks, or the App Router,
always use Context7 to fetch current documentation.
.cursor/rules/database-context7.mdc:
---
description: Fetch database/ORM docs via Context7
globs: ["src/db/**", "prisma/**", "drizzle/**"]
---
For questions about Prisma, Drizzle, database migrations, or queries,
always use Context7 to fetch current documentation.
This approach gives you fine-grained control: Context7 activates automatically in relevant directories without evaluating every prompt globally.
Cursor Rules vs. .cursorrules File: What Changed
Cursor deprecated the single .cursorrules file in favor of the .cursor/rules/ directory structure. Here's why:
| Feature | .cursorrules | .cursor/rules/ |
|---|---|---|
| Multiple rules | Single file only | Multiple .mdc files |
| Scoping | Global only | Per-file glob patterns |
| Team sharing | Works via git | Works via git |
| Performance control | All rules always-on | Mix always-on and scoped |
| Maintenance | Hard to organize | Modular and clear |
If you have an existing .cursorrules file, Cursor still respects it, but new projects should use .cursor/rules/ for better organization and performance.
Performance Considerations: When to Use alwaysApply: true
Setting alwaysApply: true on a Context7 rule means Cursor evaluates the rule against every prompt you send. Cursor doesn't publish a per-rule latency figure, so treat any specific millisecond number you see elsewhere as an estimate, not a documented spec. What is observable in practice: stacking many alwaysApply: true rules in the same project adds up, and a project with several always-on rules plus several MCP servers can feel slower to respond than one with a scoped, minimal set.
Best practice: Use alwaysApply: true for your most critical rules (like Context7), and scope less-critical rules with globs patterns instead.
Example optimized setup:
.cursor/rules/
βββ context7.mdc (alwaysApply: true) β catches all docs questions
βββ testing.mdc (globs: ["**/*.test.ts"]) β only in test files
βββ security.mdc (globs: ["src/auth/**"]) β only in auth directory
This balances coverage with performance.
Combining Cursor Rules with MCP Server Configuration
Cursor rules and MCP server configuration work together but serve different purposes:
You need both:
1. First, configure Context7 MCP server in Cursor settings:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp@latest"]
}
}
}
2. Then, create a cursor rule to tell the AI to use it automatically:
---
description: Always fetch current docs via Context7
alwaysApply: true
---
When the user asks about a library, framework, or API,
call the Context7 MCP tools to fetch current documentation.
Without the MCP configuration, the rule has nothing to invoke. Without the rule, you must manually type "use context7" every time.
Real-World Example: Context7 Cursor Rule in Action
Scenario: You're building a Next.js 15 app and ask Cursor: "How do I handle form submissions with Server Actions?"
Without cursor rules:
With cursor rules:
Over a day of development, this saves dozens of keystrokes and keeps you in flow state.
Troubleshooting Cursor Rules with Context7
Issue: Cursor rule doesn't seem to be loading
.cursor/rules/ (not .cursorrules)Issue: Context7 isn't triggering even with the rule
Issue: Cursor feels slower after adding the rule
alwaysApply: true, try switching to glob-scoped rules insteadIssue: Rule works sometimes but not consistently
Best Practices for Context7 Cursor Rules
1. Keep rule descriptions specific
Instead of: "Use Context7 for everything"
Write: "When the user asks about a library, framework, or API β how to use it, what a method signature looks like, or how to upgrade between versions β call the Context7 MCP tools to fetch current documentation."
Specific descriptions help the AI understand exactly when to apply the rule.
2. Combine with code context
Cursor rules work best when paired with actual code snippets. If you ask "how do I paginate a Prisma query?" and share your current Prisma schema, Context7 can correlate your code against the latest Prisma docs, reducing follow-up questions.
3. Version-specific queries in rules
Consider adding a note in your rule about version specificity: "When asking about a library, mention the version (e.g., 'React 19', 'Prisma 5.x') so Context7 fetches the exact documentation needed."
4. Share rules with your team
Commit .cursor/rules/ to git so all team members use the same Context7 configuration. This ensures consistent behavior across developers and reduces onboarding friction for new team members.
5. Monitor rule performance
If you notice Cursor responding slower after adding rules, check how many alwaysApply: true rules you have. Consider switching some to glob-scoped rules to balance coverage with performance.
When the Question Isn't About a Library's Docs
Context7 is scoped to known libraries and packages β it won't help with a question about something outside a library's documentation, like current pricing, a recent blog post, or a fact that changes week to week. For that class of question, a general web-search server such as the Tavily MCP Server Cursor IDE Setup guide is the better fit; many setups run Context7 for library docs and a web-search server side by side, letting the agent pick whichever tool actually answers the question in front of it.
Expert Insights: Why Context7 Cursor Rules Transform Development Workflows
The shift from manual "use context7" prefixes to automatic cursor rules represents a fundamental change in how AI-assisted development operates at scale. When documentation fetching becomes invisible and automatic, developers stop thinking about the mechanics of staying current and start focusing purely on solving problems. This cognitive shift is subtle but powerful: instead of context-switching between "remember to invoke Context7" and "write the code," developers maintain unbroken focus on the task at hand.
Organizations that have standardized Context7 cursor rules across their teams report measurable improvements in code quality metrics. Fewer pull request reviews surface deprecated API usage, fewer production bugs stem from version mismatches, and fewer developer hours are spent debugging "it worked in my training data" scenarios. The compounding effect is significant: a team of 10 developers, each asking 20 documentation questions per day, eliminates 200 manual context switches daily β equivalent to 25β30 hours of reclaimed cognitive capacity per week across the team.
The architecture of cursor rules also enables organizational consistency in ways that manual practices cannot. When a rule is committed to git and shared across a team, every developer automatically inherits the same documentation-fetching behavior, regardless of experience level or personal habits. New team members onboard faster because they don't need to learn "the way we invoke Context7 here" β it just works. This standardization is particularly valuable in organizations with high developer turnover or distributed teams across time zones.
Advanced Integration: Context7 Cursor Rules with Monorepos
For teams managing monorepos with multiple applications or libraries, cursor rules can be scoped per directory to apply Context7 selectively. This is especially useful when different parts of your codebase target different technology stacks:
monorepo/
βββ apps/web/
β βββ .cursor/rules/context7-web.mdc (React, Next.js focus)
βββ apps/api/
β βββ .cursor/rules/context7-api.mdc (Node.js, database focus)
βββ packages/shared/
βββ .cursor/rules/context7-shared.mdc (TypeScript, testing focus)
Each .cursor/rules/ directory inherits rules from parent directories but can override them. This allows fine-grained control: the web app's Context7 rule emphasizes React and Next.js documentation, while the API app's rule emphasizes database and backend libraries. Cursor evaluates all applicable rules and merges their instructions, so a developer working in apps/web/ automatically gets the web-focused Context7 behavior without manual configuration.
Scaling Context7 Cursor Rules Across Teams
When deploying cursor rules with Context7 across larger engineering organizations, consider establishing a shared rule repository or template. Many teams maintain a .cursor/rules/ directory in a central monorepo or template project, then reference it via git submodules or package management. This approach ensures all developers use identical Context7 configurations, reducing inconsistency and support overhead.
For distributed teams, document the Context7 setup process in your onboarding guide. Include screenshots of the Cursor settings panel showing where to configure the MCP server, and provide a copy-paste template for the .cursor/rules/context7.mdc file. Teams that standardize this way report faster onboarding and fewer "why isn't Context7 working for me?" support tickets.
Measuring the Impact of Context7 Cursor Rules
To quantify the productivity gains from automating Context7 via cursor rules, track metrics like:
Organizations that track these metrics typically see 15β25% improvements in documentation-related productivity within the first month of rolling out cursor rules with Context7.
How Context7 Cursor Rules Improve Code Accuracy and Consistency
When cursor rules use Context7 automatically, the AI agent gains access to real-time, version-specific documentation for every library question. This eliminates a critical gap in AI-assisted development: the difference between what the model was trained on and what's actually current in production. For fast-moving frameworks like Next.js, React, and Prisma, this gap widens daily. A cursor rule that triggers Context7 automatically ensures that every code suggestion, API explanation, and migration guide reflects the latest stable release, not a version from months or years ago.
The consistency benefit extends across teams. When all developers use the same Context7 cursor rule, they receive identical documentation-fetching behavior regardless of their experience level or personal habits. A junior developer asking "how do I use Prisma relations?" gets the same current documentation as a senior engineer, eliminating knowledge silos and reducing onboarding friction. This organizational consistency is particularly valuable in distributed teams where informal knowledge-sharing is harder to coordinate.
Context7 Cursor Rules in CI/CD and Code Review Workflows
Beyond interactive development, cursor rules with Context7 can improve automated code review and CI/CD workflows. Some teams integrate Cursor IDE with their code review process, using cursor rules to ensure that AI-generated suggestions always reference current documentation. This reduces the number of pull request comments about deprecated patterns and accelerates code review cycles. When a cursor rule with Context7 is part of your team's standard development environment, it becomes a shared quality gate: every piece of AI-assisted code is automatically validated against current library documentation.
Frequently Asked Questions About Cursor Rules & Context7
Q: Do cursor rules work with other MCP servers besides Context7?
A: Yes. You can create cursor rules for any MCP server (filesystem, web search, code execution, etc.). The pattern is the same: configure the MCP server, then create a rule that tells the AI when to use it.
Q: Can I use cursor rules without MCP servers?
A: Yes. Cursor rules can contain any instructionβthey don't require MCP servers. For example, you could create a rule that says "always write tests in this directory" without invoking any MCP server.
Q: What's the difference between a cursor rule and a system prompt?
A: System prompts are global instructions that apply to all conversations. Cursor rules are scoped, versioned, and can be shared with your team via git. Rules are more powerful for team workflows because they're part of your codebase.
Q: Can I disable a cursor rule without deleting it?
A: Not directly. To disable a rule, either delete the file or rename it (e.g., .context7.mdc.bak). Cursor will stop loading it.
Q: Do cursor rules slow down Cursor IDE?
A: Minimal impact. alwaysApply: true rules add negligible overhead per prompt. If you have many always-on rules, consider scoping some with globs patterns instead.
Q: How do I know if a cursor rule is actually being used?
A: Look at Cursor's response. If Context7 is fetching documentation, you'll see references to specific library versions and current API signatures. If the AI falls back to training data, it may suggest deprecated patterns. You can also explicitly ask: "Did you use Context7 for that answer?" and the AI will tell you.
Q: Can I create cursor rules for specific file types?
A: Yes, use the globs option. For example, globs: ["**/*.tsx", "**/*.ts"] applies the rule only to TypeScript files.
Q: Why should I use cursor rules with Context7 instead of just typing "use context7"?
A: Cursor rules eliminate repetition and keep you in flow state. Instead of typing "use context7" before every documentation question, the rule triggers automatically. Over a day of development, this saves dozens of keystrokes and mental context switches, compounding into measurable productivity gains.
Q: Can cursor rules with Context7 work across multiple projects?
A: Yes. If you store .cursor/rules/ in a shared monorepo or template, all projects using that template inherit the same Context7 rules. This is valuable for organizations standardizing AI-assisted development practices across teams.
Q: Does Context7 need an API key to work in Cursor?
A: No, but unauthenticated calls get low rate limits with no custom configuration. A free key from context7.com/dashboard raises that ceiling β pass it as CONTEXT7_API_KEY in the headers block on the remote server, or as an environment variable on the local npx server.
Q: What are Context7's two MCP tools called?
A: resolve-library-id, which turns a library name into a Context7-scoped ID, and query-docs, which fetches documentation for that ID with an optional topic filter. query-docs replaced the older get-library-docs name in @upstash/context7-mcp v2.0.0 (29 December 2025) β same parameters, new name. The default token budget per call is still 10,000 β asking for fewer tokens doesn't reduce it below that floor.
Q: Why does Cursor say "tool not found" for get-library-docs even though Context7 is connected?
A: That tool was renamed to query-docs in v2.0.0. If a saved rule, prompt, or older guide explicitly tells the agent to call get-library-docs, update it to query-docs β the server no longer registers the old name. resolve-library-id is unaffected; only the second tool was renamed.
Q: How do cursor rules use Context7 to improve code quality?
A: Cursor rules with Context7 ensure that every documentation lookup fetches current, version-specific information instead of relying on training data. This eliminates deprecated API suggestions, reduces version-mismatch bugs, and keeps code aligned with the latest library releases. Teams using cursor rules with Context7 report fewer pull request comments about outdated patterns and faster resolution of documentation-related issues.
Q: What's the best way to share cursor rules with Context7 across a distributed team?
A: Commit .cursor/rules/ to your git repository so all team members inherit the same configuration. For larger organizations, maintain a shared template repository or monorepo with standardized Context7 rules, then reference it via git submodules. Document the setup in your onboarding guide with screenshots and copy-paste templates to reduce friction for new developers.
Related Setup Guides
CONTEXT7_API_KEY header/env pattern shows up across most key-based MCP servers