Skip to main content
Glama
sanxiao-mcp
by adambbhe

sanxiao-mcp —— 金蝶云·星辰「三效项目管理」MCP Server

GC032 财务智能体 · 三效端。应用标识 bdi_projectmanagement, 订阅地址 https://cloud.kingdee.com/kae/#/market/detail?sid=1285。

依据《三效项目管理 API_2025》官方文档 + 《金蝶三效项目管理API开发框架》实现。 一期只读:查询类全开,写入类代码就位但默认被守卫拒绝。

三效 API 的形状(先理解这个,其余都好办)

三效不是"一个业务一个端点",而是通用单据(Bill)CRUD: 所有单据 —— 项目档案、借款、报销、付款、工时填报、采购申请 —— 都走同一组接口, 靠 formId + 字段标识驱动。

POST https://bj1-api.kingdee.com/bdiprojectapi/common/{action}
后端  openapi/ierp/kapi/app/bdi_projectmanagement/{action}

action ∈ { listQuery, getById, saveOrUpdate, submit, unSubmit,
           audit, unAudit, delete, push, operation }

所以本服务的结构也是"一个出口 + 两层封装",而不是几十个端点常量。

Related MCP server: iGuat-MCP

目录

sanxiao/
├── config.py    环境与鉴权四要素;url() / headers() 在这里定形
├── forms.py     formId 登记表 + 中文别名解析(项目档案 → bdi_projectfile)
├── query.py     qParams 结构化查询 DSL:构造、校验、还原成类 SQL 可读串
├── models.py    saveOrUpdate 字段模型(8 种 fType + 分录 + 下推 + 附件)
├── guards.py    白名单 + 默认拒绝 + 审计
├── client.py    唯一 HTTP 出口 _post(),读写方法都从这里过
└── server.py    28 个 MCP 工具(通用层 + 语义层)
test_connection.py   L1 配置 → L2 网络 → L3 鉴权 → L4 只读 → L5 守卫
tests/               pytest:query / models / guards / client

鉴权:四个请求头,没有签名

和 kingdee-star-mcp(jdy 开放网关)不一样 —— 三效不需要 HMAC 签名, 只要携带四个头,全部由云星辰标准 API 事先取得:

头

取值来源

Token

产品账套级 token,走星辰标准 API 鉴权获取

X-GW-Router-Addr

IDC 域名 = 【实时接收授权】推送报文里的 domain 字段

groupname

授权信息,开放平台推送至沙箱消息接收地址

accountid

同上

踩坑提示:官方文档明确写了"在云平台 API 市场调试时可忽略 X-GW-Router-Addr"。于是很多人在市场里调通了,一到代码就 404 —— 因为代码调用必须带这个头。config.headers() 已处理,别删。

拿到四要素后填进 .env(模板见 .env.example)。

快速开始

pip install -r requirements.txt
cp .env.example .env        # 填入四要素
pytest -q                   # 69 项单测应全绿
python test_connection.py   # 分层联调,结果写入 connection_test_result.txt

Windows 直接双击 run_test.bat。

MCP 工具(28 个)

元信息

工具

用途

sx_health

网关地址、只读开关、四要素就绪状态与缺失项

sx_list_forms

已登记的 formId、中文名、默认字段

sx_capabilities

可用 action、只读 operation 白名单、当前放行的写动作

通用层 —— 完整映射官方接口

工具

官方接口

sx_list_query

listQuery

sx_get_by_id

getById

sx_operation

operation(受只读白名单约束)

sx_build_query

本地工具:把简化条件译成 qParams,不发请求

语义层 —— 不必背 formId

sx_list_projects / sx_list_reimbursements / sx_list_loans / sx_list_payments / sx_list_working_hours / sx_get_bill sx_query_cost_budget / sx_query_material_budget / sx_query_working_hour_budget sx_get_user_permission / sx_get_form_config / sx_workflow_status / sx_get_app_parameter

写入层 —— 默认拒绝

sx_build_bill_payload(只组装不发送,一期也能用来给人工核对报文) sx_save_or_update / sx_submit / sx_un_submit / sx_audit / sx_un_audit / sx_delete / sx_push

查询条件怎么写

官方 qParams 是条件数组:顶层各项之间 and,条件组内由 joinKey 连接。

[
  { "childGroup": false, "qKey": "number", "qCp": "like", "qValue": "ew" },
  { "childGroup": true,  "joinKey": "or", "childCondition": [
      { "childGroup": false, "qKey": "number", "qCp": "=", "qValue": "new5" },
      { "childGroup": false, "qKey": "number", "qCp": "=", "qValue": "New" }
  ]}
]
// 等价于 number like '%ew%' and (number='new5' or number='New')

比较符:= > >= < <= != like likeLeft。没有 in —— 用 query.any_of() 或 sx_build_query 的 or 组模拟。分录字段写「分录标识.字段标识」, 如 projectfileteam.teamstaff。

安全模型

守卫是白名单 + 默认拒绝三层:

  1. action 分类 —— listQuery/getById/operation 是读,其余七个是写。

  2. operationKey 白名单 —— operation 表面是读接口,但 operationKey 是自由字符串,所以对文档 10.1–10.9 的九个方法再做一次白名单。

  3. 资金类永久禁写 —— 付款单(bdi_ex_pay*)的写与流程动作, 即使 SX_ALLOW_WRITE_ACTIONS=* 也拦。

二期开写的顺序:SX_READONLY=false → 在 SX_ALLOW_WRITE_ACTIONS 里逐个加动作灰度。不要一步到 *。

所有调用与拦截都打到 sanxiao.audit logger。

真实报文推翻了文档给人的印象

官方另给的《三效-API参考代码》是一份完整的 bdi_projectfile 单据报文 (已存为 tests/fixtures/projectfile_reference.json)。它比文档示例可信, 并且推翻了四条想当然的假设 —— 每条都在 tests/test_reference_payload.py 里钉死了,改回去会立刻红:

文档示例给人的印象

真实报文

每个字段都有 fValue

空值字段整个不出现 fValue 键,不是 fValue:""

enum 必须配 fValueText

status/enable/enablecostamtctl 都只有 fValue

fValue 都是字符串

见过原生 true / false / 0,与字符串 "10" 混用

fValueText 是 enum 专有

bd 也带,用来放基础资料的显示名

其中第三条最要命:早先 field_from_dict 里一句 str(d["fValue"]), 碰上 {"fType":"enum","fValue":true} 会产出 Python 风格的 "True" —— 大写 T 的字符串,服务端认不得,且报错信息不会告诉你是这儿的问题。 现在 fValue 一律原样透传。

好处是 getById 的返回可以直接喂回 saveOrUpdate(改一两个字段再存), 往返无损,这条路有 test_roundtrip_is_lossless 守着。

另外从报文的 bd 字段里摘出了八个基础资料 formId,已登记进 forms.py: bd_employee、bd_department、bd_customer、bdi_bd_customer_fork、 bdi_projecttypes、bdi_projectarea、bdi_projectstauts、bdi_projectroles。

bdi_projectstauts 不是笔误 —— 官方把 status 拼成了 stauts, formId 和字段名都是这个拼法。别"顺手修正"。

字段标识从哪来

别猜。 权威取法是星辰界面: 单据列表 → 更多 → 引入数据 → 模板管理 → 新增模板。

跑起来之后也可以反查:sx_get_form_config(form_id) 会调 operation.getUserconfig 返回该单据的字段配置。

forms.py 登记了 15 个 formId:七个来自官方文档 (bdi_projectfile、bdi_ex_loan、bdi_ex_bx、bdi_ex_pay、 bdi_fillinworkinghours、pur_bill_request、bd_auxinfo), 八个来自参考代码报文里的基础资料引用。其余单据把 formId 直接传给 sx_list_query 即可,不必先登记。

字段名同理 —— 只有 bdi_projectfile 的字段是从真实报文核实过的 (注意它用 status/enable,没有 billstatus;那是业务单据的字段)。 其余单据的默认字段仍是按惯例推的,跑通后请用 sx_get_form_config 核实。

与 kingdee-star-mcp 的关系

两者是同一个星辰账套的两个开放能力,各自独立部署:

kingdee-star-mcp

sanxiao-mcp

网关

api.kingdee.com jdy 网关

bj1-api.kingdee.com 三效网关

鉴权

HMAC 签名 + app-token 两层凭据

四个头,无签名

端点

/jdy/v2/{module}/{object} 数百个

common/{action} 十个

覆盖

财务(凭证、报销、往来)

项目管理(项目、工时、预算、报销)

三效的 Token 需要先经星辰标准 API 取得 —— 如果已经在 kingdee-star-mcp 里跑通了授权链路,可以把拿到的 token 与授权推送里的 domain/groupname/ accountid 直接填进本项目的 .env。

已知留白

  • 官方文档未给统一的返回体 schema,client._unwrap() 做的是宽松解包: 能认出 errcode/success/data 就归一化,认不出原样返回 —— 宁可多给数据, 不因猜错结构而吞数据。拿到真实返回后可以收紧。

  • 单据状态码文档未列全。参考代码里项目档案 status="A"、enable="1", 但 A/B/C 各代表什么、业务单据的 billstatus 取值域,都还没有权威说明。 语义层的 status 参数目前透传原始标识。

  • 参考代码里有几个字段的 fType 自相矛盾 —— phaseplanenddate、 phaseenddate 声明为 num 却明显是日期。这是厂商报文本身的不一致, 模型层照单全收不做纠正,以免"帮倒忙"。

  • 附件上传走 base64,大文件需要评估网关体积上限,文档未说明。

Available Tools

28 tools
sx_auditC

审核单据(官方 audit)。默认被只读守卫拒绝。

Inputs: data_id (required), form_id (required).

sx_build_bill_payloadA

【只组装不发送】把单据 dict 校验并序列化成官方 dataJsonStr,供人工核对。

bill 形如: {"billFormId":"bdi_fillinworkinghours","billId":"0","billNo":"", "fields":[{"fType":"text","fKey":"billno","fValue":"..."}, {"fType":"bd","fFormId":"bdi_projectfile","fKey":"projectfiles","fValue":"..."}, {"fType":"entry","fKey":"entryworkinghours", "fEntities":[{"entryId":"0","entryFields":[...]}]}]} 本工具不调用任何接口,只读环境下也可放心使用。

Inputs: bill (required).

sx_build_queryA

把简化条件翻译成官方 qParams 数组,不发起请求,用于先验证再查询。

conditions 每项形如 {"key": "billdate", "op": ">=", "value": "2025-01-01"}; 或分组 {"join": "or", "children": [ ...同上... ]}。 返回 qParams 数组与类 SQL 的可读描述。

Inputs: conditions (required).

sx_capabilitiesA

列出可用的 action、只读 operation 方法白名单,以及当前放行的写动作。

Inputs: no named parameters.

sx_deleteB

删除单据(官方 delete)。默认被只读守卫拒绝。

Inputs: data_id (required), form_id (required).

sx_get_app_parameterC

获取三效系统参数(operation.loadAppParameter)。

Inputs: para_code (required), app_code.

sx_get_billB

查任意单据详情,form_id 支持中文别名。with_attachments=True 时带上默认附件面板。

Inputs: data_id (required), form_id (required), with_attachments.

sx_get_by_idC

按单据 Id 查详情(官方 getById)。attach_keys 为附件面板标识,如 ["attachmentpanel"]。

Inputs: data_id (required), form_id (required), attach_keys.

sx_get_form_configC

查询单据字段配置(operation.getUserconfig)——想知道某单据有哪些字段标识时用这个。

Inputs: form_id (required), form_id_ex, entry_marks.

sx_get_user_permissionC

查询当前用户对若干单据的权限(operation.getUserPermission)。

Inputs: form_ids (required).

sx_healthB

健康检查:返回网关地址、只读开关、鉴权四要素就绪状态与缺失项。

Inputs: no named parameters.

sx_list_formsA

列出本服务已登记的三效单据标识(formId)、中文名与默认查询字段。

未登记的单据仍可直接把 formId 传给 sx_list_query,此表只是便利。 formId 与字段标识的权威来源:星辰单据列表 → 更多 → 引入数据 → 模板管理 → 新增模板。

Inputs: no named parameters.

sx_list_loansC

查询借款单(bdi_ex_loan)。

Inputs: fields, status, bill_no, date_to, +4 more.

sx_list_paymentsB

查询付款单(bdi_ex_pay)。只读——付款类写操作在本服务中永久禁止。

Inputs: fields, status, bill_no, date_to, +4 more.

sx_list_projectsC

查询项目档案(bdi_projectfile)。keyword 对项目名称做 like 模糊匹配。

Inputs: fields, keyword, order_by, page_size, +1 more.

sx_list_queryA

列表查询任意三效单据(官方 listQuery)。

form_id: 单据标识或中文别名,如 bdi_projectfile / "项目档案" fields: 字段标识,逗号分隔;分录字段写「分录标识.字段标识」, 如 "id,number,name,projectfileteam.teamstaff";留空取默认字段 params: qParams 条件数组,叶子形如 {"childGroup": false, "qKey": "number", "qCp": "like", "qValue": "ew"} 条件组形如 {"childGroup": true, "joinKey": "or", "childCondition": [ ...叶子... ]} 顶层各项之间是 and。比较符:=,>,>=,<,<=,!=,like,likeLeft order_by: 如 "id desc,name asc" data_permission: all 全部 / self 仅制单人自己

Inputs: form_id (required), fields, params, order_by, +3 more.

sx_list_reimbursementsB

查询报销单(bdi_ex_bx)。日期形如 2025-01-01;status 为单据状态标识,如 A 暂存。

Inputs: fields, status, bill_no, date_to, +4 more.

sx_list_working_hoursC

查询工时填报(bdi_fillinworkinghours)。分录标识 entryworkinghours。

Inputs: fields, status, bill_no, date_to, +4 more.

sx_operationB

执行三效自定义方法(官方 operation)。

只读白名单:loadAppParameter, getUserPermission, getUserconfig, materialBudget, costBudget, workingHourBudget, getAttachFieldPermission, enableWorkflow, isInWorkflow。参数用 dict 传,本工具负责序列化成 官方要求的 operationParJsonStr 字符串。

Inputs: operation_key (required), par.

sx_pushA

单据下推(官方 push),如借款单下推报销单。

按单据下推传 bill_ids;按分录下推传 entry_ids + src_entry_mark(源单分录标识)。 返回的目标单据数据包在保存时需回传 pushPar。默认被只读守卫拒绝。

Inputs: src_form_id (required), dest_form_id (required), bill_ids, entry_ids, +1 more.

sx_query_cost_budgetB

查询费用预算(operation.costBudget)。now_bill_id 新建单据传 0。

Inputs: form_id (required), project_id (required), cost_id, now_bill_id, +2 more.

sx_query_material_budgetC

查询物料预算(operation.materialBudget)。

Inputs: form_id (required), project_id (required), material_id, now_bill_id, +1 more.

sx_query_working_hour_budgetC

查询工时预算(operation.workingHourBudget)。

Inputs: form_id (required), project_id (required), now_bill_id.

sx_save_or_updateB

保存/修改单据(官方 saveOrUpdate)。默认被只读守卫拒绝,需 SX_READONLY=false 且 SX_ALLOW_WRITE_ACTIONS 含 saveOrUpdate 才会真正发送。

Inputs: bill (required).

sx_submitC

提交单据审批(官方 submit)。默认被只读守卫拒绝。

Inputs: data_id (required), form_id (required).

sx_un_auditC

反审核单据(官方 unAudit)。默认被只读守卫拒绝。

Inputs: data_id (required), form_id (required).

sx_un_submitC

撤销提交(官方 unSubmit)。默认被只读守卫拒绝。

Inputs: data_id (required), form_id (required).

sx_workflow_statusC

查工作流状态:是否启用工作流;给了 bill_id 时再查该单是否已在流程中。

Inputs: form_id (required), bill_id.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    C2.9/5.0

    Scored across 28 tools

    Disambiguation4/5

    Most tools target distinct resources or actions, e.g. list_query is generic while list_projects is form-specific. However, sx_get_by_id and sx_get_bill both retrieve single bills with similar semantics, and sx_operation overlaps with specific query tools, creating minor ambiguity.

    Naming Consistency3/5

    All tools share the sx_ prefix, and most follow verb_noun patterns (sx_list_*, sx_get_*, sx_query_*, sx_build_*). However, sx_health and sx_capabilities are nouns rather than verbs, and there is mixing between list/get/query verbs with no strict rule, slightly reducing predictability.

    Tool Count2/5

    With 28 tools, the server clearly exceeds the 25-tool threshold for heavy sets. While many tools target specific query types, generic tools like sx_list_query could absorb some of them, making the surface feel redundant and bloated.

    Completeness4/5

    The toolset covers the full lifecycle of bills: list, get, save/update, delete, audit, submit, unsubmit, unaudit, and push. It also includes capabilities like budget queries, permissions, form config, and health checks. Only minor gaps exist, such as batch operations or specialized export tools, but core workflows are well-supported.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      A
      quality
      D
      maintenance
      Enables read-only access to Kingdee Cloud Star financial data, invoice tax calculation, and generation of reimbursement draft payloads through MCP tools.
      17
      -
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables read-only queries of i桂航 campus data, including schedules, classes, terms, and campus information through MCP tools.
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      Provides MCP access to an internal performance and consulting project collaboration system, enabling management of projects, stages, tasks, materials, evidence, approvals, and experience in a traceable chain, with Feishu for organization sync and collaboration.
      Apache 2.0
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables Claude, Cursor, and other AI assistants to query and operate Kingdee Cloud Star ERP—covering purchasing, sales, inventory, manufacturing, costing, fixed assets, financial reports, and approvals—using natural language through 87 MCP tools.
      -