Skip to main content
Glama
CSMAR MCP Server

CSMAR MCP Server

by ww11-max

CSMAR MCP Server

License MCP Protocol Node.js Python

A Model Context Protocol (MCP) server for the CSMAR financial database, enabling direct access to CSMAR financial data within Claude Code.

✨ Features

  • Full CSMAR Data Access: Supports 240+ databases, including financial statements, stock trading data, company information, and more.

  • Intelligent Login Management: Supports automatic login via environment variables and token caching.

  • 11 MCP Tools: Comprehensive functionality covering database exploration, data querying, previewing, and more.

  • Persistent Python Process: Reuses Python sessions to significantly improve performance.

  • Request Retry Mechanism: Automatically retries when network instability occurs.

  • Graceful Shutdown: Supports SIGTERM/SIGINT signals.

  • Health Checks: Monitor service status at any time.

  • Python Middleware: Stable encapsulation based on the CSMAR-PYTHON SDK.

  • Simple Configuration: One-click configuration with native Claude Code integration.

Related MCP server: CSMAR MCP Server

📋 Prerequisites

  1. CSMAR Account: A valid CSMAR (GTA) institutional account (personal or institutional accounts are both supported).

  2. Python 3.8+: Requires the CSMAR-PYTHON SDK and its dependencies.

    • Install Python dependencies: pip install urllib3 websocket websocket_client pandas prettytable

    • Download and install the CSMAR-PYTHON SDK (from the official website or by contacting CSMAR).

  3. Node.js 18+: To run the MCP server.

  4. Claude Code: The latest version of the Claude Code editor.

🚀 Quick Start

1. Clone the Project

git clone https://github.com/ww11-max/Csmar-MCP-server.git
cd Csmar-MCP-server

2. Install Dependencies

# 安装Node.js依赖
npm install

# 安装Python依赖(CSMAR SDK所需)
pip install urllib3 websocket websocket_client pandas prettytable

# 安装CSMAR-PYTHON SDK
# 从CSMAR官网下载SDK压缩包,解压到Python的site-packages目录
# 或者按照官方文档安装:https://www.gtadata.com/products/csmar-api

3. Configure Environment Variables

Create a .env file in the project root directory:

# CSMAR 配置
CSMAR_API_BASE=https://api.gtarsc.com
CSMAR_USERNAME=你的CSMAR用户名
CSMAR_PASSWORD=你的CSMAR密码
CSMAR_LANG=0  # 0=中文, 1=英文

⚠️ Security Tip: Do not commit the .env file to Git! It is already configured in .gitignore to be ignored automatically.

4. Configure Claude Code (Includes both Claude Desktop and VS Code extension configuration methods)

Add the MCP server configuration to your Claude Code configuration file:

Windows (%APPDATA%/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "csmar": {
      "command": "node",
      "args": ["C:\\path\\to\\Csmar-MCP-server\\src\\index.js"],
      "env": {
        "CSMAR_API_BASE": "https://api.gtarsc.com",
        "CSMAR_USERNAME": "你的CSMAR用户名",
        "CSMAR_PASSWORD": "你的CSMAR密码",
        "CSMAR_LANG": "0"
      }
    }
  }
}

macOS/Linux (~/.config/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "csmar": {
      "command": "node",
      "args": ["/path/to/Csmar-MCP-server/src/index.js"],
      "env": {
        "CSMAR_API_BASE": "https://api.gtarsc.com",
        "CSMAR_USERNAME": "你的CSMAR用户名",
        "CSMAR_PASSWORD": "你的CSMAR密码",
        "CSMAR_LANG": "0"
      }
    }
  }
}

If you are using the Claude Code extension in VS Code, configure it as follows:

After configuring the env file, modify the Claude Code MCP configuration. The MCP configuration file for Claude Code in VS Code is located at:

%APPDATA%/Code/User/globalStorage/saoudval.claude-code/mcp.json

Alternatively, search for "MCP" in VS Code settings to find the MCP Servers configuration entry. Add the configuration:

{
  "mcpServers": {
    "csmar": {
      "command": "node",
      "args": ["C:\\path\\to\\Csmar-MCP-server\\src\\index.js"],
      "env": {
        "CSMAR_API_BASE": "https://api.gtarsc.com",
        "CSMAR_USERNAME": "你的CSMAR用户名",
        "CSMAR_PASSWORD": "你的CSMAR密码",
        "CSMAR_LANG": "0"
      }
    }
  }
}

⚠️ The path must be replaced with your actual cloned project path, e.g., D:\Projects\Csmar-MCP-server\src\index.js

5. Restart Claude Code

Restart Claude Code to load the MCP server.

🔧 Usage

Verify Installation

mcp__csmar__csmar_health_check()

Basic Data Exploration

# 列出所有可用数据库(约240个)
mcp__csmar__csmar_list_databases()

# 查看"财务报表"数据库中的表
mcp__csmar__csmar_list_tables(database_name="财务报表")

# 查看"FS_Combas"表的字段
mcp__csmar__csmar_list_fields(table_name="FS_Combas")

# 预览表数据(前几行)
mcp__csmar__csmar_preview(table_name="FS_Combas")

Data Query Example

# 查询财务报表数据
mcp__csmar__csmar_query(
    table_name="FS_Combas",
    columns=["Stkcd", "ShortName", "Accper", "Typrep", "A001000000"],
    condition="Stkcd like '3%' and Typrep='A'",
    start_time="2020-01-01",
    end_time="2021-12-31",
    limit=5
)

# 查询记录数量
mcp__csmar__csmar_query_count(
    table_name="FS_Combas",
    condition="Stkcd like '3%'",
    start_time="2020-01-01",
    end_time="2021-12-31"
)

# 获取股票数据
mcp__csmar__get_stock_data(
    stock_code="000001",
    start_date="2024-01-01",
    end_date="2024-12-31",
    frequency="daily"
)

# 获取财务数据
mcp__csmar__get_financial_data(
    stock_code="000001",
    start_date="2020-01-01",
    end_date="2024-12-31",
    indicators=["A001000000", "A002000000"]
)

# 获取公司信息
mcp__csmar__get_company_info(stock_code="000001")

🛠️ Available Tools

Tool Name

Description

Parameters

csmar_health_check

Check service health status

None

csmar_login

Log in to CSMAR account

account, pwd, lang

csmar_list_databases

List accessible databases

None

csmar_list_tables

List tables in a database

database_name

csmar_list_fields

List fields in a table

table_name

csmar_query

General data query

table_name, columns, condition, start_time, end_time, limit, format

csmar_preview

Preview table data

table_name

csmar_query_count

Query record count

table_name, columns, condition, start_time, end_time

get_stock_data

Get stock trading data

stock_code, start_date, end_date, frequency

get_financial_data

Get financial data

stock_code, start_date, end_date, indicators

get_company_info

Get basic company info

stock_code

📁 Project Structure

csmar-mcp-server/
├── src/
│   ├── index.js              # MCP 服务器主文件
│   └── python_client.py      # Python 客户端
├── config/
│   ├── .env.example          # 环境变量示例
│   └── .mcp.json             # MCP 配置示例
├── docs/
│   ├── CSMAR_MCP_配置完成报告.md
│   ├── 快速开始指南.md
│   └── CSMAR机构账号配置指南.md
├── examples/
│   └── test_input.json       # 测试输入示例
├── package.json              # Node.js 依赖
├── README.md                 # 本文件
└── .gitignore               # Git 忽略文件

Common Databases

  • Financial Statements: 财务报表, FS_Combas, FS_Comins, FS_Comscfd

  • Stock Trading: 股票市场交易数据, 股票日行情

  • Company Info: 公司基本信息, 上市公司基本信息

  • Macroeconomics: 宏观经济数据库

Data Time Range

  • Financial Statements: 2018-2022

  • AI-related Data: 2024-2025

  • Stock Trading: Updated in real-time

⚠️ Notes

Query Limits

  • Max 200,000 records per query: Large datasets require paginated queries.

  • 30-minute rate limit for identical conditions: Avoid frequent queries with the same conditions.

  • Time Format: Must use "YYYY-MM-DD" format.

Paginated Query Example

# 第1页
condition = "Stkcd like '3%' limit 0,200000"
# 第2页
condition = "Stkcd like '3%' limit 200000,200000"

mcp__csmar__csmar_query(
    table_name="FS_Combas",
    columns=["Stkcd", "ShortName", "Accper", "Typrep"],
    condition=condition
)

🐛 Troubleshooting

Common Issues

1. "MCP Server not responding"

  • Confirm Claude Code has been restarted.

  • Check if the configuration file path is correct.

  • Manually test the Python client:

    echo '{"action":"check_availability","params":{}}' | python src/python_client.py --once

2. "Database does not exist"

  • Use csmar_list_databases() to get the exact name.

  • Check if the database name contains spaces.

  • Confirm your account has access to that database.

3. Query results are empty

  • Check if the time range is correct.

  • Verify the query condition syntax.

  • Use preview() to check the data format first.

4. CSMAR SDK import failure

  • Confirm the CSMAR-PYTHON SDK is installed correctly.

  • Run python src/python_client.py to view detailed error information.

Log Files

  • Python Client Logs: Output via stderr.

  • MCP Server Logs: Output via stderr.

🔄 Changelog

v1.1.0 (2026-04-15)

  • ✨ Added persistent Python process mode for significantly improved performance.

  • ✨ Added csmar_health_check tool.

  • ✨ Implemented get_stock_data, get_financial_data, and get_company_info tools.

  • 🔧 Fixed hardcoded Python path issue; now automatically detects site-packages.

  • 🔧 Fixed zod import issue.

  • 🔧 Added request retry mechanism.

  • 🔧 Added graceful shutdown support.

v1.0.0

  • 🎉 Initial release.

🤝 Contributing

Issues and Pull Requests are welcome!

  1. Fork the project.

  2. Create a feature branch (git checkout -b feature/amazing-feature).

  3. Commit your changes (git commit -m 'Add amazing feature').

  4. Push to the branch (git push origin feature/amazing-feature).

  5. Create a Pull Request.

📄 License

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

🙏 Acknowledgments

  • CSMAR (GTA): For providing financial data services.

  • Anthropic: For developing the Model Context Protocol.

  • Claude Code: For the excellent AI programming environment.

📞 Support


💡 Tip: Before you start, ensure your CSMAR account and environment variables are configured correctly!

Available Tools

11 tools
csmar_health_checkA

检查 CSMAR 服务健康状态

Inputs: no named parameters.

csmar_list_databasesA

列出用户有权访问的 CSMAR 数据库

Inputs: no named parameters.

csmar_list_fieldsB

列出指定表中的所有字段

Inputs: table_name (required).

csmar_list_tablesB

列出指定数据库中的所有表

Inputs: database_name (required).

csmar_loginC

登录 CSMAR 账户

Inputs: account (required), pwd (required), lang.

csmar_previewC

预览表数据 (前几行)

Inputs: table_name (required).

csmar_queryD

通用 CSMAR 数据查询

Inputs: table_name (required), columns, condition, start_time, +3 more.

csmar_query_countC

查询满足条件的记录数量

Inputs: table_name (required), columns, condition, start_time, +1 more.

get_company_infoC

获取公司基本信息

Inputs: stock_code (required).

get_financial_dataC

获取 CSMAR 财务数据

Inputs: stock_code (required), start_date (required), end_date (required), indicators.

get_stock_dataC

获取 CSMAR 股票交易数据

Inputs: stock_code (required), start_date (required), end_date (required), frequency.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    C2.9/5.0

    Scored across 11 tools

    Disambiguation4/5

    Most tools have clearly distinct purposes (e.g., listing databases vs tables vs fields, login vs query). However, the three 'get_*' tools (get_company_info, get_financial_data, get_stock_data) could overlap with the generic csmar_query since all fetch data, but descriptions and specific naming mitigate confusion.

    Naming Consistency3/5

    Tools are in snake_case, but eight are prefixed with 'csmar_' while three (get_company_info, get_financial_data, get_stock_data) lack this prefix. This inconsistency breaks the pattern and could cause agents to misgroup tools.

    Tool Count5/5

    11 tools is appropriate for a data retrieval service covering login, database exploration, querying, counting, previewing, and specific data endpoints. Each tool earns its place without being excessive.

    Completeness4/5

    The tool set covers core CRUD-like operations for data retrieval: listing databases/tables/fields, querying, counting, previewing, and accessing specific data types. Missing write/update/delete operations, but those likely fall outside the scope of a read-only CSMAR data service.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Provides professional financial data access for LLMs via MCP, supporting providers like Tushare, Wind, and DataYes.
      14
      57
      Apache 2.0
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables access to the CSMAR financial database via MCP, providing tools for querying financial data, stock data, company info, and more through natural language in compatible clients like Codex and Claude Code.
      3
      MIT
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables AI assistants to access real-time quotes, K-line data, technical indicators, sector/futures/options data, and composite stock analysis across A-share, Hong Kong, US, and fund markets through MCP tools, prompts, and resources.
      140 npm
      ISC
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables AI assistants to access real-time and historical stock, fund, futures, and options market data across A-share, Hong Kong, and US markets, along with technical indicators, sector analysis, composite screening, and market overviews through MCP tools, prompts, and resources.
      140 npm
      ISC