( config: ExecutorMcpServerConfig<E>, )
| 401 | }); |
| 402 | |
| 403 | const createMcpAssembly = <E extends Cause.YieldableError>( |
| 404 | config: ExecutorMcpServerConfig<E>, |
| 405 | ): ExecutorMcpAssembly<McpServer, McpServerRequestContext> => { |
| 406 | const sessionful = config.sessionful ?? false; |
| 407 | const initialAppsEnabled = sessionful |
| 408 | ? (config.restoredAppsEnabled ?? config.appsEnabled) |
| 409 | : config.appsEnabled; |
| 410 | const requestStateCodec = (binding: string) => |
| 411 | createRequestStateCodec<NativeRequestState>({ |
| 412 | key: config.requestStateSigningKey, |
| 413 | ...(config.requestStateTtlSeconds === undefined |
| 414 | ? {} |
| 415 | : { ttlSeconds: config.requestStateTtlSeconds }), |
| 416 | bind: () => binding, |
| 417 | }); |
| 418 | const verifyRequestState = async (state: string, context: ServerContext) => { |
| 419 | const binding = await requestStateBindingForContext( |
| 420 | config.requestStateBinding, |
| 421 | config.requestStatePrincipal, |
| 422 | context, |
| 423 | ); |
| 424 | const decoded = await requestStateCodec(binding).verify(state, context); |
| 425 | return Effect.runPromise(Schema.decodeUnknownEffect(NativeRequestStateSchema)(decoded)); |
| 426 | }; |
| 427 | const server = new McpServer( |
| 428 | { name: "executor", version: "1.0.0" }, |
| 429 | { |
| 430 | capabilities: { resources: {}, tools: {} }, |
| 431 | requestState: { verify: verifyRequestState }, |
| 432 | }, |
| 433 | ); |
| 434 | |
| 435 | const registerTool: ExecutorMcpAssembly<McpServer, McpServerRequestContext>["registerTool"] = ( |
| 436 | name, |
| 437 | toolConfig, |
| 438 | callback, |
| 439 | ) => { |
| 440 | const inputSchema = z.object(toolConfig.inputSchema); |
| 441 | return server.registerTool<z.ZodObject<z.ZodRawShape>, typeof inputSchema>( |
| 442 | name, |
| 443 | { ...toolConfig, inputSchema }, |
| 444 | async (args, context) => toolResult(await callback(args, requestJoinKeys(context))), |
| 445 | ); |
| 446 | }; |
| 447 | |
| 448 | const registerApp: ExecutorMcpAssembly<McpServer, McpServerRequestContext>["registerAppTool"] = ( |
| 449 | name, |
| 450 | toolConfig, |
| 451 | callback, |
| 452 | ) => { |
| 453 | const inputSchema = z.object(toolConfig.inputSchema); |
| 454 | const metadata = normalizedAppMetadata(toolConfig._meta); |
| 455 | if (!sessionful && !config.appsEnabled && visibilityIncludes(metadata, "model")) { |
| 456 | const plainMetadata = withoutAppMetadata(metadata); |
| 457 | return server.registerTool<z.ZodObject<z.ZodRawShape>, typeof inputSchema>( |
| 458 | name, |
| 459 | { |
| 460 | ...toolConfig, |
no test coverage detected