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

Function executeCode

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

Source from the content-addressed store, hash-verified

1242 .pipe(Effect.map(toMcpResult));
1243
1244 const executeCode = (
1245 code: string,
1246 extra: McpRequestJoinKeys,
1247 ): Effect.Effect<McpToolResult, E> =>
1248 Effect.gen(function* () {
1249 yield* startMarker("mcp.host.tool.execute.start", {
1250 "mcp.tool.name": "execute",
1251 "mcp.execute.code_length": code.length,
1252 });
1253 debugLog("execute.call", {
1254 elicitationMode: elicitationMode.mode,
1255 elicitationSupport: getElicitationSupport(server),
1256 clientCapabilities: server.server.getClientCapabilities() ?? null,
1257 codeLength: code.length,
1258 });
1259 if (elicitationMode.mode === "native") {
1260 return yield* executeWithNativeElicitation(code, extra);
1261 }
1262 const outcome = yield* engine.executeWithPause(code);
1263 debugLog("execute.paused_flow_result", {
1264 status: outcome.status,
1265 executionId: outcome.status === "paused" ? outcome.execution.id : undefined,
1266 interactionKind:
1267 outcome.status === "paused"
1268 ? pausedInteractionKind(outcome.execution.elicitationContext.request)
1269 : undefined,
1270 });
1271 if (outcome.status === "paused") {
1272 const deadline = pauseDeadline();
1273 yield* Effect.annotateCurrentSpan({
1274 "mcp.execute.paused": true,
1275 "mcp.execute.paused_execution_id": outcome.execution.id,
1276 "mcp.execute.pause_source": "execute",
1277 });
1278 yield* onExecutionPaused(outcome.execution.id, deadline);
1279 return elicitationMode.mode === "browser"
1280 ? yield* requireUserResumeApproval(outcome.execution.id)
1281 : toMcpPausedResult(formatPausedExecution(outcome.execution, { deadline }));
1282 }
1283 return toMcpResult(outcome.result);
1284 }).pipe(
1285 Effect.withSpan("mcp.host.tool.execute", {
1286 attributes: {
1287 "mcp.tool.name": "execute",
1288 "mcp.execute.code_length": code.length,
1289 },
1290 }),
1291 Effect.annotateSpans(joinKeyAttributes(extra)),
1292 );
1293
1294 // `search_<integration>` is `execute` running `tools.search` with the
1295 // 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