MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / createExecutorMcpServer

Function createExecutorMcpServer

packages/hosts/mcp/src/tool-server.ts:1516–2920  ·  view source on GitHub ↗
(
  config: ExecutorMcpServerConfig<E>,
)

Source from the content-addressed store, hash-verified

1514// ---------------------------------------------------------------------------
1515
1516export 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 ({

Callers 15

makeMcpBuildServerFunction · 0.90
startMcpHarnessForEngineFunction · 0.90
withClientFunction · 0.90
withClientFunction · 0.90
buildServerFunction · 0.90
withClientFunction · 0.90
withClientFunction · 0.90
openSessionFunction · 0.90

Calls 15

createExecutionEngineFunction · 0.90
skillCatalogForFunction · 0.90
passthroughInstructionsFunction · 0.90
extractInventoryFunction · 0.85
readDebugDefaultFunction · 0.85
registerPassthroughToolsFunction · 0.85
runToolEffectFunction · 0.85
skillsResultFunction · 0.85
resumeExecutionFunction · 0.85
parseJsonContentFunction · 0.85

Tested by 7

startMcpHarnessForEngineFunction · 0.72
withClientFunction · 0.72
withClientFunction · 0.72
buildServerFunction · 0.72
withClientFunction · 0.72
withClientFunction · 0.72
openSessionFunction · 0.72