@adcp/sdk API Reference - v7.9.0
    Preparing search index...

    Function adcpError

    • Build an L3-compliant MCP tool error response with all three transport layers:

      1. structuredContent.adcp_error — programmatic extraction (L3)
      2. content[0].text — JSON text fallback (L2)
      3. isError: true — MCP error signal

      Recovery is auto-populated from the standard error code table when not provided.

      Before returning, any field NOT allowlisted for the given code in ADCP_ERROR_FIELD_ALLOWLIST is dropped — sellers get the builder's ergonomics for every code AND the strict wire shape for codes that have a registered allowlist. IDEMPOTENCY_CONFLICT is the canonical case: recovery, field, suggestion, and details all silently drop so the envelope can't become a stolen-key read oracle. Codes without a registered allowlist pass through unchanged.

      Two-layer wire shape. This builder emits the envelope layer (structuredContent.adcp_error) only. For tools whose response schema declares a typed Error arm (errors[] required at the top level), the framework dispatcher synthesises the payload-layer errors[] from the same data at finalize time, so the wire carries both the envelope marker and the typed Error arm together — no adopter code change required. The list of affected tools is derived at server build from the bundled schema cache. RFC: docs/proposals/adcperror-two-layer-emission.md.

      Parameters

      • code:
            | "INVALID_REQUEST"
            | "AUTH_REQUIRED"
            | "RATE_LIMITED"
            | "SERVICE_UNAVAILABLE"
            | "POLICY_VIOLATION"
            | "PRODUCT_NOT_FOUND"
            | "PRODUCT_UNAVAILABLE"
            | "PROPOSAL_EXPIRED"
            | "BUDGET_TOO_LOW"
            | "CREATIVE_REJECTED"
            | "UNSUPPORTED_FEATURE"
            | "AUDIENCE_TOO_SMALL"
            | "ACCOUNT_NOT_FOUND"
            | "ACCOUNT_SETUP_REQUIRED"
            | "ACCOUNT_AMBIGUOUS"
            | "ACCOUNT_PAYMENT_REQUIRED"
            | "ACCOUNT_SUSPENDED"
            | "COMPLIANCE_UNSATISFIED"
            | "GOVERNANCE_DENIED"
            | "BUDGET_EXHAUSTED"
            | "BUDGET_EXCEEDED"
            | "CONFLICT"
            | "IDEMPOTENCY_CONFLICT"
            | "IDEMPOTENCY_EXPIRED"
            | "CREATIVE_DEADLINE_EXCEEDED"
            | "INVALID_STATE"
            | "MEDIA_BUY_NOT_FOUND"
            | "NOT_CANCELLABLE"
            | "PACKAGE_NOT_FOUND"
            | "CREATIVE_NOT_FOUND"
            | "SIGNAL_NOT_FOUND"
            | "SESSION_NOT_FOUND"
            | "PLAN_NOT_FOUND"
            | "REFERENCE_NOT_FOUND"
            | "SESSION_TERMINATED"
            | "VALIDATION_ERROR"
            | "PRODUCT_EXPIRED"
            | "PROPOSAL_NOT_COMMITTED"
            | "IO_REQUIRED"
            | "TERMS_REJECTED"
            | "REQUOTE_REQUIRED"
            | "VERSION_UNSUPPORTED"
            | "CAMPAIGN_SUSPENDED"
            | "GOVERNANCE_UNAVAILABLE"
            | "PERMISSION_DENIED"
            | string & {}
      • options: AdcpErrorOptions

      Returns AdcpErrorResponse

      import { adcpError } from '@adcp/sdk';

      server.registerTool("get_products", { inputSchema: schema }, async ({ query }) => {
      if (!products.length) {
      return adcpError('PRODUCT_NOT_FOUND', {
      message: 'No products match query',
      field: 'query',
      suggestion: 'Try a broader search term',
      });
      }
      return { content: [...], structuredContent: { products } };
      });