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

Function createExecutorMcpServer

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

Source from the content-addressed store, hash-verified

1050// ---------------------------------------------------------------------------
1051
1052export const createExecutorMcpServer = <E extends Cause.YieldableError>(
1053 config: ExecutorMcpServerConfig<E>,
1054): Effect.Effect<McpServer> =>
1055 Effect.gen(function* () {
1056 const engine = "engine" in config ? config.engine : createExecutionEngine(config);
1057 const description =
1058 config.description ??
1059 (yield* engine.getDescription.pipe(Effect.withSpan("mcp.host.get_description")));
1060 // The same live integration inventory the description carries, re-used by
1061 // the `skills` tool so the `execute` guide lists what is connected too.
1062 const executeInventory = extractInventory(description);
1063 // Artifacts are on unless this connection opted out (`?artifacts=false`).
1064 // One flag decides the whole surface: the tools, the shell resource, and
1065 // the skills catalog below.
1066 const artifactsEnabled = config.artifactsEnabled ?? true;
1067 const skillCatalog: readonly Skill[] = skillCatalogFor({ artifacts: artifactsEnabled });
1068
1069 // Captured at construction time. SDK callbacks fire later (often
1070 // deferred past the outer Effect's await), so we use the runtime to
1071 // re-enter Effect-land at each callback edge.
1072 const context = yield* Effect.context<never>();
1073 const debugEnabled = config.debug ?? readDebugDefault();
1074 const debugLog = (event: string, data: Record<string, unknown>) => {
1075 if (!debugEnabled) return;
1076 // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: debug logging must tolerate non-serializable SDK capability snapshots
1077 try {
1078 console.error(`[executor:mcp] ${event} ${JSON.stringify(data)}`);
1079 } catch {
1080 console.error(`[executor:mcp] ${event}`, data);
1081 }
1082 };
1083 const elicitationMode =
1084 config.elicitationMode ??
1085 ({
1086 mode: "model",
1087 } as const);
1088 const pauseDeadline = (): PausedExecutionDeadline | undefined => {
1089 const ttlMs = config.pausedExecutionLeaseMs;
1090 return ttlMs === undefined || ttlMs <= 0
1091 ? undefined
1092 : { ttlMs, expiresAt: new Date(Date.now() + ttlMs).toISOString() };
1093 };
1094 const onExecutionPaused = (
1095 executionId: string,
1096 deadline: PausedExecutionDeadline | undefined,
1097 ): Effect.Effect<void> =>
1098 config.pausedExecutionHooks?.onExecutionPaused?.(executionId, deadline) ?? Effect.void;
1099 const onResumeStarted = (executionId: string): Effect.Effect<void> =>
1100 config.pausedExecutionHooks?.onResumeStarted?.(executionId) ?? Effect.void;
1101 const onResumeSettled = (executionId: string): Effect.Effect<void> =>
1102 config.pausedExecutionHooks?.onResumeSettled?.(executionId) ?? Effect.void;
1103 const resumeWithLifecycle = (executionId: string, response: ResumeResponse) =>
1104 Effect.gen(function* () {
1105 yield* onResumeStarted(executionId);
1106 return yield* engine.resume(executionId, response);
1107 }).pipe(Effect.ensuring(onResumeSettled(executionId)));
1108
1109 const localExecutionAlreadySettled = (executionId: string): Effect.Effect<boolean> =>

Callers 11

makeMcpBuildServerFunction · 0.90
startMcpHarnessForEngineFunction · 0.90
withClientFunction · 0.90
withClientFunction · 0.90
openSessionFunction · 0.90
buildMcpServerMethod · 0.90
buildMcpServerMethod · 0.90
createMcpRequestHandlerFunction · 0.90
runMcpStdioServerFunction · 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
createArtifactFunction · 0.85
editArtifactFunction · 0.85
listArtifactsFunction · 0.85

Tested by 4

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