(
code: string,
artifactId: string | undefined,
)
| 1240 | // invented a five-segment address would only be naming a role the artifact |
| 1241 | // has no binding for, and would be refused. |
| 1242 | const executeCodeFromApp = ( |
| 1243 | code: string, |
| 1244 | artifactId: string | undefined, |
| 1245 | ): Effect.Effect<McpToolResult, E> => |
| 1246 | Effect.gen(function* () { |
| 1247 | const resolution = yield* resolveArtifactAction({ code, artifactId, loadArtifact }); |
| 1248 | debugLog("execute_action.call", { |
| 1249 | elicitationMode: elicitationMode.mode, |
| 1250 | elicitationSupport: getElicitationSupport(server), |
| 1251 | codeLength: code.length, |
| 1252 | status: resolution.status, |
| 1253 | artifactId: artifactId ?? null, |
| 1254 | }); |
| 1255 | if (resolution.status === "invalid_action_code") { |
| 1256 | yield* Effect.annotateCurrentSpan({ "mcp.execute_action.rejected": true }); |
| 1257 | return actionRejectedResult(); |
| 1258 | } |
| 1259 | if (resolution.status === "artifact_unavailable") { |
| 1260 | return actionArtifactUnavailableResult(); |
| 1261 | } |
| 1262 | if (resolution.status === "binding_unresolved") { |
| 1263 | yield* Effect.annotateCurrentSpan({ |
| 1264 | "mcp.execute_action.binding_unresolved": true, |
| 1265 | "mcp.execute_action.role": resolution.role, |
| 1266 | }); |
| 1267 | return bindingUnresolvedResult({ |
| 1268 | role: resolution.role, |
| 1269 | integration: resolution.integration, |
| 1270 | message: resolution.message, |
| 1271 | candidates: yield* bindingCandidates(resolution.integration), |
| 1272 | }); |
| 1273 | } |
| 1274 | const boundCode = resolution.code; |
| 1275 | |
| 1276 | if (elicitationMode.mode === "native") { |
| 1277 | const result = yield* engine.execute(boundCode, { |
| 1278 | onElicitation: makeMcpElicitationHandler(server, debugLog), |
| 1279 | }); |
| 1280 | return toMcpResult(result); |
| 1281 | } |
| 1282 | const outcome = yield* engine.executeWithPause(boundCode); |
| 1283 | debugLog("execute_action.paused_flow_result", { |
| 1284 | status: outcome.status, |
| 1285 | executionId: outcome.status === "paused" ? outcome.execution.id : undefined, |
| 1286 | interactionKind: |
| 1287 | outcome.status === "paused" |
| 1288 | ? pausedInteractionKind(outcome.execution.elicitationContext.request) |
| 1289 | : undefined, |
| 1290 | }); |
| 1291 | if (outcome.status === "paused") { |
| 1292 | return yield* formatPausedModelResult(outcome.execution, "execute_action"); |
| 1293 | } |
| 1294 | return toMcpResult(outcome.result); |
| 1295 | }).pipe( |
| 1296 | Effect.withSpan("mcp.host.tool.execute_action", { |
| 1297 | attributes: { |
| 1298 | "mcp.tool.name": "execute-action", |
| 1299 | "mcp.execute.code_length": code.length, |
no test coverage detected