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

Function createExecutorMcpServer

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

Source from the content-addressed store, hash-verified

569// ---------------------------------------------------------------------------
570
571export const createExecutorMcpServer = <E extends Cause.YieldableError>(
572 config: ExecutorMcpServerConfig<E>,
573): Effect.Effect<McpServer> =>
574 Effect.gen(function* () {
575 const engine = "engine" in config ? config.engine : createExecutionEngine(config);
576 const description =
577 config.description ??
578 (yield* engine.getDescription.pipe(Effect.withSpan("mcp.host.get_description")));
579 // The same live integration inventory the description carries, re-used by
580 // the `skills` tool so the `execute` guide lists what is connected too.
581 const executeInventory = extractInventory(description);
582
583 // Captured at construction time. SDK callbacks fire later (often
584 // deferred past the outer Effect's await), so we use the runtime to
585 // re-enter Effect-land at each callback edge.
586 const context = yield* Effect.context<never>();
587 const debugEnabled = config.debug ?? readDebugDefault();
588 const debugLog = (event: string, data: Record<string, unknown>) => {
589 if (!debugEnabled) return;
590 // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: debug logging must tolerate non-serializable SDK capability snapshots
591 try {
592 console.error(`[executor:mcp] ${event} ${JSON.stringify(data)}`);
593 } catch {
594 console.error(`[executor:mcp] ${event}`, data);
595 }
596 };
597 const elicitationMode =
598 config.elicitationMode ??
599 ({
600 mode: "model",
601 } as const);
602 const onExecutionPaused = (executionId: string): Effect.Effect<void> =>
603 config.pausedExecutionHooks?.onExecutionPaused?.(executionId) ?? Effect.void;
604 const onResumeStarted = (executionId: string): Effect.Effect<void> =>
605 config.pausedExecutionHooks?.onResumeStarted?.(executionId) ?? Effect.void;
606 const onResumeSettled = (executionId: string): Effect.Effect<void> =>
607 config.pausedExecutionHooks?.onResumeSettled?.(executionId) ?? Effect.void;
608 const resumeWithLifecycle = (executionId: string, response: ResumeResponse) =>
609 Effect.gen(function* () {
610 yield* onResumeStarted(executionId);
611 return yield* engine.resume(executionId, response);
612 }).pipe(Effect.ensuring(onResumeSettled(executionId)));
613
614 const resolveParentSpan = (): Tracer.AnySpan | undefined => {
615 const ps = config.parentSpan;
616 return typeof ps === "function" ? ps() : ps;
617 };
618 const anchor = <A, EffE>(effect: Effect.Effect<A, EffE>): Effect.Effect<A, EffE> => {
619 const parent = resolveParentSpan();
620 return parent ? Effect.withParentSpan(effect, parent) : effect;
621 };
622 const runToolEffect = <EffE>(effect: Effect.Effect<McpToolResult, EffE>) =>
623 Effect.runPromiseWith(context)(
624 anchor(effect).pipe(
625 Effect.catchCause((cause) => Effect.succeed(toMcpFailureResult(cause))),
626 ),
627 );
628

Callers 7

makeMcpBuildServerFunction · 0.90
withClientFunction · 0.90
openSessionFunction · 0.90
buildMcpServerMethod · 0.90
buildMcpServerMethod · 0.90
createMcpRequestHandlerFunction · 0.90
runMcpStdioServerFunction · 0.90

Calls 14

createExecutionEngineFunction · 0.90
extractInventoryFunction · 0.85
readDebugDefaultFunction · 0.85
runToolEffectFunction · 0.85
skillsResultFunction · 0.85
resumeExecutionFunction · 0.85
parseJsonContentFunction · 0.85
capabilitySnapshotFunction · 0.85
debugLogFunction · 0.85
getElicitationSupportFunction · 0.85
syncMethod · 0.80

Tested by 2

withClientFunction · 0.72
openSessionFunction · 0.72