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

    Function serve

    • Start an HTTP server that serves an AdCP MCP agent.

      Creates a new MCP server instance per request (stateless), wires up the StreamableHTTPServerTransport, and returns the underlying http.Server for lifecycle control.

      A shared task store is created once and passed to the factory on every request via ServeContext. This ensures MCP Tasks (create → poll → result) work correctly across stateless HTTP requests.

      Multi-host. Pass functions for publicUrl and protectedResource and branch on ctx.host in the factory to front multiple hostnames from one process. The framework resolves host from X-Forwarded-Host (when trustForwardedHost: true) or Host, threads it through ServeContext, and caches per-host publicUrl/PRM so each hostname advertises its own audience-bound resource.

      Parameters

      • createAgent: (ctx: ServeContext) => AdcpServer | McpServer

        Factory function that returns a configured server — either an AdcpServer from createAdcpServer() or a raw SDK McpServer from createTaskCapableServer(). Called once per request so each gets a fresh instance (a server can only be connected once). Receives a ServeContext with a shared taskStore and the resolved host — branch on host to return host-specific handlers in multi-host mode.

      • Optionaloptions: ServeOptions

        Port, path, and callback configuration.

      Returns Server

      The http.Server instance. Use the onListening callback or listen for the 'listening' event to know when it's ready.