Skip to main content

Install SEC API in LangChain

Use LangChain’s MCP adapters to register SEC API as a streamable HTTP tool server with an x-api-key header.

Prerequisites

  • SEC API key. Sign up at secapi.ai. Set SECAPI_API_KEY.
  • Python: langchain-mcp-adapters, langchain, langgraph, and a model provider package.
  • JavaScript / TypeScript: @langchain/mcp-adapters, @langchain/core, @langchain/langgraph, and a model provider package.

Python

pip install langchain-mcp-adapters langchain langgraph langchain-anthropic
import asyncio, os
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain.agents import create_agent

async def main():
    client = MultiServerMCPClient({
        "sec-api": {
            "transport": "streamable_http",
            "url": "https://api.secapi.ai/mcp",
            "headers": {"x-api-key": os.environ["SECAPI_API_KEY"]},
        }
    })
    tools = await client.get_tools()
    agent = create_agent("anthropic:claude-sonnet-4-5", tools)
    result = await agent.ainvoke({"messages": [("user", "Show me Apple's latest 8-K filing.")]})
    print(result["messages"][-1].content)

asyncio.run(main())

JavaScript / TypeScript

npm install @langchain/mcp-adapters @langchain/core @langchain/anthropic @langchain/langgraph langchain
import { MultiServerMCPClient } from "@langchain/mcp-adapters";
import { ChatAnthropic } from "@langchain/anthropic";
import { createReactAgent } from "@langchain/langgraph/prebuilt";

const client = new MultiServerMCPClient({
  "sec-api": {
    transport: "streamable_http",
    url: "https://api.secapi.ai/mcp",
    headers: { "x-api-key": process.env.SECAPI_API_KEY! },
  },
});
const tools = await client.getTools();
const agent = createReactAgent({ llm: new ChatAnthropic({ model: "claude-sonnet-4-5" }), tools });
const result = await agent.invoke({ messages: [{ role: "user", content: "Show me Apple's latest 8-K filing." }] });
console.log(result.messages.at(-1)?.content);

Verify

Run either snippet. The agent should call the filings.latest tool with ticker: AAPL, form: 8-K and print the filing URL plus a short summary.

Troubleshooting

  • 401 Unauthorizedx-api-key is missing or wrong. Sanity check: curl https://api.secapi.ai/v1/limits -H "x-api-key: $SECAPI_API_KEY".
  • 429 Too Many Requests — rate limit hit. See GET https://api.secapi.ai/v1/billing for your plan’s cap.
  • No tools returned — confirm the URL ends in /mcp (not /sse); the SSE transport is deprecated as of MCP 2025-03-26.
  • Streaming notifications missing — if your adapter version does not support MCP progress events, tool calls can still complete while long-running progress updates are omitted.

Next