# Connect LangChain and LangGraph to SAM.gov data

To use SAM.gov data in LangChain or LangGraph, create a MultiServerMCPClient with a samgovapi server using transport http, url https://samgovapi.io/api/mcp and an Authorization header, await get_tools(), and pass the tools to create_agent. Each MCP tool becomes a LangChain tool the agent can call.

langchain-mcp-adapters turns MCP tools into LangChain tools, so they work in any LangChain agent and in LangGraph graphs. LangChain 1.4 and later also ship a beta MCPAdapter in the core package; the adapters package below is the stable path.

- Connects with: MCP
- MCP server: https://samgovapi.io/api/mcp
- REST base: https://samgovapi.io/api/v1
- Auth: Authorization: Bearer <key>, kept in SAMGOVAPI_API_KEY
- Tested: langchain-mcp-adapters 0.3.2: get_tools returned every tool and the search tool returned results (2026-11-13)

## Get a key

Free key at https://samgovapi.io/sign-up, or have the agent call start_signup and approve the link it shows you. Read SAMGOVAPI_API_KEY from the environment when building the client.

## Set up LangChain and LangGraph

1. Install

Terminal:

```bash
pip install langchain langchain-mcp-adapters
```

2. Load the tools and build an agent: Headers are supported on the http and sse transports.

agent.py:

```python
import asyncio, os
from langchain.agents import create_agent
from langchain_mcp_adapters.client import MultiServerMCPClient

async def main():
    client = MultiServerMCPClient({
        "samgovapi": {
            "transport": "http",
            "url": "https://samgovapi.io/api/mcp",
            "headers": {"Authorization": f"Bearer {os.environ['SAMGOVAPI_API_KEY']}"},
        }
    })
    tools = await client.get_tools()
    agent = create_agent("openai:gpt-4.1", tools)
    out = await agent.ainvoke({"messages": [{"role": "user", "content": "Is UEI ZXBCU6K5KL99 registered in SAM.gov, and when does its registration expire?"}]})
    print(out["messages"][-1].content)

asyncio.run(main())
```

## Finish account setup once

Data tools unlock after the account answers its onboarding questions: ask the agent to set up your samgovapi account (get_onboarding_questions, then answer_onboarding). Free.

## Check that it works

Ask: "Is UEI ZXBCU6K5KL99 registered in SAM.gov, and when does its registration expire?"

Expected tool call:

```json
{"name":"registration_status","arguments":{"id":"ZXBCU6K5KL99","user_request":"check a registration and its expiry"}}
```

## Things to know

- The model string is an example; use any chat model LangChain supports.

## Troubleshooting

- Too many tools confuse the model: Filter the list by name before passing it to the agent.
- INVALID_API_KEY in tool output: The header was built before the variable was set.
- ONBOARDING_REQUIRED: Answer the onboarding questions once for the account.

## Questions

### Does this work inside LangGraph?

Yes. The tools are ordinary LangChain tools; use them in a ToolNode or a prebuilt agent.

## Official documentation

- LangChain: MCP: https://docs.langchain.com/oss/python/langchain/mcp
- langchain-mcp-adapters README: https://github.com/langchain-ai/langchain-mcp-adapters

Checked 2026-11-13. All guides: https://samgovapi.io/agents.md

Independent. Not affiliated with, endorsed by or sponsored by GSA, SAM.gov or any U.S. government agency. Registering in SAM.gov is free at sam.gov.
