idatafield-mcp
# idatafield-mcp · 星罗数场数据分析 MCP Server
针对 [www.idatafield.com](https://www.idatafield.com/)(星罗数场·可信数据流通平台)的 **MCP 数据分析服务 + 智能体技能**。
封装平台公开门户数据与登录态个人数据,内置运营分析报告生成(离线 HTML 交互图表 + Excel),可安装到 Codex、Claude Code、Cursor、Claude Desktop 等支持 MCP 的智能体工具,也可托管部署到 ModelScope MCP 广场。
## 服务配置(MCP Server Config)
STDIO 类型,使用 PyPI 包 `idatafield-mcp`,通过 `uvx` 运行。**默认不配置凭据,仅使用公开数据**(公开产品/空间/场景/需求检索 + 运营分析报告):
```json
{
"mcpServers": {
"idatafield": {
"command": "uvx",
"args": ["idatafield-mcp@latest"]
}
}
}
```
如需**个人数据**(订单/用量/交易/账户),在 `env` 中任选一种配置即可自动启用(未配置则个人数据工具返回配置指引,公开分析不受影响):
```json
{
"mcpServers": {
"idatafield": {
"command": "uvx",
"args": ["idatafield-mcp@latest"],
"env": {
"IDATAFIELD_TOKEN": "你的 access token(与账号密码二选一)"
}
}
}
}
```
```json
{
"mcpServers": {
"idatafield": {
"command": "uvx",
"args": ["idatafield-mcp@latest"],
"env": {
"IDATAFIELD_USERNAME": "登录手机号/用户名",
"IDATAFIELD_PASSWORD": "登录密码"
}
}
}
}
```
### 认证与能力模式
| 配置 | 模式 | 可用能力 |
|---|---|---|
| 均不配置 | `public` | 全部公开数据工具 + 运营分析报告 |
| `IDATAFIELD_TOKEN` | `authenticated` | 公开数据 + 个人数据(直接使用 token) |
| `IDATAFIELD_USERNAME` + `IDATAFIELD_PASSWORD` | `authenticated` | 公开数据 + 个人数据(自动登录、token 缓存、过期重登) |
优先级:`IDATAFIELD_TOKEN` > `IDATAFIELD_USERNAME/PASSWORD` > 仅公开数据。
连接后可调用 `get_connection_status` 查看当前模式、认证来源与 token 过期时间。
## 功能特性
**公开数据(无需登录)**
- 数据产品检索/详情(370+ 产品,支持行业/供方/定价/数据主体/地域/时间/排序筛选)
- 数据空间列表与分类统计、应用场景、数据需求、数据资源、全局搜索、行业资讯
**登录态个人数据(配置账号密码后)**
- 个人资料、我的订单(申请/供应)、交易概览(本月/上月订单额、分成额、订单数)
- 用量明细、账户开票/支付信息、我加入/管理的空间、消息中心、需求响应
**分析与报告**
- `analyze_operations`:全量运营指标聚合(行业/供方/主体/定价分布、上架趋势、热度排行、空间生态、自动洞察)
- `generate_operations_report`:生成**单文件离线 HTML 报告**(内联 ECharts 交互图表)+ **Excel 工作簿**(含原生图表)
- `export_data`:任意实体导出 CSV/XLSX
## 工具清单
| 类别 | 工具 |
|---|---|
| 公开数据 | `search_products` `get_product_detail` `list_data_spaces` `list_demands` `get_demand_detail` `list_scenes` `list_resources` `global_search` `list_news` |
| 个人数据(需登录) | `get_my_profile` `list_my_orders` `get_transaction_summary` `get_usage_details` `get_account_summary` `list_my_spaces` `get_my_messages` |
| 分析报告 | `analyze_operations` `generate_operations_report` `export_data` |
## 快速开始(本地)
需要 [uv](https://docs.astral.sh/uv/):
```bash
uvx idatafield-mcp@latest # 直接从 PyPI 运行
# 或从源码
git clone https://github.com/zhsheng26/idatafield-mcp.git
cd idatafield-mcp && uv sync && uv run idatafield-mcp
```
任意 MCP 客户端使用上面的「服务配置」即可接入。
## 个人数据(需登录)
平台登录走 Keycloak SSO,支持**两种凭据方式**(任选其一):
| 变量 | 说明 |
|---|---|
| `IDATAFIELD_TOKEN` | 直接注入 access token(最简单,失效需更新) |
| `IDATAFIELD_USERNAME` | 平台登录手机号/用户名(与 PASSWORD 配套,自动登录) |
| `IDATAFIELD_PASSWORD` | 登录密码 |
| `IDATAFIELD_CACHE_DIR` | 可选,token 缓存目录(默认 `~/.idatafield-mcp`) |
- 配置 `TOKEN`:直接使用,无需登录流程;token 过期且存在账号密码时会自动回退登录。
- 配置 `USERNAME+PASSWORD`:首次连接自动登录,token 缓存到本地,过期自动重登。
- 两种都配置时,`TOKEN` 优先。
- 获取 token:浏览器登录 www.idatafield.com 后,开发者工具 → Application → Session Storage → 键 `IDATA-token` 的值。
> 托管部署(如 ModelScope MCP 广场)为共享实例,**不要**写入个人凭据,保持公开数据模式;需要个人数据时请按上面的 `env` 自托管。
## 各智能体接入
- **Codex**:见 [`examples/codex-config.toml`](examples/codex-config.toml)
- **Claude Code**:见 [`examples/claude-code.mcp.json`](examples/claude-code.mcp.json)
- **Cursor**:见 [`examples/cursor.mcp.json`](examples/cursor.mcp.json)
- **Claude Desktop**:见 [`examples/claude-desktop.json`](examples/claude-desktop.json)
技能安装(可选,指导智能体组合工具产出报告):将 `skills/idatafield-analysis/` 复制到 `~/.codex/skills/` 或 `~/.claude/skills/`。
## 部署到 ModelScope MCP 广场
1. 本仓库根目录 README 已包含可被自动解析的 STDIO 服务配置(上文 `mcpServers` 块)。
2. 包已发布到 PyPI(`idatafield-mcp`),ModelScope 通过 `uvx` 下载安装并调用 `list_tools` 完成部署检测。
3. 在 [ModelScope MCP 创建页](https://modelscope.cn/mcp/servers/create) 填入本仓库地址 `https://github.com/zhsheng26/idatafield-mcp`,托管类型选「可托管部署」。
4. 检测通过后即获得 `可部署` / `hosted` 标签,社区用户可一键连接。
## 开发
```bash
uv sync
uv run pytest # 单元测试(20 项)
uv run python scripts/smoke_live.py # 只读冒烟测试 + 生成样例报告
```
## 说明
- **只读**:不含下单、加入空间、发布等写操作。
- 公开接口已实测验证;个人数据接口需账号有相应业务数据方有内容。
- 托管环境下 `generate_operations_report` 生成的文件位于服务端容器内,社区用户建议以自托管方式获取报告文件;数据分析类工具(`analyze_operations`/检索类)在托管环境可直接使用。
TDQS
Scored across 20 tools
Most tools target clearly distinct resources or actions: public catalog browsing, personal account data, analytics, reporting, and export are separated. There is some potential overlap among personal/account tools such as get_usage_details, get_transaction_summary, list_my_orders, and get_account_summary, but descriptions make the boundaries mostly clear.
Tool names consistently use snake_case and mostly follow a verb_noun pattern such as get_product_detail, list_demands, search_products, and generate_operations_report. The main minor deviation is global_search, which is adjective_noun rather than verb_noun, but the convention remains readable and predictable overall.
The server covers several domains: public data discovery, personal account data, operations analytics, reporting, and export. Twenty tools is somewhat broad, but each tool appears to serve a specific purpose within that scope rather than duplicating others.
The surface covers core read and analytics workflows for products, spaces, demands, scenes, resources, news, personal orders, and transactions. However, it lacks detail operations for some listed entities such as spaces/scenes/resources/news and has no create/update/delete lifecycle tools, so it is incomplete for a full marketplace management domain.