Gov info api

Gov info api

an api wrapper for the us government info api

Category
访问服务器

README

GovInfo API MCP Server

A Model Context Protocol (MCP) server and REST API wrapper for accessing the GovInfo API. This tool provides easy access to government documents, bills, regulations, and related information through both MCP protocol and HTTP REST endpoints.

The government api is located here https://api.govinfo.gov/docs/

This is not the govenments mcp they have their own here https://github.com/usgpo/api/blob/main/docs/mcp.md

I wanted one that exposes all of the apis endpoints for deep research.

I highly suggest understanding the data structures before making promts. The mcp handels the api limits for you but it should be as targeted as possible.

Features

  • 🔍 Advanced Search: Search government documents with filtering, sorting, and pagination
  • 📚 Collections: Browse all available GovInfo collections
  • 📋 Package Details: Get metadata and granule information for specific documents
  • 📅 Date Filtering: Find documents by publication or modification dates
  • 🔗 Relationships: Discover related documents across collections
  • ⏱️ Rate Limiting: Built-in rate limiting (1000 calls/hour)
  • 🌐 Dual Interface: Use via MCP protocol or simple HTTP REST endpoints

Setup

1. Get Your API Key

  1. Go to api.data.gov
  2. Sign up for a free API key
  3. Request the GovInfo API access
  4. Copy your API key

2. Configure Environment

Create a .env file in the project root:

GOV_API_KEY=your_api_key_here

3. Install Dependencies

pip install -r requirements.txt

Running the Servers

Option 1: REST API Server Only (Recommended for Testing)

python api_server.py

Server runs on: http://127.0.0.1:8030

Swagger Docs: http://127.0.0.1:8030/docs

Option 2: MCP Server Only

python gov.api.mcp.py

Option 3: Run Both Simultaneously

In terminal 1:

python gov.api.mcp.py

In terminal 2:

python api_server.py

REST API Endpoints

Search Documents

Endpoint: POST /search

Parameters (query parameters or form data):

  • query (required): Search query (e.g., "congress bills")
  • offsetMark (optional): Pagination marker (default: "*")
  • sort (optional): Sort field (publishDate, lastModified, title)
  • collection (optional): Collection list to search (BILLS, CFR, FR, etc.)
  • historical (optional): Include historical documents (true/false, default: false)
  • pageSize (optional): Results per page (default: 10)

Example:

curl -X POST "http://127.0.0.1:8030/search?query=border+security&collection=BILLS&pageSize=50"

Search Synthesis

Endpoint: POST /search_synthesis

Description: 🎯 Synthesize search results into a concise summary with AI analysis

Parameters (JSON body):

  • search_query (required): Search query for synthesis
  • committees (optional): List of collection codes (e.g., ["BILLS", "FR"])

Examples:

# Immigration search with specific collections
curl -X POST "http://127.0.0.1:8030/search_synthesis" \
  -H "Content-Type: application/json" \
  -d '{"search_query": "immigration policy", "committees": ["BILLS", "FR"]}'

# Healthcare search with auto-detection
curl -X POST "http://127.0.0.1:8030/search_synthesis" \
  -H "Content-Type: application/json" \
  -d '{"search_query": "healthcare reform"}'

Get Collections

Endpoint: GET /collections

Returns all available GovInfo collections.

Example:

curl "http://127.0.0.1:8030/collections"

Search Collection by Date

Endpoint: GET /collections/{collection_id}/{last_modified}

Parameters:

  • collection_id: Collection identifier (e.g., USCODE, BILLS)
  • last_modified: Date in YYYY-MM-DD format
  • pageSize (optional): Results per page (default: 10)
  • offsetMark (optional): Pagination marker (default: "*")
  • congress (optional): Congress number (default: -1)
  • docClass (optional): Document class
  • billVersion (optional): Bill version
  • courtCode (optional): Court code
  • courtType (optional): Court type
  • state (optional): State
  • topic (optional): Topic
  • isGLP (optional): GLP status
  • natureSuitCode (optional): Nature of suit code
  • natureSuit (optional): Nature of suit

Example:

curl "http://127.0.0.1:8030/collections/USCODE/2025-01-01?pageSize=20&congress=118"

Search Collection by Date Range

Endpoint: GET /collections/{collection_id}/{start_date}/{end_date}

Parameters:

  • collection_id: Collection identifier
  • start_date: Start date (YYYY-MM-DD)
  • end_date: End date (YYYY-MM-DD)
  • pageSize (optional): Results per page (default: 10)
  • offsetMark (optional): Pagination marker (default: "*")
  • Additional filtering parameters: congress, docClass, billVersion, courtCode, courtType, state, topic, isGLP, natureSuitCode, natureSuit

Example:

curl "http://127.0.0.1:8030/collections/BILLS/2024-01-01/2024-12-31?pageSize=50"

Package Summary

Endpoint: GET /package/{package_id}/summary

Get detailed metadata for a specific package.

Example:

curl "http://127.0.0.1:8030/package/BILLS-118hr123ih/summary"

Package Granules

Endpoint: GET /package/{package_id}/granules

Get all granules (sub-documents) for a package.

Parameters:

  • package_id: Package identifier
  • pageSize (optional): Results per page (default: 10)
  • offsetMark (optional): Pagination marker (default: "*")

Example:

curl "http://127.0.0.1:8030/package/BILLS-118hr123ih/granules?pageSize=50"

Package Granule Summary

Endpoint: GET /package/{package_id}/granules/{granule_id}/summary

Get summary for a specific granule within a package.

Parameters:

  • package_id: Package identifier
  • granule_id: Granule identifier
  • pageSize (optional): Results per page (default: 10)

Example:

curl "http://127.0.0.1:8030/package/BILLS-118hr123ih/granules/BILLS-118hr123ih-1/summary"

Published Documents

Endpoint: GET /published/{start_date}

Get documents published on or after a specific date.

Parameters:

  • start_date: Date in YYYY-MM-DD format
  • collection (required): Collection identifier
  • pageSize (optional): Results per page (default: 10)
  • offsetMark (optional): Pagination marker (default: "*")

Example:

curl "http://127.0.0.1:8030/published/2025-01-01?collection=BILLS&pageSize=100"

Published Range

Endpoint: GET /published/{start_date}/{end_date}

Get documents published within a date range.

Parameters:

  • start_date: Start date in YYYY-MM-DD format
  • end_date: End date in YYYY-MM-DD format
  • collection (required): Collection identifier
  • pageSize (optional): Results per page (default: 10)
  • offsetMark (optional): Pagination marker (default: "*")

Example:

curl "http://127.0.0.1:8030/published/2024-01-01/2024-12-31?collection=FR&pageSize=50"

Related Documents

Endpoint: GET /related/{access_id}

Find documents related to a specific access ID.

Example:

curl "http://127.0.0.1:8030/related/BILLS-118hr123ih"

Related Documents in Collection

Endpoint: GET /related/{access_id}/{collection_id}

Find related documents within a specific collection.

Example:

curl "http://127.0.0.1:8030/related/BILLS-118hr123ih/USCODE"

Testing with Postman

  1. Import the collection or manually create requests for each endpoint
  2. Use the examples above as templates
  3. Replace {API_KEY} with your actual key (handled automatically by the server)
  4. Test each endpoint with your desired parameters

Rate Limiting

  • Limit: 1000 API calls per hour
  • Status: Automatically tracked across all requests
  • Warning: Server will return {"error": "API limit reached"} when limit is exceeded
  • Reset: Counter resets every hour

Common Issues

API Key Not Found

Error: "API key not found" Solution: Create a .env file with GOV_API_KEY=your_key_here

404 Errors on Endpoints

Issue: Using collection names instead of document IDs Solution: Use valid IDs (e.g., BILLS-118hr123ih, not USCODE for related documents)

400 Bad Request

Issue: Incorrect date format Solution: Use YYYY-MM-DD format for dates

Empty Response

Issue: Valid request but no matching results Solution: Try different search parameters or date ranges

Architecture

Two-Server Design

  1. gov.api.mcp.py - FastMCP Server

    • Implements MCP protocol for AI assistants
    • Runs on port 8090 with MCP transport
    • Ideal for integration with Claude and other AI tools
  2. api_server.py - FastAPI Server

    • Exposes simple REST HTTP endpoints
    • Imports and wraps tool functions from MCP server
    • Easier for testing and direct HTTP clients
    • Swagger UI at /docs

Data Flow

HTTP Request → api_server.py → MCP Tool Functions → GovInfo API
    ↓
  JSON Response

Available Collections

Common GovInfo collections:

  • BILLS: Congressional Bills
  • USCODE: U.S. Code
  • STATUE: U.S. Statutes
  • CFR: Code of Federal Regulations
  • FR: Federal Register
  • GOVPUB: Government Publications
  • PPP: Presidential Papers

Examples

Search for Bills About Energy

curl -X POST "http://127.0.0.1:8030/search?query=energy+efficiency&collection=BILLS&sort=publishDate&pageSize=50"

Find Federal Register Documents from Last Month

curl "http://127.0.0.1:8030/published/2024-12-01?collection=FR&pageSize=200"

Get CFR Changes in 2025

curl "http://127.0.0.1:8030/published/2025-01-01?collection=CFR"

Synthesize Immigration Policy Research

curl -X POST "http://127.0.0.1:8030/search_synthesis" \
  -H "Content-Type: application/json" \
  -d '{"search_query": "immigration reform legislation", "committees": ["BILLS", "CREC"]}'

Support

For issues with the GovInfo API itself, see api.govinfo.gov

For questions about this wrapper, check the code comments or submit an issue.

License

This project wraps the publicly accessible GovInfo API provided by the U.S. Government.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选