Repository Public MIT
1import { handleMcpRequest } from "@skills/registry-mcp";2import { clientIp } from "@/server/context";3import { env } from "@/server/env";4import { ApiError } from "@/server/errors";5import { rateLimit } from "@/server/ratelimit";67export const dynamic = "force-dynamic";89/** MCP Streamable HTTP endpoint (stateless). Tools call the REST API over loopback with the caller's bearer token. */10async function h(req: Request) {11 const ip = clientIp(req.headers);12 try {13 rateLimit("mcp", ip);14 } catch (e) {15 const err = e as ApiError;16 return new Response(JSON.stringify({ jsonrpc: "2.0", error: { code: -32000, message: err.message }, id: null }), { status: 429, headers: { "Content-Type": "application/json", ...(err.headers ?? {}) } });17 }18 return handleMcpRequest(req, { apiBaseUrl: env.internalUrl, clientIp: ip });19}20export { h as GET, h as POST, h as DELETE };21