fix: folder search parameter

This commit is contained in:
Abdusshh 2025-04-08 20:29:04 +03:00
parent d7ca6b94e4
commit dd3b1661c1
3 changed files with 32 additions and 9 deletions

View File

@ -70,6 +70,19 @@ npm run lint
npm run build npm run build
``` ```
### Local Configuration
```json
{
"mcpServers": {
"context7": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/PARENT/FOLDER/context7-mcp/build/index.js"]
}
}
}
```
### Testing with MCP Inspector ### Testing with MCP Inspector
You can also use the MCP Inspector to test the tools by following the MCP documentation for setting up the inspector. You can also use the MCP Inspector to test the tools by following the MCP documentation for setting up the inspector.

View File

@ -80,7 +80,7 @@ server.tool(
libraryName: z libraryName: z
.string() .string()
.describe( .describe(
"Name of the library to retrieve documentation for (e.g., 'upstash-redis', 'nextjs'). Must match exactly a library name from 'list-available-docs'." "Name of the library to retrieve documentation for (e.g., 'mongodb/docs', 'vercel/nextjs'). Must match exactly a library name from 'list-available-docs'."
), ),
topic: z topic: z
.string() .string()

View File

@ -33,33 +33,43 @@ export async function fetchLibraryDocumentation(
topic: string = "" topic: string = ""
): Promise<string | null> { ): Promise<string | null> {
try { try {
let contextURL = `${CONTEXT7_BASE_URL}/${libraryName}/llms.txt`; // if libraryName has a "/" as the first character, remove it
const params = []; if (libraryName.startsWith("/")) {
libraryName = libraryName.slice(1);
}
// Handle folders parameter
let basePath = libraryName;
let folders = "";
if (libraryName.includes("?folders=")) {
const [path, foldersParam] = libraryName.split("?folders=");
basePath = path;
folders = foldersParam;
}
let contextURL = `${CONTEXT7_BASE_URL}/${basePath}/llms.txt`;
const params = [];
if (folders) {
params.push(`folders=${encodeURIComponent(folders)}`);
}
if (tokens) { if (tokens) {
params.push(`tokens=${tokens}`); params.push(`tokens=${tokens}`);
} }
if (topic) { if (topic) {
params.push(`topic=${encodeURIComponent(topic)}`); params.push(`topic=${encodeURIComponent(topic)}`);
} }
if (params.length > 0) { if (params.length > 0) {
contextURL += `?${params.join("&")}`; contextURL += `?${params.join("&")}`;
} }
const response = await fetch(contextURL); const response = await fetch(contextURL);
if (!response.ok) { if (!response.ok) {
console.error(`Failed to fetch documentation: ${response.status}`); console.error(`Failed to fetch documentation: ${response.status}`);
return null; return null;
} }
const text = await response.text(); const text = await response.text();
if (!text || text === "No content available" || text === "No context data available") { if (!text || text === "No content available" || text === "No context data available") {
return null; return null;
} }
return text; return text;
} catch (error) { } catch (error) {
console.error("Error fetching library documentation:", error); console.error("Error fetching library documentation:", error);