Skip to main content
Use @ai-sdk/mcp when a server-side AI SDK route needs SEC API tools. Create the client in a route handler, server action, worker, or backend service. The API key authorizes access to SEC API, so keep it in the hosting environment or secret manager instead of sending it to a client component.

Make one server-side filing call

Load the tools and verify filings.latest before using a language model:
The AI SDK HTTP transport accepts request headers and exposes MCP tools as an AI SDK tool set. Closing the MCP client is part of the lifecycle: it releases the connection after a one-shot request, including an error path. For a streaming route, keep the client alive for the request and close it when the stream settles; do not create a fresh client for each token. The AI SDK MCP guide is the source for transport and close behavior when you upgrade @ai-sdk/mcp.

Add it to a model turn after it works

Once the direct filing call works, pass await mcp.tools() to generateText or streamText in the same server-side request lifecycle. Use a small, reviewed tool subset where your application does not need the whole catalog. Put issuer, form, date range, and list-limit constraints in your application policy before the model begins a multi-step plan.

Keep the filing trail in the response

filings.latest provides accessionNumber, filingDate, and filingUrl for the source record. The MCP envelope includes requestId and traceparent. Persist those fields beside an answer, cache entry, or audit record. Preserve provenance, freshness, and source metadata from search and extraction tools; do not collapse them into unsupported model prose.

Errors and limits

Catch errors around both client creation and tool execution. Repair 401 credentials, resolve 402 account state, and on 429 or temporary 503 honor Retry-After before a bounded retry. For mcp_tool_timeout, lower the scope or result limit. Log the MCP JSON-RPC error, SEC API error.data.code, and request ID without logging the API key.

Next step

Use the verified tool set in your server-side AI SDK handler, and require the source filing identity and request metadata in every SEC API-backed response.