kingdee-k3cloud-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,19 @@
1
+ # 金蝶云星空 API 配置
2
+ KD_ACCT_ID=your_acct_id
3
+ KD_USERNAME=your_username
4
+ KD_APP_ID=your_app_id
5
+ KD_APP_SEC=your_app_secret
6
+ KD_SERVER_URL=https://your-server/k3cloud/
7
+ KD_LCID=2052
8
+ KD_ORG_NUM=
9
+
10
+ # SSE 传输模式(仅 --transport sse 时生效)
11
+ # FASTMCP_HOST=127.0.0.1 # 绑定地址(0.0.0.0 可远程访问)
12
+ # FASTMCP_PORT=8000 # 端口
13
+
14
+ # Bearer Token 鉴权(仅 SSE/streamable-http 模式生效)
15
+ # MCP_API_KEY=your-secret-api-key # 不设置则不启用鉴权
16
+ # MCP_ISSUER_URL=http://127.0.0.1:8000 # 与客户端连接地址一致(默认 http://localhost:8000)
17
+
18
+ # 服务模式(readonly: 仅查询工具;readwrite: 全部工具,默认)
19
+ # MCP_MODE=readwrite
@@ -0,0 +1,28 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Install uv and set Python ${{ matrix.python-version }}
20
+ uses: astral-sh/setup-uv@v5
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+
24
+ - name: Install dependencies
25
+ run: uv sync --all-extras --dev
26
+
27
+ - name: Run tests
28
+ run: uv run --frozen pytest
@@ -0,0 +1,36 @@
1
+ name: Release to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ id-token: write # required for PyPI Trusted Publishing (OIDC)
13
+ contents: write # required to create GitHub Release
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - uses: astral-sh/setup-uv@v5
19
+ with:
20
+ python-version: '3.12'
21
+
22
+ - run: uv sync --frozen
23
+
24
+ - run: uv build
25
+
26
+ - run: uv run --with twine twine check dist/*
27
+
28
+ - name: Publish to PyPI
29
+ uses: pypa/gh-action-pypi-publish@release/v1
30
+
31
+ - name: Create GitHub Release
32
+ uses: softprops/action-gh-release@v2
33
+ with:
34
+ files: dist/*
35
+ generate_release_notes: true
36
+ body_path: CHANGELOG.md
@@ -0,0 +1,57 @@
1
+ # ============================================================
2
+ # 凭证与敏感配置(绝对不能提交)
3
+ # ============================================================
4
+ .env
5
+ .env.*
6
+ !.env.example
7
+ *.env
8
+ secrets/
9
+ credentials/
10
+
11
+ # ============================================================
12
+ # Python
13
+ # ============================================================
14
+ __pycache__/
15
+ *.py[cod]
16
+ *$py.class
17
+ *.so
18
+ *.egg
19
+ *.egg-info/
20
+ dist/
21
+ build/
22
+ .eggs/
23
+
24
+ # 虚拟环境
25
+ .venv/
26
+ venv/
27
+ env/
28
+ ENV/
29
+
30
+ # 测试与覆盖率
31
+ .pytest_cache/
32
+ .coverage
33
+ htmlcov/
34
+
35
+ # uv
36
+ .python-version
37
+
38
+ # ============================================================
39
+ # 编辑器与 IDE
40
+ # ============================================================
41
+ .vscode/
42
+ .idea/
43
+ *.swp
44
+ *.swo
45
+ *~
46
+
47
+ # ============================================================
48
+ # macOS
49
+ # ============================================================
50
+ .DS_Store
51
+ .AppleDouble
52
+ ._*
53
+
54
+ # ============================================================
55
+ # Claude Code 本地配置
56
+ # ============================================================
57
+ .claude/
@@ -0,0 +1,52 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-04-12
11
+
12
+ ### Added
13
+
14
+ **Core MCP tools (11 total)**
15
+
16
+ | Tool | Type | Description |
17
+ |------|------|-------------|
18
+ | `query_bill` | query | 按字段键列表查询单据,支持过滤、排序、分页 |
19
+ | `query_bill_json` | query | 查询单据并返回完整 JSON 字段(适合字段名未知时探索) |
20
+ | `view_bill` | query | 按单据 ID 或单号查询单条完整单据 |
21
+ | `query_metadata` | query | 查询表单元数据与字段定义 |
22
+ | `query_by_number` | query | 批量按单号查询单据 |
23
+ | `query_business_info` | query | 查询扩展业务数据视图 |
24
+ | `save_bill` | write | 新建或更新单据 |
25
+ | `submit_bill` | write | 提交单据审批 |
26
+ | `audit_bill` | write | 审核通过单据 |
27
+ | `unaudit_bill` | write | 撤销单据审核 |
28
+ | `delete_bill` | write | 删除草稿单据 |
29
+ | `execute_operation` | write | 调用金蝶 K/3 Cloud 任意业务操作 |
30
+ | `push_bill` | write | 单据下推,将源单转换为下游单据类型 |
31
+
32
+ **Transport & auth**
33
+ - Three transport protocols: `stdio` (default), `SSE`, `streamable-http`
34
+ - Optional Bearer-token authentication via `MCP_API_KEY` env var (SSE / streamable-http only); stdio mode is unaffected
35
+ - `--mode readonly` flag (and `MCP_MODE=readonly` env var) to expose only the 4 query tools — safe for read-only deployments
36
+
37
+ **Session management**
38
+ - `RetryableK3CloudApiSdk`: automatic session recovery when K/3 Cloud returns "会话信息已丢失"
39
+ - Fire-and-forget SID reset: on expiry, clears stale `cookiesStore` and makes one call to establish a fresh SID; returns the error immediately instead of blocking
40
+ - 300-second cooldown prevents back-to-back resets from destroying a newly-issued SID before it activates server-side
41
+ - Unicode-escaped session expiry messages correctly detected (`\u4f1a\u8bdd...`)
42
+ - `hasattr` guard on `cookiesStore` reset for forward-compatibility with future SDK versions
43
+
44
+ **Package & tooling**
45
+ - Proper `src/` layout, fully PEP 621 compliant `pyproject.toml`
46
+ - Dependency upper bounds: `kingdee-cdp-webapi-sdk>=8.2.0,<9`, `mcp>=1.26.0,<2`, `python-dotenv>=1.2.1,<2`
47
+ - `py.typed` marker for downstream `mypy` support
48
+ - Apache 2.0 license
49
+ - GitHub Actions CI matrix (Python 3.10 / 3.11 / 3.12)
50
+ - GitHub Actions release workflow with PyPI Trusted Publishing (OIDC)
51
+
52
+ [0.1.0]: https://github.com/adamzhang1987/kingdee-k3cloud-mcp/releases/tag/v0.1.0
@@ -0,0 +1,43 @@
1
+ # Contributing to kingdee-k3cloud-mcp
2
+
3
+ Thank you for your interest in contributing!
4
+
5
+ ## Prerequisites
6
+
7
+ - Python 3.10+
8
+ - [uv](https://docs.astral.sh/uv/)
9
+ - Access to a Kingdee K3Cloud instance (for manual testing)
10
+
11
+ ## Setup
12
+
13
+ ```bash
14
+ git clone https://github.com/adamzhang1987/kingdee-k3cloud-mcp.git
15
+ cd kingdee-k3cloud-mcp
16
+ uv sync
17
+ ```
18
+
19
+ ## Running Tests
20
+
21
+ ```bash
22
+ uv run pytest
23
+ ```
24
+
25
+ ## Making Changes
26
+
27
+ 1. Fork the repo and create a feature branch from `main`
28
+ 2. Make your changes
29
+ 3. Add or update tests if applicable
30
+ 4. Run `uv run pytest` to ensure tests pass
31
+ 5. Submit a pull request
32
+
33
+ ## Reporting Issues
34
+
35
+ Please open an issue with:
36
+ - A clear description of the problem
37
+ - Steps to reproduce
38
+ - Expected vs actual behavior
39
+ - Kingdee K3Cloud version if relevant
40
+
41
+ ## Security Issues
42
+
43
+ Please do **not** open public issues for security vulnerabilities. See [SECURITY.md](SECURITY.md) instead.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Adam Zhang
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,224 @@
1
+ Metadata-Version: 2.4
2
+ Name: kingdee-k3cloud-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP Server for Kingdee K3Cloud ERP — connect AI assistants to 金蝶云星空 via natural language
5
+ Project-URL: Homepage, https://github.com/adamzhang1987/kingdee-k3cloud-mcp
6
+ Project-URL: Repository, https://github.com/adamzhang1987/kingdee-k3cloud-mcp
7
+ Project-URL: Issues, https://github.com/adamzhang1987/kingdee-k3cloud-mcp/issues
8
+ Author-email: Adam Zhang <adamzhang1987@gmail.com>
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: agent,ai,erp,k3cloud,kingdee,llm,mcp
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Office/Business
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: kingdee-cdp-webapi-sdk<9.0.0,>=8.2.0
25
+ Requires-Dist: mcp<2,>=1.26.0
26
+ Requires-Dist: python-dotenv<2,>=1.2.1
27
+ Description-Content-Type: text/markdown
28
+
29
+ # Kingdee K3Cloud MCP
30
+
31
+ [![PyPI version](https://img.shields.io/pypi/v/kingdee-k3cloud-mcp)](https://pypi.org/project/kingdee-k3cloud-mcp/)
32
+ [![Python](https://img.shields.io/pypi/pyversions/kingdee-k3cloud-mcp)](https://pypi.org/project/kingdee-k3cloud-mcp/)
33
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
34
+ [![CI](https://github.com/adamzhang1987/kingdee-k3cloud-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/adamzhang1987/kingdee-k3cloud-mcp/actions/workflows/ci.yml)
35
+
36
+ 金蝶云星空 K3Cloud MCP Server,让 AI 助手(Claude Desktop、Claude Code、Cursor、Cline、Cherry Studio、Openclaw 等任意支持 MCP 协议的客户端)通过自然语言查询和操作金蝶 ERP 系统。
37
+
38
+ > **提示**:Claude Code 用户可配合 [kingdee-k3cloud-skill](https://github.com/adamzhang1987/kingdee-k3cloud-skill) 获得更佳体验。Skill 为 Claude Code 注入金蝶表单字段、常用查询模式和工作流知识,大幅减少试错次数。
39
+
40
+ MCP Server for Kingdee K3Cloud ERP. Connect AI assistants to your ERP system via the [Model Context Protocol](https://modelcontextprotocol.io/).
41
+
42
+ ## 功能特性
43
+
44
+ - **11 个 MCP 工具**:覆盖查询、新增、提交、审核、反审核、删除、下推等核心操作
45
+ - **通用接口设计**:单一 `form_id` 参数支持物料、客户、销售订单、采购订单等所有表单,无需为每种业务单独配置
46
+ - **只读/读写模式**:可限制 AI 只能查询,防止误操作
47
+ - **自动会话恢复**:长时间运行时自动处理会话超时,无需人工干预
48
+ - **多传输协议**:支持 stdio(本地)、SSE、streamable-http(远程共享)
49
+
50
+ ## 快速开始
51
+
52
+ ### 方式一:uvx 直接运行(推荐)
53
+
54
+ 无需克隆仓库,直接通过 uvx 运行:
55
+
56
+ ```bash
57
+ # 确保已安装 uv: https://docs.astral.sh/uv/
58
+ uvx kingdee-k3cloud-mcp
59
+ ```
60
+
61
+ ### 方式二:从源码运行
62
+
63
+ ```bash
64
+ git clone https://github.com/adamzhang1987/kingdee-k3cloud-mcp.git
65
+ cd kingdee-k3cloud-mcp
66
+ uv sync
67
+ uv run kingdee-k3cloud-mcp
68
+ ```
69
+
70
+ ## 配置
71
+
72
+ 复制环境变量模板并填写:
73
+
74
+ ```bash
75
+ cp .env.example .env
76
+ ```
77
+
78
+ | 环境变量 | 说明 | 示例 |
79
+ |----------|------|------|
80
+ | `KD_SERVER_URL` | 金蝶服务器地址(必须以 `/k3cloud/` 结尾) | `https://your-server/k3cloud/` |
81
+ | `KD_ACCT_ID` | 账套 ID | `your_acct_id` |
82
+ | `KD_USERNAME` | 用户名 | `your_username` |
83
+ | `KD_APP_ID` | 第三方应用 ID | `your_app_id` |
84
+ | `KD_APP_SEC` | 第三方应用密钥 | `your_app_secret` |
85
+ | `KD_LCID` | 语言(默认 2052 中文) | `2052` |
86
+ | `KD_ORG_NUM` | 组织编码(可选) | |
87
+
88
+ > 第三方应用 ID 和密钥需在金蝶云星空管理端的「第三方系统登录授权」中申请。
89
+
90
+ ## 客户端配置
91
+
92
+ ### Claude Desktop
93
+
94
+ 编辑 `~/Library/Application Support/Claude/claude_desktop_config.json`(macOS):
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "kingdee-k3cloud": {
100
+ "command": "uvx",
101
+ "args": ["kingdee-k3cloud-mcp"],
102
+ "env": {
103
+ "KD_SERVER_URL": "https://your-server/k3cloud/",
104
+ "KD_ACCT_ID": "your_acct_id",
105
+ "KD_USERNAME": "your_username",
106
+ "KD_APP_ID": "your_app_id",
107
+ "KD_APP_SEC": "your_app_secret",
108
+ "KD_LCID": "2052"
109
+ }
110
+ }
111
+ }
112
+ }
113
+ ```
114
+
115
+ ### Claude Code
116
+
117
+ 在项目目录下创建 `.mcp.json`:
118
+
119
+ ```json
120
+ {
121
+ "mcpServers": {
122
+ "kingdee-k3cloud": {
123
+ "command": "uvx",
124
+ "args": ["kingdee-k3cloud-mcp"],
125
+ "env": {
126
+ "KD_SERVER_URL": "https://your-server/k3cloud/",
127
+ "KD_ACCT_ID": "your_acct_id",
128
+ "KD_USERNAME": "your_username",
129
+ "KD_APP_ID": "your_app_id",
130
+ "KD_APP_SEC": "your_app_secret",
131
+ "KD_LCID": "2052"
132
+ }
133
+ }
134
+ }
135
+ }
136
+ ```
137
+
138
+ ### Cursor / Windsurf 及其他 MCP 客户端
139
+
140
+ 配置方式与 Claude Desktop 类似,参考各客户端的 MCP 配置文档,使用相同的 `uvx` 命令和环境变量。
141
+
142
+ ### SSE 模式(远程共享)
143
+
144
+ 如需多人共用同一个服务实例:
145
+
146
+ ```bash
147
+ # 启动 SSE 服务(默认端口 8000)
148
+ FASTMCP_HOST=0.0.0.0 FASTMCP_PORT=8080 uvx kingdee-k3cloud-mcp --transport sse
149
+ ```
150
+
151
+ 客户端连接地址:`http://your-server:8080/sse`
152
+
153
+ 可通过 `MCP_API_KEY` 环境变量启用 Bearer Token 鉴权。
154
+
155
+ ## 可用工具
156
+
157
+ | 工具 | 类型 | 说明 |
158
+ |------|------|------|
159
+ | `query_bill` | 查询 | 查询单据数据(返回二维数组) |
160
+ | `query_bill_json` | 查询 | 查询单据数据(返回 JSON,字段名作为 key) |
161
+ | `view_bill` | 查询 | 查看单条记录完整详情 |
162
+ | `query_metadata` | 查询 | 查询表单字段结构(元数据) |
163
+ | `save_bill` | 写入 | 保存/新增单据 |
164
+ | `submit_bill` | 写入 | 提交单据 |
165
+ | `audit_bill` | 写入 | 审核单据 |
166
+ | `unaudit_bill` | 写入 | 反审核单据 |
167
+ | `delete_bill` | 写入 | 删除单据 |
168
+ | `execute_operation` | 写入 | 执行自定义操作(禁用、反禁用等) |
169
+ | `push_bill` | 写入 | 下推单据(如销售订单→发货通知单) |
170
+
171
+ 所有工具通过 `form_id` 参数支持任意表单(物料、客户、供应商、销售订单、采购订单等)。
172
+
173
+ ## 只读模式
174
+
175
+ 通过 `--mode readonly` 或 `MCP_MODE=readonly` 限制服务器只暴露 4 个查询工具,防止 AI 误操作写入数据。
176
+
177
+ ```json
178
+ "args": ["kingdee-k3cloud-mcp", "--mode", "readonly"]
179
+ ```
180
+
181
+ 或:
182
+
183
+ ```json
184
+ "env": {
185
+ "MCP_MODE": "readonly",
186
+ ...
187
+ }
188
+ ```
189
+
190
+ ## 调试
191
+
192
+ 使用 MCP Inspector 可视化调试工具:
193
+
194
+ ```bash
195
+ uvx mcp dev src/kingdee_k3cloud_mcp/server.py
196
+ ```
197
+
198
+ ## 架构说明
199
+
200
+ ```
201
+ AI 助手(Claude Desktop / Claude Code / Cursor / Cline / Openclaw 等)
202
+ │ MCP 协议
203
+
204
+ kingdee-k3cloud-mcp(本项目)
205
+ │ Kingdee Web API SDK
206
+
207
+ 金蝶云星空 K3Cloud
208
+ ```
209
+
210
+ 本项目使用官方金蝶 Python SDK([kingdee-cdp-webapi-sdk](https://pypi.org/project/kingdee-cdp-webapi-sdk/))与 K3Cloud API 通信,并通过 [FastMCP](https://github.com/modelcontextprotocol/python-sdk) 将其封装为标准 MCP 工具。
211
+
212
+ ## 配套 Skill(Claude Code 用户)
213
+
214
+ [kingdee-k3cloud-skill](https://github.com/adamzhang1987/kingdee-k3cloud-skill) 是面向 Claude Code 的配套 Skill,提供:
215
+
216
+ - 常用表单 ID 速查表(BD_MATERIAL、SAL_SaleOrder 等)
217
+ - 已验证字段名列表(避免字段名错误导致 500)
218
+ - 日报、客户查询、销售分析、库存分析、订单追踪等完整工作流
219
+
220
+ 安装后 Claude Code 可自动掌握金蝶 ERP 的正确查询方式,无需反复试错。
221
+
222
+ ## 许可证
223
+
224
+ Apache License 2.0 — 详见 [LICENSE](LICENSE)