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

Function createExecutorMcpServer

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

Source from the content-addressed store, hash-verified

1090// ---------------------------------------------------------------------------
1091
1092export const createExecutorMcpServer = <E extends Cause.YieldableError>(
1093 config: ExecutorMcpServerConfig<E>,
1094): Effect.Effect<McpServer> =>
1095 Effect.gen(function* () {
1096 const engine = "engine" in config ? config.engine : createExecutionEngine(config);
1097 const description =
1098 config.description ??
1099 (yield* engine.getDescription.pipe(Effect.withSpan("mcp.host.get_description")));
1100 // The same live integration inventory the description carries, re-used by
1101 // the `skills` tool so the `execute` guide lists what is connected too.
1102 const executeInventory = extractInventory(description);
1103 // Artifacts are on unless this connection opted out (`?artifacts=false`).
1104 // One flag decides the whole surface: the tools, the shell resource, and
1105 // the skills catalog below.
1106 const artifactsEnabled = config.artifactsEnabled ?? true;
1107 const skillCatalog: readonly Skill[] = skillCatalogFor({ artifacts: artifactsEnabled });
1108 // Per-integration search tools are off unless this connection opted in
1109 // (`?search_tools=true`).
1110 const searchToolsEnabled = config.searchToolsEnabled ?? false;
1111
1112 // Captured at construction time. SDK callbacks fire later (often
1113 // deferred past the outer Effect's await), so we use the runtime to
1114 // re-enter Effect-land at each callback edge.
1115 const context = yield* Effect.context<never>();
1116 const debugEnabled = config.debug ?? readDebugDefault();
1117 const debugLog = (event: string, data: Record<string, unknown>) => {
1118 if (!debugEnabled) return;
1119 // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: debug logging must tolerate non-serializable SDK capability snapshots
1120 try {
1121 console.error(`[executor:mcp] ${event} ${JSON.stringify(data)}`);
1122 } catch {
1123 console.error(`[executor:mcp] ${event}`, data);
1124 }
1125 };
1126 const elicitationMode =
1127 config.elicitationMode ??
1128 ({
1129 mode: "model",
1130 } as const);
1131 const pauseDeadline = (): PausedExecutionDeadline | undefined => {
1132 const ttlMs = config.pausedExecutionLeaseMs;
1133 return ttlMs === undefined || ttlMs <= 0
1134 ? undefined
1135 : { ttlMs, expiresAt: new Date(Date.now() + ttlMs).toISOString() };
1136 };
1137 const onExecutionPaused = (
1138 executionId: string,
1139 deadline: PausedExecutionDeadline | undefined,
1140 ): Effect.Effect<void> =>
1141 config.pausedExecutionHooks?.onExecutionPaused?.(executionId, deadline) ?? Effect.void;
1142 const onResumeStarted = (executionId: string): Effect.Effect<void> =>
1143 config.pausedExecutionHooks?.onResumeStarted?.(executionId) ?? Effect.void;
1144 const onResumeSettled = (executionId: string): Effect.Effect<void> =>
1145 config.pausedExecutionHooks?.onResumeSettled?.(executionId) ?? Effect.void;
1146 const resumeWithLifecycle = (executionId: string, response: ResumeResponse) =>
1147 Effect.gen(function* () {
1148 yield* onResumeStarted(executionId);
1149 return yield* engine.resume(executionId, response);

Callers 14

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

Calls 15

createExecutionEngineFunction · 0.90
skillCatalogForFunction · 0.90
extractInventoryFunction · 0.85
readDebugDefaultFunction · 0.85
runToolEffectFunction · 0.85
skillsResultFunction · 0.85
resumeExecutionFunction · 0.85
parseJsonContentFunction · 0.85
searchNamespaceCodeFunction · 0.85
createArtifactFunction · 0.85

Tested by 6

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