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

Function enforceApproval

packages/core/sdk/src/executor.ts:6280–6306  ·  view source on GitHub ↗
(
      annotations: ToolAnnotations | undefined,
      address: ToolAddress,
      args: unknown,
      policy: EffectivePolicy,
      handler: ElicitationHandler,
    )

Source from the content-addressed store, hash-verified

6278 };
6279
6280 const enforceApproval = (
6281 annotations: ToolAnnotations | undefined,
6282 address: ToolAddress,
6283 args: unknown,
6284 policy: EffectivePolicy,
6285 handler: ElicitationHandler,
6286 ) =>
6287 Effect.gen(function* () {
6288 if (!approvalRequired(annotations, policy)) return;
6289 const policyForcesApproval = policy.action === "require_approval";
6290 const message = annotations?.approvalDescription
6291 ? annotations.approvalDescription
6292 : policyForcesApproval && policy.pattern
6293 ? `Approve ${address}? (matched policy: ${policy.pattern})`
6294 : `Approve ${address}?`;
6295 const request = FormElicitation.make({
6296 message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`,
6297 requestedSchema: { type: "object", properties: {} },
6298 });
6299 const response = yield* handler({ address, args, request, source: "policy" });
6300 if (response.action !== "accept") {
6301 return yield* new ElicitationDeclinedError({
6302 address,
6303 action: response.action,
6304 });
6305 }
6306 });
6307
6308 // ------------------------------------------------------------------
6309 // execute — the invoke path.

Callers 1

executeFunction · 0.85

Calls 3

approvalRequiredFunction · 0.85
approvalArgumentPreviewFunction · 0.85
handlerFunction · 0.50

Tested by

no test coverage detected