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

Function executeCodeFromApp

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

Source from the content-addressed store, hash-verified

1263 // invented a five-segment address would only be naming a role the artifact
1264 // has no binding for, and would be refused.
1265 const executeCodeFromApp = (
1266 code: string,
1267 artifactId: string | undefined,
1268 ): Effect.Effect<McpToolResult, E> =>
1269 Effect.gen(function* () {
1270 const resolution = yield* resolveArtifactAction({ code, artifactId, loadArtifact });
1271 debugLog("execute_action.call", {
1272 elicitationMode: elicitationMode.mode,
1273 elicitationSupport: getElicitationSupport(server),
1274 codeLength: code.length,
1275 status: resolution.status,
1276 artifactId: artifactId ?? null,
1277 });
1278 if (resolution.status === "invalid_action_code") {
1279 yield* Effect.annotateCurrentSpan({ "mcp.execute_action.rejected": true });
1280 return actionRejectedResult();
1281 }
1282 if (resolution.status === "artifact_unavailable") {
1283 return actionArtifactUnavailableResult();
1284 }
1285 if (resolution.status === "binding_unresolved") {
1286 yield* Effect.annotateCurrentSpan({
1287 "mcp.execute_action.binding_unresolved": true,
1288 "mcp.execute_action.role": resolution.role,
1289 });
1290 return bindingUnresolvedResult({
1291 role: resolution.role,
1292 integration: resolution.integration,
1293 message: resolution.message,
1294 candidates: yield* bindingCandidates(resolution.integration),
1295 });
1296 }
1297 const boundCode = resolution.code;
1298
1299 if (elicitationMode.mode === "native") {
1300 const result = yield* engine.execute(boundCode, {
1301 onElicitation: makeMcpElicitationHandler(server, debugLog),
1302 });
1303 return toMcpResult(result);
1304 }
1305 const outcome = yield* engine.executeWithPause(boundCode);
1306 debugLog("execute_action.paused_flow_result", {
1307 status: outcome.status,
1308 executionId: outcome.status === "paused" ? outcome.execution.id : undefined,
1309 interactionKind:
1310 outcome.status === "paused"
1311 ? pausedInteractionKind(outcome.execution.elicitationContext.request)
1312 : undefined,
1313 });
1314 if (outcome.status === "paused") {
1315 return yield* formatPausedModelResult(outcome.execution, "execute_action");
1316 }
1317 return toMcpResult(outcome.result);
1318 }).pipe(
1319 Effect.withSpan("mcp.host.tool.execute_action", {
1320 attributes: {
1321 "mcp.tool.name": "execute-action",
1322 "mcp.execute.code_length": code.length,

Callers 1

createExecutorMcpServerFunction · 0.85

Calls 12

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

Tested by

no test coverage detected