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

Function executeCode

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

Source from the content-addressed store, hash-verified

1194 .pipe(Effect.map(toMcpResult));
1195
1196 const executeCode = (
1197 code: string,
1198 extra: McpRequestJoinKeys,
1199 ): Effect.Effect<McpToolResult, E> =>
1200 Effect.gen(function* () {
1201 yield* startMarker("mcp.host.tool.execute.start", {
1202 "mcp.tool.name": "execute",
1203 "mcp.execute.code_length": code.length,
1204 });
1205 debugLog("execute.call", {
1206 elicitationMode: elicitationMode.mode,
1207 elicitationSupport: getElicitationSupport(server),
1208 clientCapabilities: server.server.getClientCapabilities() ?? null,
1209 codeLength: code.length,
1210 });
1211 if (elicitationMode.mode === "native") {
1212 return yield* executeWithNativeElicitation(code, extra);
1213 }
1214 const outcome = yield* engine.executeWithPause(code);
1215 debugLog("execute.paused_flow_result", {
1216 status: outcome.status,
1217 executionId: outcome.status === "paused" ? outcome.execution.id : undefined,
1218 interactionKind:
1219 outcome.status === "paused"
1220 ? pausedInteractionKind(outcome.execution.elicitationContext.request)
1221 : undefined,
1222 });
1223 if (outcome.status === "paused") {
1224 const deadline = pauseDeadline();
1225 yield* Effect.annotateCurrentSpan({
1226 "mcp.execute.paused": true,
1227 "mcp.execute.paused_execution_id": outcome.execution.id,
1228 "mcp.execute.pause_source": "execute",
1229 });
1230 yield* onExecutionPaused(outcome.execution.id, deadline);
1231 return elicitationMode.mode === "browser"
1232 ? yield* requireUserResumeApproval(outcome.execution.id)
1233 : toMcpPausedResult(formatPausedExecution(outcome.execution, { deadline }));
1234 }
1235 return toMcpResult(outcome.result);
1236 }).pipe(
1237 Effect.withSpan("mcp.host.tool.execute", {
1238 attributes: {
1239 "mcp.tool.name": "execute",
1240 "mcp.execute.code_length": code.length,
1241 },
1242 }),
1243 Effect.annotateSpans(joinKeyAttributes(extra)),
1244 );
1245
1246 /** What the caller could bind an unresolved role to. Best effort: the
1247 * connections port is optional, and a failure to enumerate must not

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