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

Function executeCode

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

Source from the content-addressed store, hash-verified

1163 ).pipe(Effect.withSpan("mcp.host.create_server"));
1164
1165 const executeCode = (
1166 code: string,
1167 extra: McpRequestJoinKeys,
1168 ): Effect.Effect<McpToolResult, E> =>
1169 Effect.gen(function* () {
1170 yield* startMarker("mcp.host.tool.execute.start", {
1171 "mcp.tool.name": "execute",
1172 "mcp.execute.code_length": code.length,
1173 });
1174 debugLog("execute.call", {
1175 elicitationMode: elicitationMode.mode,
1176 elicitationSupport: getElicitationSupport(server),
1177 clientCapabilities: server.server.getClientCapabilities() ?? null,
1178 codeLength: code.length,
1179 });
1180 if (elicitationMode.mode === "native") {
1181 const result = yield* engine.execute(code, {
1182 onElicitation: makeMcpElicitationHandler(server, debugLog),
1183 });
1184 return toMcpResult(result);
1185 }
1186 const outcome = yield* engine.executeWithPause(code);
1187 debugLog("execute.paused_flow_result", {
1188 status: outcome.status,
1189 executionId: outcome.status === "paused" ? outcome.execution.id : undefined,
1190 interactionKind:
1191 outcome.status === "paused"
1192 ? pausedInteractionKind(outcome.execution.elicitationContext.request)
1193 : undefined,
1194 });
1195 if (outcome.status === "paused") {
1196 const deadline = pauseDeadline();
1197 yield* Effect.annotateCurrentSpan({
1198 "mcp.execute.paused": true,
1199 "mcp.execute.paused_execution_id": outcome.execution.id,
1200 "mcp.execute.pause_source": "execute",
1201 });
1202 yield* onExecutionPaused(outcome.execution.id, deadline);
1203 return elicitationMode.mode === "browser"
1204 ? yield* requireUserResumeApproval(outcome.execution.id)
1205 : toMcpPausedResult(formatPausedExecution(outcome.execution, { deadline }));
1206 }
1207 return toMcpResult(outcome.result);
1208 }).pipe(
1209 Effect.withSpan("mcp.host.tool.execute", {
1210 attributes: {
1211 "mcp.tool.name": "execute",
1212 "mcp.execute.code_length": code.length,
1213 },
1214 }),
1215 Effect.annotateSpans(joinKeyAttributes(extra)),
1216 );
1217
1218 /** What the caller could bind an unresolved role to. Best effort: the
1219 * connections port is optional, and a failure to enumerate must not

Callers 1

createExecutorMcpServerFunction · 0.70

Calls 13

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

Tested by

no test coverage detected