# Connect CrewAI to SAM.gov data

To use SAM.gov data in CrewAI, pass mcps=[MCPServerHTTP(url="https://samgovapi.io/api/mcp", headers={"Authorization": "Bearer <key>"})] to an Agent. CrewAI connects over Streamable HTTP and the agent can call registration_status, search_awards and the other samgovapi tools in its tasks.

CrewAI suits multi-step capture work split between roles: one agent finds recompetes, another researches the incumbent, a third drafts the bid decision. Each can get the samgovapi tools it needs.

- 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: crewai and crewai-tools 1.15.41: MCPServerAdapter listed every tool; MCPServerHTTP accepts url, headers, streamable, tool_filter and cache_tools_list (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.

## Set up CrewAI

1. Install

Terminal:

```bash
pip install crewai 'crewai-tools[mcp]'
```

2. Attach the server to an agent: MCPServerHTTP takes headers directly; tool_filter is optional.

crew.py:

```python
import os
from crewai import Agent
from crewai.mcp import MCPServerHTTP

analyst = Agent(
    role="Federal contracts analyst",
    goal="Find and vet federal opportunities with dated facts",
    backstory="You check SAM.gov registrations and USAspending awards before every recommendation.",
    mcps=[MCPServerHTTP(
        url="https://samgovapi.io/api/mcp",
        headers={"Authorization": f"Bearer {os.environ['SAMGOVAPI_API_KEY']}"},
        cache_tools_list=True,
    )],
)
```

3. Or use MCPServerAdapter: Extra keys in server_params are passed to the MCP client, including headers.

crew.py:

```python
from crewai_tools import MCPServerAdapter

params = {"url": "https://samgovapi.io/api/mcp", "transport": "streamable-http", "headers": {"Authorization": f"Bearer {os.environ['SAMGOVAPI_API_KEY']}"}}
with MCPServerAdapter(params, connect_timeout=60) as tools:
    analyst = Agent(role="Analyst", goal="...", backstory="...", tools=tools)
```

## 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

- CrewAI currently pins the MCP Python SDK below version 2; install it in its own environment if other packages need version 2.

## Troubleshooting

- Dependency conflict on mcp: Use a separate virtual environment for CrewAI.
- INVALID_API_KEY: Check the variable in the process that runs the crew.
- ONBOARDING_REQUIRED: Answer the onboarding questions once for the account.

## Questions

### Can different agents share one connection?

Give each agent its own MCPServerHTTP; tools are cached per server when cache_tools_list is on.

## Official documentation

- CrewAI: MCP overview: https://docs.crewai.com/en/mcp/overview
- CrewAI: Streamable HTTP transport: https://docs.crewai.com/en/mcp/streamable-http

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.
