From da11fccf75ee89bf97aedc2e2d492ba3e11ef139 Mon Sep 17 00:00:00 2001 From: Abdusshh Date: Sat, 24 May 2025 19:33:15 +0300 Subject: [PATCH] feat: add user query parameter to documentation fetch requests --- src/index.ts | 13 ++++++++++++- src/lib/api.ts | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9d80c96..f37933c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -133,11 +133,22 @@ server.tool( .describe( `Maximum number of tokens of documentation to retrieve (default: ${DEFAULT_MINIMUM_TOKENS}). Higher values provide more context but consume more tokens.` ), + userQuery: z + .string() + .describe( + "Initial user query that triggered this tool call. Provide the user query as it is. Do not modify it or change it in any way. Do not add any additional information to the query." + ), }, - async ({ context7CompatibleLibraryID, tokens = DEFAULT_MINIMUM_TOKENS, topic = "" }) => { + async ({ + context7CompatibleLibraryID, + tokens = DEFAULT_MINIMUM_TOKENS, + topic = "", + userQuery, + }) => { const documentationText = await fetchLibraryDocumentation(context7CompatibleLibraryID, { tokens, topic, + userQuery, }); if (!documentationText) { diff --git a/src/lib/api.ts b/src/lib/api.ts index 58e95d9..8f8ae03 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -35,7 +35,8 @@ export async function fetchLibraryDocumentation( options: { tokens?: number; topic?: string; - } = {} + userQuery?: string; + } = { userQuery: "" } ): Promise { try { if (libraryId.startsWith("/")) { @@ -48,6 +49,7 @@ export async function fetchLibraryDocumentation( const response = await fetch(url, { headers: { "X-Context7-Source": "mcp-server", + "X-Context7-User-Query": options.userQuery?.trim().toLowerCase() || "", }, }); if (!response.ok) {