@qingflow-tech/qingflow-cli 1.1.61-beta.9 → 1.1.62-beta.1
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.
- package/README.md +3 -3
- package/package.json +2 -1
- package/pyproject.toml +2 -1
- package/skills/qingflow-cli/reference/builder/70-portal.md +46 -6
- package/skills/qingflow-cli/reference/examples/portal/portal_sections_all_types.example.json +22 -5
- package/src/qingflow_mcp/builder_facade/models.py +16 -0
- package/src/qingflow_mcp/builder_facade/schemas/portals/v1alpha1/complete.json +2 -2
- package/src/qingflow_mcp/builder_facade/schemas/portals/v1alpha1/components/filter.json +111 -29
- package/src/qingflow_mcp/cli/main.py +18 -10
- package/src/qingflow_mcp/cli/permission_gate.py +59 -0
- package/src/qingflow_mcp/entity_permissions.py +10 -0
- package/src/qingflow_mcp/permission_catalog.json +1210 -0
- package/src/qingflow_mcp/tool_catalog.py +9 -10
- package/src/qingflow_mcp/tool_catalog_i18n.py +0 -3
- package/src/qingflow_mcp/tool_policy.py +24 -30
|
@@ -4,6 +4,7 @@ import re
|
|
|
4
4
|
from typing import Iterable, Mapping
|
|
5
5
|
|
|
6
6
|
from . import __version__
|
|
7
|
+
from .entity_permissions import permission_catalog
|
|
7
8
|
from .public_surface import PUBLIC_TOOL_BY_KEY
|
|
8
9
|
from .tool_catalog_i18n import DEFAULT_LOCALE, SUPPORTED_LOCALES, TOOL_DISPLAY_TEXT
|
|
9
10
|
|
|
@@ -21,15 +22,11 @@ EXEMPT_TOOL_IDS = frozenset(
|
|
|
21
22
|
"user:auth_whoami",
|
|
22
23
|
"user:auth_logout",
|
|
23
24
|
"user:get_login_link",
|
|
24
|
-
"user:workspace_list",
|
|
25
|
-
"user:workspace_get",
|
|
26
25
|
"user:workspace_select",
|
|
27
26
|
"builder:auth_use_credential",
|
|
28
27
|
"builder:auth_whoami",
|
|
29
28
|
"builder:auth_logout",
|
|
30
29
|
"builder:get_login_link",
|
|
31
|
-
"builder:workspace_list",
|
|
32
|
-
"builder:workspace_get",
|
|
33
30
|
}
|
|
34
31
|
)
|
|
35
32
|
|
|
@@ -55,12 +52,9 @@ LEGACY_STDIO_TOOL_IDS = frozenset(
|
|
|
55
52
|
"user:package_get_base",
|
|
56
53
|
"user:package_list",
|
|
57
54
|
"user:package_update",
|
|
58
|
-
"user:portal_create",
|
|
59
55
|
"user:portal_delete",
|
|
60
56
|
"user:portal_get_base_info",
|
|
61
57
|
"user:portal_publish",
|
|
62
|
-
"user:portal_update",
|
|
63
|
-
"user:portal_update_base_info",
|
|
64
58
|
"user:qingbi_report_delete",
|
|
65
59
|
"user:qingbi_report_get_base",
|
|
66
60
|
"user:qingbi_report_get_config",
|
|
@@ -201,14 +195,11 @@ TOOL_DESCRIPTIONS: dict[str, str] = {
|
|
|
201
195
|
"user:package_get_base": "读取应用包基础信息。",
|
|
202
196
|
"user:package_list": "列出应用包。",
|
|
203
197
|
"user:package_update": "更新应用包配置。",
|
|
204
|
-
"user:portal_create": "创建门户。",
|
|
205
198
|
"user:portal_delete": "删除门户。",
|
|
206
199
|
"user:portal_get": "读取门户详情。",
|
|
207
200
|
"user:portal_get_base_info": "读取门户基础信息。",
|
|
208
201
|
"user:portal_list": "列出门户。",
|
|
209
202
|
"user:portal_publish": "发布门户。",
|
|
210
|
-
"user:portal_update": "更新门户内容配置。",
|
|
211
|
-
"user:portal_update_base_info": "更新门户基础信息。",
|
|
212
203
|
"user:qingbi_report_delete": "删除轻析报表。",
|
|
213
204
|
"user:qingbi_report_get_base": "读取轻析报表基础信息。",
|
|
214
205
|
"user:qingbi_report_get_config": "读取轻析报表配置。",
|
|
@@ -323,6 +314,13 @@ def build_tool_catalog(
|
|
|
323
314
|
if set(TOOL_DISPLAY_TEXT) != REGISTERED_TOOL_IDS:
|
|
324
315
|
raise ValueError("工具多语言文案与完整登记表不一致")
|
|
325
316
|
|
|
317
|
+
display = permission_catalog()
|
|
318
|
+
classified = [tool for entity in display["entities"] for tool in entity["tools"]]
|
|
319
|
+
classified_ids = [tool["id"] for tool in classified]
|
|
320
|
+
if len(set(classified_ids)) != len(classified_ids) or set(classified_ids) != REGISTERED_TOOL_IDS - EXEMPT_TOOL_IDS:
|
|
321
|
+
raise ValueError("业务工具展示分类与真实登记表不一致")
|
|
322
|
+
if any(tool["level"] not in {"read", "manage", "special"} for tool in classified):
|
|
323
|
+
raise ValueError("工具权限档位未分类")
|
|
326
324
|
tools: list[dict[str, object]] = []
|
|
327
325
|
for stable_id in sorted(entrypoints):
|
|
328
326
|
description = TOOL_DESCRIPTIONS[stable_id]
|
|
@@ -346,6 +344,7 @@ def build_tool_catalog(
|
|
|
346
344
|
return {
|
|
347
345
|
"catalogVersion": CATALOG_VERSION,
|
|
348
346
|
"policyVersion": POLICY_VERSION,
|
|
347
|
+
"permissionCatalog": display,
|
|
349
348
|
"provider": {"name": "qingflow-mcp", "version": __version__},
|
|
350
349
|
"defaultLocale": DEFAULT_LOCALE,
|
|
351
350
|
"locales": list(SUPPORTED_LOCALES),
|
|
@@ -105,14 +105,11 @@ TOOL_DISPLAY_TEXT: dict[str, tuple[str, str, str]] = {
|
|
|
105
105
|
"user:package_get_base": ("读取应用包基础信息", "Read application package base information", "Read application package base information."),
|
|
106
106
|
"user:package_list": ("列出应用包", "List application packages", "List application packages."),
|
|
107
107
|
"user:package_update": ("更新应用包", "Update application package", "Update application package configuration."),
|
|
108
|
-
"user:portal_create": ("创建门户", "Create portal", "Create a portal."),
|
|
109
108
|
"user:portal_delete": ("删除门户", "Delete portal", "Delete a portal."),
|
|
110
109
|
"user:portal_get": ("读取门户详情", "Read portal details", "Read portal details."),
|
|
111
110
|
"user:portal_get_base_info": ("读取门户基础信息", "Read portal base information", "Read portal base information."),
|
|
112
111
|
"user:portal_list": ("列出门户", "List portals", "List portals."),
|
|
113
112
|
"user:portal_publish": ("发布门户", "Publish portal", "Publish a portal."),
|
|
114
|
-
"user:portal_update": ("更新门户内容", "Update portal content", "Update portal content configuration."),
|
|
115
|
-
"user:portal_update_base_info": ("更新门户基础信息", "Update portal base information", "Update portal base information."),
|
|
116
113
|
"user:qingbi_report_delete": ("删除轻析报表", "Delete Qingbi report", "Delete a Qingbi report."),
|
|
117
114
|
"user:qingbi_report_get_base": ("读取轻析报表基础信息", "Read Qingbi report base information", "Read Qingbi report base information."),
|
|
118
115
|
"user:qingbi_report_get_config": ("读取轻析报表配置", "Read Qingbi report configuration", "Read Qingbi report configuration."),
|
|
@@ -21,18 +21,15 @@ TOOL_POLICY_DENIED = "TOOL_POLICY_DENIED"
|
|
|
21
21
|
|
|
22
22
|
@dataclass(frozen=True, slots=True)
|
|
23
23
|
class ToolPolicySnapshot:
|
|
24
|
-
mode: Literal["unrestricted", "restricted"
|
|
24
|
+
mode: Literal["unrestricted", "restricted"]
|
|
25
25
|
allowed_tools: tuple[str, ...] = ()
|
|
26
|
-
error: str | None = None
|
|
27
26
|
|
|
28
27
|
def violation_for(self, stable_id: str) -> "ToolPolicyViolation | None":
|
|
29
|
-
#
|
|
28
|
+
# 基础恢复能力不受业务工具开关限制。
|
|
30
29
|
if tool_is_exempt(stable_id):
|
|
31
30
|
return None
|
|
32
31
|
if self.mode == "unrestricted":
|
|
33
32
|
return None
|
|
34
|
-
if self.mode == "invalid":
|
|
35
|
-
return ToolPolicyViolation(TOOL_POLICY_INVALID, stable_id, self.error or "工具策略无效")
|
|
36
33
|
if stable_id in self.allowed_tools:
|
|
37
34
|
return None
|
|
38
35
|
return ToolPolicyViolation(TOOL_POLICY_DENIED, stable_id, "当前策略未允许该工具")
|
|
@@ -62,6 +59,7 @@ class ToolPolicyViolation(Exception):
|
|
|
62
59
|
|
|
63
60
|
|
|
64
61
|
def parse_tool_policy(value: str | Mapping[str, Any] | None) -> ToolPolicySnapshot:
|
|
62
|
+
"""只解析工具开关;非法输入等同未配置,合法空数组仍为受限空清单。"""
|
|
65
63
|
if value is None:
|
|
66
64
|
return ToolPolicySnapshot("unrestricted")
|
|
67
65
|
payload: Any = value
|
|
@@ -71,54 +69,49 @@ def parse_tool_policy(value: str | Mapping[str, Any] | None) -> ToolPolicySnapsh
|
|
|
71
69
|
try:
|
|
72
70
|
payload = json.loads(value)
|
|
73
71
|
except json.JSONDecodeError:
|
|
74
|
-
return ToolPolicySnapshot("
|
|
72
|
+
return ToolPolicySnapshot("unrestricted")
|
|
75
73
|
if not isinstance(payload, Mapping):
|
|
76
|
-
return ToolPolicySnapshot("
|
|
74
|
+
return ToolPolicySnapshot("unrestricted")
|
|
77
75
|
if set(payload) != {"version", "allowed_tools"}:
|
|
78
|
-
return ToolPolicySnapshot("
|
|
76
|
+
return ToolPolicySnapshot("unrestricted")
|
|
79
77
|
if type(payload.get("version")) is not int or payload.get("version") != 1: # noqa: E721
|
|
80
|
-
return ToolPolicySnapshot("
|
|
78
|
+
return ToolPolicySnapshot("unrestricted")
|
|
81
79
|
allowed = payload.get("allowed_tools")
|
|
82
80
|
if not isinstance(allowed, list):
|
|
83
|
-
return ToolPolicySnapshot("
|
|
81
|
+
return ToolPolicySnapshot("unrestricted")
|
|
84
82
|
normalized: set[str] = set()
|
|
85
83
|
for stable_id in allowed:
|
|
86
84
|
if not isinstance(stable_id, str) or TOOL_ID_PATTERN.fullmatch(stable_id) is None:
|
|
87
|
-
return ToolPolicySnapshot("
|
|
85
|
+
return ToolPolicySnapshot("unrestricted")
|
|
88
86
|
normalized.add(stable_id)
|
|
89
87
|
return ToolPolicySnapshot("restricted", tuple(sorted(normalized)))
|
|
90
88
|
|
|
91
89
|
|
|
92
90
|
def parse_http_tool_policy(header: str | None, query_string: bytes) -> ToolPolicySnapshot:
|
|
93
|
-
|
|
91
|
+
# 请求头是显式配置,覆盖 URL 默认配置;非法显式配置也按未配置处理,不回落旧限制。
|
|
92
|
+
if header is not None:
|
|
93
|
+
return parse_tool_policy(header)
|
|
94
94
|
# 保留空值并在 URL 解码后检查重复,tools= 与缺省不能合并为同一种状态。
|
|
95
95
|
values = parse_qs(query_string.decode("latin1"), keep_blank_values=True).get("tools", [])
|
|
96
96
|
if len(values) > 1:
|
|
97
|
-
return ToolPolicySnapshot("
|
|
98
|
-
|
|
97
|
+
return ToolPolicySnapshot("unrestricted")
|
|
98
|
+
return parse_tool_policy(
|
|
99
99
|
{"version": 1, "allowed_tools": values[0].split(",") if values[0] else []}
|
|
100
100
|
if values else None
|
|
101
101
|
)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def read_current_tool_policy() -> ToolPolicySnapshot:
|
|
105
|
+
"""只读取调用方传入的环境策略,不查询外部服务。"""
|
|
106
|
+
return parse_tool_policy(os.getenv(TOOL_POLICY_ENV))
|
|
113
107
|
|
|
114
108
|
|
|
115
109
|
class PolicyAwareFastMCP(FastMCP):
|
|
116
|
-
"""
|
|
110
|
+
"""MCP 列表与调用在 handler 边界分别读取当前工具开关。"""
|
|
117
111
|
|
|
118
112
|
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
119
113
|
self._tool_policy_bindings: dict[str, str] | None = None
|
|
120
114
|
self._tool_policy_source: Literal["environment", "request"] = "environment"
|
|
121
|
-
self._tool_policy_environment_snapshot = ToolPolicySnapshot("unrestricted")
|
|
122
115
|
super().__init__(*args, **kwargs)
|
|
123
116
|
|
|
124
117
|
def configure_tool_policy(
|
|
@@ -138,8 +131,6 @@ class PolicyAwareFastMCP(FastMCP):
|
|
|
138
131
|
require_registered_tool_id(stable_id)
|
|
139
132
|
self._tool_policy_bindings = dict(bindings)
|
|
140
133
|
self._tool_policy_source = source
|
|
141
|
-
if source == "environment":
|
|
142
|
-
self._tool_policy_environment_snapshot = parse_tool_policy(os.getenv(TOOL_POLICY_ENV))
|
|
143
134
|
|
|
144
135
|
@property
|
|
145
136
|
def tool_policy_bindings(self) -> dict[str, str]:
|
|
@@ -167,6 +158,8 @@ class PolicyAwareFastMCP(FastMCP):
|
|
|
167
158
|
},
|
|
168
159
|
ensure_ascii=False,
|
|
169
160
|
))
|
|
161
|
+
if tool_is_exempt(stable_id):
|
|
162
|
+
return await super().call_tool(name, arguments)
|
|
170
163
|
violation = self._current_snapshot().violation_for(stable_id)
|
|
171
164
|
if violation is not None:
|
|
172
165
|
raise ToolError(json.dumps(violation.payload(camel_case=True), ensure_ascii=False))
|
|
@@ -184,7 +177,8 @@ class PolicyAwareFastMCP(FastMCP):
|
|
|
184
177
|
return snapshot
|
|
185
178
|
# 保留未经过 HTTP 入口的请求头上下文用法,绝不回退共享 env。
|
|
186
179
|
return parse_tool_policy(current_tool_policy_header.get())
|
|
187
|
-
|
|
180
|
+
# 长连接不冻结启动时的工具开关,每次列表或调用都读取当前配置。
|
|
181
|
+
return read_current_tool_policy()
|
|
188
182
|
|
|
189
183
|
|
|
190
184
|
def configure_tool_policy(
|