Tool Selection
| Scenario |
Tool |
Reason |
| Known library, need code examples |
Context7 |
Optimized for retrieving code snippets |
| General API reference lookup |
Context7 |
Fast, structured documentation access |
| Obscure/niche library |
Ref |
Broader search across multiple sources |
| Concept explanation or tutorials |
Ref |
Better for prose and explanatory content |
| Debugging with error messages |
Ref |
Can search Stack Overflow, GitHub issues |
| Cross-library comparison |
Ref |
Searches across multiple documentation sources |
| Version-specific behavior |
Both |
Context7 for latest docs, Ref to find version-specific pages |
| Multi-library question |
Both |
Resolve each library separately, then combine findings |
Decision Flow
Is the library well-known (React, Python stdlib, popular npm packages)?
- Yes: Start with Context7 -- it is faster and returns structured results.
- No: Start with Ref -- it has broader coverage of niche and less popular libraries.
Do you need code snippets or API signatures?
- Yes: Prefer Context7.
- No (need explanations, tutorials, or community discussion): Prefer Ref.
Is the question version-specific (e.g., "I'm using React 17, not 18")?
- If Context7 returns docs for the wrong version, fall back to Ref and search for version-specific documentation pages. Include the version number in your Ref query (e.g., "react 17 lifecycle methods").
- Context7 typically serves the latest version of a library's docs. If the user is on an older version, verify that the API you found actually existed in their version.
Does the question span multiple libraries (e.g., "how to use pandas with SQLAlchemy")?
- Resolve each library separately in Context7 (call
resolve-library-id for each), then query each one.
- Alternatively, use Ref with a combined query since it can search across sources.
Are you unsure which tool to use?
- Try Context7 first since it is faster and returns structured results. If it returns insufficient results, fall back to Ref.
Did the first tool return insufficient results?
- Yes: Try the other tool. See "Error Handling and Fallbacks" below.
Crafting Effective Queries
Good queries are specific and include the library name, the function or concept, and the action. Avoid vague natural-language questions.
For Context7 resolve-library-id:
- Use the library's canonical name. Keep it short.
- Good:
pandas, react, fastapi, express
- Poor:
the python data analysis library, facebook's frontend framework
For Context7 query-docs:
- Be specific about the function, class, or concept. Include the action you want.
- Good:
read_csv skip rows -- names the function and the parameter concern
- Good:
useEffect cleanup function -- names the hook and the specific aspect
- Good:
Router middleware order of execution -- names the component and the behavior
- Poor:
how to skip rows -- too vague, missing function name
- Poor:
how does useEffect work -- too broad, will return too much
- Poor:
middleware -- too generic
For Ref ref_search_documentation:
- Include the language or framework name in the query. Be descriptive but not conversational.
- Good:
python pandas read_csv skiprows parameter
- Good:
express.js error handling middleware next function
- Good:
rust serde deserialize enum variants
- Poor:
how to skip rows in a csv file -- missing library name
- Poor:
error handling -- far too vague
- Poor:
why doesn't my middleware work -- conversational, not searchable
Tool Usage
Context7 workflow:
- Call
resolve-library-id with the library name to get the Context7 library ID.
- Example: resolve-library-id with query
pandas
- Example: resolve-library-id with query
react
- If multiple candidates are returned, pick the one with the highest snippet count and trust score. A library with 5000 snippets is almost certainly the correct one over a library with 12 snippets.
- Call
query-docs with the returned library ID and a specific query.
- Example: query-docs with library ID
/python/pandas and query read_csv skiprows parameter
- Example: query-docs with library ID
/facebook/react and query useEffect cleanup return function
Ref workflow:
- Call
ref_search_documentation with a descriptive query including the language/framework name.
- Example:
python pandas read_csv skip rows
- Example:
express.js middleware error handling next
- Example:
rust tokio spawn blocking vs spawn
- Call
ref_read_url with the exact URL from results (include the #hash portion if present).
- Always use the full URL including any fragment identifier -- these point to the specific section relevant to the query.
Error Handling and Fallbacks
When a tool returns no results:
- Rephrase the query. Remove overly specific terms and try broader keywords.
- Switch to the other tool. If Context7 found nothing, try Ref, and vice versa.
- For Context7: verify that
resolve-library-id returned the correct library. Some libraries have non-obvious IDs.
When a tool returns too many results or irrelevant results:
- Narrow the query. Add the specific function name, class name, or parameter.
- For Ref: add the language name to disambiguate (e.g.,
python requests timeout instead of requests timeout).
When resolve-library-id returns multiple candidates:
- Compare the snippet count and trust/reputation score.
- The candidate with significantly more snippets is almost always the correct one.
- If two candidates have similar snippet counts, prefer the one whose name or description most closely matches the user's context (e.g., the Python
requests library vs. an unrelated npm package also called requests).
When results seem outdated or conflict with what you know:
- Flag this to the user. State which version the documentation appears to cover.
- Use Ref to search for the specific version's documentation or changelog.
- Do not silently use outdated information -- always note version discrepancies.
Synthesizing Results
When combining information from multiple sources or tool calls:
- Prioritize official documentation over community answers. Official docs are the ground truth for API signatures, parameter names, and return types.
- Note version discrepancies. If Context7 returns docs for v3 but the user is on v2, say so explicitly. Do not present v3 APIs as if they work on v2.
- Flag deprecated APIs. If the documentation marks something as deprecated, warn the user and suggest the recommended replacement.
- When official docs and community answers disagree, trust the official docs for "what the API does" and community answers for "practical workarounds and edge cases."
- If you found information from multiple sources, briefly mention where key facts came from so the user can follow up.
Version-Specific Lookups
Libraries change between major versions. When the user specifies a version (or when their code implies one):
- Context7 typically returns documentation for the latest stable version. If the user is on an older version, the APIs shown may not exist or may behave differently.
- Use Ref to search for version-specific documentation. Many libraries host versioned docs (e.g.,
https://reactjs.org/docs/ vs. https://legacy.reactjs.org/). Include the version number in your Ref search query.
- When you cannot find version-specific docs, note this clearly: "I found documentation for version X, but you are using version Y. The behavior may differ."
- Pay special attention to migration guides and changelogs -- these are the best source for understanding what changed between versions.
Combining Tools
For comprehensive research, use both tools:
- Context7 for official API documentation and code examples.
- Ref for community solutions, tutorials, and edge cases.
When both tools return results, synthesize findings into actionable guidance. Do not dump raw documentation at the user -- extract the relevant parts and explain how they apply to the user's specific question.
1---2name: searching-docs3description: Search library/API documentation via Context7 and Ref MCP tools.4---56## Tool Selection78| Scenario | Tool | Reason |9|----------|------|--------|10| Known library, need code examples | Context7 | Optimized for retrieving code snippets |11| General API reference lookup | Context7 | Fast, structured documentation access |12| Obscure/niche library | Ref | Broader search across multiple sources |13| Concept explanation or tutorials | Ref | Better for prose and explanatory content |14| Debugging with error messages | Ref | Can search Stack Overflow, GitHub issues |15| Cross-library comparison | Ref | Searches across multiple documentation sources |16| Version-specific behavior | Both | Context7 for latest docs, Ref to find version-specific pages |17| Multi-library question | Both | Resolve each library separately, then combine findings |1819## Decision Flow20211. Is the library well-known (React, Python stdlib, popular npm packages)?22 - Yes: Start with Context7 -- it is faster and returns structured results.23 - No: Start with Ref -- it has broader coverage of niche and less popular libraries.24252. Do you need code snippets or API signatures?26 - Yes: Prefer Context7.27 - No (need explanations, tutorials, or community discussion): Prefer Ref.28293. Is the question version-specific (e.g., "I'm using React 17, not 18")?30 - If Context7 returns docs for the wrong version, fall back to Ref and search for version-specific documentation pages. Include the version number in your Ref query (e.g., "react 17 lifecycle methods").31 - Context7 typically serves the latest version of a library's docs. If the user is on an older version, verify that the API you found actually existed in their version.32334. Does the question span multiple libraries (e.g., "how to use pandas with SQLAlchemy")?34 - Resolve each library separately in Context7 (call `resolve-library-id` for each), then query each one.35 - Alternatively, use Ref with a combined query since it can search across sources.36375. Are you unsure which tool to use?38 - Try Context7 first since it is faster and returns structured results. If it returns insufficient results, fall back to Ref.39406. Did the first tool return insufficient results?41 - Yes: Try the other tool. See "Error Handling and Fallbacks" below.4243## Crafting Effective Queries4445Good queries are specific and include the library name, the function or concept, and the action. Avoid vague natural-language questions.4647**For Context7 `resolve-library-id`:**48- Use the library's canonical name. Keep it short.49- Good: `pandas`, `react`, `fastapi`, `express`50- Poor: `the python data analysis library`, `facebook's frontend framework`5152**For Context7 `query-docs`:**53- Be specific about the function, class, or concept. Include the action you want.54- Good: `read_csv skip rows` -- names the function and the parameter concern55- Good: `useEffect cleanup function` -- names the hook and the specific aspect56- Good: `Router middleware order of execution` -- names the component and the behavior57- Poor: `how to skip rows` -- too vague, missing function name58- Poor: `how does useEffect work` -- too broad, will return too much59- Poor: `middleware` -- too generic6061**For Ref `ref_search_documentation`:**62- Include the language or framework name in the query. Be descriptive but not conversational.63- Good: `python pandas read_csv skiprows parameter`64- Good: `express.js error handling middleware next function`65- Good: `rust serde deserialize enum variants`66- Poor: `how to skip rows in a csv file` -- missing library name67- Poor: `error handling` -- far too vague68- Poor: `why doesn't my middleware work` -- conversational, not searchable6970## Tool Usage7172**Context7 workflow:**731. Call `resolve-library-id` with the library name to get the Context7 library ID.74 - Example: resolve-library-id with query `pandas`75 - Example: resolve-library-id with query `react`76 - If multiple candidates are returned, pick the one with the highest snippet count and trust score. A library with 5000 snippets is almost certainly the correct one over a library with 12 snippets.772. Call `query-docs` with the returned library ID and a specific query.78 - Example: query-docs with library ID `/python/pandas` and query `read_csv skiprows parameter`79 - Example: query-docs with library ID `/facebook/react` and query `useEffect cleanup return function`8081**Ref workflow:**821. Call `ref_search_documentation` with a descriptive query including the language/framework name.83 - Example: `python pandas read_csv skip rows`84 - Example: `express.js middleware error handling next`85 - Example: `rust tokio spawn blocking vs spawn`862. Call `ref_read_url` with the exact URL from results (include the #hash portion if present).87 - Always use the full URL including any fragment identifier -- these point to the specific section relevant to the query.8889## Error Handling and Fallbacks9091**When a tool returns no results:**92- Rephrase the query. Remove overly specific terms and try broader keywords.93- Switch to the other tool. If Context7 found nothing, try Ref, and vice versa.94- For Context7: verify that `resolve-library-id` returned the correct library. Some libraries have non-obvious IDs.9596**When a tool returns too many results or irrelevant results:**97- Narrow the query. Add the specific function name, class name, or parameter.98- For Ref: add the language name to disambiguate (e.g., `python requests timeout` instead of `requests timeout`).99100**When `resolve-library-id` returns multiple candidates:**101- Compare the snippet count and trust/reputation score.102- The candidate with significantly more snippets is almost always the correct one.103- If two candidates have similar snippet counts, prefer the one whose name or description most closely matches the user's context (e.g., the Python `requests` library vs. an unrelated npm package also called `requests`).104105**When results seem outdated or conflict with what you know:**106- Flag this to the user. State which version the documentation appears to cover.107- Use Ref to search for the specific version's documentation or changelog.108- Do not silently use outdated information -- always note version discrepancies.109110## Synthesizing Results111112When combining information from multiple sources or tool calls:1131141. Prioritize official documentation over community answers. Official docs are the ground truth for API signatures, parameter names, and return types.1152. Note version discrepancies. If Context7 returns docs for v3 but the user is on v2, say so explicitly. Do not present v3 APIs as if they work on v2.1163. Flag deprecated APIs. If the documentation marks something as deprecated, warn the user and suggest the recommended replacement.1174. When official docs and community answers disagree, trust the official docs for "what the API does" and community answers for "practical workarounds and edge cases."1185. If you found information from multiple sources, briefly mention where key facts came from so the user can follow up.119120## Version-Specific Lookups121122Libraries change between major versions. When the user specifies a version (or when their code implies one):123124- Context7 typically returns documentation for the latest stable version. If the user is on an older version, the APIs shown may not exist or may behave differently.125- Use Ref to search for version-specific documentation. Many libraries host versioned docs (e.g., `https://reactjs.org/docs/` vs. `https://legacy.reactjs.org/`). Include the version number in your Ref search query.126- When you cannot find version-specific docs, note this clearly: "I found documentation for version X, but you are using version Y. The behavior may differ."127- Pay special attention to migration guides and changelogs -- these are the best source for understanding what changed between versions.128129## Combining Tools130131For comprehensive research, use both tools:1321. Context7 for official API documentation and code examples.1332. Ref for community solutions, tutorials, and edge cases.134135When both tools return results, synthesize findings into actionable guidance. Do not dump raw documentation at the user -- extract the relevant parts and explain how they apply to the user's specific question.