@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
filings.latest before using a language model:
@ai-sdk/mcp.
Add it to a model turn after it works
Once the direct filing call works, passawait 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. Repair401
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.

