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

Function createExecutorMcpServer

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

Source from the content-addressed store, hash-verified

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