- Move MCP session registry and preview broker out of `Layers/` and `Services/` - Update imports, tests, and server wiring to use the new module layout
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import type { EnvironmentId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
|
|
import { PreviewAutomationUnavailableError } from "@t3tools/contracts";
|
|
import * as Context from "effect/Context";
|
|
import * as Effect from "effect/Effect";
|
|
|
|
export type McpCapability = "preview";
|
|
|
|
export interface McpInvocationScope {
|
|
readonly environmentId: EnvironmentId;
|
|
readonly threadId: ThreadId;
|
|
readonly providerSessionId: string;
|
|
readonly providerInstanceId: ProviderInstanceId;
|
|
readonly capabilities: ReadonlySet<McpCapability>;
|
|
readonly issuedAt: number;
|
|
readonly expiresAt: number;
|
|
}
|
|
|
|
export class McpInvocationContext extends Context.Service<
|
|
McpInvocationContext,
|
|
McpInvocationScope
|
|
>()("t3/mcp/McpInvocationContext") {}
|
|
|
|
export const requireMcpCapability = Effect.fn("mcp.requireCapability")(function* (
|
|
capability: McpCapability,
|
|
) {
|
|
const invocation = yield* McpInvocationContext;
|
|
if (!invocation.capabilities.has(capability)) {
|
|
return yield* new PreviewAutomationUnavailableError({
|
|
message: `MCP credential does not grant the ${capability} capability.`,
|
|
});
|
|
}
|
|
return invocation;
|
|
});
|