mirror of
https://github.com/upstash/context7.git
synced 2025-12-14 08:38:08 +00:00
fix: folder search parameter
This commit is contained in:
parent
d7ca6b94e4
commit
dd3b1661c1
13
README.md
13
README.md
@ -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.
|
||||||
|
|||||||
@ -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()
|
||||||
@ -93,7 +93,7 @@ server.tool(
|
|||||||
.min(5000)
|
.min(5000)
|
||||||
.optional()
|
.optional()
|
||||||
.describe(
|
.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 = "" }) => {
|
async ({ libraryName, tokens = 5000, topic = "" }) => {
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user