@adcp/sdk API Reference - v10.0.1
    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: payload-shaped diagnostics like field, suggestion, and details silently drop while standard recovery metadata is preserved as the canonical standard-table value. 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

      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 } };
      });