CSMAR MCP
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@CSMAR MCPList all available CSMAR databases"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
CSMAR MCP
面向 Agent 工作流的精简 MCP 服务器:提供 CSMAR 元数据发现、查询可行性探测,以及本地物化。
对外接口
工具
csmar_list_databases确定性枚举已购买的数据库。命中元数据缓存时零 API 调用。csmar_list_tables确定性枚举指定数据库下的表。命中元数据缓存时零 API 调用;若持旧缓存撞上not_purchased会自动失效并重取一次。csmar_get_table_schema返回纯表结构与字段元数据,不返回样本行。命中元数据缓存时零 API 调用。csmar_bulk_schema一次性获取多个table_code的表结构(上限 20 个)。cache-first:已缓存的条目零 API 调用,只有真正的 miss 会并发(上限 4)打 CSMAR。首选,避免重复调用csmar_get_table_schema。csmar_probe_query对查询进行预检,返回validation_id、query_fingerprint、行数、少量样本、无效列,以及物化可行性。csmar_materialize_query按validation_id将先前预检过的查询物化为本地文件。csmar_refresh_cache⚠️ 危险工具 显式失效元数据缓存(databases/tables/schema/all,可选指定key)。仅在用户明确要求刷新时调用 —— 例如用户怀疑表结构变更或新购了数据库。调用后后续元数据查询会直接打受限流的 CSMAR API,绝不可在常规探索中预调用。
Related MCP server: smart-financial-mcp
设计原则
每个工具职责单一。
JSON 输出精简:只返回下一步所需字段。
面向修复的错误:
code、message、hint,以及可选的retry_after_seconds、suggested_args_patch。日期区间只做格式与顺序校验,随后原样透传给 SDK。
查询的预检与物化通过
validation_id串联。运行时状态持久化在 SQLite 中,默认落在用户缓存目录,跨工作目录的会话天然共享同一份缓存。
工具示例
csmar_list_databases
{}csmar_list_tables
{
"database_name": "股票市场交易"
}csmar_get_table_schema
{
"table_code": "FS_Combas"
}csmar_bulk_schema
{
"table_codes": ["BANK_Index", "BANK_Loan", "BANK_CreditRisks"]
}csmar_refresh_cache
{
"namespace": "schema",
"key": "BANK_Loan"
}csmar_probe_query
{
"table_code": "FS_Combas",
"columns": ["Stkcd", "Accper", "Typrep"],
"condition": "Stkcd='000001'",
"start_date": "2010-01-01",
"end_date": "2024-12-31",
"sample_rows": 2
}csmar_materialize_query
{
"validation_id": "validation_1234567890",
"output_dir": "D:/tmp/csmar"
}运行时默认值
lang = "0"belong = "0"poll_interval_seconds = 3poll_timeout_seconds = 900cache_ttl_minutes = 4320(即 3 天,对业务查询缓存probes / validations / downloads生效)metadata_ttl_days = 30(元数据缓存databases / tables / schema的默认 TTL,可用CSMAR_MCP_METADATA_TTL_DAYS覆盖)rate_limit_cooldown_minutes = 30(上游限流冷却窗口,与业务缓存 TTL 解耦)state_dir = 用户缓存目录/csmar-mcp/(Windows 默认为%LOCALAPPDATA%\csmar-mcp;Unix-like 默认为$XDG_CACHE_HOME/csmar-mcp或~/.cache/csmar-mcp;可用CSMAR_MCP_STATE_DIR环境变量显式覆盖)
缓存与限流策略
CSMAR 后端每日 API 配额非常严苛,MCP 的核心策略是把绝大多数调用挡在本地缓存层,远程调用只用于真正必须拉数的 probe_query / materialize_query 以及首次的元数据拉取。
缓存分层
命名空间 | 用途 | 默认 TTL | 说明 |
| 元数据 | 30 天 | 表结构长期不变;cache hit 完全不打 CSMAR |
| 业务查询结果 | 3 天 | 覆盖同一查询在短期内的重复访问 |
| 上游限流冷却 | 30 分钟(固定) | 与业务 TTL 解耦,避免误锁 3 天 |
跨目录共享
缓存 SQLite 文件固定在用户缓存目录下的 csmar-mcp/state.sqlite3,不跟随 cwd。在任何目录启动 MCP 会话都共享同一份缓存 —— 这是把限流风险降到最低的关键前提。
持旧缓存自愈
若 Agent 拿着过期的 databases 缓存去请求某个未购库,list_tables / get_table_schema 会捕获 not_purchased / database_not_found / table_not_found,自动失效 databases 缓存并重取一次上游,单点配额消耗换来整条链路的一致性。
Agent 最佳实践
批量需要多个表结构时优先用
csmar_bulk_schema,合并为一次 tool call。不要在无明确理由的情况下调用
csmar_refresh_cache,它会强制穿透到 CSMAR API。
环境要求
Python >= 3.12
用户安装(推荐)
发布到 PyPI 后,MCP 客户端应优先运行固定版本的包,而不是直接运行源码目录:
uvx csmar-mcp==0.1.0推荐通过系统环境变量或 MCP 客户端配置传入 CSMAR 凭据。
MCP 配置
{
"mcpServers": {
"csmar": {
"command": "uvx",
"args": ["csmar-mcp==0.1.0"],
"env": {
"CSMAR_MCP_ACCOUNT": "YOUR_ACCOUNT",
"CSMAR_MCP_PASSWORD": "YOUR_PASSWORD"
}
}
}
}说明:
csmar-mcp会优先读取CSMAR_MCP_ACCOUNT/CSMAR_MCP_PASSWORD;若当前工作目录存在.env,也会自动加载。仍兼容
--account/--password,但不建议继续使用,因为命令行参数更容易暴露在进程列表、启动配置和日志中。.env只是比命令行参数更稳妥,不是密文存储;请保持本地文件不入库。生产环境更适合用系统级环境变量或密钥管理服务。
开发模式(源码)
源码模式会运行工作区里的当前代码,适合本地开发和调试;它会跟随未发布改动变化,不适合作为稳定的用户安装方式。
uv sync
cp .env.example .env
# fill in CSMAR_MCP_ACCOUNT / CSMAR_MCP_PASSWORD
uv run csmar-mcp开发:lint 与钩子
安装开发依赖:
uv sync --group dev本地 lint:
uv run python scripts/check.py(默认只检查;--fix模式跑 ruff 自动修复 + 格式化)启用本地 git 钩子(一次性,基于 pre-commit framework):
uv run pre-commit install # 装 pre-commit 钩子:commit 前跑 --fix uv run pre-commit install --hook-type pre-push # 装 pre-push 钩子:push 前跑 check-only配置见仓内
.pre-commit-config.yaml。pre-commit framework 原生做 stash-and-restore,partial stage 安全。CI:
.github/workflows/lint.yml在 push 与 pull_request 上跑同一套scripts/check.py扫描范围:
csmar_mcp与tests,遗留 SDKcsmarapi/排除在外
发布流程
在
pyproject.toml更新version。本地确认
uv run python scripts/check.py与uv run python -m unittest discover -s tests -p "test_*.py" -v通过。在 PyPI 配置 Trusted Publisher:project
csmar-mcp,workflowpublish.yml,environmentpypi。在 GitHub 创建
pypienvironment,然后发布 GitHub Release。发布后检查
https://pypi.org/p/csmar-mcp,并用uvx csmar-mcp==<version> --help做安装级冒烟验证。
说明
服务器在鉴权过期时会自动重新登录并重试一次。
预检与物化流程尽量复用缓存,以缓解上游限流。
工具调用会审计到本地 SQLite,包含请求参数、结果摘要与上游错误元数据。
无效的
database_name或table_code会返回面向修复的错误与可执行的修复建议。工具响应不返回完整数据集。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/JinYuKiKK0/CSMAR-Data-MCP'
If you have feedback or need assistance with the MCP directory API, please join our Discord server