braid-coding-agent 0.1.0__py3-none-any.whl
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.
- braid_coding_agent/__init__.py +13 -0
- braid_coding_agent/assembly.py +460 -0
- braid_coding_agent/cancellation.py +25 -0
- braid_coding_agent/checkpoint/__init__.py +106 -0
- braid_coding_agent/checkpoint/git.py +305 -0
- braid_coding_agent/checkpoint/settings.py +26 -0
- braid_coding_agent/checkpoint/store.py +1261 -0
- braid_coding_agent/checkpoint/workspace.py +220 -0
- braid_coding_agent/cli.py +2168 -0
- braid_coding_agent/commands/__init__.py +50 -0
- braid_coding_agent/commands/auth.py +161 -0
- braid_coding_agent/commands/config.py +180 -0
- braid_coding_agent/commands/doctor.py +511 -0
- braid_coding_agent/commands/mcp.py +928 -0
- braid_coding_agent/commands/models.py +95 -0
- braid_coding_agent/commands/setup.py +89 -0
- braid_coding_agent/commands/uninstall.py +277 -0
- braid_coding_agent/commands/upgrade.py +381 -0
- braid_coding_agent/compaction/__init__.py +174 -0
- braid_coding_agent/compaction/prepare.py +430 -0
- braid_coding_agent/compaction/summarize.py +542 -0
- braid_coding_agent/compaction/tokens.py +204 -0
- braid_coding_agent/compaction/tool_results.py +196 -0
- braid_coding_agent/compaction/utils.py +181 -0
- braid_coding_agent/config.py +2776 -0
- braid_coding_agent/config_files.py +191 -0
- braid_coding_agent/credentials.py +252 -0
- braid_coding_agent/discovery.py +415 -0
- braid_coding_agent/extensions/__init__.py +77 -0
- braid_coding_agent/extensions/api.py +480 -0
- braid_coding_agent/extensions/runner.py +553 -0
- braid_coding_agent/formatting/__init__.py +62 -0
- braid_coding_agent/formatting/settings.py +87 -0
- braid_coding_agent/formatting/tool.py +179 -0
- braid_coding_agent/lsp/__init__.py +105 -0
- braid_coding_agent/lsp/client.py +546 -0
- braid_coding_agent/lsp/manager.py +187 -0
- braid_coding_agent/lsp/model.py +316 -0
- braid_coding_agent/lsp/protocol.py +105 -0
- braid_coding_agent/lsp/settings.py +120 -0
- braid_coding_agent/lsp/tool.py +429 -0
- braid_coding_agent/mcp/__init__.py +101 -0
- braid_coding_agent/mcp/cache.py +230 -0
- braid_coding_agent/mcp/catalog.py +108 -0
- braid_coding_agent/mcp/config.py +664 -0
- braid_coding_agent/mcp/config_store.py +142 -0
- braid_coding_agent/mcp/inspector.py +85 -0
- braid_coding_agent/mcp/panel.py +254 -0
- braid_coding_agent/mcp/runtime.py +1060 -0
- braid_coding_agent/mcp/tools.py +579 -0
- braid_coding_agent/mcp/trust.py +150 -0
- braid_coding_agent/mcp/tui_panel.py +444 -0
- braid_coding_agent/messages.py +152 -0
- braid_coding_agent/models_view.py +105 -0
- braid_coding_agent/modes/__init__.py +64 -0
- braid_coding_agent/modes/json_mode.py +480 -0
- braid_coding_agent/modes/lifecycle.py +217 -0
- braid_coding_agent/modes/print_mode.py +257 -0
- braid_coding_agent/modes/repl.py +2687 -0
- braid_coding_agent/modes/repl_commands.py +263 -0
- braid_coding_agent/modes/rpc.py +953 -0
- braid_coding_agent/modes/skill_commands.py +88 -0
- braid_coding_agent/modes/tui.py +2226 -0
- braid_coding_agent/modes/tui_control.py +90 -0
- braid_coding_agent/modes/tui_model.py +1043 -0
- braid_coding_agent/modes/tui_render.py +327 -0
- braid_coding_agent/modes/tui_rich.py +751 -0
- braid_coding_agent/modes/tui_style.py +42 -0
- braid_coding_agent/modes/wire.py +81 -0
- braid_coding_agent/netsafe.py +82 -0
- braid_coding_agent/network/__init__.py +20 -0
- braid_coding_agent/network/cache.py +77 -0
- braid_coding_agent/network/fetch.py +311 -0
- braid_coding_agent/network/html_text.py +160 -0
- braid_coding_agent/network/search.py +347 -0
- braid_coding_agent/network/settings.py +103 -0
- braid_coding_agent/network/urls.py +89 -0
- braid_coding_agent/observability/__init__.py +101 -0
- braid_coding_agent/observability/audit.py +124 -0
- braid_coding_agent/observability/collector.py +314 -0
- braid_coding_agent/observability/exporter.py +74 -0
- braid_coding_agent/observability/logging_setup.py +149 -0
- braid_coding_agent/observability/redaction.py +96 -0
- braid_coding_agent/observability/settings.py +29 -0
- braid_coding_agent/observability/spans.py +239 -0
- braid_coding_agent/permissions/__init__.py +185 -0
- braid_coding_agent/permissions/command.py +586 -0
- braid_coding_agent/permissions/engine.py +522 -0
- braid_coding_agent/permissions/evaluate.py +309 -0
- braid_coding_agent/permissions/matching.py +233 -0
- braid_coding_agent/permissions/model.py +278 -0
- braid_coding_agent/permissions/policy.py +99 -0
- braid_coding_agent/permissions/readonly.py +236 -0
- braid_coding_agent/permissions/store.py +379 -0
- braid_coding_agent/project_init.py +313 -0
- braid_coding_agent/prompt/__init__.py +98 -0
- braid_coding_agent/prompt/context_files.py +253 -0
- braid_coding_agent/prompt/project_context.py +172 -0
- braid_coding_agent/prompt/system_prompt.py +378 -0
- braid_coding_agent/questions.py +71 -0
- braid_coding_agent/render/__init__.py +56 -0
- braid_coding_agent/render/batch.py +66 -0
- braid_coding_agent/render/history.py +143 -0
- braid_coding_agent/render/stream.py +823 -0
- braid_coding_agent/render/theme.py +243 -0
- braid_coding_agent/sandbox/__init__.py +89 -0
- braid_coding_agent/sandbox/backend.py +184 -0
- braid_coding_agent/sandbox/bubblewrap.py +96 -0
- braid_coding_agent/sandbox/operations.py +301 -0
- braid_coding_agent/sandbox/policy.py +221 -0
- braid_coding_agent/sandbox/proxy.py +320 -0
- braid_coding_agent/sandbox/seatbelt.py +222 -0
- braid_coding_agent/sdk/__init__.py +31 -0
- braid_coding_agent/sdk/async_client.py +366 -0
- braid_coding_agent/sdk/client.py +386 -0
- braid_coding_agent/sdk/errors.py +52 -0
- braid_coding_agent/sdk/events.py +162 -0
- braid_coding_agent/sdk/types.py +63 -0
- braid_coding_agent/sdk/wire.py +59 -0
- braid_coding_agent/server/__init__.py +54 -0
- braid_coding_agent/server/errors.py +52 -0
- braid_coding_agent/server/http_server.py +419 -0
- braid_coding_agent/server/hub.py +530 -0
- braid_coding_agent/server/openapi.py +157 -0
- braid_coding_agent/server/registry.py +354 -0
- braid_coding_agent/server/router.py +275 -0
- braid_coding_agent/server/run.py +148 -0
- braid_coding_agent/server/schema.py +194 -0
- braid_coding_agent/server/service.py +975 -0
- braid_coding_agent/session/__init__.py +293 -0
- braid_coding_agent/session/agent_session.py +2706 -0
- braid_coding_agent/session/context_breakdown.py +302 -0
- braid_coding_agent/session/discovery.py +212 -0
- braid_coding_agent/session/entries.py +809 -0
- braid_coding_agent/session/evidence.py +295 -0
- braid_coding_agent/session/lock.py +176 -0
- braid_coding_agent/session/manager.py +1185 -0
- braid_coding_agent/session/plan.py +243 -0
- braid_coding_agent/session/plan_mode.py +423 -0
- braid_coding_agent/session/projection.py +262 -0
- braid_coding_agent/session/rewind.py +257 -0
- braid_coding_agent/session/status.py +240 -0
- braid_coding_agent/settings.py +94 -0
- braid_coding_agent/skills/__init__.py +70 -0
- braid_coding_agent/skills/loader.py +681 -0
- braid_coding_agent/startup/__init__.py +76 -0
- braid_coding_agent/startup/cache.py +72 -0
- braid_coding_agent/startup/diagnostics.py +37 -0
- braid_coding_agent/startup/monitor.py +245 -0
- braid_coding_agent/startup/phases.py +79 -0
- braid_coding_agent/startup/project.py +165 -0
- braid_coding_agent/startup/report.py +560 -0
- braid_coding_agent/startup/scheduler.py +347 -0
- braid_coding_agent/statusline.py +163 -0
- braid_coding_agent/subagents/__init__.py +22 -0
- braid_coding_agent/subagents/contract.py +75 -0
- braid_coding_agent/subagents/definitions.py +583 -0
- braid_coding_agent/subagents/registry.py +277 -0
- braid_coding_agent/subagents/runtime.py +610 -0
- braid_coding_agent/subagents/settings.py +156 -0
- braid_coding_agent/subagents/worktree.py +63 -0
- braid_coding_agent/tools/__init__.py +327 -0
- braid_coding_agent/tools/args.py +87 -0
- braid_coding_agent/tools/bash.py +359 -0
- braid_coding_agent/tools/edit.py +298 -0
- braid_coding_agent/tools/edit_diff.py +344 -0
- braid_coding_agent/tools/find.py +158 -0
- braid_coding_agent/tools/grep.py +305 -0
- braid_coding_agent/tools/ignore.py +198 -0
- braid_coding_agent/tools/ls.py +127 -0
- braid_coding_agent/tools/mutation_queue.py +90 -0
- braid_coding_agent/tools/operations.py +274 -0
- braid_coding_agent/tools/output_accumulator.py +282 -0
- braid_coding_agent/tools/output_store.py +244 -0
- braid_coding_agent/tools/path_utils.py +91 -0
- braid_coding_agent/tools/plan.py +141 -0
- braid_coding_agent/tools/prompt_notes.py +52 -0
- braid_coding_agent/tools/question.py +180 -0
- braid_coding_agent/tools/read.py +223 -0
- braid_coding_agent/tools/submit_plan.py +102 -0
- braid_coding_agent/tools/truncate.py +423 -0
- braid_coding_agent/tools/write.py +100 -0
- braid_coding_agent/untrusted.py +50 -0
- braid_coding_agent/verify/__init__.py +78 -0
- braid_coding_agent/verify/runner.py +260 -0
- braid_coding_agent/verify/settings.py +64 -0
- braid_coding_agent/verify/tool.py +143 -0
- braid_coding_agent-0.1.0.dist-info/METADATA +19 -0
- braid_coding_agent-0.1.0.dist-info/RECORD +192 -0
- braid_coding_agent-0.1.0.dist-info/WHEEL +4 -0
- braid_coding_agent-0.1.0.dist-info/entry_points.txt +3 -0
- braid_coding_agent-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
"""MCP 服务器配置:读 ``mcp.json``,产出 stdio、http、sse 或 ws 的连接参数。
|
|
2
|
+
|
|
3
|
+
文件形状沿用其它 MCP 客户端的 ``mcpServers`` 对象,已经有配置的人可以直接复制过来:
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{
|
|
7
|
+
"mcpServers": {
|
|
8
|
+
"filesystem": {
|
|
9
|
+
"command": "npx",
|
|
10
|
+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
|
|
11
|
+
},
|
|
12
|
+
"local-db": {
|
|
13
|
+
"type": "stdio",
|
|
14
|
+
"command": "uvx",
|
|
15
|
+
"args": ["mcp-server-sqlite"],
|
|
16
|
+
"env": { "DB": "${DB_PATH}" }
|
|
17
|
+
},
|
|
18
|
+
"issue-tracker": {
|
|
19
|
+
"type": "http",
|
|
20
|
+
"url": "https://mcp.example.com/mcp",
|
|
21
|
+
"headers": { "X-Tenant": "${TENANT_ID}" },
|
|
22
|
+
"oauth": { "scopes": ["issues.read"] },
|
|
23
|
+
"timeout": 30,
|
|
24
|
+
"loading": "lazy",
|
|
25
|
+
"tools": { "create_issue": { "enabled": false } },
|
|
26
|
+
"permissions": { "allow": ["get_*"], "ask": ["create_*"], "deny": ["delete_*"] }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
读取顺序:``~/.braid/mcp.json``(全局)→ ``<cwd>/.braid/mcp.json``(项目)。
|
|
33
|
+
项目配置里同名条目**整体替换**全局条目:项目内改一个命令参数,不该出现"全局的
|
|
34
|
+
args 拼上项目的 args"这种谁也说不清的合并结果。
|
|
35
|
+
|
|
36
|
+
## 传输字段是互斥的
|
|
37
|
+
|
|
38
|
+
``command`` 与 ``url`` 恰好给一个。混用(例如远程地址配 ``env``)在读配置阶段就
|
|
39
|
+
报错:这些字段在另一种传输里没有含义,静默忽略只会让人以为设置生效了。
|
|
40
|
+
|
|
41
|
+
``type`` 可以不写,按字段推断;写了就必须与字段一致。
|
|
42
|
+
|
|
43
|
+
``http`` 与 ``sse`` 使用 ``http/https`` 地址,``ws`` 使用 ``ws/wss`` 地址。
|
|
44
|
+
|
|
45
|
+
## 远程地址的安全默认值
|
|
46
|
+
|
|
47
|
+
``https`` 之外只接受回环地址上的 ``http``:Bearer 令牌与工具参数在明文连接上等于
|
|
48
|
+
公开的。想连局域网里的明文服务,请自己架一层 TLS 代理——"我知道我在做什么"这句
|
|
49
|
+
话不该由一份被复制来的配置文件替你写。
|
|
50
|
+
|
|
51
|
+
## ``${NAME}`` 展开
|
|
52
|
+
|
|
53
|
+
``env``、``args``、``headers`` 与 ``oauth`` 的字符串字段里的 ``${NAME}`` 从进程环境
|
|
54
|
+
取值,取不到就把该条目记为错误。凭证写进 ``mcp.json`` 会在仓库里留痕,展开是让
|
|
55
|
+
"配置进版本库、密钥进环境"成立的唯一方式。不做 ``!command`` 形式的命令替换:从
|
|
56
|
+
配置文件里执行任意命令,等于让一份被复制来的配置直接获得代码执行权。
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
from __future__ import annotations
|
|
60
|
+
|
|
61
|
+
import json
|
|
62
|
+
import os
|
|
63
|
+
import re
|
|
64
|
+
from dataclasses import dataclass, field
|
|
65
|
+
from pathlib import Path
|
|
66
|
+
from typing import Literal
|
|
67
|
+
from urllib.parse import urlsplit
|
|
68
|
+
|
|
69
|
+
from braid_ai.types import JsonValue
|
|
70
|
+
from braid_coding_agent.netsafe import is_loopback
|
|
71
|
+
|
|
72
|
+
#: 全局配置文件(相对 ``~/.braid``)。
|
|
73
|
+
GLOBAL_CONFIG_NAME = "mcp.json"
|
|
74
|
+
#: 项目配置目录(相对工作目录)。
|
|
75
|
+
PROJECT_CONFIG_DIR = ".braid"
|
|
76
|
+
#: 单条请求的默认超时(秒)。
|
|
77
|
+
DEFAULT_TIMEOUT_SECONDS = 60.0
|
|
78
|
+
|
|
79
|
+
type McpTransportKind = Literal["stdio", "http", "sse", "ws"]
|
|
80
|
+
|
|
81
|
+
#: 支持的传输类型。
|
|
82
|
+
TRANSPORT_NAMES: tuple[McpTransportKind, ...] = ("stdio", "http", "sse", "ws")
|
|
83
|
+
|
|
84
|
+
#: 使用 ``url`` 的传输。
|
|
85
|
+
REMOTE_TRANSPORTS: frozenset[McpTransportKind] = frozenset({"http", "sse", "ws"})
|
|
86
|
+
|
|
87
|
+
_ENV_REFERENCE = re.compile(r"\$\{([A-Za-z_][A-Za-z0-9_]*)\}")
|
|
88
|
+
_OAUTH_KEYS = frozenset({"client_id", "client_secret", "scopes", "authorization_server"})
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@dataclass(slots=True)
|
|
92
|
+
class McpOAuthConfig:
|
|
93
|
+
"""远程服务器的 OAuth 设置。全为空表示「自动发现 + 动态注册」。"""
|
|
94
|
+
|
|
95
|
+
#: 服务器已经分配过客户端时写它,跳过动态注册。
|
|
96
|
+
client_id: str | None = None
|
|
97
|
+
#: 公开客户端通常没有 secret;有就一起带上。
|
|
98
|
+
client_secret: str | None = None
|
|
99
|
+
#: 请求的 scope。留空用授权服务器元数据里的建议值。
|
|
100
|
+
scopes: tuple[str, ...] = ()
|
|
101
|
+
#: 授权服务器地址。留空按受保护资源元数据发现。
|
|
102
|
+
authorization_server: str | None = None
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@dataclass(slots=True)
|
|
106
|
+
class McpToolConfig:
|
|
107
|
+
"""单个工具的覆盖设置。``eager`` 为空表示跟随服务器与全局默认。"""
|
|
108
|
+
|
|
109
|
+
enabled: bool = True
|
|
110
|
+
eager: bool | None = None
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@dataclass(slots=True)
|
|
114
|
+
class McpPermissionConfig:
|
|
115
|
+
"""服务器级与工具级调用策略。模式匹配使用 ``fnmatch``,按工具原名匹配。"""
|
|
116
|
+
|
|
117
|
+
allow: tuple[str, ...] = ()
|
|
118
|
+
ask: tuple[str, ...] = ()
|
|
119
|
+
deny: tuple[str, ...] = ()
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@dataclass(slots=True)
|
|
123
|
+
class McpServerConfig:
|
|
124
|
+
"""一个 MCP 服务器的连接参数。
|
|
125
|
+
|
|
126
|
+
``timeout_s`` 是**单条请求**的超时,不是连接超时:握手、``tools/list``、
|
|
127
|
+
``tools/call`` 各自计时,服务端发进度通知会重新计时(见 ``McpClient._arm_timeout``)。
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
name: str
|
|
131
|
+
transport: McpTransportKind = "stdio"
|
|
132
|
+
#: stdio:要启动的命令。
|
|
133
|
+
command: str | None = None
|
|
134
|
+
args: tuple[str, ...] = ()
|
|
135
|
+
cwd: str | None = None
|
|
136
|
+
env: dict[str, str] = field(default_factory=dict[str, str])
|
|
137
|
+
#: HTTP:服务端地址。
|
|
138
|
+
url: str | None = None
|
|
139
|
+
headers: dict[str, str] = field(default_factory=dict[str, str])
|
|
140
|
+
oauth: McpOAuthConfig | None = None
|
|
141
|
+
description: str | None = None
|
|
142
|
+
timeout_s: float = DEFAULT_TIMEOUT_SECONDS
|
|
143
|
+
#: 配置里是否显式写了 ``timeout``。没有写时由全局 ``mcp.call_timeout_s`` 决定。
|
|
144
|
+
timeout_explicit: bool = True
|
|
145
|
+
#: 建立连接与握手的上限。空表示用全局 ``mcp.connect_timeout_s``。
|
|
146
|
+
connect_timeout_s: float | None = None
|
|
147
|
+
#: 配置里显式写了 ``"trusted": true``。没有它就要走一次风险确认(见 ``mcp/trust.py``)。
|
|
148
|
+
trusted: bool = False
|
|
149
|
+
#: ``enabled: false`` 的服务器仍留在配置里,状态显示为 ``disabled``。
|
|
150
|
+
enabled: bool = True
|
|
151
|
+
#: 工具加载方式。空表示用全局 ``mcp.loading``。
|
|
152
|
+
loading: Literal["lazy", "eager"] | None = None
|
|
153
|
+
#: 工具名 → 覆盖设置。被禁用的工具不注册,也不进入搜索目录。
|
|
154
|
+
tool_settings: dict[str, McpToolConfig] = field(default_factory=dict[str, McpToolConfig])
|
|
155
|
+
#: 调用策略。与连接信任分开:信任回答"能不能连",策略回答"调用放不放行"。
|
|
156
|
+
permissions: McpPermissionConfig | None = None
|
|
157
|
+
|
|
158
|
+
@property
|
|
159
|
+
def timeout_ms(self) -> float:
|
|
160
|
+
"""``braid_mcp`` 用毫秒表达超时。"""
|
|
161
|
+
return self.timeout_s * 1000
|
|
162
|
+
|
|
163
|
+
@property
|
|
164
|
+
def endpoint(self) -> str:
|
|
165
|
+
"""给人看的一行:stdio 是命令行,HTTP 是地址。"""
|
|
166
|
+
if self.transport in REMOTE_TRANSPORTS:
|
|
167
|
+
return self.url or ""
|
|
168
|
+
return " ".join((self.command or "", *self.args)).strip()
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@dataclass(slots=True)
|
|
172
|
+
class LoadedMcpConfig:
|
|
173
|
+
"""两个配置文件合并后的结果。
|
|
174
|
+
|
|
175
|
+
用 ``errors`` 收错误、不抛异常:一条写坏的服务器条目不该让整个进程起不来,其余
|
|
176
|
+
条目照常连接,写坏的那条在 stderr 上说清楚。文件本身不是 JSON 也归到这里,因为它
|
|
177
|
+
同样只影响 MCP 这一块能力。
|
|
178
|
+
"""
|
|
179
|
+
|
|
180
|
+
servers: dict[str, McpServerConfig] = field(default_factory=dict[str, McpServerConfig])
|
|
181
|
+
errors: list[str] = field(default_factory=list[str])
|
|
182
|
+
sources: list[str] = field(default_factory=list[str])
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def load_mcp_config(agent_dir: Path, cwd: str) -> LoadedMcpConfig:
|
|
186
|
+
"""读全局与项目配置。两个文件都不存在时返回空结果,不算错误。"""
|
|
187
|
+
loaded = LoadedMcpConfig()
|
|
188
|
+
_read_into(agent_dir / GLOBAL_CONFIG_NAME, loaded)
|
|
189
|
+
_read_into(Path(cwd) / PROJECT_CONFIG_DIR / GLOBAL_CONFIG_NAME, loaded)
|
|
190
|
+
return loaded
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _read_into(path: Path, loaded: LoadedMcpConfig) -> None:
|
|
194
|
+
"""读一个文件并并进 ``loaded``。项目文件覆盖同名全局条目。"""
|
|
195
|
+
if not path.is_file():
|
|
196
|
+
return
|
|
197
|
+
try:
|
|
198
|
+
# utf-8-sig:某些编辑器保存时会带 BOM,json 解析器不认它。
|
|
199
|
+
payload: JsonValue = json.loads(path.read_text(encoding="utf-8-sig"))
|
|
200
|
+
except (OSError, UnicodeDecodeError, json.JSONDecodeError) as exc:
|
|
201
|
+
loaded.errors.append(f"{path}: 无法读取 MCP 配置:{exc}")
|
|
202
|
+
return
|
|
203
|
+
servers, errors = parse_mcp_document(payload, source=path)
|
|
204
|
+
loaded.errors.extend(errors)
|
|
205
|
+
loaded.servers.update(servers)
|
|
206
|
+
loaded.sources.append(str(path))
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def parse_mcp_document(
|
|
210
|
+
payload: JsonValue, *, source: Path
|
|
211
|
+
) -> tuple[dict[str, McpServerConfig], list[str]]:
|
|
212
|
+
"""把一份 ``mcpServers`` 文档解析成配置表与错误列表。
|
|
213
|
+
|
|
214
|
+
单条目校验失败只丢这一条:一个二十个服务器的配置里写错一个名字,
|
|
215
|
+
另外十九个仍然可用。
|
|
216
|
+
"""
|
|
217
|
+
if not isinstance(payload, dict):
|
|
218
|
+
return {}, [f"{source}: MCP 配置必须是 JSON 对象"]
|
|
219
|
+
raw_servers = payload.get("mcpServers", {})
|
|
220
|
+
if not isinstance(raw_servers, dict):
|
|
221
|
+
return {}, [f"{source}: mcpServers 必须是对象"]
|
|
222
|
+
|
|
223
|
+
servers: dict[str, McpServerConfig] = {}
|
|
224
|
+
errors: list[str] = []
|
|
225
|
+
for name, entry in raw_servers.items():
|
|
226
|
+
if not name:
|
|
227
|
+
errors.append(f"{source}: 服务器名不能为空")
|
|
228
|
+
continue
|
|
229
|
+
config, error = _parse_server(name, entry, source=source)
|
|
230
|
+
if config is not None:
|
|
231
|
+
servers[name] = config
|
|
232
|
+
if error is not None:
|
|
233
|
+
errors.append(error)
|
|
234
|
+
return servers, errors
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def _parse_server(
|
|
238
|
+
name: str, entry: JsonValue, *, source: Path
|
|
239
|
+
) -> tuple[McpServerConfig | None, str | None]:
|
|
240
|
+
"""校验并折叠一条服务器配置。返回 ``(配置, 错误)``,两者至多一个非空。"""
|
|
241
|
+
where = f"{source}: 服务器 {name}"
|
|
242
|
+
if not isinstance(entry, dict):
|
|
243
|
+
return None, f"{where}: 必须是对象"
|
|
244
|
+
raw_enabled = entry.get("enabled", True)
|
|
245
|
+
if not isinstance(raw_enabled, bool):
|
|
246
|
+
return None, f"{where}: enabled 必须是 true 或 false"
|
|
247
|
+
|
|
248
|
+
raw_url = entry.get("url")
|
|
249
|
+
raw_command = entry.get("command")
|
|
250
|
+
if raw_url is not None and raw_command is not None:
|
|
251
|
+
return None, f"{where}: command(stdio)与 url(远程)只能给一个"
|
|
252
|
+
if raw_url is None and raw_command is None:
|
|
253
|
+
return None, f"{where}: 缺少 command 或 url"
|
|
254
|
+
|
|
255
|
+
declared_type = entry.get("type")
|
|
256
|
+
if declared_type is not None and declared_type not in TRANSPORT_NAMES:
|
|
257
|
+
allowed = "、".join(f'"{item}"' for item in TRANSPORT_NAMES)
|
|
258
|
+
return None, f"{where}: type 只支持 {allowed},收到 {declared_type!r}"
|
|
259
|
+
transport: McpTransportKind
|
|
260
|
+
if raw_url is not None:
|
|
261
|
+
transport = declared_type if declared_type in REMOTE_TRANSPORTS else "http"
|
|
262
|
+
if declared_type == "stdio":
|
|
263
|
+
return None, f"{where}: type 与字段不一致(url 不能配 stdio)"
|
|
264
|
+
else:
|
|
265
|
+
transport = "stdio"
|
|
266
|
+
if declared_type is not None and declared_type != "stdio":
|
|
267
|
+
return None, f"{where}: type 与字段不一致(command 只能配 stdio)"
|
|
268
|
+
|
|
269
|
+
if transport == "stdio":
|
|
270
|
+
return _parse_stdio_server(name, entry, where=where, source=source, enabled=raw_enabled)
|
|
271
|
+
return _parse_remote_server(
|
|
272
|
+
name,
|
|
273
|
+
entry,
|
|
274
|
+
where=where,
|
|
275
|
+
source=source,
|
|
276
|
+
transport=transport,
|
|
277
|
+
enabled=raw_enabled,
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def _parse_stdio_server(
|
|
282
|
+
name: str,
|
|
283
|
+
entry: dict[str, JsonValue],
|
|
284
|
+
*,
|
|
285
|
+
where: str,
|
|
286
|
+
source: Path,
|
|
287
|
+
enabled: bool,
|
|
288
|
+
) -> tuple[McpServerConfig | None, str | None]:
|
|
289
|
+
command = entry.get("command")
|
|
290
|
+
if not isinstance(command, str) or not command.strip():
|
|
291
|
+
return None, f"{where}: 缺少 command"
|
|
292
|
+
for key in ("headers", "oauth"):
|
|
293
|
+
if key in entry:
|
|
294
|
+
return None, f"{where}: {key} 只用于 url 形式的远程服务器"
|
|
295
|
+
|
|
296
|
+
raw_args = entry.get("args", [])
|
|
297
|
+
if not isinstance(raw_args, list):
|
|
298
|
+
return None, f"{where}: args 必须是字符串数组"
|
|
299
|
+
args: list[str] = []
|
|
300
|
+
for index, item in enumerate(raw_args):
|
|
301
|
+
if not isinstance(item, str):
|
|
302
|
+
return None, f"{where}: args 必须是字符串数组"
|
|
303
|
+
expanded, error = _expand(item, server=name, where=f"args[{index}]", source=source)
|
|
304
|
+
if error is not None:
|
|
305
|
+
return None, error
|
|
306
|
+
args.append(expanded)
|
|
307
|
+
|
|
308
|
+
raw_env = entry.get("env", {})
|
|
309
|
+
if not isinstance(raw_env, dict):
|
|
310
|
+
return None, f"{where}: env 必须是对象"
|
|
311
|
+
env: dict[str, str] = {}
|
|
312
|
+
for key, value in raw_env.items():
|
|
313
|
+
if not isinstance(value, str):
|
|
314
|
+
return None, f"{where}: env.{key} 必须是字符串"
|
|
315
|
+
expanded, error = _expand(value, server=name, where=f"env.{key}", source=source)
|
|
316
|
+
if error is not None:
|
|
317
|
+
return None, error
|
|
318
|
+
env[str(key)] = expanded
|
|
319
|
+
|
|
320
|
+
raw_cwd = entry.get("cwd")
|
|
321
|
+
if raw_cwd is not None and not isinstance(raw_cwd, str):
|
|
322
|
+
return None, f"{where}: cwd 必须是字符串"
|
|
323
|
+
|
|
324
|
+
common, error = _parse_common(entry, where=where)
|
|
325
|
+
if error is not None:
|
|
326
|
+
return None, error
|
|
327
|
+
assert common is not None
|
|
328
|
+
return (
|
|
329
|
+
McpServerConfig(
|
|
330
|
+
name=name,
|
|
331
|
+
transport="stdio",
|
|
332
|
+
command=command,
|
|
333
|
+
args=tuple(args),
|
|
334
|
+
cwd=raw_cwd,
|
|
335
|
+
env=env,
|
|
336
|
+
description=common.description,
|
|
337
|
+
timeout_s=common.timeout_s,
|
|
338
|
+
timeout_explicit=common.timeout_explicit,
|
|
339
|
+
connect_timeout_s=common.connect_timeout_s,
|
|
340
|
+
trusted=common.trusted,
|
|
341
|
+
enabled=enabled,
|
|
342
|
+
loading=common.loading,
|
|
343
|
+
tool_settings=common.tool_settings,
|
|
344
|
+
permissions=common.permissions,
|
|
345
|
+
),
|
|
346
|
+
None,
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def _parse_remote_server(
|
|
351
|
+
name: str,
|
|
352
|
+
entry: dict[str, JsonValue],
|
|
353
|
+
*,
|
|
354
|
+
where: str,
|
|
355
|
+
source: Path,
|
|
356
|
+
transport: McpTransportKind,
|
|
357
|
+
enabled: bool,
|
|
358
|
+
) -> tuple[McpServerConfig | None, str | None]:
|
|
359
|
+
raw_url = entry.get("url")
|
|
360
|
+
assert isinstance(raw_url, str)
|
|
361
|
+
expanded_url, error = _expand(raw_url, server=name, where="url", source=source)
|
|
362
|
+
if error is not None:
|
|
363
|
+
return None, error
|
|
364
|
+
url_error = _validate_url(expanded_url, transport)
|
|
365
|
+
if url_error is not None:
|
|
366
|
+
return None, f"{where}: {url_error}"
|
|
367
|
+
|
|
368
|
+
for key in ("args", "env", "cwd"):
|
|
369
|
+
if key in entry:
|
|
370
|
+
return None, f"{where}: {key} 只用于 stdio 服务器"
|
|
371
|
+
|
|
372
|
+
raw_headers = entry.get("headers", {})
|
|
373
|
+
if not isinstance(raw_headers, dict):
|
|
374
|
+
return None, f"{where}: headers 必须是对象"
|
|
375
|
+
headers: dict[str, str] = {}
|
|
376
|
+
for key, value in raw_headers.items():
|
|
377
|
+
if not isinstance(value, str):
|
|
378
|
+
return None, f"{where}: headers.{key} 必须是字符串"
|
|
379
|
+
expanded, error = _expand(value, server=name, where=f"headers.{key}", source=source)
|
|
380
|
+
if error is not None:
|
|
381
|
+
return None, error
|
|
382
|
+
headers[str(key)] = expanded
|
|
383
|
+
|
|
384
|
+
oauth, error = _parse_oauth(entry.get("oauth"), server=name, where=where, source=source)
|
|
385
|
+
if error is not None:
|
|
386
|
+
return None, error
|
|
387
|
+
|
|
388
|
+
common, error = _parse_common(entry, where=where)
|
|
389
|
+
if error is not None:
|
|
390
|
+
return None, error
|
|
391
|
+
assert common is not None
|
|
392
|
+
return (
|
|
393
|
+
McpServerConfig(
|
|
394
|
+
name=name,
|
|
395
|
+
transport=transport,
|
|
396
|
+
url=expanded_url,
|
|
397
|
+
headers=headers,
|
|
398
|
+
oauth=oauth,
|
|
399
|
+
description=common.description,
|
|
400
|
+
timeout_s=common.timeout_s,
|
|
401
|
+
timeout_explicit=common.timeout_explicit,
|
|
402
|
+
connect_timeout_s=common.connect_timeout_s,
|
|
403
|
+
trusted=common.trusted,
|
|
404
|
+
enabled=enabled,
|
|
405
|
+
loading=common.loading,
|
|
406
|
+
tool_settings=common.tool_settings,
|
|
407
|
+
permissions=common.permissions,
|
|
408
|
+
),
|
|
409
|
+
None,
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
@dataclass(slots=True)
|
|
414
|
+
class _Common:
|
|
415
|
+
description: str | None
|
|
416
|
+
timeout_s: float
|
|
417
|
+
timeout_explicit: bool
|
|
418
|
+
connect_timeout_s: float | None
|
|
419
|
+
trusted: bool
|
|
420
|
+
loading: Literal["lazy", "eager"] | None
|
|
421
|
+
tool_settings: dict[str, McpToolConfig]
|
|
422
|
+
permissions: McpPermissionConfig | None
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
def _parse_common(entry: dict[str, JsonValue], *, where: str) -> tuple[_Common | None, str | None]:
|
|
426
|
+
raw_description = entry.get("description")
|
|
427
|
+
if raw_description is not None and not isinstance(raw_description, str):
|
|
428
|
+
return None, f"{where}: description 必须是字符串"
|
|
429
|
+
|
|
430
|
+
raw_trusted = entry.get("trusted", False)
|
|
431
|
+
if not isinstance(raw_trusted, bool):
|
|
432
|
+
return None, f"{where}: trusted 必须是 true 或 false"
|
|
433
|
+
|
|
434
|
+
raw_timeout = entry.get("timeout", DEFAULT_TIMEOUT_SECONDS)
|
|
435
|
+
if isinstance(raw_timeout, bool) or not isinstance(raw_timeout, int | float):
|
|
436
|
+
return None, f"{where}: timeout 必须是正数(秒)"
|
|
437
|
+
if raw_timeout <= 0:
|
|
438
|
+
return None, f"{where}: timeout 必须是正数(秒)"
|
|
439
|
+
timeout_explicit = "timeout" in entry
|
|
440
|
+
|
|
441
|
+
raw_connect_timeout = entry.get("connectTimeout")
|
|
442
|
+
connect_timeout: float | None = None
|
|
443
|
+
if raw_connect_timeout is not None:
|
|
444
|
+
if isinstance(raw_connect_timeout, bool) or not isinstance(
|
|
445
|
+
raw_connect_timeout, int | float
|
|
446
|
+
):
|
|
447
|
+
return None, f"{where}: connectTimeout 必须是正数(秒)"
|
|
448
|
+
if raw_connect_timeout <= 0:
|
|
449
|
+
return None, f"{where}: connectTimeout 必须是正数(秒)"
|
|
450
|
+
connect_timeout = float(raw_connect_timeout)
|
|
451
|
+
|
|
452
|
+
raw_loading = entry.get("loading")
|
|
453
|
+
if raw_loading is not None and raw_loading not in ("lazy", "eager"):
|
|
454
|
+
return None, f'{where}: loading 只能是 "lazy" 或 "eager"'
|
|
455
|
+
loading: Literal["lazy", "eager"] | None = raw_loading if raw_loading else None
|
|
456
|
+
|
|
457
|
+
tool_settings, error = _parse_tool_settings(entry.get("tools"), where=where)
|
|
458
|
+
if error is not None:
|
|
459
|
+
return None, error
|
|
460
|
+
permissions, error = _parse_permissions(entry.get("permissions"), where=where)
|
|
461
|
+
if error is not None:
|
|
462
|
+
return None, error
|
|
463
|
+
|
|
464
|
+
return (
|
|
465
|
+
_Common(
|
|
466
|
+
description=raw_description,
|
|
467
|
+
timeout_s=float(raw_timeout),
|
|
468
|
+
timeout_explicit=timeout_explicit,
|
|
469
|
+
connect_timeout_s=connect_timeout,
|
|
470
|
+
trusted=raw_trusted,
|
|
471
|
+
loading=loading,
|
|
472
|
+
tool_settings=tool_settings,
|
|
473
|
+
permissions=permissions,
|
|
474
|
+
),
|
|
475
|
+
None,
|
|
476
|
+
)
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def _parse_tool_settings(
|
|
480
|
+
value: JsonValue | None, *, where: str
|
|
481
|
+
) -> tuple[dict[str, McpToolConfig], str | None]:
|
|
482
|
+
"""``tools`` 支持 ``{"name": {"enabled": false, "eager": true}}`` 与布尔简写。"""
|
|
483
|
+
if value is None:
|
|
484
|
+
return {}, None
|
|
485
|
+
if not isinstance(value, dict):
|
|
486
|
+
return {}, f"{where}: tools 必须是对象"
|
|
487
|
+
settings: dict[str, McpToolConfig] = {}
|
|
488
|
+
for tool_name, raw in value.items():
|
|
489
|
+
if not tool_name:
|
|
490
|
+
return {}, f"{where}: tools 的工具名必须是非空字符串"
|
|
491
|
+
if isinstance(raw, bool):
|
|
492
|
+
settings[tool_name] = McpToolConfig(enabled=raw)
|
|
493
|
+
continue
|
|
494
|
+
if not isinstance(raw, dict):
|
|
495
|
+
return {}, f"{where}: tools.{tool_name} 必须是布尔或对象"
|
|
496
|
+
unknown = set(raw) - {"enabled", "eager"}
|
|
497
|
+
if unknown:
|
|
498
|
+
return {}, f"{where}: tools.{tool_name} 里有未知字段 {sorted(unknown)}"
|
|
499
|
+
enabled = raw.get("enabled", True)
|
|
500
|
+
eager = raw.get("eager")
|
|
501
|
+
if not isinstance(enabled, bool):
|
|
502
|
+
return {}, f"{where}: tools.{tool_name}.enabled 必须是布尔"
|
|
503
|
+
if eager is not None and not isinstance(eager, bool):
|
|
504
|
+
return {}, f"{where}: tools.{tool_name}.eager 必须是布尔"
|
|
505
|
+
settings[tool_name] = McpToolConfig(enabled=enabled, eager=eager)
|
|
506
|
+
return settings, None
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
def _parse_permissions(
|
|
510
|
+
value: JsonValue | None, *, where: str
|
|
511
|
+
) -> tuple[McpPermissionConfig | None, str | None]:
|
|
512
|
+
if value is None:
|
|
513
|
+
return None, None
|
|
514
|
+
if not isinstance(value, dict):
|
|
515
|
+
return None, f"{where}: permissions 必须是对象"
|
|
516
|
+
unknown = set(value) - {"allow", "ask", "deny"}
|
|
517
|
+
if unknown:
|
|
518
|
+
return None, f"{where}: permissions 里有未知字段 {sorted(unknown)}"
|
|
519
|
+
parsed: dict[str, tuple[str, ...]] = {}
|
|
520
|
+
for key in ("allow", "ask", "deny"):
|
|
521
|
+
raw = value.get(key, [])
|
|
522
|
+
if not isinstance(raw, list):
|
|
523
|
+
return None, f"{where}: permissions.{key} 必须是字符串数组"
|
|
524
|
+
patterns: list[str] = []
|
|
525
|
+
for item in raw:
|
|
526
|
+
if not isinstance(item, str):
|
|
527
|
+
return None, f"{where}: permissions.{key} 必须是字符串数组"
|
|
528
|
+
patterns.append(item)
|
|
529
|
+
parsed[key] = tuple(patterns)
|
|
530
|
+
return (
|
|
531
|
+
McpPermissionConfig(
|
|
532
|
+
allow=parsed["allow"],
|
|
533
|
+
ask=parsed["ask"],
|
|
534
|
+
deny=parsed["deny"],
|
|
535
|
+
),
|
|
536
|
+
None,
|
|
537
|
+
)
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
def _parse_oauth(
|
|
541
|
+
value: JsonValue | None, *, server: str, where: str, source: Path
|
|
542
|
+
) -> tuple[McpOAuthConfig | None, str | None]:
|
|
543
|
+
"""``oauth`` 接受 ``true`` 或对象。``false`` 与缺省都表示不使用 OAuth。"""
|
|
544
|
+
if value is None or value is False:
|
|
545
|
+
return None, None
|
|
546
|
+
if value is True:
|
|
547
|
+
return McpOAuthConfig(), None
|
|
548
|
+
if not isinstance(value, dict):
|
|
549
|
+
return None, f"{where}: oauth 必须是 true 或对象"
|
|
550
|
+
unknown = set(value) - _OAUTH_KEYS
|
|
551
|
+
if unknown:
|
|
552
|
+
return None, f"{where}: oauth 里有未知字段 {sorted(unknown)}"
|
|
553
|
+
|
|
554
|
+
raw_client_id = value.get("client_id")
|
|
555
|
+
if raw_client_id is not None and not isinstance(raw_client_id, str):
|
|
556
|
+
return None, f"{where}: oauth.client_id 必须是字符串"
|
|
557
|
+
raw_secret = value.get("client_secret")
|
|
558
|
+
if raw_secret is not None and not isinstance(raw_secret, str):
|
|
559
|
+
return None, f"{where}: oauth.client_secret 必须是字符串"
|
|
560
|
+
raw_server = value.get("authorization_server")
|
|
561
|
+
if raw_server is not None and not isinstance(raw_server, str):
|
|
562
|
+
return None, f"{where}: oauth.authorization_server 必须是字符串"
|
|
563
|
+
|
|
564
|
+
raw_scopes = value.get("scopes", [])
|
|
565
|
+
if not isinstance(raw_scopes, list) or any(not isinstance(item, str) for item in raw_scopes):
|
|
566
|
+
return None, f"{where}: oauth.scopes 必须是字符串数组"
|
|
567
|
+
|
|
568
|
+
client_id, error = _optional_expand(
|
|
569
|
+
raw_client_id, server=server, where="oauth.client_id", source=source
|
|
570
|
+
)
|
|
571
|
+
if error is not None:
|
|
572
|
+
return None, error
|
|
573
|
+
secret, error = _optional_expand(
|
|
574
|
+
raw_secret, server=server, where="oauth.client_secret", source=source
|
|
575
|
+
)
|
|
576
|
+
if error is not None:
|
|
577
|
+
return None, error
|
|
578
|
+
authorization_server, error = _optional_expand(
|
|
579
|
+
raw_server, server=server, where="oauth.authorization_server", source=source
|
|
580
|
+
)
|
|
581
|
+
if error is not None:
|
|
582
|
+
return None, error
|
|
583
|
+
|
|
584
|
+
scopes: list[str] = []
|
|
585
|
+
for index, item in enumerate(raw_scopes):
|
|
586
|
+
assert isinstance(item, str)
|
|
587
|
+
expanded, error = _expand(
|
|
588
|
+
item, server=server, where=f"oauth.scopes[{index}]", source=source
|
|
589
|
+
)
|
|
590
|
+
if error is not None:
|
|
591
|
+
return None, error
|
|
592
|
+
scopes.append(expanded)
|
|
593
|
+
|
|
594
|
+
return (
|
|
595
|
+
McpOAuthConfig(
|
|
596
|
+
client_id=client_id,
|
|
597
|
+
client_secret=secret,
|
|
598
|
+
scopes=tuple(scopes),
|
|
599
|
+
authorization_server=authorization_server,
|
|
600
|
+
),
|
|
601
|
+
None,
|
|
602
|
+
)
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
def _validate_url(url: str, transport: McpTransportKind) -> str | None:
|
|
606
|
+
"""远程地址的形状与安全默认值。WebSocket 用 ws/wss,其余用 http/https。"""
|
|
607
|
+
parsed = urlsplit(url.strip())
|
|
608
|
+
schemes = ("ws", "wss") if transport == "ws" else ("http", "https")
|
|
609
|
+
if parsed.scheme not in schemes:
|
|
610
|
+
return f"url 只支持 {'/'.join(schemes)},收到 {parsed.scheme or '空'} 协议"
|
|
611
|
+
if not parsed.hostname:
|
|
612
|
+
return "url 缺少主机名"
|
|
613
|
+
if parsed.username is not None or parsed.password is not None:
|
|
614
|
+
return "url 不能内嵌用户名与密码,凭证请写在 headers 或 oauth 里"
|
|
615
|
+
plain = "ws" if transport == "ws" else "http"
|
|
616
|
+
if parsed.scheme == plain and not is_loopback(parsed.hostname):
|
|
617
|
+
return f"非回环地址必须使用 {plain}s(明文 {plain} 会暴露 Authorization 头)"
|
|
618
|
+
return None
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
def validate_remote_url(url: str, transport: McpTransportKind) -> str | None:
|
|
622
|
+
"""给写入侧复用同一套地址校验,返回错误文本或 ``None``。"""
|
|
623
|
+
return _validate_url(url, transport)
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
def _optional_expand(
|
|
627
|
+
value: str | None, *, server: str, where: str, source: Path
|
|
628
|
+
) -> tuple[str | None, str | None]:
|
|
629
|
+
if value is None:
|
|
630
|
+
return None, None
|
|
631
|
+
return _expand(value, server=server, where=where, source=source)
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
def _expand(value: str, *, server: str, where: str, source: Path) -> tuple[str, str | None]:
|
|
635
|
+
"""展开 ``${NAME}``。缺失变量返回 ``(原值, 错误)``,让条目整体作废。"""
|
|
636
|
+
missing: list[str] = []
|
|
637
|
+
|
|
638
|
+
def replace(match: re.Match[str]) -> str:
|
|
639
|
+
resolved = os.environ.get(match.group(1))
|
|
640
|
+
if resolved is None:
|
|
641
|
+
missing.append(match.group(1))
|
|
642
|
+
return match.group(0)
|
|
643
|
+
return resolved
|
|
644
|
+
|
|
645
|
+
expanded = _ENV_REFERENCE.sub(replace, value)
|
|
646
|
+
if missing:
|
|
647
|
+
names = "、".join(sorted(set(missing)))
|
|
648
|
+
return value, f"{source}: 服务器 {server} 的 {where} 引用了未设置的环境变量:{names}"
|
|
649
|
+
return expanded, None
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
__all__ = [
|
|
653
|
+
"DEFAULT_TIMEOUT_SECONDS",
|
|
654
|
+
"GLOBAL_CONFIG_NAME",
|
|
655
|
+
"PROJECT_CONFIG_DIR",
|
|
656
|
+
"TRANSPORT_NAMES",
|
|
657
|
+
"LoadedMcpConfig",
|
|
658
|
+
"McpOAuthConfig",
|
|
659
|
+
"McpServerConfig",
|
|
660
|
+
"McpTransportKind",
|
|
661
|
+
"load_mcp_config",
|
|
662
|
+
"parse_mcp_document",
|
|
663
|
+
"validate_remote_url",
|
|
664
|
+
]
|