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

Function executeCodeFromApp

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

Source from the content-addressed store, hash-verified

1322 // invented a five-segment address would only be naming a role the artifact
1323 // has no binding for, and would be refused.
1324 const executeCodeFromApp = (
1325 code: string,
1326 artifactId: string | undefined,
1327 extra: McpRequestJoinKeys,
1328 ): Effect.Effect<McpToolResult, E> =>
1329 Effect.gen(function* () {
1330 const resolution = yield* resolveArtifactAction({ code, artifactId, loadArtifact });
1331 debugLog("execute_action.call", {
1332 elicitationMode: elicitationMode.mode,
1333 elicitationSupport: getElicitationSupport(server),
1334 codeLength: code.length,
1335 status: resolution.status,
1336 artifactId: artifactId ?? null,
1337 });
1338 if (resolution.status === "invalid_action_code") {
1339 yield* Effect.annotateCurrentSpan({ "mcp.execute_action.rejected": true });
1340 return actionRejectedResult();
1341 }
1342 if (resolution.status === "artifact_unavailable") {
1343 return actionArtifactUnavailableResult();
1344 }
1345 if (resolution.status === "binding_unresolved") {
1346 yield* Effect.annotateCurrentSpan({
1347 "mcp.execute_action.binding_unresolved": true,
1348 "mcp.execute_action.role": resolution.role,
1349 });
1350 return bindingUnresolvedResult({
1351 role: resolution.role,
1352 integration: resolution.integration,
1353 message: resolution.message,
1354 candidates: yield* bindingCandidates(resolution.integration),
1355 });
1356 }
1357 const boundCode = resolution.code;
1358
1359 if (elicitationMode.mode === "native") {
1360 return yield* executeWithNativeElicitation(boundCode, extra);
1361 }
1362 const outcome = yield* engine.executeWithPause(boundCode);
1363 debugLog("execute_action.paused_flow_result", {
1364 status: outcome.status,
1365 executionId: outcome.status === "paused" ? outcome.execution.id : undefined,
1366 interactionKind:
1367 outcome.status === "paused"
1368 ? pausedInteractionKind(outcome.execution.elicitationContext.request)
1369 : undefined,
1370 });
1371 if (outcome.status === "paused") {
1372 return yield* formatPausedModelResult(outcome.execution, "execute_action");
1373 }
1374 return toMcpResult(outcome.result);
1375 }).pipe(
1376 Effect.withSpan("mcp.host.tool.execute_action", {
1377 attributes: {
1378 "mcp.tool.name": "execute-action",
1379 "mcp.execute.code_length": code.length,
1380 },
1381 }),

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