mirror of
https://github.com/upstash/context7.git
synced 2026-01-07 12:41:56 +00:00
feat: improve library search results with stars and snippets info, update descriptions
This commit is contained in:
parent
99a74eb5ee
commit
515b8e200b
27
src/index.ts
27
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}`,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user