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

Function execute

packages/core/sdk/src/executor.ts:4722–4983  ·  view source on GitHub ↗
(
      address: ToolAddress,
      args: unknown,
      options?: InvokeOptions,
    )

Source from the content-addressed store, hash-verified

4720 });
4721
4722 const execute = (
4723 address: ToolAddress,
4724 args: unknown,
4725 options?: InvokeOptions,
4726 ): Effect.Effect<unknown, ExecuteError> => {
4727 const handler = pickHandler(options);
4728 return Effect.gen(function* () {
4729 // oxlint-disable executor/no-instanceof-error, executor/no-unknown-error-message, executor/no-manual-tag-check -- boundary: normalize arbitrary unknown plugin failures into a human-readable message for ToolInvocationError/telemetry
4730 const formatInvocationCauseMessage = (cause: unknown): string => {
4731 if (cause instanceof Error && cause.message.length > 0) return cause.message;
4732 // Non-Error / empty-message causes: `String(plainObject)` renders
4733 // "[object Object]", which is what telemetry then shows as the only
4734 // label for the failure. Prefer the tag, else stringify structurally.
4735 if (typeof cause === "object" && cause !== null) {
4736 const tag = (cause as { readonly _tag?: unknown })._tag;
4737 if (typeof tag === "string") return tag;
4738 return Inspectable.toStringUnknown(cause, 0);
4739 }
4740 return String(cause);
4741 };
4742 // oxlint-enable executor/no-instanceof-error, executor/no-unknown-error-message, executor/no-manual-tag-check
4743 const wrapInvocationError = <A, E>(
4744 effect: Effect.Effect<A, E>,
4745 ): Effect.Effect<A, ToolInvocationError> =>
4746 effect.pipe(
4747 Effect.mapError(
4748 (cause) =>
4749 new ToolInvocationError({
4750 address,
4751 message: formatInvocationCauseMessage(cause),
4752 cause,
4753 }),
4754 ),
4755 );
4756
4757 // Static path — O(1) map lookup for plugin-contributed static tools
4758 // (core-tools, plugin executor namespaces). Addressed by their fqid,
4759 // not the 5-segment dynamic form.
4760 const staticEntry = staticTools.get(String(address));
4761 if (staticEntry) {
4762 const policyRules = yield* listActivePolicyRuleSet();
4763 const policy = yield* resolvePolicyFromRuleSet(
4764 String(address),
4765 policyRules,
4766 staticEntry.tool.annotations?.requiresApproval,
4767 );
4768 if (policy.action === "block") {
4769 return yield* new ToolBlockedError({
4770 address,
4771 pattern: policy.pattern ?? "*",
4772 });
4773 }
4774 yield* enforceApproval(staticEntry.tool.annotations, address, args, policy, handler);
4775 return yield* wrapInvocationError(
4776 staticEntry.tool.handler({
4777 ctx: staticEntry.ctx,
4778 args,
4779 elicit: buildElicit(address, args, handler),

Callers 4

countingConnectionReadsFunction · 0.70
createExecutorFunction · 0.70
runUserCodeFunction · 0.50

Calls 15

isToolResultFunction · 0.90
pickHandlerFunction · 0.85
listActivePolicyRuleSetFunction · 0.85
resolvePolicyFromRuleSetFunction · 0.85
enforceApprovalFunction · 0.85
wrapInvocationErrorFunction · 0.85
buildElicitFunction · 0.85
parseToolAddressFunction · 0.85
byOwnerFunction · 0.85

Tested by 1

countingConnectionReadsFunction · 0.56