@qingflow-tech/qingflow-cli 1.1.61-beta.4 → 1.1.61

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.
Files changed (48) hide show
  1. package/README.md +3 -3
  2. package/package.json +1 -1
  3. package/pyproject.toml +1 -2
  4. package/skills/qingflow-cli/SKILL.md +2 -104
  5. package/skills/qingflow-cli/reference/builder/20-build-complete-system.md +2 -2
  6. package/skills/qingflow-cli/reference/builder/30-schema-fields.md +5 -9
  7. package/skills/qingflow-cli/reference/builder/reference/app-delivery-sop.md +3 -3
  8. package/src/qingflow_mcp/app_form_compat.py +0 -3
  9. package/src/qingflow_mcp/app_form_validator.py +17 -69
  10. package/src/qingflow_mcp/builder_facade/app_form.py +100 -497
  11. package/src/qingflow_mcp/builder_facade/schemas/app_form/manifest.json +0 -1
  12. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/complete.json +30 -64
  13. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/address.json +8 -4
  14. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/amount.json +8 -4
  15. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/attachment.json +10 -6
  16. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/code_block.json +10 -6
  17. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/data_relation.json +18 -11
  18. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/date.json +8 -4
  19. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/datetime.json +8 -4
  20. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/department.json +10 -6
  21. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/email.json +8 -4
  22. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/link.json +8 -4
  23. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/long_text.json +8 -4
  24. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/member.json +10 -6
  25. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/multi_select.json +8 -4
  26. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/number.json +8 -4
  27. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/phone.json +8 -4
  28. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/q_linker.json +10 -6
  29. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/relation.json +15 -46
  30. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/single_choice.json +8 -4
  31. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/single_select.json +8 -4
  32. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/subtable.json +27 -61
  33. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/text.json +8 -4
  34. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/formula.json +0 -43
  35. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/summary.json +12 -7
  36. package/src/qingflow_mcp/builder_facade/service.py +1 -39
  37. package/src/qingflow_mcp/cli/main.py +1 -34
  38. package/src/qingflow_mcp/cloud_context.py +1 -16
  39. package/src/qingflow_mcp/public_surface.py +8 -67
  40. package/src/qingflow_mcp/response_trim.py +1 -2
  41. package/src/qingflow_mcp/server.py +6 -12
  42. package/src/qingflow_mcp/server_app_builder.py +5 -9
  43. package/src/qingflow_mcp/server_app_user.py +5 -9
  44. package/src/qingflow_mcp/server_cloud.py +7 -43
  45. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/rich_text.json +0 -146
  46. package/src/qingflow_mcp/tool_catalog.py +0 -387
  47. package/src/qingflow_mcp/tool_catalog_i18n.py +0 -185
  48. package/src/qingflow_mcp/tool_policy.py +0 -197
@@ -1,185 +0,0 @@
1
- from __future__ import annotations
2
-
3
-
4
- DEFAULT_LOCALE = "zh-CN"
5
- SUPPORTED_LOCALES = ("zh-CN", "en-US")
6
-
7
- # 每项为(中文显示名称、英文显示名称、英文能力说明);中文能力说明沿用 tool_catalog.py。
8
- # 这里只维护工具本身的文案,不包含 Wingent-X 的产品分类、排序或分类标签。
9
- TOOL_DISPLAY_TEXT: dict[str, tuple[str, str, str]] = {
10
- "builder:app_associated_resources_apply": ("配置关联资源", "Configure associated resources", "Configure associated views, reports, and their display rules for each view."),
11
- "builder:app_charts_apply": ("配置应用图表", "Configure application charts", "Create, update, delete, or reorder charts and reports using Qingflow application data sources."),
12
- "builder:app_custom_buttons_apply": ("配置自定义按钮", "Configure custom buttons", "Maintain standalone button definitions, styles, bindings across views, and ordering."),
13
- "builder:app_delete": ("删除应用", "Delete application", "Delete an application and its configuration, retaining existing permission and confirmation checks."),
14
- "builder:app_flow_apply": ("配置工作流", "Configure workflow", "Replace workflow declarations or modify nodes; deleting existing nodes retains destructive change confirmation."),
15
- "builder:app_flow_get": ("读取工作流声明", "Read workflow declaration", "Read the current draft or a specified historical workflow declaration."),
16
- "builder:app_flow_get_schema": ("读取工作流结构", "Read workflow schema", "Read the versioned schema for workflow declarations."),
17
- "builder:app_flow_list_versions": ("列出工作流版本", "List workflow versions", "List historical workflow versions available for restoration."),
18
- "builder:app_flow_restore_version": ("恢复工作流版本", "Restore workflow version", "Restore a specified historical workflow version to the draft; this is a write operation."),
19
- "builder:app_flow_validate": ("校验工作流", "Validate workflow", "Validate workflow declarations with existing maintenance and contract checks."),
20
- "builder:app_form_apply": ("配置应用表单", "Configure application form", "Create or update applications, fields, layouts, and related configuration from a complete form declaration."),
21
- "builder:app_form_get": ("读取表单声明", "Read form declaration", "Read the application's canonical form declaration."),
22
- "builder:app_form_schema": ("读取表单结构", "Read form schema", "Read versioned schemas for form declarations, fields, or formulas."),
23
- "builder:app_form_validate": ("校验表单声明", "Validate form declaration", "Validate form declarations locally without accessing the business backend."),
24
- "builder:app_form_validate_code_block": ("校验表单代码块", "Validate form code block", "Perform static code checks and, when applicable, execute a test run on the backend."),
25
- "builder:app_form_validate_formula": ("校验表单公式", "Validate form formula", "Validate formula syntax and evaluate the formula on the backend."),
26
- "builder:app_get": ("读取应用配置概览", "Read application configuration overview", "Read the application configuration overview and references to form, view, and workflow resources."),
27
- "builder:app_get_associated_resources": ("读取关联资源", "Read associated resources", "Read associated views, reports, and their display configuration."),
28
- "builder:app_get_buttons": ("读取应用按钮", "Read application buttons", "Read application button definitions and binding configuration."),
29
- "builder:app_get_charts": ("读取应用图表配置", "Read application chart configuration", "Read application chart and report configuration."),
30
- "builder:app_get_fields": ("读取应用字段", "Read application fields", "Read application fields and the field capabilities available for chart configuration."),
31
- "builder:app_get_flow": ("读取工作流概览", "Read workflow overview", "Read an overview of the application's workflow configuration."),
32
- "builder:app_get_layout": ("读取表单布局", "Read form layout", "Read the application's form layout configuration."),
33
- "builder:app_get_views": ("读取视图配置概览", "Read view configuration overview", "Read an overview of application view configuration."),
34
- "builder:app_publish_verify": ("发布并核验应用", "Publish and verify application", "Verify the application's current publication state; when needed, publish, finish editing, and verify the published result."),
35
- "builder:app_release_edit_lock_if_mine": ("释放本人编辑锁", "Release own edit lock", "Release an application edit lock only when it belongs to the current user."),
36
- "builder:app_repair_code_blocks": ("检查并修复代码块", "Inspect and repair code blocks", "Inspect and optionally repair code blocks with output bindings; apply=false/true share the same full tool permission."),
37
- "builder:app_resolve": ("定位应用", "Resolve application", "Resolve the target application by name or reference."),
38
- "builder:app_views_apply": ("配置应用视图", "Configure application views", "Create or modify views, filters, and query panels; may also create and bind view buttons."),
39
- "builder:app_views_get": ("读取视图声明", "Read view declaration", "Read canonical view declarations and related configuration."),
40
- "builder:app_views_schema": ("读取视图结构", "Read view schema", "Read the versioned schema for view declarations."),
41
- "builder:app_views_validate": ("校验视图声明", "Validate view declaration", "Validate view declarations."),
42
- "builder:auth_logout": ("退出认证", "Log out", "Leave the current authentication context and optionally clear saved credentials."),
43
- "builder:auth_use_credential": ("使用凭据认证", "Authenticate with credential", "Establish an authentication context with the supplied credential and save it when requested."),
44
- "builder:auth_whoami": ("查看当前身份", "Read current identity", "Read the current authenticated identity."),
45
- "builder:builder_tool_contract": ("读取配置工具合同", "Read builder tool contract", "Read configuration tool contracts covering forms, views, workflows, charts, application packages, and members."),
46
- "builder:button_style_catalog_get": ("读取按钮样式目录", "Read button style catalog", "Read available button styles, colors, and icons."),
47
- "builder:chart_get": ("读取图表配置", "Read chart configuration", "Read the target chart's configuration."),
48
- "builder:feedback_submit": ("提交产品反馈", "Submit product feedback", "Submit product feedback with existing user confirmation requirements."),
49
- "builder:file_upload_local": ("上传本地文件", "Upload local file", "Upload a local file to Qingflow."),
50
- "builder:get_login_link": ("生成免登录链接", "Generate login link", "Generate a short lived login link for a specified Qingflow page."),
51
- "builder:member_search": ("搜索工作区成员", "Search workspace members", "Search workspace members."),
52
- "builder:package_apply": ("配置应用包", "Configure application package", "Create or update application package metadata, visibility, groups, and ordering."),
53
- "builder:package_get": ("读取应用包详情", "Read application package", "Read application package details."),
54
- "builder:package_list": ("列出应用包", "List application packages", "List accessible application packages."),
55
- "builder:portal_apply": ("配置门户", "Configure portal", "Create or update a portal and optionally create its embedded charts."),
56
- "builder:portal_delete": ("删除门户", "Delete portal", "Delete a portal with existing destructive operation confirmation requirements."),
57
- "builder:portal_get": ("读取门户配置", "Read portal configuration", "Read portal configuration."),
58
- "builder:portal_list": ("列出门户", "List portals", "List accessible portals."),
59
- "builder:role_create": ("创建工作区角色", "Create workspace role", "Create a workspace role."),
60
- "builder:role_search": ("搜索工作区角色", "Search workspace roles", "Search workspace roles."),
61
- "builder:solution_install": ("安装完整方案", "Install complete solution", "Install a complete solution; may create application packages, applications, fields, views, workflows, charts, portals, and roles, and copy business data when requested."),
62
- "builder:view_get": ("读取视图配置", "Read view configuration", "Read the target view's configuration."),
63
- "builder:workspace_get": ("读取工作区信息", "Read workspace information", "Read workspace information."),
64
- "builder:workspace_icon_catalog_get": ("读取工作区图标目录", "Read workspace icon catalog", "Read workspace icons and colors available for application configuration."),
65
- "builder:workspace_list": ("列出工作区", "List workspaces", "List accessible workspaces."),
66
- "user:app_get": ("读取应用业务信息", "Read application business information", "Read application information, data access scope, and accessible views."),
67
- "user:app_list": ("列出应用", "List applications", "List accessible applications or search them by name."),
68
- "user:auth_login": ("登录轻流", "Log in to Qingflow", "Log in and establish a Qingflow authentication context."),
69
- "user:auth_logout": ("退出认证", "Log out", "Leave the current authentication context and optionally clear saved credentials."),
70
- "user:auth_use_credential": ("使用凭据认证", "Authenticate with credential", "Establish an authentication context with the supplied credential and save it when requested."),
71
- "user:auth_whoami": ("查看当前身份", "Read current identity", "Read the current authenticated identity."),
72
- "user:chart_get": ("读取图表", "Read chart", "Read the target chart."),
73
- "user:data_delete": ("删除应用数据", "Delete application data", "Delete application records in batches with existing data scope and permission checks."),
74
- "user:data_get": ("读取应用数据", "Read application data", "Read application data by record ID, with optional field information."),
75
- "user:data_insert": ("新增应用数据", "Insert application data", "Insert application records in batches."),
76
- "user:data_query": ("查询应用数据", "Query application data", "Query application data by field ID, with filtering, sorting, pagination, and complete CSV export."),
77
- "user:data_update": ("更新应用数据", "Update application data", "Update selected fields in application records in batches."),
78
- "user:directory_list_all_departments": ("读取全部可访问部门", "Read all accessible departments", "Read all accessible departments."),
79
- "user:directory_list_all_internal_users": ("读取全部可访问内部成员", "Read all accessible internal members", "Read all accessible internal members."),
80
- "user:directory_list_external_members": ("列出外部成员", "List external members", "List external members."),
81
- "user:directory_list_internal_departments": ("列出内部部门", "List internal departments", "List internal departments."),
82
- "user:directory_list_internal_users": ("列出内部成员", "List internal members", "List internal members."),
83
- "user:directory_list_sub_departments": ("列出子部门", "List subdepartments", "List subdepartments of a specified department."),
84
- "user:directory_search": ("搜索通讯录", "Search directory", "Search directory members or departments."),
85
- "user:feedback_submit": ("提交产品反馈", "Submit product feedback", "Submit product feedback with existing user confirmation requirements."),
86
- "user:file_get_upload_info": ("获取文件上传信息", "Read file upload information", "Read the information required for a file upload."),
87
- "user:file_upload_local": ("上传本地文件", "Upload local file", "Upload a local file to Qingflow."),
88
- "user:get_login_link": ("生成免登录链接", "Generate login link", "Generate a short lived login link for a specified Qingflow page."),
89
- "user:navigation_create": ("创建导航", "Create navigation", "Create navigation configuration."),
90
- "user:navigation_delete": ("删除导航", "Delete navigation", "Delete navigation configuration."),
91
- "user:navigation_get_detail": ("读取导航详情", "Read navigation details", "Read navigation details."),
92
- "user:navigation_get_status": ("读取导航状态", "Read navigation status", "Read navigation status."),
93
- "user:navigation_list_draft_all": ("读取全部导航草稿", "Read all navigation drafts", "Read all navigation drafts."),
94
- "user:navigation_list_draft_page": ("分页读取导航草稿", "Read navigation draft page", "Read a page of navigation drafts."),
95
- "user:navigation_list_published": ("读取已发布导航", "Read published navigation", "Read published navigation."),
96
- "user:navigation_publish": ("发布导航", "Publish navigation", "Publish navigation configuration."),
97
- "user:navigation_reorder": ("调整导航排序", "Reorder navigation", "Change navigation ordering."),
98
- "user:navigation_set_visible": ("调整导航可见性", "Set navigation visibility", "Change navigation visibility."),
99
- "user:navigation_update": ("更新导航", "Update navigation", "Update navigation configuration."),
100
- "user:package_create": ("创建应用包", "Create application package", "Create an application package."),
101
- "user:package_delete": ("删除应用包", "Delete application package", "Delete an application package; deleted_all_data may also delete business data and associated application configuration."),
102
- "user:package_get": ("读取应用包详情", "Read application package", "Read application package details."),
103
- "user:package_get_base": ("读取应用包基础信息", "Read application package base information", "Read application package base information."),
104
- "user:package_list": ("列出应用包", "List application packages", "List application packages."),
105
- "user:package_update": ("更新应用包", "Update application package", "Update application package configuration."),
106
- "user:portal_create": ("创建门户", "Create portal", "Create a portal."),
107
- "user:portal_delete": ("删除门户", "Delete portal", "Delete a portal."),
108
- "user:portal_get": ("读取门户详情", "Read portal details", "Read portal details."),
109
- "user:portal_get_base_info": ("读取门户基础信息", "Read portal base information", "Read portal base information."),
110
- "user:portal_list": ("列出门户", "List portals", "List portals."),
111
- "user:portal_publish": ("发布门户", "Publish portal", "Publish a portal."),
112
- "user:portal_update": ("更新门户内容", "Update portal content", "Update portal content configuration."),
113
- "user:portal_update_base_info": ("更新门户基础信息", "Update portal base information", "Update portal base information."),
114
- "user:qingbi_report_delete": ("删除轻析报表", "Delete Qingbi report", "Delete a Qingbi report."),
115
- "user:qingbi_report_get_base": ("读取轻析报表基础信息", "Read Qingbi report base information", "Read Qingbi report base information."),
116
- "user:qingbi_report_get_config": ("读取轻析报表配置", "Read Qingbi report configuration", "Read Qingbi report configuration."),
117
- "user:qingbi_report_get_data": ("读取轻析报表数据", "Read Qingbi report data", "Read Qingbi report data."),
118
- "user:qingbi_report_list": ("列出轻析报表", "List Qingbi reports", "List Qingbi reports."),
119
- "user:qingbi_report_list_field_options": ("读取报表字段配置项", "Read report field options", "Read available configuration options for Qingbi report fields."),
120
- "user:qingbi_report_list_fields": ("读取报表字段", "Read report fields", "Read Qingbi report fields."),
121
- "user:qingbi_report_reorder": ("调整轻析报表排序", "Reorder Qingbi reports", "Change Qingbi report ordering."),
122
- "user:record_access": ("解析记录访问入口", "Resolve record access", "Resolve application and view data access entrypoints with existing permission scopes."),
123
- "user:record_analyze": ("分析记录数据", "Analyze records", "Analyze records in a specified application or view."),
124
- "user:record_browse_schema_get": ("读取记录浏览结构", "Read record browsing schema", "Read the field contract for browsing records by view."),
125
- "user:record_code_block_run": ("执行记录代码块", "Run record code block", "Execute a code block related to record data."),
126
- "user:record_code_block_schema_get": ("读取记录代码块结构", "Read record code block schema", "Read the input and output contract for a record code block."),
127
- "user:record_delete": ("删除记录", "Delete record", "Delete records through the existing record API."),
128
- "user:record_department_candidates": ("读取字段可选部门", "Read field department candidates", "Read department candidates for record fields."),
129
- "user:record_export_direct": ("直接导出记录", "Export records directly", "Export record data directly."),
130
- "user:record_export_get": ("获取记录导出结果", "Read record export result", "Read a record export result."),
131
- "user:record_export_start": ("启动记录导出", "Start record export", "Start a record export task."),
132
- "user:record_export_status_get": ("读取记录导出状态", "Read record export status", "Read the status of a record export task."),
133
- "user:record_get": ("读取单条记录", "Read record", "Read a single record."),
134
- "user:record_import_repair_local": ("修复本地导入文件", "Repair local import file", "Repair a local record import file."),
135
- "user:record_import_schema_get": ("读取记录导入结构", "Read record import schema", "Read the field contract for importing records."),
136
- "user:record_import_start": ("启动记录导入", "Start record import", "Start a record import task."),
137
- "user:record_import_status_get": ("读取记录导入状态", "Read record import status", "Read the status of a record import task."),
138
- "user:record_import_template_get": ("获取记录导入模板", "Read record import template", "Read a record import template."),
139
- "user:record_import_verify": ("校验记录导入结果", "Verify record import", "Verify record import results."),
140
- "user:record_insert": ("新增记录", "Insert record", "Insert records through the existing record API."),
141
- "user:record_insert_schema_get": ("读取记录新增结构", "Read record insertion schema", "Read the field contract for inserting records."),
142
- "user:record_list": ("按视图列出记录", "List records by view", "Read records by view."),
143
- "user:record_logs_get": ("读取记录操作日志", "Read record operation logs", "Read record operation logs."),
144
- "user:record_member_candidates": ("读取字段可选成员", "Read field member candidates", "Read member candidates for record fields."),
145
- "user:record_schema_get": ("读取申请表单结构", "Read applicant form schema", "Read the field contract for the applicant form."),
146
- "user:record_update": ("更新记录", "Update record", "Update records through the existing record API."),
147
- "user:record_update_schema_get": ("读取记录更新结构", "Read record update schema", "Read the field contract for updating records."),
148
- "user:role_create": ("创建工作区角色", "Create workspace role", "Create a workspace role."),
149
- "user:role_delete": ("删除工作区角色", "Delete workspace role", "Delete a workspace role."),
150
- "user:role_search": ("搜索工作区角色", "Search workspace roles", "Search workspace roles."),
151
- "user:role_update": ("更新工作区角色", "Update workspace role", "Update a workspace role."),
152
- "user:solution_build_all": ("搭建完整方案", "Build complete solution", "Plan, apply, or repair a complete solution; may create application packages, roles, applications, fields, workflows, views, charts, portals, navigation, and initial business data."),
153
- "user:solution_build_analytics_portal": ("搭建图表与门户", "Build charts and portals", "Plan, apply, or repair charts and portals; may enable the corresponding workspace plugins."),
154
- "user:solution_build_app": ("搭建应用", "Build application", "Plan, apply, or repair an application; may create application packages, roles, fields, and initial business data."),
155
- "user:solution_build_app_flow": ("搭建应用与流程", "Build application and workflow", "Plan, apply, or repair applications and workflows; may create application packages, roles, fields, and initial business data."),
156
- "user:solution_build_app_from_requirements": ("按需求搭建应用", "Build application from requirements", "Build an application from requirements; may create application packages, roles, fields, and initial business data."),
157
- "user:solution_build_flow": ("搭建流程", "Build workflow", "Plan, apply, or repair workflows; may create workspace roles referenced by the workflow."),
158
- "user:solution_build_navigation": ("搭建导航", "Build navigation", "Plan, apply, or repair navigation; may enable the corresponding workspace plugins."),
159
- "user:solution_build_status": ("读取方案搭建状态", "Read solution build status", "Read the progress and results of a solution build task."),
160
- "user:solution_build_views": ("搭建视图", "Build views", "Plan, apply, or repair view configuration in a solution."),
161
- "user:solution_design_session": ("管理本地方案设计会话", "Manage local solution design session", "Create, read, or update a local solution design session."),
162
- "user:solution_schema_example": ("读取方案结构与示例", "Read solution schema and examples", "Read solution declaration schemas and examples."),
163
- "user:task_action_execute": ("执行待办动作", "Execute task action", "Execute a task action with existing approval permissions and confirmation requirements."),
164
- "user:task_associated_report_detail_get": ("读取待办关联报表", "Read task associated report", "Read details of a report associated with a task."),
165
- "user:task_get": ("读取待办详情", "Read task details", "Read task details."),
166
- "user:task_list": ("列出待办", "List tasks", "List tasks."),
167
- "user:task_workbench": ("使用交互式待办工作台", "Use interactive task workbench", "Open the interactive task workbench to read tasks and execute their existing approval actions."),
168
- "user:task_workflow_log_get": ("读取待办流程日志", "Read task workflow logs", "Read workflow logs for a task."),
169
- "user:view_board_get_lane_base_info": ("读取看板泳道信息", "Read board lane information", "Read lane information for a board view."),
170
- "user:view_get": ("读取视图业务信息", "Read view business information", "Read an accessible view's business information and export capabilities."),
171
- "user:view_get_base_info": ("读取视图基础信息", "Read view base information", "Read view base information."),
172
- "user:view_get_config": ("读取视图配置", "Read view configuration", "Read view configuration."),
173
- "user:view_get_future_nodes": ("读取视图后续流程节点", "Read future view workflow nodes", "Read future workflow nodes for records in a view."),
174
- "user:view_get_workflow_status": ("读取视图记录流程状态", "Read view record workflow status", "Read workflow status for records in a view."),
175
- "user:view_list": ("列出视图", "List views", "List views."),
176
- "user:view_list_associations": ("读取视图关联资源", "Read view associations", "Read resources associated with a view."),
177
- "user:view_list_flat": ("读取扁平视图列表", "Read flat view list", "Read a flat list of views."),
178
- "user:view_list_questions": ("读取视图字段", "Read view fields", "Read view fields."),
179
- "user:workflow_get_future_nodes": ("读取记录后续流程节点", "Read future record workflow nodes", "Read future workflow nodes for a record."),
180
- "user:workflow_get_future_nodes_app": ("读取应用后续流程节点", "Read future application workflow nodes", "Read future nodes in an application's workflow."),
181
- "user:workspace_get": ("读取工作区信息", "Read workspace information", "Read workspace information."),
182
- "user:workspace_list": ("列出工作区", "List workspaces", "List accessible workspaces."),
183
- "user:workspace_select": ("切换工作区", "Select workspace", "Switch the current workspace context."),
184
- "user:workspace_set_plugin_status": ("启停工作区插件", "Enable or disable workspace plugins", "Enable or disable workspace business plugins; this is a controlled business write operation."),
185
- }
@@ -1,197 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import json
4
- import os
5
- from dataclasses import dataclass
6
- from typing import Any, Literal, Mapping, Sequence
7
- from urllib.parse import parse_qs
8
-
9
- from mcp.server.fastmcp import FastMCP
10
- from mcp.server.fastmcp.exceptions import ToolError
11
-
12
- from .cloud_context import current_http_tool_policy, current_tool_policy_header
13
- from .tool_catalog import TOOL_ID_PATTERN, require_registered_tool_id, tool_is_exempt
14
-
15
-
16
- TOOL_POLICY_ENV = "QINGFLOW_TOOL_POLICY"
17
- TOOL_POLICY_HEADER = "X-Qingflow-Tool-Policy"
18
- TOOL_POLICY_INVALID = "TOOL_POLICY_INVALID"
19
- TOOL_POLICY_DENIED = "TOOL_POLICY_DENIED"
20
-
21
-
22
- @dataclass(frozen=True, slots=True)
23
- class ToolPolicySnapshot:
24
- mode: Literal["unrestricted", "restricted", "invalid"]
25
- allowed_tools: tuple[str, ...] = ()
26
- error: str | None = None
27
-
28
- def violation_for(self, stable_id: str) -> "ToolPolicyViolation | None":
29
- # 基础恢复能力在非法策略下也必须可用。
30
- if tool_is_exempt(stable_id):
31
- return None
32
- if self.mode == "unrestricted":
33
- return None
34
- if self.mode == "invalid":
35
- return ToolPolicyViolation(TOOL_POLICY_INVALID, stable_id, self.error or "工具策略无效")
36
- if stable_id in self.allowed_tools:
37
- return None
38
- return ToolPolicyViolation(TOOL_POLICY_DENIED, stable_id, "当前策略未允许该工具")
39
-
40
-
41
- class ToolPolicyViolation(Exception):
42
- def __init__(self, code: str, tool_id_value: str, message: str) -> None:
43
- super().__init__(message)
44
- self.code = code
45
- self.tool_id = tool_id_value
46
- self.message = message
47
-
48
- def payload(self, *, camel_case: bool = False) -> dict[str, Any]:
49
- if camel_case:
50
- return {
51
- "status": "failed",
52
- "errorCode": self.code,
53
- "message": self.message,
54
- "toolId": self.tool_id,
55
- }
56
- return {
57
- "status": "failed",
58
- "error_code": self.code,
59
- "message": self.message,
60
- "toolId": self.tool_id,
61
- }
62
-
63
-
64
- def parse_tool_policy(value: str | Mapping[str, Any] | None) -> ToolPolicySnapshot:
65
- if value is None:
66
- return ToolPolicySnapshot("unrestricted")
67
- payload: Any = value
68
- if isinstance(value, str):
69
- if value == "":
70
- return ToolPolicySnapshot("unrestricted")
71
- try:
72
- payload = json.loads(value)
73
- except json.JSONDecodeError:
74
- return ToolPolicySnapshot("invalid", error="工具策略不是合法 JSON")
75
- if not isinstance(payload, Mapping):
76
- return ToolPolicySnapshot("invalid", error="工具策略必须是对象")
77
- if set(payload) != {"version", "allowed_tools"}:
78
- return ToolPolicySnapshot("invalid", error="工具策略字段必须为 version 和 allowed_tools")
79
- if type(payload.get("version")) is not int or payload.get("version") != 1: # noqa: E721
80
- return ToolPolicySnapshot("invalid", error="工具策略 version 必须为 1")
81
- allowed = payload.get("allowed_tools")
82
- if not isinstance(allowed, list):
83
- return ToolPolicySnapshot("invalid", error="allowed_tools 必须是数组")
84
- normalized: set[str] = set()
85
- for stable_id in allowed:
86
- if not isinstance(stable_id, str) or TOOL_ID_PATTERN.fullmatch(stable_id) is None:
87
- return ToolPolicySnapshot("invalid", error="allowed_tools 包含非法工具 ID")
88
- normalized.add(stable_id)
89
- return ToolPolicySnapshot("restricted", tuple(sorted(normalized)))
90
-
91
-
92
- def parse_http_tool_policy(header: str | None, query_string: bytes) -> ToolPolicySnapshot:
93
- header_policy = parse_tool_policy(header)
94
- # 保留空值并在 URL 解码后检查重复,tools= 与缺省不能合并为同一种状态。
95
- values = parse_qs(query_string.decode("latin1"), keep_blank_values=True).get("tools", [])
96
- if len(values) > 1:
97
- return ToolPolicySnapshot("invalid", error="tools 查询参数不能重复")
98
- url_policy = parse_tool_policy(
99
- {"version": 1, "allowed_tools": values[0].split(",") if values[0] else []}
100
- if values else None
101
- )
102
- if header_policy.mode == "invalid":
103
- return header_policy
104
- if url_policy.mode == "invalid":
105
- return ToolPolicySnapshot("invalid", error=f"tools 查询参数无效: {url_policy.error}")
106
- if header_policy.mode == "unrestricted":
107
- return url_policy
108
- if url_policy.mode == "unrestricted":
109
- return header_policy
110
- return ToolPolicySnapshot(
111
- "restricted", tuple(sorted(set(header_policy.allowed_tools).intersection(url_policy.allowed_tools)))
112
- )
113
-
114
-
115
- class PolicyAwareFastMCP(FastMCP):
116
- """让 MCP 列表与调用在 FastMCP handler 边界共用策略快照。"""
117
-
118
- def __init__(self, *args: Any, **kwargs: Any) -> None:
119
- self._tool_policy_bindings: dict[str, str] | None = None
120
- self._tool_policy_source: Literal["environment", "request"] = "environment"
121
- self._tool_policy_environment_snapshot = ToolPolicySnapshot("unrestricted")
122
- super().__init__(*args, **kwargs)
123
-
124
- def configure_tool_policy(
125
- self,
126
- bindings: Mapping[str, str],
127
- *,
128
- source: Literal["environment", "request"],
129
- ) -> None:
130
- registered = set(self._tool_manager._tools)
131
- bound = set(bindings)
132
- if registered != bound:
133
- missing = sorted(registered - bound)
134
- extra = sorted(bound - registered)
135
- raise ValueError(f"工具策略绑定不完整: missing={missing}, extra={extra}")
136
- for stable_id in bindings.values():
137
- # 登记校验只依赖提供方稳定 ID,不依赖 Wingent-X 的产品分类。
138
- require_registered_tool_id(stable_id)
139
- self._tool_policy_bindings = dict(bindings)
140
- self._tool_policy_source = source
141
- if source == "environment":
142
- self._tool_policy_environment_snapshot = parse_tool_policy(os.getenv(TOOL_POLICY_ENV))
143
-
144
- @property
145
- def tool_policy_bindings(self) -> dict[str, str]:
146
- return dict(self._tool_policy_bindings or {})
147
-
148
- async def list_tools(self): # type: ignore[no-untyped-def]
149
- tools = await super().list_tools()
150
- bindings = self._require_bindings()
151
- snapshot = self._current_snapshot()
152
- return [
153
- tool
154
- for tool in tools
155
- if snapshot.violation_for(bindings[tool.name]) is None
156
- ]
157
-
158
- async def call_tool(self, name: str, arguments: dict[str, Any]) -> Sequence[Any] | dict[str, Any]:
159
- bindings = self._require_bindings()
160
- stable_id = bindings.get(name)
161
- if stable_id is None:
162
- raise ToolError(json.dumps(
163
- {
164
- "status": "failed",
165
- "errorCode": TOOL_POLICY_INVALID,
166
- "message": "工具未登记稳定 ID",
167
- },
168
- ensure_ascii=False,
169
- ))
170
- violation = self._current_snapshot().violation_for(stable_id)
171
- if violation is not None:
172
- raise ToolError(json.dumps(violation.payload(camel_case=True), ensure_ascii=False))
173
- return await super().call_tool(name, arguments)
174
-
175
- def _require_bindings(self) -> dict[str, str]:
176
- if self._tool_policy_bindings is None:
177
- raise RuntimeError("MCP 工具策略绑定尚未配置")
178
- return self._tool_policy_bindings
179
-
180
- def _current_snapshot(self) -> ToolPolicySnapshot:
181
- if self._tool_policy_source == "request":
182
- snapshot = current_http_tool_policy.get()
183
- if snapshot is not None:
184
- return snapshot
185
- # 保留未经过 HTTP 入口的请求头上下文用法,绝不回退共享 env。
186
- return parse_tool_policy(current_tool_policy_header.get())
187
- return self._tool_policy_environment_snapshot
188
-
189
-
190
- def configure_tool_policy(
191
- server: PolicyAwareFastMCP,
192
- bindings: Mapping[str, str],
193
- *,
194
- source: Literal["environment", "request"],
195
- ) -> PolicyAwareFastMCP:
196
- server.configure_tool_policy(bindings, source=source)
197
- return server