Skip to content

Context7 Platform -- Up-to-date docs for AI agents

feat: add version support in search results and update descriptions

Abdusshhce2a63a37ac0
diff --git a/src/index.ts b/src/index.ts
index b1b49890..e5a96f23 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -39,7 +39,7 @@ server.tool(
"resolve-library-id",
`Resolves a package/product name to a Context7-compatible library ID and returns a list of matching libraries.
-You MUST call this function before 'get-library-docs' to obtain a valid Context7-compatible library ID UNLESS the user explicitly provides a library ID in the format 'library:/org/project' or 'library:/org/project/version' in their query.
+You MUST call this function before 'get-library-docs' to obtain a valid Context7-compatible library ID UNLESS the user explicitly provides a library ID in the format '/org/project' or '/org/project/version' in their query.
Selection Process:
1. Analyze the query to understand what library/package the user is looking for
@@ -95,7 +95,7 @@ For ambiguous queries, request clarification before proceeding with a best-guess
text: `Available Libraries (top matches):
Each result includes:
-- Library ID: Context7-compatible identifier (format: /org/repo)
+- Library ID: Context7-compatible identifier (format: /org/project)
- Name: Library or package name
- Description: Short summary
- Code Snippets: Number of available code examples
@@ -115,12 +115,12 @@ ${resultsText}`,
server.tool(
"get-library-docs",
- "Fetches up-to-date documentation for a library. You must call 'resolve-library-id' first to obtain the exact Context7-compatible library ID required to use this tool, UNLESS the user explicitly provides a library ID in the format 'library:/org/project' or 'library:/org/project/version' in their query.",
+ "Fetches up-to-date documentation for a library. You must call 'resolve-library-id' first to obtain the exact Context7-compatible library ID required to use this tool, UNLESS the user explicitly provides a library ID in the format '/org/project' or '/org/project/version' in their query.",
{
context7CompatibleLibraryID: z
.string()
.describe(
- "Exact Context7-compatible library ID (e.g., 'mongodb/docs', 'vercel/nextjs', 'supabase/supabase', 'vercel/nextjs/v14.3.0-canary.87') retrieved from 'resolve-library-id' or directly from user query in the format 'library:/org/project' or 'library:/org/project/version'."
+ "Exact Context7-compatible library ID (e.g., '/mongodb/docs', '/vercel/next.js', '/supabase/supabase', '/vercel/next.js/v14.3.0-canary.87') retrieved from 'resolve-library-id' or directly from user query in the format '/org/project' or '/org/project/version'."
),
topic: z
.string()
diff --git a/src/lib/types.ts b/src/lib/types.ts
index 6bfe10f4..46e050b5 100644
--- a/src/lib/types.ts
+++ b/src/lib/types.ts
@@ -10,6 +10,7 @@ export interface SearchResult {
totalPages: number;
stars?: number;
trustScore?: number;
+ versions?: string[];
}
export interface SearchResponse {
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index 742e9bf0..bb4912c1 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -25,6 +25,11 @@ export function formatSearchResult(result: SearchResult): string {
formattedResult.push(`- Trust Score: ${result.trustScore}`);
}
+ // Only add versions if it's a valid value
+ if (result.versions !== undefined && result.versions.length > 0) {
+ formattedResult.push(`- Versions: ${result.versions.join(", ")}`);
+ }
+
// Join all parts with newlines
return formattedResult.join("\n");
}