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

Function execute

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

Source from the content-addressed store, hash-verified

3635 });
3636
3637 const execute = (
3638 address: ToolAddress,
3639 args: unknown,
3640 options?: InvokeOptions,
3641 ): Effect.Effect<unknown, ExecuteError> => {
3642 const handler = pickHandler(options);
3643 return Effect.gen(function* () {
3644 // 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
3645 const formatInvocationCauseMessage = (cause: unknown): string => {
3646 if (cause instanceof Error && cause.message.length > 0) return cause.message;
3647 // Non-Error / empty-message causes: `String(plainObject)` renders
3648 // "[object Object]", which is what telemetry then shows as the only
3649 // label for the failure. Prefer the tag, else stringify structurally.
3650 if (typeof cause === "object" && cause !== null) {
3651 const tag = (cause as { readonly _tag?: unknown })._tag;
3652 if (typeof tag === "string") return tag;
3653 return Inspectable.toStringUnknown(cause, 0);
3654 }
3655 return String(cause);
3656 };
3657 // oxlint-enable executor/no-instanceof-error, executor/no-unknown-error-message, executor/no-manual-tag-check
3658 const wrapInvocationError = <A, E>(
3659 effect: Effect.Effect<A, E>,
3660 ): Effect.Effect<A, ToolInvocationError> =>
3661 effect.pipe(
3662 Effect.mapError(
3663 (cause) =>
3664 new ToolInvocationError({
3665 address,
3666 message: formatInvocationCauseMessage(cause),
3667 cause,
3668 }),
3669 ),
3670 );
3671
3672 // Static path — O(1) map lookup for plugin-contributed static tools
3673 // (core-tools, plugin executor namespaces). Addressed by their fqid,
3674 // not the 5-segment dynamic form.
3675 const staticEntry = staticTools.get(String(address));
3676 if (staticEntry) {
3677 const policyRules = yield* listActivePolicyRuleSet();
3678 const policy = yield* resolvePolicyFromRuleSet(
3679 String(address),
3680 policyRules,
3681 staticEntry.tool.annotations?.requiresApproval,
3682 );
3683 if (policy.action === "block") {
3684 return yield* new ToolBlockedError({
3685 address,
3686 pattern: policy.pattern ?? "*",
3687 });
3688 }
3689 yield* enforceApproval(staticEntry.tool.annotations, address, args, policy, handler);
3690 return yield* wrapInvocationError(
3691 staticEntry.tool.handler({
3692 ctx: staticEntry.ctx,
3693 args,
3694 elicit: buildElicit(address, args, handler),

Callers 2

createExecutorFunction · 0.70
runUserCodeFunction · 0.50

Calls 15

pickHandlerFunction · 0.85
listActivePolicyRuleSetFunction · 0.85
resolvePolicyFromRuleSetFunction · 0.85
enforceApprovalFunction · 0.85
wrapInvocationErrorFunction · 0.85
buildElicitFunction · 0.85
parseToolAddressFunction · 0.85
byOwnerFunction · 0.85
toolSuggestionsFunction · 0.85
rowToToolFunction · 0.85

Tested by

no test coverage detected