kingdee-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(cd:*)"
5
+ ]
6
+ }
7
+ }
@@ -0,0 +1,17 @@
1
+ # 金蝶云星空私有云连接配置
2
+ # 复制本文件为 .env 并填入真实值
3
+
4
+ # 私有云地址(末尾加 /k3cloud/)
5
+ KINGDEE_SERVER_URL=http://192.168.1.100:8080/k3cloud/
6
+
7
+ # 账套ID(金蝶管理中心 → 数据中心标识)
8
+ KINGDEE_ACCT_ID=your_acct_id
9
+
10
+ # 集成用户名(系统管理 → 第三方系统登录授权 → 集成用户,不要用 Administrator)
11
+ KINGDEE_USERNAME=API集成
12
+
13
+ # 应用ID(第三方系统登录授权生成)
14
+ KINGDEE_APP_ID=your_app_id
15
+
16
+ # 应用密钥(第三方系统登录授权生成)
17
+ KINGDEE_APP_SEC=your_app_secret
@@ -0,0 +1,41 @@
1
+ name: Deploy to GitHub Pages
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths:
8
+ - 'docs/**'
9
+ - '.github/workflows/deploy-pages.yml'
10
+ workflow_dispatch:
11
+
12
+ permissions:
13
+ contents: read
14
+ pages: write
15
+ id-token: write
16
+
17
+ concurrency:
18
+ group: "pages"
19
+ cancel-in-progress: false
20
+
21
+ jobs:
22
+ deploy:
23
+ environment:
24
+ name: github-pages
25
+ url: ${{ steps.deployment.outputs.page_url }}
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - name: Checkout
29
+ uses: actions/checkout@v4
30
+
31
+ - name: Setup Pages
32
+ uses: actions/configure-pages@v4
33
+
34
+ - name: Upload artifact
35
+ uses: actions/upload-pages-artifact@v3
36
+ with:
37
+ path: 'docs'
38
+
39
+ - name: Deploy to GitHub Pages
40
+ id: deployment
41
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,43 @@
1
+ # Simple workflow for deploying static content to GitHub Pages
2
+ name: Deploy static content to Pages
3
+
4
+ on:
5
+ # Runs on pushes targeting the default branch
6
+ push:
7
+ branches: ["main"]
8
+
9
+ # Allows you to run this workflow manually from the Actions tab
10
+ workflow_dispatch:
11
+
12
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13
+ permissions:
14
+ contents: read
15
+ pages: write
16
+ id-token: write
17
+
18
+ # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19
+ # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20
+ concurrency:
21
+ group: "pages"
22
+ cancel-in-progress: false
23
+
24
+ jobs:
25
+ # Single deploy job since we're just deploying
26
+ deploy:
27
+ environment:
28
+ name: github-pages
29
+ url: ${{ steps.deployment.outputs.page_url }}
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - name: Checkout
33
+ uses: actions/checkout@v4
34
+ - name: Setup Pages
35
+ uses: actions/configure-pages@v5
36
+ - name: Upload artifact
37
+ uses: actions/upload-pages-artifact@v3
38
+ with:
39
+ # Upload entire repository
40
+ path: 'docs'
41
+ - name: Deploy to GitHub Pages
42
+ id: deployment
43
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,31 @@
1
+ # Build
2
+ dist/
3
+ build/
4
+ *.egg-info/
5
+ *.egg
6
+
7
+ # Python
8
+ __pycache__/
9
+ *.py[cod]
10
+ *$py.class
11
+ .Python
12
+ *.so
13
+
14
+ # Virtual environments
15
+ venv/
16
+ .venv/
17
+ ENV/
18
+
19
+ # IDE
20
+ .idea/
21
+ .vscode/
22
+ *.swp
23
+ *.swo
24
+
25
+ # Sensitive files
26
+ .env
27
+ .mcp.json
28
+
29
+ # OS
30
+ .DS_Store
31
+ Thumbs.db
@@ -0,0 +1,15 @@
1
+ {
2
+ "mcpServers": {
3
+ "kingdee": {
4
+ "command": "uvx",
5
+ "args": ["kingdee-mcp"],
6
+ "env": {
7
+ "KINGDEE_SERVER_URL": "http://your-server/k3cloud/",
8
+ "KINGDEE_ACCT_ID": "your-acct-id",
9
+ "KINGDEE_USERNAME": "your-username",
10
+ "KINGDEE_APP_ID": "your-app-id",
11
+ "KINGDEE_APP_SEC": "your-app-secret"
12
+ }
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,68 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Commands
6
+
7
+ ```bash
8
+ # Install in development mode
9
+ pip install -e .
10
+
11
+ # Run the MCP server directly
12
+ kingdee-mcp
13
+
14
+ # Run with uvx (no install needed)
15
+ uvx kingdee-mcp
16
+
17
+ # Build distribution package
18
+ pip install hatchling
19
+ python -m hatchling build
20
+
21
+ # Install with all deps
22
+ pip install "mcp[cli]>=1.0.0" httpx pydantic
23
+ ```
24
+
25
+ There are no tests in this project currently.
26
+
27
+ ## Architecture
28
+
29
+ This is a single-file MCP Server (`src/kingdee_mcp/server.py`) that bridges AI clients to Kingdee Cloud K/3 ERP via its WebAPI.
30
+
31
+ ### Request Flow
32
+
33
+ 1. AI client calls a tool → FastMCP dispatches to the decorated async function
34
+ 2. Function calls `_post(ep_key, payload)` with a `[form_id, {params}]` list
35
+ 3. `_post()` checks the global `_session_id` cache; calls `_login()` if absent
36
+ 4. On 401 or session-expired response, auto re-logins and retries once
37
+ 5. All tools return JSON strings (success or error message from `_err()`)
38
+
39
+ ### Key Internals
40
+
41
+ - **`_EP` dict** — maps short names (`"query"`, `"save"`, etc.) to full Kingdee WebAPI endpoint paths
42
+ - **`_session_id` global** — cached session cookie (`kdservice-sessionid`) from `LoginByAppSecret`
43
+ - **`FORM_CATALOG` dict** — maps `form_id` → `{name, alias[], fields}` used by `kingdee_list_forms` and `kingdee_get_fields` to help the AI discover form IDs without hitting the API
44
+ - **Pydantic input models** — each tool has a dedicated model (`QueryInput`, `SaveInput`, `BillIdsInput`, etc.) with `extra="forbid"` for strict validation
45
+
46
+ ### Tool Categories
47
+
48
+ | Category | Tools |
49
+ |----------|-------|
50
+ | Metadata | `kingdee_list_forms`, `kingdee_get_fields` |
51
+ | Read-only queries | `kingdee_query_bills`, `kingdee_view_bill`, `kingdee_query_purchase_orders`, `kingdee_query_sale_orders`, `kingdee_query_stock_bills`, `kingdee_query_inventory`, `kingdee_query_materials`, `kingdee_query_partners` |
52
+ | Write operations | `kingdee_save_bill`, `kingdee_submit_bills`, `kingdee_audit_bills`, `kingdee_unaudit_bills`, `kingdee_delete_bills`, `kingdee_push_bill` |
53
+ | Workflow | `kingdee_query_pending_approvals`, `kingdee_query_workflow_status`, `kingdee_workflow_approve`, `kingdee_query_expense_reimburse` |
54
+
55
+ ### Environment Variables (required at runtime)
56
+
57
+ | Variable | Description |
58
+ |----------|-------------|
59
+ | `KINGDEE_SERVER_URL` | Server URL ending in `/k3cloud/` |
60
+ | `KINGDEE_ACCT_ID` | Account set ID |
61
+ | `KINGDEE_USERNAME` | Integration user name |
62
+ | `KINGDEE_APP_ID` | App ID from Kingdee admin |
63
+ | `KINGDEE_APP_SEC` | App Secret from Kingdee admin |
64
+
65
+ ### GitHub Pages (`docs/`)
66
+
67
+ The website at `https://wahailong.github.io/KingdeeMCP/` is a single static HTML file (`docs/index.html`). The deploy workflow (`.github/workflows/deploy-pages.yml`) triggers on push to `main` branch — **note the repo uses `master`**, so the workflow must be triggered manually via `workflow_dispatch` or the branch trigger needs updating.
68
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,226 @@
1
+ Metadata-Version: 2.4
2
+ Name: kingdee-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP Server for Kingdee Cloud K/3 - Works with any MCP-compatible AI client
5
+ Project-URL: Homepage, https://github.com/WaHaiLong/KingdeeMCP
6
+ Project-URL: Repository, https://github.com/WaHaiLong/KingdeeMCP
7
+ Project-URL: Documentation, https://github.com/WaHaiLong/KingdeeMCP#readme
8
+ Author: WaHaiLong
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: ai,claude,cline,cursor,erp,k3cloud,kingdee,mcp,windsurf
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Office/Business :: Financial :: Accounting
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: httpx>=0.27.0
22
+ Requires-Dist: mcp[cli]>=1.0.0
23
+ Requires-Dist: pydantic>=2.0.0
24
+ Description-Content-Type: text/markdown
25
+
26
+ # Kingdee MCP Server —— 让 AI 直接操作金蝶云星空 ERP
27
+
28
+ [![PyPI version](https://img.shields.io/pypi/v/kingdee-mcp?style=flat-square&color=2563eb)](https://pypi.org/project/kingdee-mcp/)
29
+ [![Downloads](https://img.shields.io/pypi/dm/kingdee-mcp?style=flat-square&color=10b981)](https://pypi.org/project/kingdee-mcp/)
30
+ [![Python versions](https://img.shields.io/pypi/pyversions/kingdee-mcp?style=flat-square)](https://pypi.org/project/kingdee-mcp/)
31
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](LICENSE)
32
+
33
+ **Kingdee MCP Server** 是金蝶云星空(Kingdee Cloud Star)ERP 的 [MCP(Model Context Protocol)](https://modelcontextprotocol.io/) 服务端,让 Claude、Cursor、Windsurf、Cline 等 AI 助手能够通过自然语言直接操作金蝶 ERP 系统。
34
+
35
+ 官方网站:https://wahailong.github.io/KingdeeMCP/
36
+
37
+ ## 为什么需要金蝶 MCP?
38
+
39
+ 传统 ERP 操作繁琐,需要在多个界面间切换。有了 **金蝶 MCP Server**,你可以:
40
+
41
+ - 直接对 AI 说:"**查询本月已审核的采购订单**"
42
+ - 直接对 AI 说:"**帮我新建一张销售订单**"
43
+ - 直接对 AI 说:"**审核这几张入库单**"
44
+ - 在微信、WhatsApp、Telegram 中通过 OpenClaw 操作金蝶
45
+
46
+ AI 会自动调用金蝶 API 完成操作,无需手动登录 ERP 界面。
47
+
48
+ ## 支持的 AI 客户端
49
+
50
+ | 客户端 | 支持方式 |
51
+ |--------|---------|
52
+ | [Claude Desktop](https://claude.ai/download) | 原生 MCP |
53
+ | [Cursor](https://cursor.sh/) | 原生 MCP |
54
+ | [Windsurf](https://codeium.com/windsurf) | 原生 MCP |
55
+ | [Cline](https://github.com/cline/cline) | 原生 MCP |
56
+ | [Continue](https://continue.dev/) | 原生 MCP |
57
+ | [Claude Code CLI](https://claude.ai/claude-code) | 原生 MCP |
58
+ | [OpenClaw](https://openclaw.ai/) | 微信/WhatsApp/Telegram 中使用 |
59
+ | 其他 MCP 兼容客户端 | 原生 MCP |
60
+
61
+ ## 功能特性
62
+
63
+ - **13+ 实用工具**:涵盖采购、销售、库存、基础资料等核心业务
64
+ - **自然语言操作**:用中文直接描述需求,AI 自动转换为 API 调用
65
+ - **异步高性能**:基于 async/await,支持并发请求
66
+ - **自动重试**:Session 过期自动重登,连接失败自动重试
67
+ - **安全认证**:采用金蝶官方 WebAPI 认证,支持 AppSecret 方式
68
+ - **类型安全**:基于 Pydantic 数据验证,参数自动补全
69
+ - **易于扩展**:基于 FastMCP 框架,轻松添加自定义工具
70
+
71
+ ## 快速安装
72
+
73
+ ```bash
74
+ pip install kingdee-mcp
75
+ ```
76
+
77
+ 或使用 uvx 直接运行(推荐,无需手动安装):
78
+
79
+ ```bash
80
+ uvx kingdee-mcp
81
+ ```
82
+
83
+ ## 配置教程
84
+
85
+ ### 第一步:金蝶云星空后台授权
86
+
87
+ 1. 进入 **系统管理 → 第三方系统登录授权 → 新增**
88
+ 2. 新建一个集成用户(**不要用 Administrator**)
89
+ 3. 生成 **AppID** 和 **AppSecret**
90
+ 4. 为该用户分配所需模块的操作权限
91
+
92
+ ### 第二步:配置 MCP 客户端
93
+
94
+ 在你的 MCP 客户端配置文件中添加以下内容:
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "kingdee": {
100
+ "command": "uvx",
101
+ "args": ["kingdee-mcp"],
102
+ "env": {
103
+ "KINGDEE_SERVER_URL": "http://your-server/k3cloud/",
104
+ "KINGDEE_ACCT_ID": "你的账套ID",
105
+ "KINGDEE_USERNAME": "集成用户名",
106
+ "KINGDEE_APP_ID": "AppID",
107
+ "KINGDEE_APP_SEC": "AppSecret"
108
+ }
109
+ }
110
+ }
111
+ }
112
+ ```
113
+
114
+ **配置文件位置:**
115
+
116
+ | 客户端 | 配置文件路径 |
117
+ |--------|-------------|
118
+ | Claude Desktop (Windows) | `%APPDATA%\Claude\claude_desktop_config.json` |
119
+ | Claude Desktop (macOS) | `~/Library/Application Support/Claude/claude_desktop_config.json` |
120
+ | Cursor | Settings → MCP → Add Server |
121
+ | Claude Code CLI | `~/.claude/settings.json` |
122
+ | OpenClaw | 参考 [OpenClaw MCP 文档](https://docs.openclaw.ai/) |
123
+
124
+ ### 第三步:重启客户端
125
+
126
+ 配置完成后重启你的 MCP 客户端即可开始使用。
127
+
128
+ ## 环境变量说明
129
+
130
+ | 变量 | 说明 | 示例 |
131
+ |------|------|------|
132
+ | `KINGDEE_SERVER_URL` | 金蝶私有云服务器地址(需包含 /k3cloud/) | `http://192.168.1.100/k3cloud/` |
133
+ | `KINGDEE_ACCT_ID` | 账套ID | `69ae8ed35dab20` |
134
+ | `KINGDEE_USERNAME` | 集成用户名 | `API集成` |
135
+ | `KINGDEE_APP_ID` | 应用ID | `338898_xxxxx` |
136
+ | `KINGDEE_APP_SEC` | 应用密钥(AppSecret) | `f8b75d4ccxxxx` |
137
+
138
+ ## 可用工具列表
139
+
140
+ ### 元数据查询
141
+
142
+ | 工具名称 | 功能说明 |
143
+ |----------|---------|
144
+ | `kingdee_list_forms` | 搜索可用表单(不知道 form_id 时使用) |
145
+ | `kingdee_get_fields` | 获取表单字段列表 |
146
+
147
+ ### 数据查询(只读操作)
148
+
149
+ | 工具名称 | 功能说明 |
150
+ |----------|---------|
151
+ | `kingdee_query_bills` | 通用单据查询,支持任意 form_id |
152
+ | `kingdee_view_bill` | 查看单据完整详情 |
153
+ | `kingdee_query_purchase_orders` | 查询采购订单 |
154
+ | `kingdee_query_sale_orders` | 查询销售订单 |
155
+ | `kingdee_query_stock_bills` | 查询出入库单据 |
156
+ | `kingdee_query_inventory` | 查询即时库存 |
157
+ | `kingdee_query_materials` | 查询物料档案 |
158
+ | `kingdee_query_partners` | 查询客户/供应商档案 |
159
+
160
+ ### 单据操作(写操作)
161
+
162
+ | 工具名称 | 功能说明 |
163
+ |----------|---------|
164
+ | `kingdee_save_bill` | 新建或修改单据 |
165
+ | `kingdee_submit_bills` | 提交单据 |
166
+ | `kingdee_audit_bills` | 审核单据 |
167
+ | `kingdee_unaudit_bills` | 反审核单据 |
168
+ | `kingdee_delete_bills` | 删除单据 |
169
+
170
+ ## 使用示例
171
+
172
+ 配置完成后,在 Claude 或其他 AI 客户端中直接用自然语言操作:
173
+
174
+ ```
175
+ # 查询类
176
+ 查询最近 20 条已审核的采购订单
177
+ 查一下物料编码 MAT001 的即时库存
178
+ 查询客户编码 C001 的所有销售订单
179
+ 显示本月所有未提交的销售订单
180
+
181
+ # 操作类
182
+ 帮我新建一张采购订单,供应商 S001,物料 MAT001,数量 100,单价 10.5
183
+ 审核这几张采购入库单:12345, 12346, 12347
184
+ 反审核销售订单 SO2024001
185
+ ```
186
+
187
+ ## 支持的单据类型(form_id)
188
+
189
+ | form_id | 说明 |
190
+ |---------|------|
191
+ | `PUR_PurchaseOrder` | 采购订单 |
192
+ | `SAL_SaleOrder` | 销售订单 |
193
+ | `STK_InStock` | 采购入库单 |
194
+ | `SAL_OUTSTOCK` | 销售出库单 |
195
+ | `STK_MisDelivery` | 其他出库单 |
196
+ | `STK_Miscellaneous` | 其他入库单 |
197
+ | `STK_TransferDirect` | 直接调拨单 |
198
+ | `BD_Material` | 物料档案 |
199
+ | `BD_Customer` | 客户档案 |
200
+ | `BD_Supplier` | 供应商档案 |
201
+ | `STK_Inventory` | 即时库存 |
202
+
203
+ ## 常见问题
204
+
205
+ **Q: 提示认证失败怎么办?**
206
+ 检查 AppID / AppSecret 是否正确,集成用户是否有对应模块的访问权限。
207
+
208
+ **Q: 连接超时怎么解决?**
209
+ 检查 `KINGDEE_SERVER_URL` 是否正确(需包含 `/k3cloud/` 后缀),确保服务器可访问。
210
+
211
+ **Q: 支持金蝶云星空公有云吗?**
212
+ 目前主要针对私有云测试,公有云用户可能需要调整认证方式。
213
+
214
+ **Q: 如何添加自定义工具?**
215
+ 基于 FastMCP 框架,在 `server.py` 中添加 `@mcp.tool()` 装饰器方法即可扩展。
216
+
217
+ ## 相关链接
218
+
219
+ - [官方网站](https://wahailong.github.io/KingdeeMCP/)
220
+ - [PyPI 包页面](https://pypi.org/project/kingdee-mcp/)
221
+ - [MCP 协议文档](https://modelcontextprotocol.io/)
222
+ - [金蝶云星空官网](https://www.kingdee.com/)
223
+
224
+ ## License
225
+
226
+ MIT © WaHaiLong
@@ -0,0 +1,201 @@
1
+ # Kingdee MCP Server —— 让 AI 直接操作金蝶云星空 ERP
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/kingdee-mcp?style=flat-square&color=2563eb)](https://pypi.org/project/kingdee-mcp/)
4
+ [![Downloads](https://img.shields.io/pypi/dm/kingdee-mcp?style=flat-square&color=10b981)](https://pypi.org/project/kingdee-mcp/)
5
+ [![Python versions](https://img.shields.io/pypi/pyversions/kingdee-mcp?style=flat-square)](https://pypi.org/project/kingdee-mcp/)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](LICENSE)
7
+
8
+ **Kingdee MCP Server** 是金蝶云星空(Kingdee Cloud Star)ERP 的 [MCP(Model Context Protocol)](https://modelcontextprotocol.io/) 服务端,让 Claude、Cursor、Windsurf、Cline 等 AI 助手能够通过自然语言直接操作金蝶 ERP 系统。
9
+
10
+ 官方网站:https://wahailong.github.io/KingdeeMCP/
11
+
12
+ ## 为什么需要金蝶 MCP?
13
+
14
+ 传统 ERP 操作繁琐,需要在多个界面间切换。有了 **金蝶 MCP Server**,你可以:
15
+
16
+ - 直接对 AI 说:"**查询本月已审核的采购订单**"
17
+ - 直接对 AI 说:"**帮我新建一张销售订单**"
18
+ - 直接对 AI 说:"**审核这几张入库单**"
19
+ - 在微信、WhatsApp、Telegram 中通过 OpenClaw 操作金蝶
20
+
21
+ AI 会自动调用金蝶 API 完成操作,无需手动登录 ERP 界面。
22
+
23
+ ## 支持的 AI 客户端
24
+
25
+ | 客户端 | 支持方式 |
26
+ |--------|---------|
27
+ | [Claude Desktop](https://claude.ai/download) | 原生 MCP |
28
+ | [Cursor](https://cursor.sh/) | 原生 MCP |
29
+ | [Windsurf](https://codeium.com/windsurf) | 原生 MCP |
30
+ | [Cline](https://github.com/cline/cline) | 原生 MCP |
31
+ | [Continue](https://continue.dev/) | 原生 MCP |
32
+ | [Claude Code CLI](https://claude.ai/claude-code) | 原生 MCP |
33
+ | [OpenClaw](https://openclaw.ai/) | 微信/WhatsApp/Telegram 中使用 |
34
+ | 其他 MCP 兼容客户端 | 原生 MCP |
35
+
36
+ ## 功能特性
37
+
38
+ - **13+ 实用工具**:涵盖采购、销售、库存、基础资料等核心业务
39
+ - **自然语言操作**:用中文直接描述需求,AI 自动转换为 API 调用
40
+ - **异步高性能**:基于 async/await,支持并发请求
41
+ - **自动重试**:Session 过期自动重登,连接失败自动重试
42
+ - **安全认证**:采用金蝶官方 WebAPI 认证,支持 AppSecret 方式
43
+ - **类型安全**:基于 Pydantic 数据验证,参数自动补全
44
+ - **易于扩展**:基于 FastMCP 框架,轻松添加自定义工具
45
+
46
+ ## 快速安装
47
+
48
+ ```bash
49
+ pip install kingdee-mcp
50
+ ```
51
+
52
+ 或使用 uvx 直接运行(推荐,无需手动安装):
53
+
54
+ ```bash
55
+ uvx kingdee-mcp
56
+ ```
57
+
58
+ ## 配置教程
59
+
60
+ ### 第一步:金蝶云星空后台授权
61
+
62
+ 1. 进入 **系统管理 → 第三方系统登录授权 → 新增**
63
+ 2. 新建一个集成用户(**不要用 Administrator**)
64
+ 3. 生成 **AppID** 和 **AppSecret**
65
+ 4. 为该用户分配所需模块的操作权限
66
+
67
+ ### 第二步:配置 MCP 客户端
68
+
69
+ 在你的 MCP 客户端配置文件中添加以下内容:
70
+
71
+ ```json
72
+ {
73
+ "mcpServers": {
74
+ "kingdee": {
75
+ "command": "uvx",
76
+ "args": ["kingdee-mcp"],
77
+ "env": {
78
+ "KINGDEE_SERVER_URL": "http://your-server/k3cloud/",
79
+ "KINGDEE_ACCT_ID": "你的账套ID",
80
+ "KINGDEE_USERNAME": "集成用户名",
81
+ "KINGDEE_APP_ID": "AppID",
82
+ "KINGDEE_APP_SEC": "AppSecret"
83
+ }
84
+ }
85
+ }
86
+ }
87
+ ```
88
+
89
+ **配置文件位置:**
90
+
91
+ | 客户端 | 配置文件路径 |
92
+ |--------|-------------|
93
+ | Claude Desktop (Windows) | `%APPDATA%\Claude\claude_desktop_config.json` |
94
+ | Claude Desktop (macOS) | `~/Library/Application Support/Claude/claude_desktop_config.json` |
95
+ | Cursor | Settings → MCP → Add Server |
96
+ | Claude Code CLI | `~/.claude/settings.json` |
97
+ | OpenClaw | 参考 [OpenClaw MCP 文档](https://docs.openclaw.ai/) |
98
+
99
+ ### 第三步:重启客户端
100
+
101
+ 配置完成后重启你的 MCP 客户端即可开始使用。
102
+
103
+ ## 环境变量说明
104
+
105
+ | 变量 | 说明 | 示例 |
106
+ |------|------|------|
107
+ | `KINGDEE_SERVER_URL` | 金蝶私有云服务器地址(需包含 /k3cloud/) | `http://192.168.1.100/k3cloud/` |
108
+ | `KINGDEE_ACCT_ID` | 账套ID | `69ae8ed35dab20` |
109
+ | `KINGDEE_USERNAME` | 集成用户名 | `API集成` |
110
+ | `KINGDEE_APP_ID` | 应用ID | `338898_xxxxx` |
111
+ | `KINGDEE_APP_SEC` | 应用密钥(AppSecret) | `f8b75d4ccxxxx` |
112
+
113
+ ## 可用工具列表
114
+
115
+ ### 元数据查询
116
+
117
+ | 工具名称 | 功能说明 |
118
+ |----------|---------|
119
+ | `kingdee_list_forms` | 搜索可用表单(不知道 form_id 时使用) |
120
+ | `kingdee_get_fields` | 获取表单字段列表 |
121
+
122
+ ### 数据查询(只读操作)
123
+
124
+ | 工具名称 | 功能说明 |
125
+ |----------|---------|
126
+ | `kingdee_query_bills` | 通用单据查询,支持任意 form_id |
127
+ | `kingdee_view_bill` | 查看单据完整详情 |
128
+ | `kingdee_query_purchase_orders` | 查询采购订单 |
129
+ | `kingdee_query_sale_orders` | 查询销售订单 |
130
+ | `kingdee_query_stock_bills` | 查询出入库单据 |
131
+ | `kingdee_query_inventory` | 查询即时库存 |
132
+ | `kingdee_query_materials` | 查询物料档案 |
133
+ | `kingdee_query_partners` | 查询客户/供应商档案 |
134
+
135
+ ### 单据操作(写操作)
136
+
137
+ | 工具名称 | 功能说明 |
138
+ |----------|---------|
139
+ | `kingdee_save_bill` | 新建或修改单据 |
140
+ | `kingdee_submit_bills` | 提交单据 |
141
+ | `kingdee_audit_bills` | 审核单据 |
142
+ | `kingdee_unaudit_bills` | 反审核单据 |
143
+ | `kingdee_delete_bills` | 删除单据 |
144
+
145
+ ## 使用示例
146
+
147
+ 配置完成后,在 Claude 或其他 AI 客户端中直接用自然语言操作:
148
+
149
+ ```
150
+ # 查询类
151
+ 查询最近 20 条已审核的采购订单
152
+ 查一下物料编码 MAT001 的即时库存
153
+ 查询客户编码 C001 的所有销售订单
154
+ 显示本月所有未提交的销售订单
155
+
156
+ # 操作类
157
+ 帮我新建一张采购订单,供应商 S001,物料 MAT001,数量 100,单价 10.5
158
+ 审核这几张采购入库单:12345, 12346, 12347
159
+ 反审核销售订单 SO2024001
160
+ ```
161
+
162
+ ## 支持的单据类型(form_id)
163
+
164
+ | form_id | 说明 |
165
+ |---------|------|
166
+ | `PUR_PurchaseOrder` | 采购订单 |
167
+ | `SAL_SaleOrder` | 销售订单 |
168
+ | `STK_InStock` | 采购入库单 |
169
+ | `SAL_OUTSTOCK` | 销售出库单 |
170
+ | `STK_MisDelivery` | 其他出库单 |
171
+ | `STK_Miscellaneous` | 其他入库单 |
172
+ | `STK_TransferDirect` | 直接调拨单 |
173
+ | `BD_Material` | 物料档案 |
174
+ | `BD_Customer` | 客户档案 |
175
+ | `BD_Supplier` | 供应商档案 |
176
+ | `STK_Inventory` | 即时库存 |
177
+
178
+ ## 常见问题
179
+
180
+ **Q: 提示认证失败怎么办?**
181
+ 检查 AppID / AppSecret 是否正确,集成用户是否有对应模块的访问权限。
182
+
183
+ **Q: 连接超时怎么解决?**
184
+ 检查 `KINGDEE_SERVER_URL` 是否正确(需包含 `/k3cloud/` 后缀),确保服务器可访问。
185
+
186
+ **Q: 支持金蝶云星空公有云吗?**
187
+ 目前主要针对私有云测试,公有云用户可能需要调整认证方式。
188
+
189
+ **Q: 如何添加自定义工具?**
190
+ 基于 FastMCP 框架,在 `server.py` 中添加 `@mcp.tool()` 装饰器方法即可扩展。
191
+
192
+ ## 相关链接
193
+
194
+ - [官方网站](https://wahailong.github.io/KingdeeMCP/)
195
+ - [PyPI 包页面](https://pypi.org/project/kingdee-mcp/)
196
+ - [MCP 协议文档](https://modelcontextprotocol.io/)
197
+ - [金蝶云星空官网](https://www.kingdee.com/)
198
+
199
+ ## License
200
+
201
+ MIT © WaHaiLong
@@ -0,0 +1 @@
1
+ google-site-verification: googlef357cdebef85fa15.html