tzzb-mcp
tzzb-mcp
同花顺投资账本 MCP 服务(Tonghuashun Investment Ledger MCP Server)
通过 MCP(Model Context Protocol) 查询个人多账户的持仓明细、资产趋势、交易记录、实时行情和自选列表。供 AI 助手(如 WorkBuddy)接入后,直接以自然语言查询你的投资账本数据。
功能特性
13 个 MCP 工具,覆盖登录认证、账户、持仓、趋势、交易、行情、汇率、交易日、自选查询
多账户支持:券商账户、手工账户、融资融券账户(按
fund_key/manual_id/rzrq_fund_key区分)CDP 浏览器代理:所有 API 请求通过 Chrome DevTools Protocol 在浏览器内执行,复用浏览器原生网络栈,规避 Python 直连的 401 反爬拦截
独立 Chrome Profile(
~/.tzzb_chrome_profile),不影响日常浏览器使用Cookie 持久化(
~/.tzzb_cookies.json),登录一次约 7 天内免重复登录断线自动重连:CDP 连接断开时自动重连重试一次
Related MCP server: Stock MCP Server
环境要求
Python ≥ 3.10
已安装 Chrome 浏览器
安装
cd tzzb-mcp
pip install .依赖:mcp>=1.0.0、websocket-client>=1.8.0、pydantic>=2.0.0。
安装后可通过命令 tzzb-mcp 启动服务(入口定义于 pyproject.toml 的 [project.scripts])。
MCP 配置
在 MCP 客户端(如 WorkBuddy 的 mcp.json)中通过 stdio 方式接入:
{
"mcpServers": {
"tzzb-mcp": {
"command": "python",
"args": ["-m", "src.server"],
"cwd": "/path/to/tzzb-mcp"
}
}
}cwd 需指向项目目录(含 src/ 的目录)。
快速开始
首次使用必须先调用 tzzb_login:该工具会启动一个 Chrome 调试实例,你需要在浏览器中登录投资账本(tzzb.10jqka.com.cn),登录成功后 Cookie 会被自动提取并持久化。
1. tzzb_login → 弹出 Chrome,手动登录投资账本
2. tzzb_account_list → 获取所有账户的 fund_key / manual_id
3. tzzb_positions → 查看持仓明细日常查询:
1. tzzb_account_list → 获取账户列表
2. tzzb_positions → 查看具体持仓
3. tzzb_asset_trend → 查看收益走势(可选)工具列表
工具名 | 用途 |
| 登录投资账本,提取并持久化 Cookie(首次必调) |
| 检查当前登录状态 |
| 获取所有账户列表(含 |
| 账户总览(接口不可用时自动回退) |
| 投资组合总览(同 account_summary,含回退) |
| 获取持仓明细(股票 + 基金)⭐ |
| 获取资产 / 收益趋势数据 |
| 获取当日分时收益数据 |
| 获取当日交易记录 |
| 获取股票实时行情 |
| 获取港元兑人民币汇率 |
| 获取最近交易日信息 |
| 获取自选股票和基金列表 |
⭐ 标记为最常用工具。
使用规则与注意事项
禁止并行调用:所有工具共享同一个 Chrome CDP 连接(底层有全局锁),一次只能调用一个工具,请串行调用。
查询持仓先取账户列表:
tzzb_positions的fund_key/manual_id参数来自tzzb_account_list;不传参数时返回所有账户的聚合数据(可能为空)。行情格式为
市场:代码:上证用33(如33:600519),深证用47(如47:000001)。持仓数据中的market字段"2"对应上海(33)、"1"对应深圳(47)。基金持仓接口不可用:
tzzb_positions返回的fund字段始终为{"error": "基金持仓接口不可用"}(底层接口返回 HTTP 400,已内置保护),请忽略fund字段,只使用stock数据。字段名为拼音缩写:行情返回
xianjia(现价)、zuoshou(昨收)、zqdm(代码)、scdm(市场);展示时需映射为中文。数值字段可能是字符串:持仓/行情中的数值(如
"300"、"18.09")为字符串类型,使用时注意转换。日期格式
YYYYMMDD:资产趋势返回的date为YYYYMMDD(如20260827),展示时转为YYYY-MM-DD。断线自动重试:工具调用失败(CDP 连接断开)时重试一次即可,底层会自动重连;连续两次失败需调用
tzzb_login重新认证。
技术架构
AI 助手(MCP Client)
│ stdio
▼
tzzb-mcp(MCP Server, Python)
│ Chrome DevTools Protocol :9222
▼
Chrome 浏览器(独立 Profile)
│ 浏览器原生 fetch(携带 Cookie)
▼
同花顺投资账本 API(tzzb.10jqka.com.cn)CDP 调试端口:
9222独立 Chrome Profile:
~/.tzzb_chrome_profileCookie 持久化:
~/.tzzb_cookies.json(有效期约 7 天)全局锁保证串行调用,CDP 断开自动重连
目录结构
tzzb-mcp/
├── pyproject.toml # 项目配置与依赖
├── src/
│ ├── server.py # MCP 服务入口(工具注册)
│ ├── auth.py # 登录、Cookie 提取与持久化
│ ├── client.py # Chrome CDP 连接与请求代理
│ ├── models.py # 数据模型
│ └── api/ # 各业务接口封装
│ ├── account.py # 账户列表 / 总览
│ ├── position.py # 持仓明细
│ ├── market.py # 行情 / 汇率 / 交易日
│ ├── trade.py # 交易记录 / 分时收益 / 资产趋势
│ └── watchlist.py # 自选列表
└── SKILL.md # AI 助手使用技能文档(工具详细说明)排错指南
现象 | 原因 | 解决 |
报「未登录」错误 | Cookie 不存在或已过期 | 调用 |
CDP 请求失败 | Chrome 未运行或连接断开 | 底层自动重连,重试一次即可;仍失败则调用 |
基金持仓返回空 / 报错 |
| 已内置保护,忽略 |
|
| 已内置回退到 |
Chrome 无法自动启动 | — | 手动启动: |
License
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.
Related MCP Connectors
Access real-time and historical market data for China A-shares and Hong Kong stocks, along with ne…
Read-only China A-share data for AI agents: market, limit-up, capital flow and disclosures.
Provide access to Chinese stock market data including historical prices, real-time data, news, and…
Ask your AI about bank accounts, spending, debts, holdings, and investment activity.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables querying financial data including stocks, indices, funds, and futures from Chinese, Hong Kong, and US markets. Provides real-time market information, financial indicators, news, and trading suggestions through Eastmoney and Sina data sources.133ISC
- AlicenseBqualityDmaintenanceProvides real-time market data for A-shares, Hong Kong, and US stocks using the Tencent Finance API. It enables users to manage stock positions and watchlists through an AI assistant.1220ISC
- FlicenseNot gradedqualityDmaintenanceProvides real-time quotes, fund flows, and corporate announcements for Chinese A-share stocks. It enables users to search for stocks, analyze financial indicators, and summarize quarterly reports through natural language.
- AlicenseAqualityCmaintenanceEnables AI assistants to query real-time A-share stock data, including quotes, fund flows, sector flows, and K-line history, without needing an API key.57MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- 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/Mrkelo/tzzb-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server