Context7 Platform -- Up-to-date docs for AI agents
refactor: use library instead of package
Abdusshh39a43d5b1d05
diff --git a/README.md b/README.mdindex 6dca4821..7baf319e 100644--- a/README.md+++ b/README.md@@ -1,12 +1,12 @@# Context7 MCP Server-In this repository, we provide an MCP Server for [Context7](https://context7.com), which offers access to high-quality documentation for popular packages and libraries.+In this repository, we provide an MCP Server for [Context7](https://context7.com), which offers access to high-quality documentation for popular libraries.-This lets you use Cursor, Windsurf, Claude Desktop, or any MCP Client, to use natural language to search and access documentation for packages, e.g.:+This lets you use Cursor, Windsurf, Claude Desktop, or any MCP Client, to use natural language to search and access documentation for libraries, e.g.:- "What are the main features of React hooks?"- "How do I implement authentication with Next.js?"-- "Show me documentation for Upstash Redis"+- "Rate limiting with Redis"- "Get examples of using React Query"## Usage@@ -46,11 +46,11 @@ Add this to your Windsurf MCP config file. For more info, check the [Windsurf MC### Tools-- `list-available-packages`: Lists all available documentation packages from Context7-- `get-package-documentation`: Retrieves documentation for a specific package with options for:- - `packageName`: Name of the package to retrieve docs for- - `topic`: Specific topic within the package to focus the documentation on- - `tokens`: Maximum number of tokens to retrieve (default: 5000)+- `list-available-docs`: Lists all available documentation libraries from Context7+- `get-library-documentation`: Retrieves documentation for a specific library with options for:+ - `libraryName`: Name of the library to retrieve docs for+ - `topic`: Specific topic within the library+ - `tokens`: Maximum tokens to retrieve (default: 5000)## Developmentdiff --git a/src/index.ts b/src/index.tsindex 132c8364..940167f5 100644--- a/src/index.ts+++ b/src/index.ts@@ -3,13 +3,13 @@import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";import { z } from "zod";-import { fetchProjects, fetchPackageDocumentation } from "./lib/api.js";+import { fetchProjects, fetchLibraryDocumentation } from "./lib/api.js";import { formatProjectsList } from "./lib/utils.js";// Create server instanceconst server = new McpServer({name: "Context7",- description: "Retrieves documentation for packages.",+ description: "Retrieves documentation and code examples for software libraries.",version: "1.0.0",capabilities: {resources: {},@@ -19,8 +19,8 @@ const server = new McpServer({// Register Context7 toolsserver.tool(- "list-available-packages",- "Lists all packages from Context7. The package names can be used with 'get-package-documentation' to retrieve documentation.",+ "list-available-docs",+ "Lists all available library documentation from Context7. The library names can be used with 'get-library-documentation' to retrieve documentation.",async () => {const projects = await fetchProjects();@@ -29,7 +29,7 @@ server.tool(content: [{type: "text",- text: "Failed to retrieve packages data from Context7",+ text: "Failed to retrieve library documentation data from Context7",},],};@@ -43,7 +43,7 @@ server.tool(content: [{type: "text",- text: "No finalized documentation packages available",+ text: "No finalized documentation libraries available",},],};@@ -63,18 +63,19 @@ server.tool();server.tool(- "get-package-documentation",- "Retrieves documentation for a specific package from Context7. Use 'list-available-packages' first to see what's available.",+ "get-library-documentation",+ "Retrieves documentation for a specific library from Context7. Use 'list-available-docs' first to see what's available.",{- packageName: z+ libraryName: z.string().describe(- "Name of the package/library to retrieve documentation for (e.g., 'upstash-redis', 'nextjs'). Must match exactly a package name from 'list-available-packages'."+ "Name of the library to retrieve documentation for (e.g., 'upstash-redis', 'nextjs'). Must match exactly a library name from 'list-available-docs'."),topic: z.string()+ .optional().describe(- "Specific topic within the package to focus the documentation on (e.g., 'hooks', 'routing')."+ "Specific topic within the library to focus the documentation on (e.g., 'hooks', 'routing')."),tokens: z.number()@@ -84,15 +85,15 @@ server.tool("Maximum number of tokens of documentation to retrieve (default: 5000).Higher values provide more comprehensive documentation but use more context window."),},- async ({ packageName, tokens = 5000, topic = "" }) => {- const documentationText = await fetchPackageDocumentation(packageName, tokens, topic);+ async ({ libraryName, tokens = 5000, topic = "" }) => {+ const documentationText = await fetchLibraryDocumentation(libraryName, tokens, topic);if (!documentationText) {return {content: [{type: "text",- text: "Documentation not found or not finalized for this package. Verify you've provided a valid package name exactly as listed by the 'list-available-packages' tool.",+ text: "Documentation not found or not finalized for this library. Verify you've provided a valid library name exactly as listed by the 'list-available-docs' tool.",},],};diff --git a/src/lib/api.ts b/src/lib/api.tsindex 1e881747..71364ada 100644--- a/src/lib/api.ts+++ b/src/lib/api.ts@@ -21,19 +21,19 @@ export async function fetchProjects(): Promise<Project[] | null> {}/**- * Fetches documentation context for a specific package- * @param packageName The package name to fetch documentation for+ * Fetches documentation context for a specific library+ * @param libraryName The library name to fetch documentation for* @param tokens Number of tokens to retrieve (default: 5000)* @param topic Optional topic to rerank context for* @returns The documentation text or null if the request fails*/-export async function fetchPackageDocumentation(- packageName: string,+export async function fetchLibraryDocumentation(+ libraryName: string,tokens: number = 5000,topic: string = ""): Promise<string | null> {try {- let contextURL = `${CONTEXT7_BASE_URL}/${packageName}/llm.txt`;+ let contextURL = `${CONTEXT7_BASE_URL}/${libraryName}/llm.txt`;const params = [];if (tokens) {@@ -62,7 +62,7 @@ export async function fetchPackageDocumentation(return text;} catch (error) {- console.error("Error fetching package documentation:", error);+ console.error("Error fetching library documentation:", error);return null;}}diff --git a/src/lib/utils.ts b/src/lib/utils.tsindex a12fb6b1..23d402ea 100644--- a/src/lib/utils.ts+++ b/src/lib/utils.ts@@ -6,7 +6,7 @@ import { Project } from "./types.js";* @returns Formatted project string*/export function formatProject(project: Project): string {- return `Title: ${project.settings.title}\nPackage name: ${project.settings.project}\n`;+ return `Title: ${project.settings.title}\nLibrary name: ${project.settings.project}\n`;}/**@@ -16,5 +16,5 @@ export function formatProject(project: Project): string {*/export function formatProjectsList(projects: Project[]): string {const formattedProjects = projects.map(formatProject);- return `${formattedProjects.length} available documentation packages:\n\n${formattedProjects.join("\n")}`;+ return `${formattedProjects.length} available documentation libraries:\n\n${formattedProjects.join("\n")}`;}