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

Function executeCodeFromApp

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

Source from the content-addressed store, hash-verified

1291 // invented a five-segment address would only be naming a role the artifact
1292 // has no binding for, and would be refused.
1293 const executeCodeFromApp = (
1294 code: string,
1295 artifactId: string | undefined,
1296 extra: McpRequestJoinKeys,
1297 ): Effect.Effect<McpToolResult, E> =>
1298 Effect.gen(function* () {
1299 const resolution = yield* resolveArtifactAction({ code, artifactId, loadArtifact });
1300 debugLog("execute_action.call", {
1301 elicitationMode: elicitationMode.mode,
1302 elicitationSupport: getElicitationSupport(server),
1303 codeLength: code.length,
1304 status: resolution.status,
1305 artifactId: artifactId ?? null,
1306 });
1307 if (resolution.status === "invalid_action_code") {
1308 yield* Effect.annotateCurrentSpan({ "mcp.execute_action.rejected": true });
1309 return actionRejectedResult();
1310 }
1311 if (resolution.status === "artifact_unavailable") {
1312 return actionArtifactUnavailableResult();
1313 }
1314 if (resolution.status === "binding_unresolved") {
1315 yield* Effect.annotateCurrentSpan({
1316 "mcp.execute_action.binding_unresolved": true,
1317 "mcp.execute_action.role": resolution.role,
1318 });
1319 return bindingUnresolvedResult({
1320 role: resolution.role,
1321 integration: resolution.integration,
1322 message: resolution.message,
1323 candidates: yield* bindingCandidates(resolution.integration),
1324 });
1325 }
1326 const boundCode = resolution.code;
1327
1328 if (elicitationMode.mode === "native") {
1329 return yield* executeWithNativeElicitation(boundCode, extra);
1330 }
1331 const outcome = yield* engine.executeWithPause(boundCode);
1332 debugLog("execute_action.paused_flow_result", {
1333 status: outcome.status,
1334 executionId: outcome.status === "paused" ? outcome.execution.id : undefined,
1335 interactionKind:
1336 outcome.status === "paused"
1337 ? pausedInteractionKind(outcome.execution.elicitationContext.request)
1338 : undefined,
1339 });
1340 if (outcome.status === "paused") {
1341 return yield* formatPausedModelResult(outcome.execution, "execute_action");
1342 }
1343 return toMcpResult(outcome.result);
1344 }).pipe(
1345 Effect.withSpan("mcp.host.tool.execute_action", {
1346 attributes: {
1347 "mcp.tool.name": "execute-action",
1348 "mcp.execute.code_length": code.length,
1349 },
1350 }),

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