Skip to content

Context7 Platform -- Up-to-date docs for AI agents

fix: use fallback to globalApiKey in search tool (#1255)

Enes Gulesa5228fde0d6f
diff --git a/.changeset/tired-poems-fold.md b/.changeset/tired-poems-fold.md
new file mode 100644
index 00000000..319e963c
--- /dev/null
+++ b/.changeset/tired-poems-fold.md
@@ -0,0 +1,5 @@
+---
+"@upstash/context7-mcp": patch
+---
+
+Fix API key not being passed in resolve-library-id tool when using stdio transport
\ No newline at end of file
diff --git a/packages/mcp/src/index.ts b/packages/mcp/src/index.ts
index 3ad7d122..3c194a1c 100644
--- a/packages/mcp/src/index.ts
+++ b/packages/mcp/src/index.ts
@@ -141,10 +141,11 @@ For ambiguous queries, request clarification before proceeding with a best-guess
},
async ({ libraryName }) => {
const ctx = requestContext.getStore();
+ const apiKey = ctx?.apiKey || globalApiKey;
const searchResponse: SearchResponse = await searchLibraries(
libraryName,
ctx?.clientIp,
- ctx?.apiKey
+ apiKey
);
if (!searchResponse.results || searchResponse.results.length === 0) {