MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / handleMcp

Function handleMcp

packages/core/test-servers/src/worker.ts:338–353  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

336const mcpTransports = new Map<string, WebStandardStreamableHTTPServerTransport>();
337
338const handleMcp = async (request: Request) => {
339 if (!isAuthorized(request)) return unauthorized(request);
340 const sessionId = request.headers.get("mcp-session-id") ?? undefined;
341 const existing = sessionId ? mcpTransports.get(sessionId) : undefined;
342 if (sessionId && !existing) return text("Session not found", { status: 404 });
343 if (existing) return existing.handleRequest(request);
344
345 const transport = new WebStandardStreamableHTTPServerTransport({
346 sessionIdGenerator: () => crypto.randomUUID(),
347 onsessioninitialized: (sid) => {
348 mcpTransports.set(sid, transport);
349 },
350 });
351 await createMcpServer().connect(transport);
352 return transport.handleRequest(request);
353};
354
355const handleRequest = async (request: Request): Promise<Response> => {
356 const url = new URL(request.url);

Callers 1

handleRequestFunction · 0.85

Calls 7

isAuthorizedFunction · 0.85
textFunction · 0.85
createMcpServerFunction · 0.85
setMethod · 0.80
unauthorizedFunction · 0.70
getMethod · 0.65
connectMethod · 0.65

Tested by

no test coverage detected