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

Function executeCode

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

Source from the content-addressed store, hash-verified

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