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

Function executeCodeFromApp

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

Source from the content-addressed store, hash-verified

1779 // invented a five-segment address would only be naming a role the artifact
1780 // has no binding for, and would be refused.
1781 const executeCodeFromApp = (
1782 code: string,
1783 artifactId: string | undefined,
1784 extra: McpRequestJoinKeys,
1785 ): Effect.Effect<McpToolResult, E> =>
1786 Effect.gen(function* () {
1787 const resolution = yield* resolveArtifactAction({ code, artifactId, loadArtifact });
1788 debugLog("execute_action.call", {
1789 elicitationMode: elicitationMode.mode,
1790 elicitationSupport: getElicitationSupport(server),
1791 codeLength: code.length,
1792 status: resolution.status,
1793 artifactId: artifactId ?? null,
1794 });
1795 if (resolution.status === "invalid_action_code") {
1796 yield* Effect.annotateCurrentSpan({ "mcp.execute_action.rejected": true });
1797 return actionRejectedResult();
1798 }
1799 if (resolution.status === "artifact_unavailable") {
1800 return actionArtifactUnavailableResult();
1801 }
1802 if (resolution.status === "binding_unresolved") {
1803 yield* Effect.annotateCurrentSpan({
1804 "mcp.execute_action.binding_unresolved": true,
1805 "mcp.execute_action.role": resolution.role,
1806 });
1807 return bindingUnresolvedResult({
1808 role: resolution.role,
1809 integration: resolution.integration,
1810 message: resolution.message,
1811 candidates: yield* bindingCandidates(resolution.integration),
1812 });
1813 }
1814 const boundCode = resolution.code;
1815
1816 if (elicitationMode.mode === "native") {
1817 return yield* executeWithNativeElicitation(boundCode, extra);
1818 }
1819 const outcome = yield* engine.executeWithPause(boundCode);
1820 debugLog("execute_action.paused_flow_result", {
1821 status: outcome.status,
1822 executionId: outcome.status === "paused" ? outcome.execution.id : undefined,
1823 interactionKind:
1824 outcome.status === "paused"
1825 ? pausedInteractionKind(outcome.execution.elicitationContext.request)
1826 : undefined,
1827 });
1828 if (outcome.status === "paused") {
1829 return yield* formatPausedModelResult(outcome.execution, "execute_action");
1830 }
1831 return toMcpResult(outcome.result);
1832 }).pipe(
1833 Effect.withSpan("mcp.host.tool.execute_action", {
1834 attributes: {
1835 "mcp.tool.name": "execute-action",
1836 "mcp.execute.code_length": code.length,
1837 },
1838 }),

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