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

Function executeCodeFromApp

packages/hosts/mcp/src/tool-server.ts:1350–1408  ·  view source on GitHub ↗
(
      code: string,
      artifactId: string | undefined,
      extra: McpRequestJoinKeys,
    )

Source from the content-addressed store, hash-verified

1348 // invented a five-segment address would only be naming a role the artifact
1349 // has no binding for, and would be refused.
1350 const executeCodeFromApp = (
1351 code: string,
1352 artifactId: string | undefined,
1353 extra: McpRequestJoinKeys,
1354 ): Effect.Effect<McpToolResult, E> =>
1355 Effect.gen(function* () {
1356 const resolution = yield* resolveArtifactAction({ code, artifactId, loadArtifact });
1357 debugLog("execute_action.call", {
1358 elicitationMode: elicitationMode.mode,
1359 elicitationSupport: getElicitationSupport(server),
1360 codeLength: code.length,
1361 status: resolution.status,
1362 artifactId: artifactId ?? null,
1363 });
1364 if (resolution.status === "invalid_action_code") {
1365 yield* Effect.annotateCurrentSpan({ "mcp.execute_action.rejected": true });
1366 return actionRejectedResult();
1367 }
1368 if (resolution.status === "artifact_unavailable") {
1369 return actionArtifactUnavailableResult();
1370 }
1371 if (resolution.status === "binding_unresolved") {
1372 yield* Effect.annotateCurrentSpan({
1373 "mcp.execute_action.binding_unresolved": true,
1374 "mcp.execute_action.role": resolution.role,
1375 });
1376 return bindingUnresolvedResult({
1377 role: resolution.role,
1378 integration: resolution.integration,
1379 message: resolution.message,
1380 candidates: yield* bindingCandidates(resolution.integration),
1381 });
1382 }
1383 const boundCode = resolution.code;
1384
1385 if (elicitationMode.mode === "native") {
1386 return yield* executeWithNativeElicitation(boundCode, extra);
1387 }
1388 const outcome = yield* engine.executeWithPause(boundCode);
1389 debugLog("execute_action.paused_flow_result", {
1390 status: outcome.status,
1391 executionId: outcome.status === "paused" ? outcome.execution.id : undefined,
1392 interactionKind:
1393 outcome.status === "paused"
1394 ? pausedInteractionKind(outcome.execution.elicitationContext.request)
1395 : undefined,
1396 });
1397 if (outcome.status === "paused") {
1398 return yield* formatPausedModelResult(outcome.execution, "execute_action");
1399 }
1400 return toMcpResult(outcome.result);
1401 }).pipe(
1402 Effect.withSpan("mcp.host.tool.execute_action", {
1403 attributes: {
1404 "mcp.tool.name": "execute-action",
1405 "mcp.execute.code_length": code.length,
1406 },
1407 }),

Callers 1

createExecutorMcpServerFunction · 0.85

Calls 11

resolveArtifactActionFunction · 0.90
debugLogFunction · 0.85
getElicitationSupportFunction · 0.85
actionRejectedResultFunction · 0.85
bindingUnresolvedResultFunction · 0.85
bindingCandidatesFunction · 0.85
pausedInteractionKindFunction · 0.85
formatPausedModelResultFunction · 0.85
toMcpResultFunction · 0.85

Tested by

no test coverage detected