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

Function executeCodeFromApp

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

Source from the content-addressed store, hash-verified

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

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