- Register orchestration tools on the MCP HTTP server - Grant orchestration capability to MCP sessions - Add service and integration coverage for delegated tasks and thread creation
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import {
|
|
type EnvironmentId,
|
|
PreviewAutomationUnavailableError,
|
|
type ProviderInstanceId,
|
|
type ThreadId,
|
|
} from "@t3tools/contracts";
|
|
import * as Context from "effect/Context";
|
|
import * as Effect from "effect/Effect";
|
|
|
|
export type McpCapability = "preview" | "orchestration";
|
|
|
|
export interface McpInvocationScope {
|
|
readonly environmentId: EnvironmentId;
|
|
readonly threadId: ThreadId;
|
|
readonly providerSessionId: string;
|
|
readonly providerInstanceId: ProviderInstanceId;
|
|
readonly capabilities: ReadonlySet<McpCapability>;
|
|
readonly issuedAt: 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({
|
|
capability,
|
|
environmentId: invocation.environmentId,
|
|
threadId: invocation.threadId,
|
|
providerSessionId: invocation.providerSessionId,
|
|
providerInstanceId: invocation.providerInstanceId,
|
|
});
|
|
}
|
|
return invocation;
|
|
});
|