车辆数据协议服务器

NHTSA MCP服务器提供对NHTSA API的结构化访问,涵盖车辆识别、安全评级、召回、消费者投诉、制造商和车型数据、零件以及汽车座椅检查站。

  • by Christophertdoc
  • Python
  • 本地部署
  • 4 星标
  • 更新于
在 GitHub 查看 Christophertdoc/nhtsa-mcp

使用说明

NHTSA MCP服务器

MCP(模型上下文协议)服务器,提供对NHTSA(国家公路交通安全管理局)API的结构化访问,涵盖车辆识别(VIN/WMI解码)、安全评级、召回、消费者投诉、制造商和型号数据、零件和汽车座椅检查站。

特性

  • 20个MCP工具,覆盖5个NHTSA API表面+全vPIC端点覆盖
  • 严格的Pydantic v2输入验证
  • 每个域的内存TTL缓存
  • 每IP滑动窗口速率限制
  • HTTP/SSE和stdio MCP传输
  • Typer CLI测试线束
  • LLM工具调用代理(Anthropic/OpenAI)

MCP工具

工具 说明
decode_vin_tool 通过vPIC解码17个字符的VIN
ratings_search_tool 按年份/品牌/型号搜索NCAP安全评级
ratings_by_vehicle_id_tool 获取NHTSA车辆ID的详细评级
recalls_by_vehicle_tool 按年份/品牌/型号搜索召回
recalls_by_campaign_number_tool 按活动编号查找召回
complaints_by_vehicle_tool 按年份/品牌/型号搜索投诉
complaints_by_odi_number_tool 通过ODI号码查找投诉
carseat_stations_by_zip_tool 按邮政编码查找汽车座椅检查站
carseat_stations_by_state_tool 按州代码查找车站
carseat_stations_by_geo_tool 按纬度/长度/半径查找车站
decode_wmi_tool 解码世界制造商标识符(WMI)
decode_vin_batch_tool 在一个请求中批量解码多达50个VIN
get_all_makes_tool 列出在NHTSA注册的所有车辆品牌
get_makes_tool 按制造商、车辆类型和/或年份获取品牌
get_manufacturers_tool 查找制造商、详细信息或WMI
get_models_tool 获取某个品牌的型号,可选择按年份/类型筛选
get_vehicle_types_tool 获取某品牌的车型
get_vehicle_variables_tool 列出VIN解码变量或获取变量值
get_parts_tool 按日期范围搜索NHTSA零件(轮胎/轮辋)
get_equipment_plant_codes_tool 按年份和类型获取设备工厂代码

快速开始

# Install uv (if needed)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install dependencies
uv sync --extra dev
cp .env.example .env  # edit to add API keys if using LLM agent

# Start the server
uv run uvicorn app.main:app --host 127.0.0.1 --port 8000 --reload

# Begin chat session.
uv run nhtsa-cli agent chat   # interactive REPL session

# Health check
curl http://127.0.0.1:8000/health

# MCP stdio transport (for Claude Desktop)
uv run nhtsa-mcp --transport stdio

聊天会话

与NHTSA数据交互的主要方式是通过交互式聊天会话。它将您连接到LLM代理,该代理可以访问所有MCP工具,并可以用自然语言回答有关车辆识别、安全、召回、投诉、制造商、型号等问题。

uv run nhtsa-cli agent chat

这打开了一个 >>> 提示您可以在哪里提问。代理将自动调用正确的NHTSA工具,组合来自多个来源的数据,并以摘要进行响应。您的对话历史记录会保存在同一会话中的问题中,因此您可以提出后续问题。

示例问题:

>>> Decode VIN 4S4BL86C764213492 and tell me if there are any recalls for the vehicle
>>> Are there any recalls on a 2021 Ford Mustang?
>>> What are the crash test ratings for a 2023 Toyota Camry?
>>> What models does Honda make?
>>> Show me complaints for a 2012 Toyota Corolla
>>> Find car seat inspection stations near ZIP 63640
>>> Find rim manufacturers that registered parts between 3/1/2023 and 12/31/2023. Show me just the first result.

退出聊天: 类型 exit 或 quit 在提示下,或按 Ctrl+C.

您还可以在不进入互动环节的情况下提出一个一次性问题:

uv run nhtsa-cli agent ask "What are the safety ratings for a 2020 Toyota Camry?"

其他CLI命令

# Run a preset demo of the agent
uv run nhtsa-cli agent demo

# Direct tool commands (requires running server)
uv run nhtsa-cli tool decode-vin 1FA6P8AM0G5227539
uv run nhtsa-cli tool ratings-search 2020 Toyota Camry
uv run nhtsa-cli tool recalls 2020 Toyota Camry
uv run nhtsa-cli tool complaints 2020 Toyota Camry
uv run nhtsa-cli tool carseat --zip 20001

# Server commands
uv run nhtsa-cli server health
uv run nhtsa-cli server list-tools
uv run nhtsa-cli server start --port 8000 --reload

发展

# Run unit tests
uv run pytest tests/unit/ tests/cli/ -v

# Run with coverage
uv run pytest tests/unit/ tests/cli/ --cov=app --cov=cli --cov-report=term-missing

# Integration tests (live NHTSA network)
uv run pytest tests/integration/ -m integration -v

# Lint and format
uv run ruff check app/ cli/ tests/
uv run ruff format app/ cli/ tests/

# Type check
uv run mypy app/ cli/

建筑

  • app/main.py --FastMCP实例、FastAPI健康端点、生命周期管理
  • app/config.py --复制设置配置
  • app/models/ --Pydantic v2输入验证器和输出类型
  • app/nhtsa_clients/ --带有重试、信号量和路径分配列表的键入HTTP客户端
  • app/mcp_tools/ --20个MCP工具实施
  • app/security/ --速率限制器、输出清理器、异步TTL缓存
  • cli/ --Typer CLI、MCP客户端包装器、LLM代理