| 1514 | // --------------------------------------------------------------------------- |
| 1515 | |
| 1516 | export const createExecutorMcpServer = <E extends Cause.YieldableError>( |
| 1517 | config: ExecutorMcpServerConfig<E>, |
| 1518 | ): Effect.Effect<McpServer, McpPassthroughUnavailableError> => |
| 1519 | Effect.gen(function* () { |
| 1520 | const engine = "engine" in config ? config.engine : createExecutionEngine(config); |
| 1521 | const description = |
| 1522 | config.description ?? |
| 1523 | (yield* engine.getDescription.pipe(Effect.withSpan("mcp.host.get_description"))); |
| 1524 | // The same live integration inventory the description carries, re-used by |
| 1525 | // the `skills` tool so the `execute` guide lists what is connected too. |
| 1526 | const executeInventory = extractInventory(description); |
| 1527 | // Artifacts are on unless this connection opted out (`?artifacts=false`). |
| 1528 | // One flag decides the whole surface: the tools, the shell resource, and |
| 1529 | // the skills catalog below. |
| 1530 | const artifactsEnabled = config.artifactsEnabled ?? true; |
| 1531 | const skillCatalog: readonly Skill[] = |
| 1532 | config.mode === "passthrough" |
| 1533 | ? [ |
| 1534 | SEARCH_INVOKE_SKILL, |
| 1535 | ...skillCatalogFor({ |
| 1536 | artifacts: artifactsEnabled && config.loadAppShellHtml !== undefined, |
| 1537 | discovery: "search-invoke", |
| 1538 | }), |
| 1539 | ] |
| 1540 | : skillCatalogFor({ artifacts: artifactsEnabled }); |
| 1541 | // Per-integration search tools are off unless this connection opted in |
| 1542 | // (`?search_tools=true`). |
| 1543 | const searchToolsEnabled = config.searchToolsEnabled ?? false; |
| 1544 | // Passthrough (`?mode=passthrough`) replaces the codemode surface |
| 1545 | // wholesale. The flag is read once here and every codemode-only |
| 1546 | // registration below is gated on it, so the two surfaces cannot leak into |
| 1547 | // each other. |
| 1548 | const mode: McpToolMode = config.mode ?? "codemode"; |
| 1549 | const passthrough = mode === "passthrough"; |
| 1550 | if (passthrough && (!config.tools || !config.connections || !config.integrations)) { |
| 1551 | return yield* new McpPassthroughUnavailableError({ |
| 1552 | reason: |
| 1553 | "passthrough mode requires tool list/schema, connection list, and integration list APIs", |
| 1554 | }); |
| 1555 | } |
| 1556 | |
| 1557 | // Captured at construction time. SDK callbacks fire later (often |
| 1558 | // deferred past the outer Effect's await), so we use the runtime to |
| 1559 | // re-enter Effect-land at each callback edge. |
| 1560 | const context = yield* Effect.context<never>(); |
| 1561 | const debugEnabled = config.debug ?? readDebugDefault(); |
| 1562 | const debugLog = (event: string, data: Record<string, unknown>) => { |
| 1563 | if (!debugEnabled) return; |
| 1564 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: debug logging must tolerate non-serializable SDK capability snapshots |
| 1565 | try { |
| 1566 | console.error(`[executor:mcp] ${event} ${JSON.stringify(data)}`); |
| 1567 | } catch { |
| 1568 | console.error(`[executor:mcp] ${event}`, data); |
| 1569 | } |
| 1570 | }; |
| 1571 | const elicitationMode = |
| 1572 | config.elicitationMode ?? |
| 1573 | ({ |