Skip to content

Commit f1aedc3

Browse files
committed
feat: Add Streamable HTTP support, update Admin UI, and refactor config
This commit introduces several significant updates: 1. **Streamable HTTP Transport:** * The proxy server now supports connecting to backend MCP servers удовольствие Streamable HTTP transport (`type: "http"` in `mcp_server.json`). * A new `/mcp` endpoint has been added to the proxy server itself to expose aggregated services via Streamable HTTP. 2. **Configuration Changes (IMPORTANT):** * **`mcp_server.json` now requires a `type` field** for each server configuration (`"stdio"`, `"sse"`, or `"http"`). Users upgrading MUST update their `mcp_server.json` to include this field for existing server entries. * Environment variables for client authentication to the proxy's HTTP endpoints have been renamed: * `MCP_PROXY_SSE_ALLOWED_KEYS` is now `ALLOWED_KEYS` * `MCP_PROXY_SSE_ALLOWED_TOKENS` is now `ALLOWED_TOKENS` * Users MUST update their environment variables if they were using the old names. 3. **Admin Web UI Enhancements:** * The UI now supports configuring all three server types (Stdio, SSE, HTTP). * "Add HTTP Server" button functionality is integrated. * The "Parse From Config" feature will default `type` to "sse" if a URL is present and `type` is missing, for smoother transitions. 4. **Logging and Startup Improvements:** * `SESSION_SECRET` handling is more robust: if not set or default, a new secret is generated and saved to `config/.session_secret` with a notification, rather than just a warning. * Startup logs now clearly display the `/sse` and `/mcp` endpoint URLs, along with guidance on using API keys if configured. **Action Required by Users:** * **Update `mcp_server.json`**: Add the `type` field (`"stdio"`, `"sse"`, or `"http"`) to all existing server entries. * **Update Environment Variables**: Rename `MCP_PROXY_SSE_ALLOWED_KEYS` to `ALLOWED_KEYS` and `MCP_PROXY_SSE_ALLOWED_TOKENS` to `ALLOWED_TOKENS` in your environment setup. * It is recommended to review and potentially reset/recreate `config/mcp_server.json` and `config/tool_config.json` if upgrading from a much older version to ensure compatibility with the new structures and UI functionalities.
1 parent 47533f5 commit f1aedc3

File tree

8 files changed

+440
-202
lines changed

8 files changed

+440
-202
lines changed

README.md

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
This server acts as a central hub for Model Context Protocol (MCP) resource servers. It can:
1616

17-
- Connect to and manage multiple backend MCP servers (both Stdio and SSE types).
18-
- Expose their combined capabilities (tools, resources) through a single, unified SSE interface **or** act as a single Stdio-based MCP server itself.
17+
- Connect to and manage multiple backend MCP servers (Stdio, SSE, and Streamable HTTP types).
18+
- Expose their combined capabilities (tools, resources) through a single, unified SSE interface, a Streamable HTTP interface, **or** act as a single Stdio-based MCP server itself.
1919
- Handle routing of requests to the appropriate backend servers.
2020
- Aggregate responses if needed (though primarily acts as a proxy).
2121
- Support multiple simultaneous SSE client connections with optional API key authentication.
@@ -30,7 +30,7 @@ This server acts as a central hub for Model Context Protocol (MCP) resource serv
3030

3131
### ✨ Optional Web Admin UI (`ENABLE_ADMIN_UI=true`)
3232
Provides a browser-based interface for managing the proxy server configuration and connected tools. Features include:
33-
- **Server Configuration**: View, add, edit, and delete server entries (`mcp_server.json`). Supports both Stdio and SSE server types with relevant options (command, args, env, url, apiKey, bearerToken, install config).
33+
- **Server Configuration**: View, add, edit, and delete server entries (`mcp_server.json`). Supports Stdio, SSE, and HTTP server types with relevant options (type, command, args, env, url, apiKey, bearerToken, install config).
3434
- **Tool Configuration**: View all tools discovered from active backend servers. Enable or disable specific tools. Override the display name and description for each tool (`tool_config.json`).
3535
- **Live Reload**: Apply server and tool configuration changes by triggering a configuration reload without needing to restart the entire proxy server process.
3636
- **Stdio Server Installation**: For Stdio servers, you can define installation commands in the configuration. The Admin UI allows you to:
@@ -51,6 +51,7 @@ Example `config/mcp_server.json`:
5151
{
5252
"mcpServers": {
5353
"unique-server-key1": {
54+
"type": "stdio",
5455
"name": "My Stdio Server",
5556
"active": true,
5657
"command": "/path/to/server/executable",
@@ -65,12 +66,21 @@ Example `config/mcp_server.json`:
6566
]
6667
},
6768
"another-sse-server": {
69+
"type": "sse",
6870
"name": "My SSE Server",
6971
"active": true,
7072
"url": "http://localhost:8080/sse",
7173
"apiKey": "sse_server_api_key"
7274
},
75+
"http-mcp-server": {
76+
"type": "http",
77+
"name": "My Streamable HTTP Server",
78+
"active": true,
79+
"url": "http://localhost:8081/mcp",
80+
"bearerToken": "some_secure_token_for_http_server"
81+
},
7382
"stdio-default-install": {
83+
"type": "stdio",
7484
"name": "Stdio Server with Default Install Path",
7585
"active": true,
7686
"command": "my_other_server",
@@ -84,13 +94,14 @@ Example `config/mcp_server.json`:
8494
- `mcpServers`: (Required) An object where each key is a unique identifier for a backend server.
8595
- `name`: (Optional) A user-friendly display name for the server (used in Admin UI).
8696
- `active`: (Optional, default: `true`) Set to `false` to prevent the proxy from connecting to this server.
87-
- `command`: (Required for Stdio type) The command to execute the server process.
88-
- `args`: (Optional for Stdio type) An array of string arguments to pass to the command.
89-
- `env`: (Optional for Stdio type) An object of environment variables (`KEY: "value"`) to set for the server process. These are merged with the proxy server's environment.
90-
- `url`: (Required for SSE type) The full URL of the backend server's SSE endpoint.
91-
- `apiKey`: (Optional for SSE type) An API key to send in the `X-Api-Key` header when the proxy connects to *this specific backend* SSE server.
92-
- `bearerToken`: (Optional for SSE type) A token to send in the `Authorization: Bearer <token>` header when connecting to *this specific backend* SSE server. (If both `apiKey` and `bearerToken` are provided, `bearerToken` takes precedence).
93-
- `installDirectory`: (Optional for Stdio type) The absolute path where the server *itself* should be installed (e.g., `/opt/my-server-files`). Used by the Admin UI's installation feature.
97+
- `type`: (Required) Specifies the transport type. Must be one of `"stdio"`, `"sse"`, or `"http"`.
98+
- `command`: (Required if `type` is "stdio") The command to execute the server process.
99+
- `args`: (Optional if `type` is "stdio") An array of string arguments to pass to the command.
100+
- `env`: (Optional if `type` is "stdio") An object of environment variables (`KEY: "value"`) to set for the server process. These are merged with the proxy server's environment.
101+
- `url`: (Required if `type` is "sse" or "http") The full URL of the backend server's endpoint (e.g., SSE endpoint for "sse", MCP endpoint for "http").
102+
- `apiKey`: (Optional if `type` is "sse" or "http") An API key to send in the `X-Api-Key` header when the proxy connects to *this specific backend* server.
103+
- `bearerToken`: (Optional if `type` is "sse" or "http") A token to send in the `Authorization: Bearer <token>` header when connecting to *this specific backend* server. (If both `apiKey` and `bearerToken` are provided, `bearerToken` generally takes precedence for that specific backend connection).
104+
- `installDirectory`: (Optional if `type` is "stdio") The absolute path where the server *itself* should be installed (e.g., `/opt/my-server-files`). Used by the Admin UI's installation feature.
94105
- If provided in `mcp_server.json`, this exact path is used.
95106
- If omitted, the effective directory depends on the `TOOLS_FOLDER` environment variable (see Environment Variables section).
96107
- If `TOOLS_FOLDER` is set and not empty, the server will be installed in a subdirectory named after the server key within this folder (e.g., `${TOOLS_FOLDER}/<server_key>`).
@@ -123,15 +134,15 @@ Example `config/tool_config.json`:
123134

124135
### 3. Environment Variables
125136

126-
- **`PORT`**: Port for the proxy server's main SSE endpoint (and Admin UI if enabled). Default: `3663`. **Note:** This is only used when running in SSE mode (e.g., via `npm run dev:sse` or the Docker container). The `npm run dev` script runs in Stdio mode.
137+
- **`PORT`**: Port for the proxy server's HTTP-based endpoints (`/sse`, `/mcp`, and Admin UI if enabled). Default: `3663`. **Note:** This is only used when running in a mode that starts an HTTP server (e.g., via `npm run dev:sse` or the Docker container). The `npm run dev` script runs in Stdio mode.
127138
```bash
128139
export PORT=8080
129140
```
130-
- **`MCP_PROXY_SSE_ALLOWED_KEYS`**: (Optional) Comma-separated list of API keys to secure the proxy's main `/sse` endpoint (only applicable in SSE mode). If neither `MCP_PROXY_SSE_ALLOWED_KEYS` nor `MCP_PROXY_SSE_ALLOWED_TOKENS` are set, authentication is disabled. Clients must provide a key via `X-Api-Key` header or `?key=` query parameter.
141+
- **`ALLOWED_KEYS`**: (Optional) Comma-separated list of API keys to secure the proxy's HTTP-based endpoints (`/sse`, `/mcp`). If neither `ALLOWED_KEYS` nor `ALLOWED_TOKENS` are set, authentication is disabled for these endpoints. Clients must provide a key via `X-Api-Key` header or `?key=` query parameter.
131142
```bash
132-
export MCP_PROXY_SSE_ALLOWED_KEYS="client_key1,client_key2"
143+
export ALLOWED_KEYS="client_key1,client_key2"
133144
```
134-
- **`MCP_PROXY_SSE_ALLOWED_TOKENS`**: (Optional) Comma-separated list of Bearer Tokens to secure the proxy's main `/sse` endpoint (only applicable in SSE mode). If neither `MCP_PROXY_SSE_ALLOWED_KEYS` nor `MCP_PROXY_SSE_ALLOWED_TOKENS` are set, authentication is disabled. Clients must provide a token via the `Authorization: Bearer <token>` header. If both `MCP_PROXY_SSE_ALLOWED_KEYS` and `MCP_PROXY_SSE_ALLOWED_TOKENS` are configured, Bearer Token authentication will be attempted first.
145+
- **`ALLOWED_TOKENS`**: (Optional) Comma-separated list of Bearer Tokens to secure the proxy's HTTP-based endpoints (`/sse`, `/mcp`). If neither `ALLOWED_KEYS` nor `ALLOWED_TOKENS` are set, authentication is disabled. Clients must provide a token via the `Authorization: Bearer <token>` header. If both `ALLOWED_KEYS` and `ALLOWED_TOKENS` are configured, Bearer Token authentication will be attempted first.
135146
```bash
136147
export MCP_PROXY_SSE_ALLOWED_TOKENS="your_bearer_token_1,your_bearer_token_2"
137148
```
@@ -243,7 +254,7 @@ docker run -d \
243254
-e ENABLE_ADMIN_UI=true \
244255
-e ADMIN_USERNAME=myadmin \
245256
-e ADMIN_PASSWORD=yoursupersecretpassword \
246-
-e MCP_PROXY_SSE_ALLOWED_KEYS="clientkey1" \
257+
-e ALLOWED_KEYS="clientkey1" \
247258
-e TOOLS_FOLDER=/my/custom_tools_volume # Optional: Override default /tools for server installations
248259
-v ./my_config:/mcp-proxy-server/config \
249260
-v /path/on/host/to/tools:/my/custom_tools_volume `# Mount a volume for TOOLS_FOLDER if overridden` \
@@ -285,18 +296,23 @@ This proxy server can be used in two main ways:
285296
```
286297
- Replace `/path/to/mcp-proxy-server/build/index.js` with the actual path to the built entry point of this proxy server project. Ensure the `config` directory is correctly located relative to where the command is run, or use absolute paths in the proxy's own config if needed.
287298

288-
**2. As an SSE MCP Server:**
289-
Run the proxy server in SSE mode (e.g., `npm run dev:sse` or the Docker container). Then, configure your MCP client to connect to the proxy's SSE endpoint (e.g., `http://localhost:3663/sse`). If authentication is enabled on the proxy (via `MCP_PROXY_SSE_ALLOWED_KEYS` or `MCP_PROXY_SSE_ALLOWED_TOKENS`), the client needs to provide the corresponding credentials.
299+
**2. As an SSE or Streamable HTTP MCP Server:**
300+
Run the proxy server in a mode that starts its HTTP server (e.g., `npm run dev:sse` or the Docker container). Then, configure your MCP client to connect to the proxy's appropriate endpoint:
301+
- For SSE: `http://localhost:3663/sse`
302+
- For Streamable HTTP: `http://localhost:3663/mcp`
303+
304+
If authentication is enabled on the proxy (via `ALLOWED_KEYS` or `ALLOWED_TOKENS`), the client needs to provide the corresponding credentials.
290305
291-
**Authentication Methods:**
292-
* **API Key:** Provide the key in the client configuration. For broader compatibility, providing it via the URL query parameter `?key=...` is recommended. Some clients might also support providing it in the `X-Api-Key` header.
306+
**Authentication Methods (for `/sse` and `/mcp`):**
307+
* **API Key:** Provide the key in the client configuration. For the `/sse` endpoint, the URL query parameter `?key=...` is supported. For both `/sse` and `/mcp`, the `X-Api-Key` header is supported.
293308
* **Bearer Token:** Set the `Authorization: Bearer <token>` header in the client configuration.
294309
295-
Example for Claude Desktop (`claude_desktop_config.json`):
310+
Example for Claude Desktop (`claude_desktop_config.json`) connecting to SSE:
296311
```json
297312
{
298313
"mcpServers": {
299314
"my-proxy-sse": {
315+
"type": "sse", // Important for clients that distinguish
300316
"name": "MCP Proxy (SSE)",
301317
// If using API Key authentication, append ?key=<your_key>
302318
"url": "http://localhost:3663/sse?key=clientkey1"
@@ -310,6 +326,21 @@ This proxy server can be used in two main ways:
310326
}
311327
```
312328
329+
Example for a generic Streamable HTTP client configuration:
330+
```json
331+
{
332+
"mcpServers": {
333+
"my-proxy-http": {
334+
"type": "http", // Or the client's specific designation
335+
"name": "MCP Proxy (Streamable HTTP)",
336+
"url": "http://localhost:3663/mcp",
337+
// Authentication headers would be configured according to the client's capabilities
338+
// e.g., "requestInit": { "headers": { "X-Api-Key": "clientkey1" } }
339+
}
340+
}
341+
}
342+
```
343+
313344
## Debugging
314345
315346
Use the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) for debugging communication (primarily for Stdio mode):

0 commit comments

Comments
 (0)