@jadchene/mcp-gateway-service 0.11.1 → 0.11.2

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 CHANGED
@@ -1,205 +1,209 @@
1
- English | [简体中文](./README_zh.md)
2
-
3
- # MCP Gateway
4
-
5
- ## Introduction
6
-
7
- MCP Gateway puts multiple MCP services behind one endpoint. An agent connects to the gateway and sees six routing tools; downstream services, tools, and schemas are looked up only when they are needed.
8
-
9
- The project uses the official TypeScript SDK v2 and requires Node.js 24 or later.
10
-
11
- > [!IMPORTANT]
12
- > MCP Gateway v0.6.2 and later accept only MCP `2026-07-28`, `2025-11-25`, and `2025-06-18`. Supported transports are newline-delimited stdio and single-endpoint Streamable HTTP. Standalone HTTP+SSE (`/sse`), `Content-Length` framing, and other protocol revisions are not supported.
13
-
14
- ## Why Use It
15
-
16
- - Keep the agent context small even when many MCP services are configured.
17
- - Connect the agent once, then add or remove downstream services in the gateway config.
18
- - Find tools by name or description and load schemas only when required.
19
- - Use stdio and Streamable HTTP services through the same interface.
20
- - Require user confirmation for selected tool-name patterns, or hide and block matching tools entirely.
21
- - Reload config changes without restarting the gateway.
22
-
23
- ## Quick Start
24
-
25
- ### Install
26
-
27
- ```bash
28
- npm install -g @jadchene/mcp-gateway-service
29
- ```
30
-
31
- Create `config.json`. Replace `your-mcp-service` with the command of an installed MCP server:
32
-
33
- ```json
34
- {
35
- "services": [
36
- {
37
- "serviceId": "tools",
38
- "name": "Tools",
39
- "transport": {
40
- "type": "stdio",
41
- "command": "your-mcp-service"
42
- }
43
- }
44
- ]
45
- }
46
- ```
47
-
48
- ### Stdio
49
-
50
- The agent starts the gateway process, so no separate startup command is needed.
51
-
52
- Codex `config.toml`:
53
-
54
- ```toml
55
- [mcp_servers.gateway]
56
- command = "mcp-gateway-service"
57
- args = ["--config", "./config.json"]
58
- ```
59
-
60
- Claude Code:
61
-
62
- ```bash
63
- claude mcp add gateway -- mcp-gateway-service --config ./config.json
64
- ```
65
-
66
- ### Streamable HTTP
67
-
68
- Start the gateway:
69
-
70
- ```bash
71
- mcp-gateway-service --http --config ./config.json
72
- ```
73
-
74
- The default endpoint is `http://127.0.0.1:3000/mcp`.
75
- HTTP hides `gateway_manage_service` by default. Non-loopback binds require a bearer token in `MCP_GATEWAY_AUTH_TOKEN`.
76
-
77
- Codex `config.toml`:
78
-
79
- ```toml
80
- [mcp_servers.gateway]
81
- url = "http://127.0.0.1:3000/mcp"
82
- ```
83
-
84
- Claude Code:
85
-
86
- ```bash
87
- claude mcp add --transport http gateway http://127.0.0.1:3000/mcp
88
- ```
89
-
90
- ## Configuration and Tools
91
-
92
- ### CLI Options
93
-
94
- | Option | Description | Default |
95
- | --- | --- | --- |
96
- | `--config <path>` | Config file path. | `MCP_GATEWAY_CONFIG`, then `./config.json` |
97
- | `--http` | Enables the Streamable HTTP endpoint. | Disabled |
98
- | `--host <host>` | HTTP bind address. | `127.0.0.1` |
99
- | `--port <port>` | HTTP port. | `3000` |
100
- | `--path <path>` | HTTP endpoint path. | `/mcp` |
101
- | `--auth-token-env <name>` | Environment variable containing the HTTP bearer token. | `MCP_GATEWAY_AUTH_TOKEN` |
102
- | `--http-admin-tools` | Exposes `gateway_manage_service` over authenticated HTTP. | Disabled |
103
- | `--max-concurrent-requests <n>` | Bounds in-flight HTTP requests. | `64` |
104
- | `--max-request-body-bytes <n>` | Rejects HTTP request bodies above this byte limit; maximum configurable value is 64 MiB. | `16777216` (16 MiB) |
105
- | `--max-legacy-sessions <n>` | Bounds retained stateful legacy HTTP sessions. | `256` |
106
- | `--version`, `-v` | Prints the installed version. | — |
107
-
108
- Stdio remains available when `--http` is enabled.
109
-
110
- ### Config File
111
-
112
- ```json
113
- {
114
- "logging": {
115
- "enable": false,
116
- "path": "./logs/mcp-gateway.log"
117
- },
118
- "services": [
119
- {
120
- "serviceId": "local-tools",
121
- "name": "Local Tools",
122
- "confirmationRequiredTools": ["delete_*", "deploy_?"],
123
- "disabledTools": ["internal_*", "legacy_tool"],
124
- "transport": {
125
- "type": "stdio",
126
- "command": "your-mcp-service",
127
- "args": []
128
- }
129
- },
130
- {
131
- "serviceId": "remote-tools",
132
- "name": "Remote Tools",
133
- "transport": {
134
- "type": "http",
135
- "url": "http://127.0.0.1:3200/mcp"
136
- }
137
- }
138
- ]
139
- }
140
- ```
141
-
142
- | Field | Description |
143
- | --- | --- |
144
- | `services` | List of downstream MCP services. |
145
- | `serviceId` | Required unique identifier used by gateway tools. |
146
- | `name` | Required display name. |
147
- | `description` | Optional service description. |
148
- | `enable` | Optional; defaults to `true`. |
149
- | `callTimeoutMs` | Optional downstream tool-call timeout; defaults to 120 seconds. |
150
- | `confirmationRequiredTools` | Optional unique array of case-sensitive full-name glob patterns. `*` matches zero or more characters and `?` matches one character. The gateway asks the upstream user for form elicitation confirmation before calling a matching tool. |
151
- | `disabledTools` | Optional unique array using the same glob syntax. Matching tools are hidden from tool listing and schema lookup, and calls are rejected before reaching the downstream service. |
152
- | `transport.type` | `stdio` or `http`. |
153
- | `transport.command` | Required command for a stdio service. |
154
- | `transport.args` | Optional command arguments for a stdio service. |
155
- | `transport.cwd` | Optional working directory for a stdio service. |
156
- | `transport.env` | Optional environment variables for a stdio service. |
157
- | `transport.inheritEnv` | Opts into inheriting the complete gateway environment; defaults to `false`. |
158
- | `transport.envAllowlist` | Additional process environment names passed to stdio services. |
159
- | `transport.url` | Required Streamable HTTP URL for an HTTP service. |
160
- | `transport.headers` | Optional static headers for an HTTP service. |
161
- | `logging.enable` | Enables file logging; defaults to `false`. |
162
- | `logging.path` | Log file path. Relative paths use the config file directory. |
163
- | `logging.maxBytes` | Active log size before rotation; defaults to 10 MiB. |
164
-
165
- The config file is watched for changes. Invalid updates are rejected and the last valid config stays active. See [config.example.json](./config.example.json) for another example.
166
-
167
- ### Gateway Tools
168
-
169
- | Tool | Description |
170
- | --- | --- |
171
- | `gateway_list_services` | Searches enabled services by identifier or description and can filter by availability. |
172
- | `gateway_get_service` | Shows one service's connection state, protocol revision, server identity, and recent error. |
173
- | `gateway_list_tools` | Searches a service's tools by name or description and can include schemas. |
174
- | `gateway_get_tool_schema` | Returns schemas for exact tool names. |
175
- | `gateway_manage_service` | Reconnects a service or enables/disables it in the config file. |
176
- | `gateway_call_tool` | Calls one downstream tool and returns its MCP result. |
177
-
178
- The usual flow is `gateway_list_services` → `gateway_list_tools` → `gateway_get_tool_schema` when needed → `gateway_call_tool`. Pass `{}` to `gateway_call_tool` when the downstream tool has no arguments.
179
-
180
- Calls matching `confirmationRequiredTools` show the service, tool, and arguments and require approval in the current MCP session. Clients without form elicitation support cannot invoke them. Calls with uncertain outcomes are not retried automatically.
181
-
182
- `disabledTools` takes precedence over `confirmationRequiredTools` when both match. A disabled tool is hidden and rejected immediately without asking for confirmation.
183
-
184
- Agents with Skills support can use the included [MCP Gateway Skill](./skills/mcp-gateway/SKILL.md) for the discovery and calling workflow.
185
-
186
- ## Development
187
-
188
- ```bash
189
- git clone https://github.com/jadchene/mcp-gateway.git
190
- cd mcp-gateway
191
- npm install
192
- npm run verify
193
- npm run dev -- --config ./config.json
194
- ```
195
-
196
- Build and run the compiled service:
197
-
198
- ```bash
199
- npm run build
200
- npm start -- --config ./config.json
201
- ```
202
-
203
- ## License
204
-
205
- [MIT](./LICENSE)
1
+ English | [简体中文](./README_zh.md)
2
+
3
+ # MCP Gateway
4
+
5
+ ## Introduction
6
+
7
+ MCP Gateway puts multiple MCP services behind one endpoint. An agent connects to the gateway and sees six routing tools; downstream services, tools, and schemas are looked up only when they are needed.
8
+
9
+ The project uses the official TypeScript SDK v2 and requires Node.js 24 or later.
10
+
11
+ > [!IMPORTANT]
12
+ > MCP Gateway v0.6.2 and later accept only MCP `2026-07-28`, `2025-11-25`, and `2025-06-18`. Supported transports are newline-delimited stdio and single-endpoint Streamable HTTP. Standalone HTTP+SSE (`/sse`), `Content-Length` framing, and other protocol revisions are not supported.
13
+
14
+ ## Why Use It
15
+
16
+ - Keep the agent context small even when many MCP services are configured.
17
+ - Connect the agent once, then add or remove downstream services in the gateway config.
18
+ - Find tools by name or description and load schemas only when required.
19
+ - Use stdio and Streamable HTTP services through the same interface.
20
+ - Require user confirmation for selected tool-name patterns, or hide and block matching tools entirely.
21
+ - Reload config changes without restarting the gateway.
22
+
23
+ ## Quick Start
24
+
25
+ ### Install
26
+
27
+ ```bash
28
+ npm install -g @jadchene/mcp-gateway-service
29
+ ```
30
+
31
+ Create `config.json`. Replace `your-mcp-service` with the command of an installed MCP server:
32
+
33
+ ```json
34
+ {
35
+ "services": [
36
+ {
37
+ "serviceId": "tools",
38
+ "name": "Tools",
39
+ "transport": {
40
+ "type": "stdio",
41
+ "command": "your-mcp-service"
42
+ }
43
+ }
44
+ ]
45
+ }
46
+ ```
47
+
48
+ ### Stdio
49
+
50
+ The agent starts the gateway process, so no separate startup command is needed.
51
+
52
+ Codex `config.toml`:
53
+
54
+ ```toml
55
+ [mcp_servers.gateway]
56
+ command = "mcp-gateway-service"
57
+ args = ["--config", "./config.json"]
58
+ ```
59
+
60
+ Claude Code:
61
+
62
+ ```bash
63
+ claude mcp add gateway -- mcp-gateway-service --config ./config.json
64
+ ```
65
+
66
+ ### Streamable HTTP
67
+
68
+ Start the gateway:
69
+
70
+ ```bash
71
+ mcp-gateway-service --http --config ./config.json
72
+ ```
73
+
74
+ The default endpoint is `http://127.0.0.1:3000/mcp`.
75
+ HTTP hides `gateway_manage_service` by default. Non-loopback binds require a bearer token in `MCP_GATEWAY_AUTH_TOKEN`.
76
+
77
+ Codex `config.toml`:
78
+
79
+ ```toml
80
+ [mcp_servers.gateway]
81
+ url = "http://127.0.0.1:3000/mcp"
82
+ ```
83
+
84
+ Claude Code:
85
+
86
+ ```bash
87
+ claude mcp add --transport http gateway http://127.0.0.1:3000/mcp
88
+ ```
89
+
90
+ ## Configuration and Tools
91
+
92
+ ### CLI Options
93
+
94
+ | Option | Description | Default |
95
+ | --- | --- | --- |
96
+ | `--config <path>` | Config file path. | `MCP_GATEWAY_CONFIG`, then `./config.json` |
97
+ | `--http` | Enables the Streamable HTTP endpoint. | Disabled |
98
+ | `--host <host>` | HTTP bind address. | `127.0.0.1` |
99
+ | `--port <port>` | HTTP port. | `3000` |
100
+ | `--path <path>` | HTTP endpoint path. | `/mcp` |
101
+ | `--auth-token-env <name>` | Environment variable containing the HTTP bearer token. | `MCP_GATEWAY_AUTH_TOKEN` |
102
+ | `--http-admin-tools` | Exposes `gateway_manage_service` over authenticated HTTP. | Disabled |
103
+ | `--max-concurrent-requests <n>` | Bounds in-flight HTTP requests. | `64` |
104
+ | `--max-request-body-bytes <n>` | Rejects HTTP request bodies above this byte limit; maximum configurable value is 64 MiB. | `16777216` (16 MiB) |
105
+ | `--max-legacy-sessions <n>` | Bounds retained stateful legacy HTTP sessions. | `256` |
106
+ | `--version`, `-v` | Prints the installed version. | — |
107
+
108
+ Stdio remains available when `--http` is enabled.
109
+
110
+ ### Config File
111
+
112
+ ```json
113
+ {
114
+ "logging": {
115
+ "enable": false,
116
+ "path": "./logs/mcp-gateway.log"
117
+ },
118
+ "services": [
119
+ {
120
+ "serviceId": "local-tools",
121
+ "name": "Local Tools",
122
+ "confirmationRequiredTools": ["delete_*", "deploy_?"],
123
+ "codexAutoReview": false,
124
+ "disabledTools": ["internal_*", "legacy_tool"],
125
+ "transport": {
126
+ "type": "stdio",
127
+ "command": "your-mcp-service",
128
+ "args": []
129
+ }
130
+ },
131
+ {
132
+ "serviceId": "remote-tools",
133
+ "name": "Remote Tools",
134
+ "transport": {
135
+ "type": "http",
136
+ "url": "http://127.0.0.1:3200/mcp"
137
+ }
138
+ }
139
+ ]
140
+ }
141
+ ```
142
+
143
+ | Field | Description |
144
+ | --- | --- |
145
+ | `services` | List of downstream MCP services. |
146
+ | `serviceId` | Required unique identifier used by gateway tools. |
147
+ | `name` | Required display name. |
148
+ | `description` | Optional service description. |
149
+ | `enable` | Optional; defaults to `true`. |
150
+ | `callTimeoutMs` | Optional downstream tool-call timeout; defaults to 120 seconds. |
151
+ | `confirmationRequiredTools` | Optional unique array of case-sensitive full-name glob patterns. `*` matches zero or more characters and `?` matches one character. The gateway asks the upstream user for form elicitation confirmation before calling a matching tool. |
152
+ | `codexAutoReview` | Optional boolean, defaults to `false`. Set `true` to enable Codex automatic-review metadata for gateway confirmations configured by this service’s `confirmationRequiredTools`. |
153
+ | `disabledTools` | Optional unique array using the same glob syntax. Matching tools are hidden from tool listing and schema lookup, and calls are rejected before reaching the downstream service. |
154
+ | `transport.type` | `stdio` or `http`. |
155
+ | `transport.command` | Required command for a stdio service. |
156
+ | `transport.args` | Optional command arguments for a stdio service. |
157
+ | `transport.cwd` | Optional working directory for a stdio service. |
158
+ | `transport.env` | Optional environment variables for a stdio service. |
159
+ | `transport.inheritEnv` | Opts into inheriting the complete gateway environment; defaults to `false`. |
160
+ | `transport.envAllowlist` | Additional process environment names passed to stdio services. |
161
+ | `transport.url` | Required Streamable HTTP URL for an HTTP service. |
162
+ | `transport.headers` | Optional static headers for an HTTP service. |
163
+ | `logging.enable` | Enables file logging; defaults to `false`. |
164
+ | `logging.path` | Log file path. Relative paths use the config file directory. |
165
+ | `logging.maxBytes` | Active log size before rotation; defaults to 10 MiB. |
166
+
167
+ The config file is watched for changes. Invalid updates are rejected and the last valid config stays active. See [config.example.json](./config.example.json) for another example.
168
+
169
+ ### Gateway Tools
170
+
171
+ | Tool | Description |
172
+ | --- | --- |
173
+ | `gateway_list_services` | Searches enabled services by identifier or description and can filter by availability. |
174
+ | `gateway_get_service` | Shows one service's connection state, protocol revision, server identity, and recent error. |
175
+ | `gateway_list_tools` | Searches a service's tools by name or description and can include schemas. |
176
+ | `gateway_get_tool_schema` | Returns schemas for exact tool names. |
177
+ | `gateway_manage_service` | Reconnects a service or enables/disables it in the config file. |
178
+ | `gateway_call_tool` | Calls one downstream tool and returns its MCP result. |
179
+
180
+ The usual flow is `gateway_list_services` → `gateway_list_tools` → `gateway_get_tool_schema` when needed → `gateway_call_tool`. Pass `{}` to `gateway_call_tool` when the downstream tool has no arguments.
181
+
182
+ Calls matching `confirmationRequiredTools` show the service, tool, and arguments and require approval in the current MCP session. Clients without form elicitation support cannot invoke them. Calls with uncertain outcomes are not retried automatically.
183
+
184
+ Codex automatic-review integration is disabled by default. Set `"codexAutoReview": true` in the selected `services[]` block to enable approval metadata only for gateway confirmations generated by `confirmationRequiredTools`. Downstream confirmation forms and their `_meta` are forwarded unchanged; downstream automatic-review settings operate independently. Codex uses automatic review when `approvals_reviewer = "auto_review"` is enabled; otherwise, use normal Accept / Decline / Cancel confirmation. Approval remains subject to Codex policy.
185
+
186
+ `disabledTools` takes precedence over `confirmationRequiredTools` when both match. A disabled tool is hidden and rejected immediately without asking for confirmation.
187
+
188
+ Agents with Skills support can use the included [MCP Gateway Skill](./skills/mcp-gateway/SKILL.md) for the discovery and calling workflow.
189
+
190
+ ## Development
191
+
192
+ ```bash
193
+ git clone https://github.com/jadchene/mcp-gateway.git
194
+ cd mcp-gateway
195
+ npm install
196
+ npm run verify
197
+ npm run dev -- --config ./config.json
198
+ ```
199
+
200
+ Build and run the compiled service:
201
+
202
+ ```bash
203
+ npm run build
204
+ npm start -- --config ./config.json
205
+ ```
206
+
207
+ ## License
208
+
209
+ [MIT](./LICENSE)
package/README_zh.md CHANGED
@@ -1,205 +1,209 @@
1
- [English](./README.md) | 简体中文
2
-
3
- # MCP Gateway
4
-
5
- ## 简介
6
-
7
- MCP Gateway 把多个 MCP 服务收拢到一个入口。Agent 连接网关后只会看到 6 个路由工具,具体的下游服务、工具和 schema 在需要时再查询。
8
-
9
- 项目使用官方 TypeScript SDK v2,需要 Node.js 24 或更高版本。
10
-
11
- > [!IMPORTANT]
12
- > MCP Gateway v0.6.2 及后续版本仅接受 MCP `2026-07-28`、`2025-11-25` 和 `2025-06-18`。传输方式仅支持换行分隔 stdio 和单端点 Streamable HTTP。不支持独立 HTTP+SSE(`/sse`)、`Content-Length` framing 和其他协议版本。
13
-
14
- ## 为什么使用
15
-
16
- - 即使配置了很多 MCP 服务,也不会一次性占用大量 Agent 上下文。
17
- - Agent 只需接入一次,后续增减下游服务只改网关配置。
18
- - 可以按名称或描述查找工具,需要时再读取 schema。
19
- - Stdio 和 Streamable HTTP 服务使用同一套调用方式。
20
- - 可按工具名模式要求用户确认,或隐藏并禁止调用指定工具。
21
- - 修改配置文件后自动重载,不必重启网关。
22
-
23
- ## 快速开始
24
-
25
- ### 安装
26
-
27
- ```bash
28
- npm install -g @jadchene/mcp-gateway-service
29
- ```
30
-
31
- 创建 `config.json`,将 `your-mcp-service` 替换为已经安装的 MCP 服务命令:
32
-
33
- ```json
34
- {
35
- "services": [
36
- {
37
- "serviceId": "tools",
38
- "name": "Tools",
39
- "transport": {
40
- "type": "stdio",
41
- "command": "your-mcp-service"
42
- }
43
- }
44
- ]
45
- }
46
- ```
47
-
48
- ### Stdio
49
-
50
- 网关进程由 Agent 启动,不需要单独运行启动命令。
51
-
52
- Codex `config.toml`:
53
-
54
- ```toml
55
- [mcp_servers.gateway]
56
- command = "mcp-gateway-service"
57
- args = ["--config", "./config.json"]
58
- ```
59
-
60
- Claude Code:
61
-
62
- ```bash
63
- claude mcp add gateway -- mcp-gateway-service --config ./config.json
64
- ```
65
-
66
- ### Streamable HTTP
67
-
68
- 启动网关:
69
-
70
- ```bash
71
- mcp-gateway-service --http --config ./config.json
72
- ```
73
-
74
- 默认地址为 `http://127.0.0.1:3000/mcp`。
75
- HTTP 默认隐藏 `gateway_manage_service`。监听非回环地址时,必须通过 `MCP_GATEWAY_AUTH_TOKEN` 配置 Bearer Token。
76
-
77
- Codex `config.toml`:
78
-
79
- ```toml
80
- [mcp_servers.gateway]
81
- url = "http://127.0.0.1:3000/mcp"
82
- ```
83
-
84
- Claude Code:
85
-
86
- ```bash
87
- claude mcp add --transport http gateway http://127.0.0.1:3000/mcp
88
- ```
89
-
90
- ## 配置与工具
91
-
92
- ### 启动参数
93
-
94
- | 参数 | 说明 | 默认值 |
95
- | --- | --- | --- |
96
- | `--config <path>` | 配置文件路径。 | `MCP_GATEWAY_CONFIG`,其次为 `./config.json` |
97
- | `--http` | 启用 Streamable HTTP。 | 不启用 |
98
- | `--host <host>` | HTTP 监听地址。 | `127.0.0.1` |
99
- | `--port <port>` | HTTP 监听端口。 | `3000` |
100
- | `--path <path>` | HTTP endpoint 路径。 | `/mcp` |
101
- | `--auth-token-env <名称>` | 保存 HTTP Bearer Token 的环境变量名。 | `MCP_GATEWAY_AUTH_TOKEN` |
102
- | `--http-admin-tools` | 在已认证 HTTP 入口暴露 `gateway_manage_service`。 | 不启用 |
103
- | `--max-concurrent-requests <数量>` | HTTP 并发请求上限。 | `64` |
104
- | `--max-request-body-bytes <字节数>` | HTTP 请求体字节上限,最大可配置为 64 MiB,超限返回 `413`。 | `16777216`(16 MiB) |
105
- | `--max-legacy-sessions <数量>` | 有状态旧版 HTTP 会话的保留上限。 | `256` |
106
- | `--version`、`-v` | 输出已安装版本。 | — |
107
-
108
- 启用 `--http` 后,stdio 入口仍然可用。
109
-
110
- ### 配置文件
111
-
112
- ```json
113
- {
114
- "logging": {
115
- "enable": false,
116
- "path": "./logs/mcp-gateway.log"
117
- },
118
- "services": [
119
- {
120
- "serviceId": "local-tools",
121
- "name": "Local Tools",
122
- "confirmationRequiredTools": ["delete_*", "deploy_?"],
123
- "disabledTools": ["internal_*", "legacy_tool"],
124
- "transport": {
125
- "type": "stdio",
126
- "command": "your-mcp-service",
127
- "args": []
128
- }
129
- },
130
- {
131
- "serviceId": "remote-tools",
132
- "name": "Remote Tools",
133
- "transport": {
134
- "type": "http",
135
- "url": "http://127.0.0.1:3200/mcp"
136
- }
137
- }
138
- ]
139
- }
140
- ```
141
-
142
- | 字段 | 说明 |
143
- | --- | --- |
144
- | `services` | 下游 MCP 服务列表。 |
145
- | `serviceId` | 必填,网关工具使用的唯一服务标识。 |
146
- | `name` | 必填,服务名称。 |
147
- | `description` | 可选,服务说明。 |
148
- | `enable` | 可选,默认为 `true`。 |
149
- | `callTimeoutMs` | 可选,下游工具调用超时;默认 120 秒。 |
150
- | `confirmationRequiredTools` | 可选,填写区分大小写的完整工具名 glob 模式;`*` 匹配零个或多个字符,`?` 匹配一个字符。数组项必须唯一且非空,网关在调用匹配的工具前会向上游用户发起表单 elicitation。 |
151
- | `disabledTools` | 可选,使用相同 glob 语法。匹配的工具不会出现在工具列表和 schema 查询中,调用也会在到达下游服务前被拒绝。 |
152
- | `transport.type` | `stdio` 或 `http`。 |
153
- | `transport.command` | stdio 服务必填,启动命令。 |
154
- | `transport.args` | stdio 服务的可选命令参数。 |
155
- | `transport.cwd` | stdio 服务的可选工作目录。 |
156
- | `transport.env` | stdio 服务的可选环境变量。 |
157
- | `transport.inheritEnv` | 是否继承网关完整环境;默认为 `false`。 |
158
- | `transport.envAllowlist` | 额外传递给 stdio 服务的进程环境变量名。 |
159
- | `transport.url` | HTTP 服务必填,Streamable HTTP 地址。 |
160
- | `transport.headers` | HTTP 服务的可选静态请求头。 |
161
- | `logging.enable` | 是否写入文件日志,默认为 `false`。 |
162
- | `logging.path` | 日志文件路径;相对路径按配置文件目录解析。 |
163
- | `logging.maxBytes` | 当前日志轮转前的大小上限;默认 10 MiB。 |
164
-
165
- 网关会监听配置文件变化。配置有误时不会替换当前配置,服务继续按最后一次有效配置运行。其他示例见 [config.example.json](./config.example.json)。
166
-
167
- ### 网关工具
168
-
169
- | 工具 | 说明 |
170
- | --- | --- |
171
- | `gateway_list_services` | 按服务标识或描述搜索已启用服务,并可按可用状态筛选。 |
172
- | `gateway_get_service` | 查看服务连接状态、协议版本、服务端信息和最近一次错误。 |
173
- | `gateway_list_tools` | 按名称或描述搜索服务中的工具,可同时返回 schema。 |
174
- | `gateway_get_tool_schema` | 获取准确工具名称对应的 schema。 |
175
- | `gateway_manage_service` | 重连服务,或在配置文件中启用、禁用服务。 |
176
- | `gateway_call_tool` | 调用一个下游工具并返回 MCP 结果。 |
177
-
178
- 通常按 `gateway_list_services` → `gateway_list_tools` → 按需调用 `gateway_get_tool_schema` → `gateway_call_tool` 的顺序使用。下游工具没有参数时,`gateway_call_tool` 的 `arguments` 传 `{}`。
179
-
180
- 匹配 `confirmationRequiredTools` 的调用会展示服务、工具和参数,须由当前 MCP 会话确认后才执行;不支持表单确认的客户端无法调用。状态不确定的失败调用不会自动重试。
181
-
182
- 当一个工具同时匹配 `disabledTools` 和 `confirmationRequiredTools` 时,`disabledTools` 优先:工具会被隐藏并直接拒绝,不会发起确认。
183
-
184
- 支持 Skills 的 Agent 可以使用仓库内置的 [MCP Gateway Skill](./skills/mcp-gateway/SKILL.md) 完成工具发现和调用。
185
-
186
- ## 开发
187
-
188
- ```bash
189
- git clone https://github.com/jadchene/mcp-gateway.git
190
- cd mcp-gateway
191
- npm install
192
- npm run verify
193
- npm run dev -- --config ./config.json
194
- ```
195
-
196
- 构建并运行编译产物:
197
-
198
- ```bash
199
- npm run build
200
- npm start -- --config ./config.json
201
- ```
202
-
203
- ## 版权声明
204
-
205
- [MIT](./LICENSE)
1
+ [English](./README.md) | 简体中文
2
+
3
+ # MCP Gateway
4
+
5
+ ## 简介
6
+
7
+ MCP Gateway 把多个 MCP 服务收拢到一个入口。Agent 连接网关后只会看到 6 个路由工具,具体的下游服务、工具和 schema 在需要时再查询。
8
+
9
+ 项目使用官方 TypeScript SDK v2,需要 Node.js 24 或更高版本。
10
+
11
+ > [!IMPORTANT]
12
+ > MCP Gateway v0.6.2 及后续版本仅接受 MCP `2026-07-28`、`2025-11-25` 和 `2025-06-18`。传输方式仅支持换行分隔 stdio 和单端点 Streamable HTTP。不支持独立 HTTP+SSE(`/sse`)、`Content-Length` framing 和其他协议版本。
13
+
14
+ ## 为什么使用
15
+
16
+ - 即使配置了很多 MCP 服务,也不会一次性占用大量 Agent 上下文。
17
+ - Agent 只需接入一次,后续增减下游服务只改网关配置。
18
+ - 可以按名称或描述查找工具,需要时再读取 schema。
19
+ - Stdio 和 Streamable HTTP 服务使用同一套调用方式。
20
+ - 可按工具名模式要求用户确认,或隐藏并禁止调用指定工具。
21
+ - 修改配置文件后自动重载,不必重启网关。
22
+
23
+ ## 快速开始
24
+
25
+ ### 安装
26
+
27
+ ```bash
28
+ npm install -g @jadchene/mcp-gateway-service
29
+ ```
30
+
31
+ 创建 `config.json`,将 `your-mcp-service` 替换为已经安装的 MCP 服务命令:
32
+
33
+ ```json
34
+ {
35
+ "services": [
36
+ {
37
+ "serviceId": "tools",
38
+ "name": "Tools",
39
+ "transport": {
40
+ "type": "stdio",
41
+ "command": "your-mcp-service"
42
+ }
43
+ }
44
+ ]
45
+ }
46
+ ```
47
+
48
+ ### Stdio
49
+
50
+ 网关进程由 Agent 启动,不需要单独运行启动命令。
51
+
52
+ Codex `config.toml`:
53
+
54
+ ```toml
55
+ [mcp_servers.gateway]
56
+ command = "mcp-gateway-service"
57
+ args = ["--config", "./config.json"]
58
+ ```
59
+
60
+ Claude Code:
61
+
62
+ ```bash
63
+ claude mcp add gateway -- mcp-gateway-service --config ./config.json
64
+ ```
65
+
66
+ ### Streamable HTTP
67
+
68
+ 启动网关:
69
+
70
+ ```bash
71
+ mcp-gateway-service --http --config ./config.json
72
+ ```
73
+
74
+ 默认地址为 `http://127.0.0.1:3000/mcp`。
75
+ HTTP 默认隐藏 `gateway_manage_service`。监听非回环地址时,必须通过 `MCP_GATEWAY_AUTH_TOKEN` 配置 Bearer Token。
76
+
77
+ Codex `config.toml`:
78
+
79
+ ```toml
80
+ [mcp_servers.gateway]
81
+ url = "http://127.0.0.1:3000/mcp"
82
+ ```
83
+
84
+ Claude Code:
85
+
86
+ ```bash
87
+ claude mcp add --transport http gateway http://127.0.0.1:3000/mcp
88
+ ```
89
+
90
+ ## 配置与工具
91
+
92
+ ### 启动参数
93
+
94
+ | 参数 | 说明 | 默认值 |
95
+ | --- | --- | --- |
96
+ | `--config <path>` | 配置文件路径。 | `MCP_GATEWAY_CONFIG`,其次为 `./config.json` |
97
+ | `--http` | 启用 Streamable HTTP。 | 不启用 |
98
+ | `--host <host>` | HTTP 监听地址。 | `127.0.0.1` |
99
+ | `--port <port>` | HTTP 监听端口。 | `3000` |
100
+ | `--path <path>` | HTTP endpoint 路径。 | `/mcp` |
101
+ | `--auth-token-env <名称>` | 保存 HTTP Bearer Token 的环境变量名。 | `MCP_GATEWAY_AUTH_TOKEN` |
102
+ | `--http-admin-tools` | 在已认证 HTTP 入口暴露 `gateway_manage_service`。 | 不启用 |
103
+ | `--max-concurrent-requests <数量>` | HTTP 并发请求上限。 | `64` |
104
+ | `--max-request-body-bytes <字节数>` | HTTP 请求体字节上限,最大可配置为 64 MiB,超限返回 `413`。 | `16777216`(16 MiB) |
105
+ | `--max-legacy-sessions <数量>` | 有状态旧版 HTTP 会话的保留上限。 | `256` |
106
+ | `--version`、`-v` | 输出已安装版本。 | — |
107
+
108
+ 启用 `--http` 后,stdio 入口仍然可用。
109
+
110
+ ### 配置文件
111
+
112
+ ```json
113
+ {
114
+ "logging": {
115
+ "enable": false,
116
+ "path": "./logs/mcp-gateway.log"
117
+ },
118
+ "services": [
119
+ {
120
+ "serviceId": "local-tools",
121
+ "name": "Local Tools",
122
+ "confirmationRequiredTools": ["delete_*", "deploy_?"],
123
+ "codexAutoReview": false,
124
+ "disabledTools": ["internal_*", "legacy_tool"],
125
+ "transport": {
126
+ "type": "stdio",
127
+ "command": "your-mcp-service",
128
+ "args": []
129
+ }
130
+ },
131
+ {
132
+ "serviceId": "remote-tools",
133
+ "name": "Remote Tools",
134
+ "transport": {
135
+ "type": "http",
136
+ "url": "http://127.0.0.1:3200/mcp"
137
+ }
138
+ }
139
+ ]
140
+ }
141
+ ```
142
+
143
+ | 字段 | 说明 |
144
+ | --- | --- |
145
+ | `services` | 下游 MCP 服务列表。 |
146
+ | `serviceId` | 必填,网关工具使用的唯一服务标识。 |
147
+ | `name` | 必填,服务名称。 |
148
+ | `description` | 可选,服务说明。 |
149
+ | `enable` | 可选,默认为 `true`。 |
150
+ | `callTimeoutMs` | 可选,下游工具调用超时;默认 120 秒。 |
151
+ | `confirmationRequiredTools` | 可选,填写区分大小写的完整工具名 glob 模式;`*` 匹配零个或多个字符,`?` 匹配一个字符。数组项必须唯一且非空,网关在调用匹配的工具前会向上游用户发起表单 elicitation。 |
152
+ | `codexAutoReview` | 可选 boolean,默认 `false`;设为 `true` 仅启用该服务的 `confirmationRequiredTools` 触发的网关自定义确认的 Codex 自动审批元数据。 |
153
+ | `disabledTools` | 可选,使用相同 glob 语法。匹配的工具不会出现在工具列表和 schema 查询中,调用也会在到达下游服务前被拒绝。 |
154
+ | `transport.type` | `stdio` 或 `http`。 |
155
+ | `transport.command` | stdio 服务必填,启动命令。 |
156
+ | `transport.args` | stdio 服务的可选命令参数。 |
157
+ | `transport.cwd` | stdio 服务的可选工作目录。 |
158
+ | `transport.env` | stdio 服务的可选环境变量。 |
159
+ | `transport.inheritEnv` | 是否继承网关完整环境;默认为 `false`。 |
160
+ | `transport.envAllowlist` | 额外传递给 stdio 服务的进程环境变量名。 |
161
+ | `transport.url` | HTTP 服务必填,Streamable HTTP 地址。 |
162
+ | `transport.headers` | HTTP 服务的可选静态请求头。 |
163
+ | `logging.enable` | 是否写入文件日志,默认为 `false`。 |
164
+ | `logging.path` | 日志文件路径;相对路径按配置文件目录解析。 |
165
+ | `logging.maxBytes` | 当前日志轮转前的大小上限;默认 10 MiB。 |
166
+
167
+ 网关会监听配置文件变化。配置有误时不会替换当前配置,服务继续按最后一次有效配置运行。其他示例见 [config.example.json](./config.example.json)。
168
+
169
+ ### 网关工具
170
+
171
+ | 工具 | 说明 |
172
+ | --- | --- |
173
+ | `gateway_list_services` | 按服务标识或描述搜索已启用服务,并可按可用状态筛选。 |
174
+ | `gateway_get_service` | 查看服务连接状态、协议版本、服务端信息和最近一次错误。 |
175
+ | `gateway_list_tools` | 按名称或描述搜索服务中的工具,可同时返回 schema。 |
176
+ | `gateway_get_tool_schema` | 获取准确工具名称对应的 schema。 |
177
+ | `gateway_manage_service` | 重连服务,或在配置文件中启用、禁用服务。 |
178
+ | `gateway_call_tool` | 调用一个下游工具并返回 MCP 结果。 |
179
+
180
+ 通常按 `gateway_list_services` → `gateway_list_tools` → 按需调用 `gateway_get_tool_schema` → `gateway_call_tool` 的顺序使用。下游工具没有参数时,`gateway_call_tool` 的 `arguments` 传 `{}`。
181
+
182
+ 匹配 `confirmationRequiredTools` 的调用会展示服务、工具和参数,须由当前 MCP 会话确认后才执行;不支持表单确认的客户端无法调用。状态不确定的失败调用不会自动重试。
183
+
184
+ Codex 自动审批扩展默认禁用;在指定服务的 `services[]` 配置块中显式设置 `"codexAutoReview": true`,仅为 `confirmationRequiredTools` 触发的网关自定义确认添加审批元数据。下游确认表单及其 `_meta` 原样透传,下游自动审批配置独立生效。Codex 开启 `approvals_reviewer = "auto_review"` 时自动审查,否则使用正常的 Accept / Decline / Cancel 确认;审批结果仍由 Codex 策略决定。
185
+
186
+ 当一个工具同时匹配 `disabledTools` 和 `confirmationRequiredTools` 时,`disabledTools` 优先:工具会被隐藏并直接拒绝,不会发起确认。
187
+
188
+ 支持 Skills 的 Agent 可以使用仓库内置的 [MCP Gateway Skill](./skills/mcp-gateway/SKILL.md) 完成工具发现和调用。
189
+
190
+ ## 开发
191
+
192
+ ```bash
193
+ git clone https://github.com/jadchene/mcp-gateway.git
194
+ cd mcp-gateway
195
+ npm install
196
+ npm run verify
197
+ npm run dev -- --config ./config.json
198
+ ```
199
+
200
+ 构建并运行编译产物:
201
+
202
+ ```bash
203
+ npm run build
204
+ npm start -- --config ./config.json
205
+ ```
206
+
207
+ ## 版权声明
208
+
209
+ [MIT](./LICENSE)
@@ -1,45 +1,47 @@
1
- {
2
- "logging": {
3
- "enable": false,
4
- "path": "./logs/mcp-gateway.log",
5
- "maxBytes": 10485760
6
- },
7
- "services": [
8
- {
9
- "serviceId": "demo-echo",
10
- "enable": false,
11
- "name": "Demo Echo Service",
12
- "description": "Sample echo MCP service.",
13
- "callTimeoutMs": 120000,
14
- "confirmationRequiredTools": [
15
- "echo*"
16
- ],
17
- "disabledTools": [
18
- "echo_debug*"
19
- ],
20
- "transport": {
21
- "type": "stdio",
22
- "command": "node",
23
- "args": [
24
- "--experimental-strip-types",
25
- "examples/echo-service.ts"
26
- ],
27
- "inheritEnv": false,
28
- "envAllowlist": []
29
- }
30
- },
31
- {
32
- "serviceId": "remote-http",
33
- "enable": false,
34
- "name": "Remote Streamable HTTP Service",
35
- "description": "Example downstream MCP service over Streamable HTTP.",
36
- "transport": {
37
- "type": "http",
38
- "url": "http://127.0.0.1:3200/mcp",
39
- "headers": {
40
- "Authorization": "Bearer example-token"
41
- }
42
- }
43
- }
44
- ]
45
- }
1
+ {
2
+ "logging": {
3
+ "enable": false,
4
+ "path": "./logs/mcp-gateway.log",
5
+ "maxBytes": 10485760
6
+ },
7
+ "services": [
8
+ {
9
+ "serviceId": "demo-echo",
10
+ "enable": false,
11
+ "name": "Demo Echo Service",
12
+ "description": "Sample echo MCP service.",
13
+ "callTimeoutMs": 120000,
14
+ "confirmationRequiredTools": [
15
+ "echo*"
16
+ ],
17
+ "disabledTools": [
18
+ "echo_debug*"
19
+ ],
20
+ "transport": {
21
+ "type": "stdio",
22
+ "command": "node",
23
+ "args": [
24
+ "--experimental-strip-types",
25
+ "examples/echo-service.ts"
26
+ ],
27
+ "inheritEnv": false,
28
+ "envAllowlist": []
29
+ },
30
+ "codexAutoReview": false
31
+ },
32
+ {
33
+ "serviceId": "remote-http",
34
+ "enable": false,
35
+ "name": "Remote Streamable HTTP Service",
36
+ "description": "Example downstream MCP service over Streamable HTTP.",
37
+ "transport": {
38
+ "type": "http",
39
+ "url": "http://127.0.0.1:3200/mcp",
40
+ "headers": {
41
+ "Authorization": "Bearer example-token"
42
+ }
43
+ },
44
+ "codexAutoReview": false
45
+ }
46
+ ]
47
+ }
package/dist/config.js CHANGED
@@ -85,6 +85,7 @@ function validateServiceConfig(input) {
85
85
  }
86
86
  const serviceId = requireNonEmptyString(input.serviceId, "service.serviceId");
87
87
  const enable = optionalBoolean(input.enable, `service '${serviceId}' enable`) ?? true;
88
+ const codexAutoReview = optionalBoolean(input.codexAutoReview, `service '${serviceId}' codexAutoReview`) ?? false;
88
89
  const name = requireNonEmptyString(input.name, `service '${serviceId}' name`);
89
90
  const description = optionalString(input.description, `service '${serviceId}' description`);
90
91
  const callTimeoutMs = optionalInteger(input.callTimeoutMs, `service '${serviceId}' callTimeoutMs`, 1, 24 * 60 * 60 * 1000);
@@ -93,6 +94,7 @@ function validateServiceConfig(input) {
93
94
  return {
94
95
  serviceId,
95
96
  enable,
97
+ codexAutoReview,
96
98
  name,
97
99
  description,
98
100
  transport: validateTransportConfig(serviceId, input.transport),
@@ -1,4 +1,5 @@
1
1
  import { ToolConfirmationInterceptor } from "./mcp/tool-confirmation.js";
2
+ import { withCodexApprovalMeta } from "./mcp/codex-approval.js";
2
3
  import { matchesAnyToolNamePattern } from "./tool-name-pattern.js";
3
4
  /**
4
5
  * Handles MCP JSON-RPC requests independently of the outer transport.
@@ -156,7 +157,7 @@ export class McpGatewayEngine {
156
157
  }
157
158
  if (this.toolConfirmation.handlesState(context.requestState)
158
159
  || matchesAnyToolNamePattern(toolName, snapshot?.config.confirmationRequiredTools)) {
159
- return this.toolConfirmation.execute(serviceId, toolName, toolArgs, context, invoke);
160
+ return this.toolConfirmation.execute(serviceId, toolName, toolArgs, context, invoke, (params) => withCodexApprovalMeta(params, context.clientInfo, toolName, toolArgs, serviceId, snapshot?.config.name, snapshot?.config.codexAutoReview === true));
160
161
  }
161
162
  return invoke(context);
162
163
  }
@@ -240,7 +241,7 @@ export function buildGatewayTools(options = {}) {
240
241
  },
241
242
  {
242
243
  name: "gateway_call_tool",
243
- description: "Calls one downstream tool and forwards its result. Side effects and confirmation requirements depend on that tool.",
244
+ description: "Calls one downstream tool and forwards its result.",
244
245
  inputSchema: objectSchema(["serviceId", "toolName", "arguments"], {
245
246
  serviceId: stringSchema("Exact, case-sensitive service ID from gateway_list_services."),
246
247
  toolName: stringSchema("Exact, case-sensitive tool name from gateway_list_tools."),
@@ -0,0 +1,44 @@
1
+ /**
2
+ * 按 Codex 0.160.0 的私有约定构造审批元数据,不改变服务端权限校验。
3
+ * @author chenjd
4
+ * @created 2026-10-02 22:15:29
5
+ */
6
+ export function buildCodexApprovalMeta(clientInfo, toolName, toolParams, description, sensitive = false) {
7
+ if (typeof clientInfo !== "object" || clientInfo === null || Array.isArray(clientInfo)) {
8
+ return undefined;
9
+ }
10
+ const name = clientInfo.name;
11
+ if (typeof name !== "string" || !/^codex(?:$|[-_])/i.test(name.trim())) {
12
+ return undefined;
13
+ }
14
+ return {
15
+ codex_request_type: "approval_request",
16
+ codex_approval_kind: "mcp_tool_call",
17
+ codex_strict_auto_review: true,
18
+ ...(sensitive ? { codex_sensitive_action: true } : {}),
19
+ tool_name: toolName,
20
+ tool_description: description,
21
+ tool_params: structuredClone(toolParams)
22
+ };
23
+ }
24
+ /** 仅为网关自行生成的空确认表单添加 Codex 扩展。 */
25
+ export function withCodexApprovalMeta(params, clientInfo, toolName, toolParams, serviceId, serviceName, enabled = false) {
26
+ const existing = params._meta ?? {};
27
+ if (!enabled || Object.keys(params.requestedSchema.properties).length > 0
28
+ || existing.codex_requires_user_input === true
29
+ || (existing.codex_approval_kind !== undefined && existing.codex_approval_kind !== "mcp_tool_call")) {
30
+ return params;
31
+ }
32
+ // 网关要求显式确认的调用统一同步审查,避免未知工具提前执行。
33
+ const approvalMeta = buildCodexApprovalMeta(clientInfo, toolName, toolParams, params.message, true);
34
+ if (!approvalMeta)
35
+ return params;
36
+ const meta = {
37
+ ...existing,
38
+ ...approvalMeta,
39
+ connector_id: serviceId,
40
+ connector_name: serviceName ?? serviceId
41
+ };
42
+ delete meta.persist;
43
+ return { ...params, _meta: meta };
44
+ }
@@ -1,4 +1,4 @@
1
- import { Client, ProtocolError, SdkHttpError } from "@modelcontextprotocol/client";
1
+ import { Client, CLIENT_INFO_META_KEY, ProtocolError, SdkHttpError } from "@modelcontextprotocol/client";
2
2
  import { VERSION } from "../version.js";
3
3
  import { FormElicitationBridge } from "./form-elicitation-bridge.js";
4
4
  import { SUPPORTED_MCP_PROTOCOL_VERSIONS } from "./versions.js";
@@ -117,6 +117,8 @@ export class SdkMcpClient {
117
117
  const params = {
118
118
  name,
119
119
  arguments: args,
120
+ // 将原始客户端身份随调用传递,由下游自行选择元数据格式。
121
+ ...(context.clientInfo ? { _meta: { [CLIENT_INFO_META_KEY]: structuredClone(context.clientInfo) } } : {}),
120
122
  ...(context.inputResponses ? { inputResponses: context.inputResponses } : {}),
121
123
  ...(context.requestState ? { requestState: context.requestState } : {})
122
124
  };
@@ -1,4 +1,4 @@
1
- import { CLIENT_CAPABILITIES_META_KEY, McpServer, fromJsonSchema } from "@modelcontextprotocol/server";
1
+ import { CLIENT_CAPABILITIES_META_KEY, CLIENT_INFO_META_KEY, McpServer, fromJsonSchema } from "@modelcontextprotocol/server";
2
2
  import { buildGatewayTools } from "../gateway-engine.js";
3
3
  import { VERSION } from "../version.js";
4
4
  import { SUPPORTED_MCP_PROTOCOL_VERSIONS } from "./versions.js";
@@ -39,7 +39,7 @@ export function createGatewayMcpServer(engine, options = {}) {
39
39
  inputSchema,
40
40
  ...(outputSchema ? { outputSchema } : {})
41
41
  }, async (args, context) => {
42
- const downstreamContext = toDownstreamContext(context, server.server.getClientCapabilities());
42
+ const downstreamContext = toDownstreamContext(context, server.server.getClientCapabilities(), server.server.getClientVersion());
43
43
  return engine.executeTool(tool.name, args, downstreamContext);
44
44
  });
45
45
  }
@@ -48,9 +48,13 @@ export function createGatewayMcpServer(engine, options = {}) {
48
48
  /**
49
49
  * Extracts request-scoped MRTR, capability, and cancellation state for the downstream call.
50
50
  */
51
- function toDownstreamContext(context, mcp2025ClientCapabilities) {
51
+ function toDownstreamContext(context, mcp2025ClientCapabilities, mcp2025ClientInfo) {
52
52
  const envelope = context.mcpReq.envelope;
53
53
  const envelopeCapabilities = envelope?.[CLIENT_CAPABILITIES_META_KEY];
54
+ const envelopeClientInfo = envelope?.[CLIENT_INFO_META_KEY];
55
+ const clientInfo = context.mcpReq.envelope
56
+ ? (isRecord(envelopeClientInfo) ? envelopeClientInfo : undefined)
57
+ : mcp2025ClientInfo;
54
58
  const clientCapabilities = isRecord(envelopeCapabilities)
55
59
  ? envelopeCapabilities
56
60
  : mcp2025ClientCapabilities;
@@ -60,6 +64,7 @@ function toDownstreamContext(context, mcp2025ClientCapabilities) {
60
64
  return {
61
65
  signal: context.mcpReq.signal,
62
66
  ...(clientCapabilities ? { clientCapabilities } : {}),
67
+ ...(clientInfo ? { clientInfo } : {}),
63
68
  ...(context.mcpReq.inputResponses ? { inputResponses: context.mcpReq.inputResponses } : {}),
64
69
  ...(context.mcpReq.requestState() ? { requestState: context.mcpReq.requestState() } : {}),
65
70
  ...(!context.mcpReq.envelope
@@ -31,7 +31,7 @@ export class ToolConfirmationInterceptor {
31
31
  /**
32
32
  * Confirms a fresh invocation or resumes a previously approved downstream round.
33
33
  */
34
- async execute(serviceId, toolName, args, context, invoke) {
34
+ async execute(serviceId, toolName, args, context, invoke, decorateConfirmation) {
35
35
  const requestState = context.requestState;
36
36
  if (requestState?.startsWith(APPROVED_STATE_PREFIX)) {
37
37
  const approved = this.consumeState(this.approvedContinuations, requestState, serviceId, toolName, args);
@@ -54,7 +54,7 @@ export class ToolConfirmationInterceptor {
54
54
  }
55
55
  const state = this.createState(serviceId, toolName, args);
56
56
  this.pending.set(state.requestState, state);
57
- return buildConfirmationRequest(state);
57
+ return buildConfirmationRequest(state, decorateConfirmation);
58
58
  }
59
59
  /**
60
60
  * Consumes the upstream answer before invoking the downstream tool.
@@ -137,29 +137,18 @@ export class ToolConfirmationInterceptor {
137
137
  /**
138
138
  * Creates the modern continuation result; the SDK bridges it for legacy clients.
139
139
  */
140
- function buildConfirmationRequest(state) {
140
+ function buildConfirmationRequest(state, decorateConfirmation) {
141
+ const params = {
142
+ mode: "form",
143
+ message: buildConfirmationMessage(state),
144
+ requestedSchema: { type: "object", properties: {}, additionalProperties: false }
145
+ };
141
146
  return {
142
147
  resultType: "input_required",
143
148
  inputRequests: {
144
149
  [CONFIRMATION_RESPONSE_KEY]: {
145
150
  method: "elicitation/create",
146
- params: {
147
- mode: "form",
148
- message: buildConfirmationMessage(state),
149
- requestedSchema: {
150
- type: "object",
151
- properties: {
152
- decision: {
153
- type: "string",
154
- title: "Run this tool call?",
155
- description: "Choose yes to execute the displayed call or no to reject it.",
156
- enum: ["yes", "no"]
157
- }
158
- },
159
- required: ["decision"],
160
- additionalProperties: false
161
- }
162
- }
151
+ params: decorateConfirmation ? decorateConfirmation(params) : params
163
152
  }
164
153
  },
165
154
  requestState: state.requestState
@@ -176,7 +165,7 @@ function buildConfirmationMessage(state) {
176
165
  "Risk: Gateway policy requires explicit confirmation.",
177
166
  "Arguments:",
178
167
  JSON.stringify(state.args, null, 2),
179
- "Choose yes to execute it or no to reject it."
168
+ "Accept to execute this exact call; decline or cancel to leave it unexecuted."
180
169
  ].join("\n");
181
170
  }
182
171
  /**
@@ -187,12 +176,10 @@ function supportsFormElicitation(capabilities) {
187
176
  return isRecord(elicitation) && isRecord(elicitation.form);
188
177
  }
189
178
  /**
190
- * Treats cancel, decline, malformed content, and a no decision as refusal.
179
+ * 仅在用户接受确认请求时执行;拒绝、取消或缺少响应均不执行。
191
180
  */
192
181
  function isConfirmed(response) {
193
- return response?.action === "accept"
194
- && isRecord(response.content)
195
- && response.content.decision === "yes";
182
+ return response?.action === "accept";
196
183
  }
197
184
  /**
198
185
  * Removes the gateway's private confirmation continuation before the first call.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jadchene/mcp-gateway-service",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
4
4
  "description": "A token-efficient MCP gateway that provides one unified entry point for multiple downstream MCP services.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -23,4 +23,4 @@ Use the gateway as the single entry point for downstream MCP services.
23
23
  ## Safety
24
24
 
25
25
  - Treat gateway failures and structured downstream error results as failures.
26
- - Never auto-approve an `input_required` result. Obtain the requested user input and retry with the returned opaque state and matching responses.
26
+ - Resume an `input_required` result with the returned opaque state and matching input responses.