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

Function handlerFor

packages/hosts/mcp/src/envelope.ts:300–338  ·  view source on GitHub ↗
(resource: McpResource)

Source from the content-addressed store, hash-verified

298 (signingKey ??= crypto.getRandomValues(new Uint8Array(32)));
299
300 const handlerFor = (resource: McpResource): McpHttpHandler => {
301 const key = mcpResourceKey(resource);
302 const cached = handlers.get(key);
303 if (cached) return cached;
304
305 const handler = createMcpHandler(
306 (context: McpRequestContext) => {
307 const request = context.requestInfo;
308 const inputs = request ? requestInputs.get(request) : undefined;
309 if (!request || !inputs) {
310 // oxlint-disable-next-line executor/no-effect-escape-hatch -- boundary: the third-party McpServerFactory Promise contract has no typed failure channel; missing documented request context is an SDK defect
311 return Effect.runPromise(Effect.die("Modern MCP request has no authenticated context"));
312 }
313 return Effect.runPromise(
314 Effect.gen(function* () {
315 const clientCapabilities = yield* clientCapabilitiesFromRequest(request);
316 const requestStatePrincipal = mcpRequestStatePrincipal(inputs.principal);
317 const requestStateBinding = yield* Effect.promise(() =>
318 mcpRequestStateBindingFromBody({
319 body: inputs.parsedBody,
320 principal: requestStatePrincipal,
321 resource,
322 }),
323 );
324 return yield* inputs.builder.build(inputs.principal, {
325 resource,
326 appsEnabled: appsEnabledForClientCapabilities(clientCapabilities),
327 requestStateSigningKey: getSigningKey(),
328 requestStatePrincipal,
329 ...(requestStateBinding === null ? {} : { requestStateBinding }),
330 });
331 }),
332 );
333 },
334 { legacy: "reject" },
335 );
336 handlers.set(key, handler);
337 return handler;
338 };
339
340 return {
341 fetch: async (request, principal, resource, builder) => {

Callers 1

makeModernMcpRouterFunction · 0.70

Calls 8

mcpResourceKeyFunction · 0.90
mcpRequestStatePrincipalFunction · 0.90
getSigningKeyFunction · 0.85
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected