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

Function executeCode

packages/hosts/mcp/src/tool-server-core.ts:1186–1231  ·  view source on GitHub ↗
(code: string, extra: RequestContext)

Source from the content-addressed store, hash-verified

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

Callers 1

buildExecutorMcpToolsFunction · 0.70

Calls 11

formatPausedExecutionFunction · 0.90
startMarkerFunction · 0.85
debugLogFunction · 0.85
pausedInteractionKindFunction · 0.85
pauseDeadlineFunction · 0.85
onExecutionPausedFunction · 0.85
toMcpPausedResultFunction · 0.85
toMcpResultFunction · 0.85
requestSpanAttributesFunction · 0.85

Tested by

no test coverage detected