samgov-mcp

samgov-mcp

MCP server for querying SAM.gov federal contract opportunities, providing precise search, retrieval, and attachment tools with full source traceability and explicit abstention when data is absent.

Category
访问服务器

README

samgov-mcp

An MCP server over the SAM.gov Contract Opportunities API, built for agents that have to read United States federal solicitations and then be believed about what they read.

Everything this server returns carries the exact URL it came from. Anything SAM.gov did not send comes back as null with its name listed, never as a zero, an empty string, or a plausible guess.

npm install
npm run smoke     # 20 checks, no API key, no network
npm run dev       # starts the server on stdio

Run it with no key and it serves recorded fixtures, so you can inspect every tool contract before signing up for anything.


Why this exists

I build AI systems that live inside a company's operation and answer from its own data. The failure that costs you the room is never a model that underperforms. It is a confident number nobody can trace back to anything.

An MCP server is where that gets decided. By the time a figure reaches the model it is just a token, and no prompt reliably repairs a tool that quietly returned the wrong record. So the discipline goes in the tool layer, where it can be tested.

The envelope

Every result has the same shape:

{
  "source": {
    "url": "https://api.sam.gov/opportunities/v2/search?postedFrom=07%2F01%2F2026&...&api_key=REDACTED",
    "retrieved_at": "2026-08-07T18:33:52.792Z",
    "mode": "live"
  },
  "data": { "returned": 2, "total_records_upstream": 412, "notices": [ ... ] },
  "missing": ["notices[1].response_deadline", "notices[1].set_aside_code"],
  "abstained": { "reason": "..." }
}

source is the request that produced the payload, with the API key stripped so a transcript never leaks a credential.

missing names every field the upstream did not provide. SAM.gov signals "not provided" three different ways, null, "", and an object whose inner name is "", and a model cannot tell those apart from real values. They all become null here, and they all get named.

abstained appears when the server declines. "I could not find this" and "this does not exist" are different answers, and collapsing them into an empty list is how an agent ends up telling somebody a solicitation was cancelled when it was simply posted outside the window it searched.

data.returned is counted off the array actually being returned. total_records_upstream is reported beside it, separately, because they are different numbers and mixing them is how a report claims a pipeline processed 412 documents when it read 10.

Tools

Tool What it does
search_solicitations Search a posted-date window. Filters for NAICS, procurement type, set-aside, state, title
get_solicitation One notice by its exact solicitation number
list_attachments The downloadable resource links for one notice
fetch_attachment Download one attachment
server_status Which mode it is in and where the data is coming from

Two things I got wrong, written down

1 · A 404 from this gateway means the key is bad, not the path.

api.sam.gov answers 404 with an empty body for every path when the API key is missing or unrecognised, including paths that exist. DEMO_KEY does not work, because SAM.gov runs its own gateway rather than the shared api.data.gov one. I spent a while probing endpoint variants before realising the endpoint was never the problem. The client now says so in the error text, because the obvious reading of a 404 sends you somewhere useless.

2 · The first version of this server did the exact thing it was built to prevent.

get_solicitation originally ended with ?? rows[0], a harmless-looking fallback: if the exact number is not found, use the first result. But SAM.gov's solnum filter is fuzzy and returns neighbouring notices. So for any number that did not exist, the server would have confidently handed back a different solicitation under the number that was asked for. Different deadline, different set-aside, different scope.

The smoke test did not catch it, because I had asserted that the call returned something. It now asserts abstention, and the abstention message names the neighbours it refused to pass off:

No notice numbered exactly "DOES-NOT-EXIST-0000" was posted between 07/01/2026 and 07/31/2026.
The search returned 2 nearby notice(s) which are NOT this one: FIXTURE-70FA-26-R-0001, ...

It is the same lesson as the first run of any eval suite. The first pass grades your harness, not the thing you pointed it at.

Use it

Live. Generate a free key at sam.gov under Account Details → Public API Key, then:

export SAM_API_KEY=your-key
npm run build

Claude Desktop or Claude Code, in claude_desktop_config.json or via claude mcp add:

{
  "mcpServers": {
    "samgov": {
      "command": "node",
      "args": ["/absolute/path/to/samgov-mcp/dist/index.js"],
      "env": { "SAM_API_KEY": "your-key" }
    }
  }
}

Fixtures. Omit SAM_API_KEY and it runs offline against fixtures/search.json, which is synthetic and labelled as such inside the file. Every tool contract, the grounding envelope and both abstention paths are exercised without a credential. SAM_MODE=live|fixtures overrides the default.

Environment

Variable Default Meaning
SAM_API_KEY none Free key from SAM.gov. Its presence is what selects live mode
SAM_MODE auto live or fixtures, overriding the default
SAM_TIMEOUT_MS 20000 Upstream request timeout
SAM_MAX_ATTACHMENT_BYTES 8000000 Refuse attachments larger than this rather than filling a context window

Notes on the upstream

  • postedFrom and postedTo are mandatory, MM/dd/yyyy, at most one year apart. This server refuses other formats at the schema rather than reformatting them, so a wrong window fails loudly instead of silently returning the wrong year.
  • SAM.gov puts a URL in the description field, not prose. It is returned as description_link, so an agent does not quote a link as if it were the scope of work.
  • Attachments in binary formats are reported with their content type and byte length rather than being decoded into noise. Extracting fields from fillable government forms is a separate step and is deliberately not guessed at here.

Status

Working: the five tools, the grounding envelope, both abstention paths, fixtures mode, 20 smoke checks over the real MCP stdio protocol driven by the reference client.

Next: requirement extraction from fillable PDFs into schema-validated JSON, where every extracted field carries the page and span it came from, plus an eval suite over that extraction using the harness in agent-evals.

MIT.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选