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

Function executeCode

packages/hosts/mcp/src/tool-server.ts:1675–1723  ·  view source on GitHub ↗
(
      code: string,
      extra: McpRequestJoinKeys,
    )

Source from the content-addressed store, hash-verified

1673 .pipe(Effect.map(toMcpResult));
1674
1675 const executeCode = (
1676 code: string,
1677 extra: McpRequestJoinKeys,
1678 ): Effect.Effect<McpToolResult, E> =>
1679 Effect.gen(function* () {
1680 yield* startMarker("mcp.host.tool.execute.start", {
1681 "mcp.tool.name": "execute",
1682 "mcp.execute.code_length": code.length,
1683 });
1684 debugLog("execute.call", {
1685 elicitationMode: elicitationMode.mode,
1686 elicitationSupport: getElicitationSupport(server),
1687 clientCapabilities: server.server.getClientCapabilities() ?? null,
1688 codeLength: code.length,
1689 });
1690 if (elicitationMode.mode === "native") {
1691 return yield* executeWithNativeElicitation(code, extra);
1692 }
1693 const outcome = yield* engine.executeWithPause(code);
1694 debugLog("execute.paused_flow_result", {
1695 status: outcome.status,
1696 executionId: outcome.status === "paused" ? outcome.execution.id : undefined,
1697 interactionKind:
1698 outcome.status === "paused"
1699 ? pausedInteractionKind(outcome.execution.elicitationContext.request)
1700 : undefined,
1701 });
1702 if (outcome.status === "paused") {
1703 const deadline = pauseDeadline();
1704 yield* Effect.annotateCurrentSpan({
1705 "mcp.execute.paused": true,
1706 "mcp.execute.paused_execution_id": outcome.execution.id,
1707 "mcp.execute.pause_source": "execute",
1708 });
1709 yield* onExecutionPaused(outcome.execution.id, deadline);
1710 return elicitationMode.mode === "browser"
1711 ? yield* requireUserResumeApproval(outcome.execution.id)
1712 : toMcpPausedResult(formatPausedExecution(outcome.execution, { deadline }));
1713 }
1714 return toMcpResult(outcome.result);
1715 }).pipe(
1716 Effect.withSpan("mcp.host.tool.execute", {
1717 attributes: {
1718 "mcp.tool.name": "execute",
1719 "mcp.execute.code_length": code.length,
1720 },
1721 }),
1722 Effect.annotateSpans(joinKeyAttributes(extra)),
1723 );
1724
1725 // `search_<integration>` is `execute` running `tools.search` with the
1726 // namespace pinned. The code is built HERE, from the slug the tool was

Callers 1

createExecutorMcpServerFunction · 0.70

Calls 12

formatPausedExecutionFunction · 0.90
startMarkerFunction · 0.85
debugLogFunction · 0.85
getElicitationSupportFunction · 0.85
pausedInteractionKindFunction · 0.85
pauseDeadlineFunction · 0.85
onExecutionPausedFunction · 0.85
toMcpPausedResultFunction · 0.85
toMcpResultFunction · 0.85
joinKeyAttributesFunction · 0.85

Tested by

no test coverage detected