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
```
### Local Configuration
```json
{
"mcpServers": {
"context7": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/PARENT/FOLDER/context7-mcp/build/index.js"]
}
}
}
```
### 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.

View File

@ -80,7 +80,7 @@ server.tool(
libraryName: z
.string()
.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
.string()
@ -93,7 +93,7 @@ server.tool(
.min(5000)
.optional()
.describe(
"Maximum number of tokens of documentation to retrieve (default: 5000).Higher values provide more comprehensive documentation but use more context window."
"Maximum number of tokens of documentation to retrieve (default: 5000). Higher values provide more comprehensive documentation but use more context window."
),
},
async ({ libraryName, tokens = 5000, topic = "" }) => {

View File

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