Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion apps/docs-mcp/src/__tests__/mcp.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { describe, expect, test } from "vitest";
import { describe, expect, test, vi } from "vitest";
import { app } from "../index";

describe("private MCP transport", () => {
Expand Down Expand Up @@ -34,6 +34,61 @@ describe("private MCP transport", () => {
}
});

test.each([
{
args: { libs: ["nextjs"] },
error:
"Failed to list features: Set OPENROUTER_API_KEY on the docs-mcp worker",
name: "get-available-features",
},
{
args: { query: "tracing" },
error:
"Failed to search docs: Failed to fetch https://docs.sentry.io/doctree.json: 503 Service Unavailable",
name: "search-docs",
},
])("marks $name failures as MCP errors", async ({ args, error, name }) => {
vi.stubGlobal(
"fetch",
vi.fn(
async () =>
new Response("Unavailable", {
status: 503,
statusText: "Service Unavailable",
}),
),
);

const client = new Client({ name: "docs-mcp-test", version: "1.0.0" });
const transport = new StreamableHTTPClientTransport(
new URL("https://docs-mcp.internal/mcp"),
{
fetch: async (input, init) =>
await app.request(new Request(input, init), undefined, {
CF_VERSION_METADATA: { id: "test", tag: "test", timestamp: "test" },
}),
},
);

try {
await client.connect(transport);
const result = await client.callTool({ arguments: args, name });

expect(result).toEqual({
content: [
{
text: JSON.stringify({ error }),
type: "text",
},
],
isError: true,
});
} finally {
vi.unstubAllGlobals();
await client.close();
}
});

test("rejects MCP requests outside the service binding", async () => {
const response = await app.request(
"https://docs-mcp.getsentry.workers.dev/mcp",
Expand Down
1 change: 1 addition & 0 deletions apps/docs-mcp/src/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function errorEnvelope(message: string) {
type: "text" as const,
},
],
isError: true,
};
}

Expand Down
Loading