1// A real upstream MCP endpoint for verifying credentials sent by Cloudflare.
2export default {
3 async fetch(request: Request): Promise<Response> {
4 if (new URL(request.url).pathname === "/health") {
5 return new Response("ready");
6 }
7 const authorization = request.headers.get("authorization");
8 const version =
9 authorization === "Bearer alchemy-mcp-rotation-v1"
10 ? "v1"
11 : authorization === "Bearer alchemy-mcp-rotation-v2"
12 ? "v2"
13 : undefined;
14 if (!version) return new Response("Unauthorized", { status: 401 });
15 if (request.method !== "POST") {
16 return new Response(null, { status: 405 });
17 }
18 const message = (await request.json()) as {
19 id?: number | string;
20 method: string;
21 };
22 if (message.id === undefined) return new Response(null, { status: 202 });
23 const result =
24 message.method === "initialize"
25 ? {
26 protocolVersion: "2025-03-26",
27 capabilities: { tools: {}, prompts: {} },
28 serverInfo: { name: "alchemy-credential-test", version: "1.0.0" },
29 }
30 : message.method === "tools/list"
31 ? {
32 tools: [
33 {
34 name: `authenticated_${version}`,
35 inputSchema: { type: "object" },
36 },
37 ],
38 }
39 : message.method === "prompts/list"
40 ? { prompts: [] }
41 : {};
42 return Response.json({ jsonrpc: "2.0", id: message.id, result });
43 },
44};