Context7 Platform -- Up-to-date docs for AI agents
fix: set isError on failed query-docs results (#2989)
Aleksei Kharitonovdd48abc13cb7
diff --git a/.changeset/query-docs-is-error.md b/.changeset/query-docs-is-error.mdnew file mode 100644index 00000000..653458f4--- /dev/null+++ b/.changeset/query-docs-is-error.md@@ -0,0 +1,5 @@+---+"@upstash/context7-mcp": patch+---++query-docs now sets `isError` on its result when the documentation request fails (invalid library ID, API or network error), so clients that branch on `isError` no longer treat the error text as documentation.diff --git a/packages/mcp/src/index.ts b/packages/mcp/src/index.tsindex d16cb338..171ba2bd 100644--- a/packages/mcp/src/index.ts+++ b/packages/mcp/src/index.ts@@ -348,6 +348,11 @@ Do not call this tool more than 3 times per question.`,text: response.data,},],+ // Flag failures at the protocol level. Without this an unset `isError`+ // defaults to success, so a caller that branches on `isError` treats an+ // error message (invalid ID, upstream failure) as documentation.+ // "No documentation found" is a valid answer, not an error.+ ...(response.outcome === "error" ? { isError: true } : {}),};});diff --git a/packages/mcp/test/integration.test.ts b/packages/mcp/test/integration.test.tsindex 0762eef6..edf1003b 100644--- a/packages/mcp/test/integration.test.ts+++ b/packages/mcp/test/integration.test.ts@@ -540,6 +540,16 @@ describe.each([}});+ test("flags a failed query-docs lookup as an error result", async () => {+ const result = await client.callTool({+ name: "query-docs",+ arguments: { libraryId: "/vercel/next.js", query: UPSTREAM_ERROR_QUERY },+ });+ expect(result.isError).toBe(true);+ const text = (result.content as { type: string; text: string }[])[0].text;+ expect(text).toContain("stub upstream failure");+ });+test("calls resolve-library-id end to end", async () => {const result = await client.callTool({name: "resolve-library-id",