Skip to content

Commit 5a00a09

Browse files
committed
feat: 解决冲突
2 parents dcd947c + 62a9e29 commit 5a00a09

39 files changed

Lines changed: 5041 additions & 783 deletions

File tree

server/mcp_server_computer_use/README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,18 @@ The following environment variables are available for configuring the MCP server
7878
| Environment Variable | Description | Default Value |
7979
|----------|------|--------|
8080
| `MCP_SERVER_PORT` | MCP server listening port | `8000` |
81-
| `TOOL_SERVER_ENDPOINT` | Tool server endpoint | - |
81+
| `TOOL_SERVER_ENDPOINT` | Tool server endpoint. Use `https://...` when HTTPS is enabled. | - |
82+
| `AUTH_API_KEY` | API key sent to tool server via the `X-API-Key` header. Must match `auth_key` configured on the tool server. Leave empty to disable authentication. | `""` |
83+
| `TOOL_SERVER_ENABLE_HTTPS` | Set to `true` when the tool server is served over HTTPS so that the SDK validates the TLS server certificate. | `false` |
84+
| `TOOL_SERVER_CLIENT_CA` | Absolute path to the CA certificate that signed the tool server's server certificate. Required when `TOOL_SERVER_ENABLE_HTTPS=true`. | `""` |
8285

8386
For example, set these environment variables before starting the server:
8487

8588
```bash
8689
# Set fastmcp port and [tool server]() endpoint here
8790
export MCP_SERVER_PORT=8000
8891
export TOOL_SERVER_ENDPOINT={endpoint}
92+
export AUTH_API_KEY={your-secret-api-key} # optional
8993
cd mcp_server_computer_use
9094
uv run mcp-server-computer-use
9195
```
@@ -103,14 +107,35 @@ uv run mcp-server-computer-use
103107
],
104108
"env": {
105109
"MCP_SERVER_PORT": 8000,
106-
"TOOL_SERVER_ENDPOINT": "{endpoint}"
110+
"TOOL_SERVER_ENDPOINT": "{endpoint}",
111+
"AUTH_API_KEY": "{your-secret-api-key}"
107112
}
108113
}
109114
}
110115
}
111116

112117
```
113118

119+
### Authentication & HTTPS
120+
121+
By default the MCP server talks to the tool server over plain HTTP without authentication, which is fine for local development. For any deployment that exposes the tool server outside a fully trusted network, you should turn on at least the API-key authentication, and ideally HTTPS as well, so that the `X-API-Key` header is not transmitted in plain text.
122+
123+
1. **API-key authentication (recommended baseline)**
124+
125+
Configure the **same** secret value on both sides:
126+
127+
- On the **tool server**, set `auth_key` in its `config.toml`.
128+
- On the **MCP server**, set `AUTH_API_KEY` via the environment variable above.
129+
130+
When `auth_key` is set on the tool server, requests without a matching `X-API-Key` header will be rejected with `401 Permission denied`.
131+
132+
2. **HTTPS (recommended for any non-trusted network)**
133+
134+
- On the **tool server**, enable HTTPS (`plugins.enable_https = true`) with `ssl.server_cert` and `ssl.server_key`.
135+
- On the **MCP server**, set `TOOL_SERVER_ENABLE_HTTPS=true` and `TOOL_SERVER_CLIENT_CA=/abs/path/ca.crt` (the CA that signed the tool server certificate). Make sure `TOOL_SERVER_ENDPOINT` uses `https://`.
136+
137+
Both ends must agree on whether HTTPS is enabled, otherwise the TLS handshake will fail.
138+
114139

115140
# License
116-
volcengine/mcp-server is licensed under the [MIT License](https://github.com/volcengine/mcp-server/blob/main/LICENSE).
141+
volcengine/mcp-server is licensed under the [MIT License](https://github.com/volcengine/mcp-server/blob/main/LICENSE).

server/mcp_server_computer_use/README_zh.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,17 @@ uv run mcp-server-computer-use -t sse
8787
| 环境变量 | 描述 | 默认值 |
8888
|----------|------|--------|
8989
| `MCP_SERVER_PORT` | MCP Server 端口 | `8000` |
90-
| `TOOL_SERVER_ENDPOINT` | Tool server 端口 | - |
90+
| `TOOL_SERVER_ENDPOINT` | Tool server 地址。启用 HTTPS 时填 `https://...` | - |
91+
| `AUTH_API_KEY` | 调用 Tool Server 时随 `X-API-Key` 请求头携带的鉴权 Key,需与 Tool Server `config.toml``auth_key` 一致;为空则不鉴权 | `""` |
92+
| `TOOL_SERVER_ENABLE_HTTPS` | Tool Server 启用 HTTPS 时设为 `true`,SDK 将校验 TLS 服务端证书 | `false` |
93+
| `TOOL_SERVER_CLIENT_CA` | 签发 Tool Server 服务端证书的 CA 证书绝对路径,`TOOL_SERVER_ENABLE_HTTPS=true` 时必填 | `""` |
9194

9295
例如,在启动服务器前设置这些环境变量:
9396

9497
```bash
9598
export MCP_SERVER_PORT=8000
9699
export TOOL_SERVER_ENDPOINT={endpoint}
100+
export AUTH_API_KEY={your-secret-api-key} # 可选
97101
cd mcp_server_computer_use
98102
uv run mcp-server-computer-use
99103
```
@@ -111,14 +115,23 @@ uv run mcp-server-computer-use
111115
],
112116
"env": {
113117
"MCP_SERVER_PORT": 8000,
114-
"TOOL_SERVER_ENDPOINT": "{endpoint}"
118+
"TOOL_SERVER_ENDPOINT": "{endpoint}",
119+
"AUTH_API_KEY": "{your-secret-api-key}"
115120
}
116121
}
117122
}
118123
}
119124

120125
```
121126

127+
### 鉴权与 HTTPS
128+
129+
默认情况下 MCP Server 与 Tool Server 之间走 HTTP 明文通信、且不做鉴权,只适合本地调试。一旦 Tool Server 暴露在受信任网络之外,建议至少启用 API Key 鉴权,最好同时启用 HTTPS,避免 `X-API-Key` 明文传输。
130+
131+
1. **API Key 鉴权(最低安全基线)**:在 Tool Server `config.toml` 中配置 `auth_key`,并在本 MCP Server 的环境变量 `AUTH_API_KEY` 中填入相同值。Tool Server 配置了 `auth_key` 后,未携带匹配 `X-API-Key` 的请求会返回 `401 Permission denied`
132+
133+
2. **HTTPS(公网/跨机房推荐)**:在 Tool Server 启用 HTTPS(`plugins.enable_https = true``ssl.server_cert/server_key` 指向证书文件);本 MCP Server 设置 `TOOL_SERVER_ENABLE_HTTPS=true``TOOL_SERVER_CLIENT_CA=/abs/path/ca.crt`,并把 `TOOL_SERVER_ENDPOINT` 协议改为 `https://`。两端 HTTPS 状态必须一致,否则 TLS 握手失败。
134+
122135

123136
# 证书
124-
volcengine/mcp-server is licensed under the [MIT License](https://github.com/volcengine/mcp-server/blob/main/LICENSE).
137+
volcengine/mcp-server is licensed under the [MIT License](https://github.com/volcengine/mcp-server/blob/main/LICENSE).

server/mcp_server_computer_use/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ dependencies = [
1010
"concurrent-log-handler==0.9.25",
1111
"dynaconf==3.2.10",
1212
"jsonref==1.1.0",
13-
"tool_server_client==1.0.0rc7",
13+
"tool_server_client==1.0.0rc19",
1414
]
1515

1616
[project.scripts]
1717
mcp-server-computer-use = "mcp_server_computer_use.main:main"
1818

1919
[build-system]
2020
requires = ["hatchling"]
21-
build-backend = "hatchling.build"
21+
build-backend = "hatchling.build"
Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,57 @@
11
import os
2+
from typing import Optional
23

34
from tool_server_client.client import ComputerUseClient, new_computer_use_client
45

56
from mcp_server_computer_use.common.logs import LOG
6-
from mcp_server_computer_use.common.config import tool_server_config
7+
from mcp_server_computer_use.common.config import (
8+
tool_server_config,
9+
plugins_config,
10+
ssl_config,
11+
)
712

813
_local_client = None
914

1015

16+
def _resolve_auth_key() -> str:
17+
return os.environ.get("AUTH_API_KEY") or tool_server_config.get("auth_key", "")
18+
19+
20+
def _resolve_client_ca() -> Optional[str]:
21+
enable_https_env = os.environ.get("TOOL_SERVER_ENABLE_HTTPS")
22+
if enable_https_env is not None:
23+
enable_https = enable_https_env.strip().lower() in ("1", "true", "yes", "on")
24+
else:
25+
enable_https = bool(plugins_config.get("enable_https", False))
26+
27+
if not enable_https:
28+
return None
29+
30+
return os.environ.get("TOOL_SERVER_CLIENT_CA") or ssl_config.get("client_ca") or None
31+
32+
1133
def tool_server_client(endpoint: str = None) -> ComputerUseClient:
1234
global _local_client
1335

36+
auth_key = _resolve_auth_key()
37+
client_ca = _resolve_client_ca()
38+
1439
try:
1540
if tool_server_config["local"]:
1641
if _local_client is None:
1742
endpoint = endpoint or os.environ.get(
1843
"TOOL_SERVER_ENDPOINT") or tool_server_config["endpoint"]
19-
_local_client = new_computer_use_client(endpoint)
44+
_local_client = new_computer_use_client(
45+
endpoint, auth_key=auth_key, client_ca=client_ca
46+
)
2047

2148
return _local_client
2249
else:
2350
LOG.info(f"Get client, endpoint: {endpoint}")
24-
return new_computer_use_client(endpoint)
51+
return new_computer_use_client(
52+
endpoint, auth_key=auth_key, client_ca=client_ca
53+
)
2554

2655
except Exception as e:
2756
LOG.error(f"Get client failed: {str(e)}")
28-
raise e
57+
raise e

server/mcp_server_computer_use/src/mcp_server_computer_use/common/config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,22 @@
88
tool_server_config = {
99
"local": True,
1010
"endpoint": "",
11+
# Optional shared secret. When tool_server is configured with a non-empty
12+
# `auth_key`, clients must send the same value via the `X-API-Key` header.
13+
# Can be overridden by the AUTH_API_KEY environment variable.
14+
"auth_key": "",
1115
}
16+
17+
# Optional HTTPS settings. When tool_server is served over HTTPS, set
18+
# `enable_https` to True and provide `client_ca` (the CA certificate path that
19+
# signs tool_server's server certificate) so the SDK can validate the TLS
20+
# server certificate. Both can be overridden by environment variables:
21+
# - TOOL_SERVER_ENABLE_HTTPS = "true" / "false"
22+
# - TOOL_SERVER_CLIENT_CA = "/absolute/path/to/ca.crt"
23+
plugins_config = {
24+
"enable_https": False,
25+
}
26+
27+
ssl_config = {
28+
"client_ca": "",
29+
}

0 commit comments

Comments
 (0)