(
sessionId: string,
principal: Principal,
resource: McpResource,
request: Request,
)
| 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 |
no test coverage detected