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

Function executeCode

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

Source from the content-addressed store, hash-verified

1216 .pipe(Effect.map(toMcpResult));
1217
1218 const executeCode = (
1219 code: string,
1220 extra: McpRequestJoinKeys,
1221 ): Effect.Effect<McpToolResult, E> =>
1222 Effect.gen(function* () {
1223 yield* startMarker("mcp.host.tool.execute.start", {
1224 "mcp.tool.name": "execute",
1225 "mcp.execute.code_length": code.length,
1226 });
1227 debugLog("execute.call", {
1228 elicitationMode: elicitationMode.mode,
1229 elicitationSupport: getElicitationSupport(server),
1230 clientCapabilities: server.server.getClientCapabilities() ?? null,
1231 codeLength: code.length,
1232 });
1233 if (elicitationMode.mode === "native") {
1234 return yield* executeWithNativeElicitation(code, extra);
1235 }
1236 const outcome = yield* engine.executeWithPause(code);
1237 debugLog("execute.paused_flow_result", {
1238 status: outcome.status,
1239 executionId: outcome.status === "paused" ? outcome.execution.id : undefined,
1240 interactionKind:
1241 outcome.status === "paused"
1242 ? pausedInteractionKind(outcome.execution.elicitationContext.request)
1243 : undefined,
1244 });
1245 if (outcome.status === "paused") {
1246 const deadline = pauseDeadline();
1247 yield* Effect.annotateCurrentSpan({
1248 "mcp.execute.paused": true,
1249 "mcp.execute.paused_execution_id": outcome.execution.id,
1250 "mcp.execute.pause_source": "execute",
1251 });
1252 yield* onExecutionPaused(outcome.execution.id, deadline);
1253 return elicitationMode.mode === "browser"
1254 ? yield* requireUserResumeApproval(outcome.execution.id)
1255 : toMcpPausedResult(formatPausedExecution(outcome.execution, { deadline }));
1256 }
1257 return toMcpResult(outcome.result);
1258 }).pipe(
1259 Effect.withSpan("mcp.host.tool.execute", {
1260 attributes: {
1261 "mcp.tool.name": "execute",
1262 "mcp.execute.code_length": code.length,
1263 },
1264 }),
1265 Effect.annotateSpans(joinKeyAttributes(extra)),
1266 );
1267
1268 // `search_<integration>` is `execute` running `tools.search` with the
1269 // 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