Owner avatar beijing-car-quota-draw

Owner avatar beijing-car-quota-draw

Owner avatar beijing-car-quota-draw

Category
访问服务器

README

Beijing Car Quota Lottery MCP Server

An MCP (Model Context Protocol) server that provides AI agents with the ability to query Beijing car quota lottery results. This server scrapes data from the Beijing Transportation Commission website and exposes search capabilities through a standardized MCP interface.

Features

  • 🔍 Smart Search: Search by application code (申请编码) or partial ID number
  • 📄 PDF Processing: Automatically parses different PDF formats (waiting lists and score rankings)
  • 🌐 Web Scraping: Scrapes latest data from Beijing Transportation Commission website
  • 🤖 AI Integration: Exposes functionality as MCP tools for AI agents like Claude, Cursor, etc.
  • 💾 Data Persistence: Stores processed data locally with fast indexing
  • 📊 Statistics: Provides insights into loaded data and search results

Tech Stack

  • Language: Python 3.9+
  • Web Framework: FastAPI
  • MCP Framework: fastapi-mcp
  • PDF Processing: pdfplumber
  • Web Scraping: crawl4ai
  • Dependency Management: uv

Installation

Prerequisites

  • Python 3.9 or higher
  • uv (recommended) or pip

Using uv (Recommended)

# Clone the repository
git clone <repository-url>
cd bjhjyd-mcp

# Install dependencies
uv sync

# Activate virtual environment
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

Using pip

# Clone the repository
git clone <repository-url>
cd bjhjyd-mcp

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -e .

Quick Start

1. Start the MCP Server

# Using the main module
python -m bjhjyd_mcp.main

# Or with custom settings
python -m bjhjyd_mcp.main --host 0.0.0.0 --port 8080 --log-level DEBUG

The server will start at http://127.0.0.1:8000 by default.

2. Access the API

  • API Documentation: http://127.0.0.1:8000/docs
  • MCP Endpoint: http://127.0.0.1:8000/mcp
  • Health Check: http://127.0.0.1:8000/health

3. Configure AI Clients

For Cursor IDE

  1. Go to Settings → MCP → Add new MCP server
  2. Add this configuration:
{
  "mcpServers": {
    "Beijing Car Quota": {
      "url": "http://127.0.0.1:8000/mcp"
    }
  }
}

For Claude Desktop

  1. Install mcp-proxy: uv tool install mcp-proxy
  2. Configure in claude_desktop_config.json:
{
  "mcpServers": {
    "Beijing Car Quota": {
      "command": "mcp-proxy",
      "args": ["http://127.0.0.1:8000/mcp"]
    }
  }
}

Available MCP Tools

The server exposes the following tools for AI agents:

1. search_by_application_code

Search for quota results by application code (申请编码).

Parameters:

  • application_code (string): The application code to search for

Example:

{
  "application_code": "1437100439239"
}

2. search_by_id_number

Search for quota results by partial ID number (first 6 and last 4 digits).

Parameters:

  • id_prefix (string): First 6 digits of ID number
  • id_suffix (string): Last 4 digits of ID number

Example:

{
  "id_prefix": "110228",
  "id_suffix": "1240"
}

3. get_data_statistics

Get statistics about loaded quota data.

Returns: Information about total files, entries, and data breakdown.

4. refresh_data

Refresh quota data by scraping the latest PDFs from the website.

Parameters:

  • max_pages (integer, optional): Maximum pages to scrape (default: 5)

5. list_data_files

List all loaded quota data files with metadata.

6. health_check

Check server health and status.

Data Formats

The server handles two types of PDF formats from the Beijing Transportation Commission:

1. Waiting List (轮候序号列表)

  • Fields: 序号, 申请编码, 轮候时间
  • Purpose: Time-based ordering for quota applications

2. Score Ranking (积分排序入围名单)

  • Fields: 序号, 申请编码, 姓名, 身份证号, 家庭代际数, 积分, 注册时间
  • Purpose: Score-based ranking with personal information
  • Privacy: ID numbers are masked (e.g., 110228********1240)

Development

Project Structure

src/
├── bjhjyd_mcp/
│   ├── __init__.py
│   ├── main.py              # Entry point
│   ├── models/              # Data models
│   │   ├── quota_result.py
│   ├── parsers/             # PDF parsing
│   │   ├── pdf_parser.py
│   ├── scrapers/            # Web scraping
│   │   ├── web_scraper.py
│   ├── server/              # MCP server
│   │   ├── mcp_server.py
│   ├── storage/             # Data storage
│   │   ├── data_store.py
│   └── utils/               # Utilities
│       ├── logging_config.py
└── tests/
    ├── unit/
    └── integration/

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=src --cov-report=html

# Run specific test file
pytest src/tests/unit/test_pdf_parser.py

Code Quality

# Format code
black src/

# Sort imports
isort src/

# Type checking
mypy src/

# Linting
flake8 src/

Configuration

Environment Variables

  • LOG_LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  • DATA_DIR: Directory for storing processed data
  • DOWNLOADS_DIR: Directory for downloaded PDF files

Command Line Options

python -m bjhjyd_mcp.main --help

API Examples

Direct API Usage

import httpx

# Search by application code
response = httpx.post(
    "http://127.0.0.1:8000/search/application-code",
    json={"application_code": "1437100439239"}
)
print(response.json())

# Get statistics
response = httpx.get("http://127.0.0.1:8000/data/statistics")
print(response.json())

Using with AI Agents

Once configured, AI agents can use natural language to query the data:

  • "Check if application code 1437100439239 won the lottery"
  • "Search for ID number starting with 110228 and ending with 1240"
  • "Show me the latest quota lottery statistics"
  • "Refresh the data with new PDFs from the website"

Troubleshooting

Common Issues

  1. Server won't start

    • Check if port 8000 is available
    • Verify all dependencies are installed
    • Check logs for specific error messages
  2. No data found

    • Run refresh_data tool to scrape latest PDFs
    • Check if example PDFs exist in the examples/ directory
    • Verify network connectivity for web scraping
  3. PDF parsing errors

    • Check PDF format compatibility
    • Verify PDF files are not corrupted
    • Review parsing logs for specific issues

Logging

Enable debug logging for detailed information:

python -m bjhjyd_mcp.main --log-level DEBUG --log-file logs/server.log

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This tool is for educational and research purposes only. Please respect the Beijing Transportation Commission's terms of service and rate limits when scraping their website.

推荐服务器

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

官方
精选