Skip to main content
Glama
agentladle

AgentLadle MCP CNINFO

by agentladle
README.md
# AgentLadle MCP CNINFO

**English** | [ไธญๆ–‡](README_zh.md)

> ๐Ÿ‡จ๐Ÿ‡ณ/๐Ÿ‡ญ๐Ÿ‡ฐ Cloud-hosted MCP for A-share & HK listed companies (Past 3 years annual & latest interim reports). [Read more](https://github.com/achuan101/agentladle-mcp) | [Get API Key](https://agentladle.com/register)

A [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) server that provides tools for **discovering, downloading, parsing, and searching** China A-share announcements from [CNINFO (ๅทจๆฝฎ่ต„่ฎฏ็ฝ‘)](http://www.cninfo.com.cn).

It enables AI assistants (Claude, Cursor, etc.) to access CNINFO announcement data through 6 structured tools โ€” from discovering available announcements to keyword-searching within their pages.

> **Scope (v0.1):** Announcements only. Periodic reports (ๅนดๆŠฅ / ๅŠๅนดๆŠฅ / ไธ€ๅญฃๆŠฅ / ไธ‰ๅญฃๆŠฅ) are out of scope.

## Features

- **6 MCP tools** for CNINFO announcement data: state-driven retrieval (search directly, fallback to download/parse only when needed)
- **PDF document parsing** using [PyMuPDF](https://pymupdf.readthedocs.io/) โ€” physical page extraction into page-split JSON
- **Local keyword search** with TF + position-boost scoring, zero external search dependencies
- **Idempotent** โ€” already-downloaded/parsed files are automatically skipped
- **Zero-config install** โ€” one line to add to your MCP client, no clone or manual setup needed
- **Pure Python**, cross-platform (Windows / macOS / Linux)

## Prerequisites

- **Python 3.10+** โ€” [Download Python](https://www.python.org/downloads/)
- **uv** โ€” [Install uv](https://docs.astral.sh/uv/getting-started/installation/)

> **Note:** After installing uv, restart your terminal and MCP client (e.g. Cherry Studio) to ensure the `uv` command is recognized.

## Quick Start

Add to your MCP client configuration (Claude Desktop, Cursor, etc.):

```json
{
  "mcpServers": {
    "mcp-cninfo": {
      "command": "uvx",
      "args": ["agentladle-mcp-cninfo"]
    }
  }
}
```

That's it. `uvx` will automatically download the package and its dependencies from PyPI โ€” no clone, no manual install, no path configuration.

### Alternative: pip install

If you prefer managing the environment yourself:

```bash
pip install agentladle-mcp-cninfo
```

Then configure:

```json
{
  "mcpServers": {
    "mcp-cninfo": {
      "command": "agentladle-mcp-cninfo"
    }
  }
}
```

### Alternative: Run from source (local development)

Clone the repository and run directly:

```bash
git clone https://github.com/agentladle/mcp-cninfo.git
```

Then configure your MCP client:

```json
{
  "mcpServers": {
    "mcp-cninfo": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/mcp-cninfo", "agentladle-mcp-cninfo"]
    }
  }
}
```

Replace `/path/to/mcp-cninfo` with the actual path to the cloned repository.

## Data Flow

```
CNINFO API                        Local Files (~/.agentladle/mcp-cninfo/data/)
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                    โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
szse_stock.json        โ”€โ”€โ†’       companies.json               (stock_codeโ†’orgId mapping)
                                     โ”‚
hisAnnouncement/query  โ”€โ”€โ†’        pdf/{LOCAL_KEY}/            (Tool 2: primary PDF/HTML + manifest)
                                     โ”‚
PyMuPDF parsing        โ”€โ”€โ†’        json/*.json                 (Tool 3: parse, page-split)
                                     โ”‚
Local TF search        โ”€โ”€โ†’        search results              (Tool 4: keyword search)
Page range read        โ”€โ”€โ†’        page content                (Tool 5: read pages)
```

## Tools

| # | Tool | Description |
|---|------|-------------|
| 1 | `list_cninfo_announcements` | Discover available CNINFO announcements for a company |
| 2 | `download_cninfo_announcement` | Download announcement PDF (HTML fallback); idempotent |
| 3 | `parse_cninfo_announcement` | Parse PDF/HTML into page-split JSON using PyMuPDF |
| 4 | `keyword_search` | Full-text keyword search with TF relevance scoring |
| 5 | `get_announcement_pages` | Read announcement content by page number range |
| 6 | `lookup_stock_code` | **Diagnostic**: look up stock_codeโ†’orgId mapping when resolution fails |

### Tool 1: `list_cninfo_announcements`

List available CNINFO announcements for a company. Use this tool ONLY when the exact date/title is unspecified by the user, or when a download attempt fails due to an ambiguous match. Default categories exclude periodic reports (ๅนดๆŠฅ / ๅŠๅนดๆŠฅ / ไธ€ๅญฃๆŠฅ / ไธ‰ๅญฃๆŠฅ).

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `stock_code` | string | โœ… | 6-digit stock code, e.g. `"000001"` |
| `category` | string | โŒ | Category key, short code, or Chinese label, e.g. `"่‘ฃไบ‹ไผš"`, `"DSH"`, `"category_dshgg_szsh"`. Omit to list default announcement categories |
| `start_date` | string | โŒ | Start date `YYYY-MM-DD` |
| `end_date` | string | โŒ | End date `YYYY-MM-DD` |
| `title_keyword` | string | โŒ | Title keyword filter |
| `limit` | int | โŒ | Max announcements to return, default 10, max 50 |

### Tool 2: `download_cninfo_announcement`

Download a specific CNINFO announcement from static.cninfo.com.cn. Prefer `local_key` from `list_cninfo_announcements` when available. Idempotent.

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `stock_code` | string | โœ… | 6-digit stock code, e.g. `"000001"` |
| `announce_date` | string | โŒ | Announce date `YYYY-MM-DD` (optional if `local_key` provided) |
| `title_keyword` | string | โŒ | Title substring to disambiguate same-day announcements |
| `category` | string | โŒ | Optional category filter |
| `announcement_id` | string | โŒ | CNINFO announcement id if known |
| `local_key` | string | โŒ | Exact local bundle key from list results |

### Tool 3: `parse_cninfo_announcement`

Parse a downloaded announcement PDF/HTML into page-split JSON. Uses PyMuPDF for PDF physical-page text extraction.

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `local_key` | string | โœ… | Bundle key returned by list/download, e.g. `"000001_DSH_2026-07-02_8b1ad607"` |

### Tool 4: `keyword_search`

Full-text keyword search across all pages. Results ranked by TF + position-boost score.

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `local_key` | string | โœ… | Bundle key |
| `keywords` | string[] | โœ… | 1โ€“5 search keywords |
| `match_mode` | string | โŒ | `"ANY"` (default, any keyword matches) / `"ALL"` (all must match) |
| `max_results` | int | โŒ | Max results to return, default 5, max 50 |

### Tool 5: `get_announcement_pages`

Read full page content by page number range.

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `local_key` | string | โœ… | Bundle key |
| `start_page` | int | โœ… | Start page number (1-based) |
| `page_count` | int | โŒ | Number of pages to return, default 3, max 5 |

### Tool 6: `lookup_stock_code`

Diagnostic tool: look up stock_codeโ†’orgId mapping. Use only when `download_cninfo_announcement` / `list_cninfo_announcements` returns `Stock code not found`. Bypasses the session failed-code cache.

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `stock_code` | string | โœ… | 6-digit stock code, e.g. `"000001"` |
| `refresh` | bool | โŒ | Force re-download of `szse_stock.json` from CNINFO (default: `false`) |

## Configuration

On first run, a default config file is created at `~/.agentladle/mcp-cninfo/config.yaml`:

```yaml
paths:
  data_dir: "~/.agentladle/mcp-cninfo/data"
  pdf_dir: "~/.agentladle/mcp-cninfo/data/pdf"
  json_dir: "~/.agentladle/mcp-cninfo/data/json"

download:
  delay_between_requests: 0.3
  min_file_size: 500
  list_page_size: 30
  list_max_pages: 5

company:
  cache_ttl_days: 7
```

## Data Directory Structure

```
~/.agentladle/mcp-cninfo/
โ”œโ”€โ”€ config.yaml                        # Configuration (auto-created)
โ””โ”€โ”€ data/
    โ”œโ”€โ”€ companies.json                 # stock_codeโ†’orgId mapping (auto-downloaded & cached)
    โ”œโ”€โ”€ pdf/                           # Downloaded announcement bundles
    โ”‚   โ”œโ”€โ”€ 000001_DSH_2026-07-02_8b1ad607/
    โ”‚   โ”‚   โ”œโ”€โ”€ primary.pdf
    โ”‚   โ”‚   โ””โ”€โ”€ manifest.json
    โ”‚   โ””โ”€โ”€ ...
    โ””โ”€โ”€ json/                          # Parsed page-split JSON
        โ”œโ”€โ”€ 000001_DSH_2026-07-02_8b1ad607.json
        โ””โ”€โ”€ ...
```

**File naming convention:** `{STOCK_CODE}_{CAT_SHORT}_{ANNOUNCE_DATE}_{ID_HASH}`

## Example Usage

The tools are designed with an **EAFP (Easier to Ask for Forgiveness than Permission)** approach. AI assistants should attempt to retrieve data directly and rely on errors to trigger downloads.

**Scenario A: File already exists locally (Shortest Path)**
```
User: "Search 000001 board resolution for ๅ›ž่ดญ"

1. keyword_search(local_key="000001_DSH_2026-07-02_8b1ad607", keywords=["ๅ›ž่ดญ", "ๅ†ณ่ฎฎ"])
   โ†’ Returns page snippets matching the keywords immediately.
```

**Scenario B: File missing (Fallback triggered)**
```
User: "What did Ping An Bank announce in its latest board notice?"

1. list_cninfo_announcements(stock_code="000001", category="่‘ฃไบ‹ไผš", limit=3)
   โ†’ Returns local_key / announce_date / title.

2. keyword_search(local_key="...", keywords=["่‘ฃไบ‹ไผš", "ๅ†ณ่ฎฎ"])
   โ†’ Error: File not found.

3. download_cninfo_announcement(stock_code="000001", local_key="...")
   โ†’ Downloads PDF to ~/.agentladle/mcp-cninfo/data/pdf/

4. parse_cninfo_announcement(local_key="...")
   โ†’ Parses into JSON.

5. keyword_search(local_key="...", keywords=["่‘ฃไบ‹ไผš", "ๅ†ณ่ฎฎ"])
   โ†’ Retries search and returns data.
```

## Tech Stack

| Component | Choice | Purpose |
|-----------|--------|---------|
| MCP Framework | `mcp` (FastMCP) | MCP server with stdio transport |
| HTTP Client | `httpx` | CNINFO API requests & file downloads |
| PDF Parsing | `pymupdf` + `beautifulsoup4` | PDF page text extraction; HTML fallback |
| Search | Python built-in | TF + position-boost scoring |
| Config | `pyyaml` | YAML configuration file |

## Project Structure

```
src/mcp_cninfo/
โ”œโ”€โ”€ __init__.py
โ”œโ”€โ”€ server.py                 # MCP Server entry point
โ”œโ”€โ”€ config.py                 # Config loading (~/.agentladle/mcp-cninfo/config.yaml, singleton cached)
โ”œโ”€โ”€ models.py                 # Data models
โ”œโ”€โ”€ categories.py             # Announcement category whitelist / blacklist
โ”œโ”€โ”€ response.py               # Unified JSON responses
โ”œโ”€โ”€ instances.py              # Service singletons
โ”œโ”€โ”€ tools/
โ”‚   โ”œโ”€โ”€ list_announcements.py # Tool 1: list_cninfo_announcements
โ”‚   โ”œโ”€โ”€ download.py           # Tool 2: download_cninfo_announcement
โ”‚   โ”œโ”€โ”€ parse.py              # Tool 3: parse_cninfo_announcement
โ”‚   โ”œโ”€โ”€ search.py             # Tool 4: keyword_search
โ”‚   โ”œโ”€โ”€ page.py               # Tool 5: get_announcement_pages
โ”‚   โ””โ”€โ”€ lookup.py             # Tool 6: lookup_stock_code
โ””โ”€โ”€ services/
    โ”œโ”€โ”€ company.py            # CNINFO szse_stock.json + stock_codeโ†’orgId
    โ”œโ”€โ”€ downloader.py         # CNINFO query + PDF download
    โ”œโ”€โ”€ parser.py             # PDF/HTMLโ†’JSON parsing (PyMuPDF)
    โ”œโ”€โ”€ searcher.py           # Local JSON search + TF scoring
    โ””โ”€โ”€ keys.py               # local_key helpers
```

## License

MIT

TDQS

A4.6/5.0

Scored across 6 tools

Disambiguation5/5

Each tool has a distinct role: listing, downloading, parsing, searching, page retrieval, and stock code lookup. No overlap in functionality, making it easy for an agent to select the correct tool.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern in snake_case (e.g., list_cninfo_announcements, download_cninfo_announcement, lookup_stock_code). Minor variation in verb choice ('lookup' vs 'list') is negligible.

Tool Count5/5

With 6 tools covering the core workflow of discovering, downloading, parsing, and searching announcements, the count is well-scoped and avoids bloat. Each tool serves a necessary step in the process.

Completeness4/5

The tool set covers the primary lifecycle: list, download, parse, keyword search within a document, and page retrieval. Missing a cross-announcement search or category listing, but these are minor gaps that do not break the workflow.

Maintenance

ActivityMaintained
ResponsivenessNo issues