Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

26 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { verifyMcp } from "./mcp-readiness.mjs";
4
5test("MCP initializes, notifies, forwards negotiated headers and verifies action scopes", async () => {
6 const methods = [];
7 const fetcher = async (_url, options) => {
8 if (!options.body) return Response.json({ tools: [{ name: "repository", actions: [{ name: "get", scope: "repo:read" }] }], scopes_supported: ["repo:read"] });
9 const request = JSON.parse(options.body);
10 methods.push(request.method);
11 if (request.method === "initialize") return Response.json({ id: 1, result: { protocolVersion: "2025-03-26" } }, { headers: { "mcp-session-id": "test-session" } });
12 assert.equal(options.headers["MCP-Protocol-Version"], "2025-03-26");
13 assert.equal(options.headers["Mcp-Session-Id"], "test-session");
14 if (request.method === "notifications/initialized") {
15 assert.equal(request.id, undefined);
16 return new Response(null, { status: 202 });
17 }
18 return Response.json({ id: 2, result: { tools: [{ name: "repository", inputSchema: { type: "object", properties: { action: { enum: ["get"] } } } }] } });
19 };
20 assert.deepEqual(await verifyMcp("test-token", fetcher), { tools: 1, actions: 1 });
21 assert.deepEqual(methods, ["initialize", "notifications/initialized", "tools/list"]);
22});
23
24test("MCP authorization failures are reported without credential contents", async () => {
25 await assert.rejects(verifyMcp("secret", async () => new Response(null, { status: 401 })), /401/);
26});