(
code: string,
extra: McpRequestJoinKeys,
)
| 1140 | ).pipe(Effect.withSpan("mcp.host.create_server")); |
| 1141 | |
| 1142 | const executeCode = ( |
| 1143 | code: string, |
| 1144 | extra: McpRequestJoinKeys, |
| 1145 | ): Effect.Effect<McpToolResult, E> => |
| 1146 | Effect.gen(function* () { |
| 1147 | yield* startMarker("mcp.host.tool.execute.start", { |
| 1148 | "mcp.tool.name": "execute", |
| 1149 | "mcp.execute.code_length": code.length, |
| 1150 | }); |
| 1151 | debugLog("execute.call", { |
| 1152 | elicitationMode: elicitationMode.mode, |
| 1153 | elicitationSupport: getElicitationSupport(server), |
| 1154 | clientCapabilities: server.server.getClientCapabilities() ?? null, |
| 1155 | codeLength: code.length, |
| 1156 | }); |
| 1157 | if (elicitationMode.mode === "native") { |
| 1158 | const result = yield* engine.execute(code, { |
| 1159 | onElicitation: makeMcpElicitationHandler(server, debugLog), |
| 1160 | }); |
| 1161 | return toMcpResult(result); |
| 1162 | } |
| 1163 | const outcome = yield* engine.executeWithPause(code); |
| 1164 | debugLog("execute.paused_flow_result", { |
| 1165 | status: outcome.status, |
| 1166 | executionId: outcome.status === "paused" ? outcome.execution.id : undefined, |
| 1167 | interactionKind: |
| 1168 | outcome.status === "paused" |
| 1169 | ? pausedInteractionKind(outcome.execution.elicitationContext.request) |
| 1170 | : undefined, |
| 1171 | }); |
| 1172 | if (outcome.status === "paused") { |
| 1173 | const deadline = pauseDeadline(); |
| 1174 | yield* Effect.annotateCurrentSpan({ |
| 1175 | "mcp.execute.paused": true, |
| 1176 | "mcp.execute.paused_execution_id": outcome.execution.id, |
| 1177 | "mcp.execute.pause_source": "execute", |
| 1178 | }); |
| 1179 | yield* onExecutionPaused(outcome.execution.id, deadline); |
| 1180 | return elicitationMode.mode === "browser" |
| 1181 | ? yield* requireUserResumeApproval(outcome.execution.id) |
| 1182 | : toMcpPausedResult(formatPausedExecution(outcome.execution, { deadline })); |
| 1183 | } |
| 1184 | return toMcpResult(outcome.result); |
| 1185 | }).pipe( |
| 1186 | Effect.withSpan("mcp.host.tool.execute", { |
| 1187 | attributes: { |
| 1188 | "mcp.tool.name": "execute", |
| 1189 | "mcp.execute.code_length": code.length, |
| 1190 | }, |
| 1191 | }), |
| 1192 | Effect.annotateSpans(joinKeyAttributes(extra)), |
| 1193 | ); |
| 1194 | |
| 1195 | /** What the caller could bind an unresolved role to. Best effort: the |
| 1196 | * connections port is optional, and a failure to enumerate must not |
no test coverage detected