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

Function forward

packages/hosts/mcp/src/in-memory-session-store.ts:387–407  ·  view source on GitHub ↗
(
    sessionId: string,
    principal: Principal,
    resource: McpResource,
    request: Request,
  )

Source from the content-addressed store, hash-verified

385
386 /** Forward to an existing session, enforcing ownership against the principal. */
387 const forward = (
388 sessionId: string,
389 principal: Principal,
390 resource: McpResource,
391 request: Request,
392 ): Effect.Effect<McpDispatchResult> => {
393 const transport = transports.get(sessionId);
394 const owner = owners.get(sessionId);
395 if (!transport || !owner) return Effect.succeed("not-found");
396 if (!sessionOwnerMatches(owner, principal, resource)) return Effect.succeed("forbidden");
397 owners.set(sessionId, { principal, resource });
398 touch(sessionId);
399 // Claim before the await, release in the finalizer — `runHandleRequest`
400 // already recovers every failure to a 500, but `ensuring` also covers an
401 // interrupt, so the counter cannot be left permanently raised (which would
402 // make the session immortal, the opposite leak).
403 beginRequest(sessionId);
404 return runHandleRequest(transport, request, orgWriteAccessForPrincipal(principal)).pipe(
405 Effect.ensuring(Effect.sync(() => endRequest(sessionId))),
406 );
407 };
408
409 /**
410 * The browser-mode wiring for a create request: when the client asks for

Callers 1

Calls 9

sessionOwnerMatchesFunction · 0.85
touchFunction · 0.85
beginRequestFunction · 0.85
runHandleRequestFunction · 0.85
endRequestFunction · 0.85
getMethod · 0.65
setMethod · 0.65
syncMethod · 0.65

Tested by

no test coverage detected