diff --git a/src/index.ts b/src/index.ts index d41baa0..2387459 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,7 +37,17 @@ const server = new McpServer({ // Register Context7 tools server.tool( "resolve-library-id", - "Required first step: Resolves a general package name into a Context7-compatible library ID. Must be called before using 'get-library-docs' to retrieve a valid Context7-compatible library ID.", + `Resolves a package 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. + +When selecting the best match, consider: +- Name similarity to the query +- Description relevance +- Code Snippet count (documentation coverage) +- GitHub Stars (popularity) + +Return the selected library ID and explain your choice. If there are multiple good matches, mention this but proceed with the most relevant one.`, { libraryName: z .string() @@ -74,7 +84,20 @@ server.tool( content: [ { type: "text", - text: "Available libraries and their Context7-compatible library IDs:\n\n" + resultsText, + text: `Available Libraries (top matches): + +Each result includes: +- Library ID: Context7-compatible identifier (format: /org/repo) +- Name: Library or package name +- Description: Short summary +- Code Snippets: Number of available code examples +- GitHub Stars: Popularity indicator + +For best results, select libraries based on name match, popularity (stars), snippet coverage, and relevance to your use case. + +--- + +${resultsText}`, }, ], }; diff --git a/src/lib/types.ts b/src/lib/types.ts index dcf88d5..f107b70 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -8,6 +8,7 @@ export interface SearchResult { totalTokens: number; totalSnippets: number; totalPages: number; + stars: number; } export interface SearchResponse { @@ -15,11 +16,4 @@ export interface SearchResponse { } // Version state is still needed for validating search results -export type DocumentState = - | "initial" - | "parsed" - | "finalized" - | "invalid_docs" - | "error" - | "stop" - | "delete"; +export type DocumentState = "initial" | "finalized" | "error" | "delete"; diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 849112a..e949058 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -6,7 +6,11 @@ import { SearchResponse, SearchResult } from "./types.js"; * @returns Formatted search result string */ export function formatSearchResult(result: SearchResult): string { - return `Title: ${result.title}\n\nContext7-compatible library ID: ${result.id}\n\nDescription: ${result.description}`; + return `- Title: ${result.title} +- Context7-compatible library ID: ${result.id} +- Description: ${result.description} +- Code Snippets: ${result.totalSnippets} +- GitHub Stars: ${result.stars}`; } /** @@ -20,5 +24,5 @@ export function formatSearchResults(searchResponse: SearchResponse): string { } const formattedResults = searchResponse.results.map(formatSearchResult); - return formattedResults.join("\n\n--------------------\n"); + return formattedResults.join("\n---\n"); }