mcp-proxy 5.5.6 → 5.6.0
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 +60 -0
- package/dist/bin/mcp-proxy.js +6 -1
- package/dist/bin/mcp-proxy.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/{stdio-CQWnvum1.js → stdio-Cm2W-uxV.js} +36 -2
- package/dist/stdio-Cm2W-uxV.js.map +1 -0
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/authentication.test.ts +117 -0
- package/src/authentication.ts +43 -0
- package/src/bin/mcp-proxy.ts +5 -0
- package/src/startHTTPServer.test.ts +374 -0
- package/src/startHTTPServer.ts +13 -0
- package/dist/stdio-CQWnvum1.js.map +0 -1
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ options:
|
|
|
37
37
|
- `--port`: Specify the port to listen on (default: 8080)
|
|
38
38
|
- `--debug`: Enable debug logging
|
|
39
39
|
- `--shell`: Spawn the server via the user's shell
|
|
40
|
+
- `--apiKey`: API key for authenticating requests (uses X-API-Key header)
|
|
40
41
|
|
|
41
42
|
### Passing arguments to the wrapped command
|
|
42
43
|
|
|
@@ -83,6 +84,64 @@ npx mcp-proxy --port 8080 --stateless --server stream tsx server.js
|
|
|
83
84
|
- **Request isolation**: When you need complete independence between requests
|
|
84
85
|
- **Simple deployments**: When you don't need to maintain connection state
|
|
85
86
|
|
|
87
|
+
### API Key Authentication
|
|
88
|
+
|
|
89
|
+
MCP Proxy supports optional API key authentication to secure your endpoints. When enabled, clients must provide a valid API key in the `X-API-Key` header to access the proxy.
|
|
90
|
+
|
|
91
|
+
#### Enabling Authentication
|
|
92
|
+
|
|
93
|
+
Authentication is disabled by default for backward compatibility. To enable it, provide an API key via:
|
|
94
|
+
|
|
95
|
+
**Command-line:**
|
|
96
|
+
```bash
|
|
97
|
+
npx mcp-proxy --port 8080 --apiKey "your-secret-key" tsx server.js
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Environment variable:**
|
|
101
|
+
```bash
|
|
102
|
+
export MCP_PROXY_API_KEY="your-secret-key"
|
|
103
|
+
npx mcp-proxy --port 8080 tsx server.js
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Client Configuration
|
|
107
|
+
|
|
108
|
+
Clients must include the API key in the `X-API-Key` header:
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// For streamable HTTP transport
|
|
112
|
+
const transport = new StreamableHTTPClientTransport(
|
|
113
|
+
new URL('http://localhost:8080/mcp'),
|
|
114
|
+
{
|
|
115
|
+
headers: {
|
|
116
|
+
'X-API-Key': 'your-secret-key'
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// For SSE transport
|
|
122
|
+
const transport = new SSEClientTransport(
|
|
123
|
+
new URL('http://localhost:8080/sse'),
|
|
124
|
+
{
|
|
125
|
+
headers: {
|
|
126
|
+
'X-API-Key': 'your-secret-key'
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
#### Exempt Endpoints
|
|
133
|
+
|
|
134
|
+
The following endpoints do not require authentication:
|
|
135
|
+
- `/ping` - Health check endpoint
|
|
136
|
+
- `OPTIONS` requests - CORS preflight requests
|
|
137
|
+
|
|
138
|
+
#### Security Notes
|
|
139
|
+
|
|
140
|
+
- **Use HTTPS in production**: API keys should only be transmitted over secure connections
|
|
141
|
+
- **Keep keys secure**: Never commit API keys to version control
|
|
142
|
+
- **Generate strong keys**: Use cryptographically secure random strings for API keys
|
|
143
|
+
- **Rotate keys regularly**: Change API keys periodically for better security
|
|
144
|
+
|
|
86
145
|
### Node.js SDK
|
|
87
146
|
|
|
88
147
|
The Node.js SDK provides several utilities that are used to create a proxy.
|
|
@@ -137,6 +196,7 @@ Options:
|
|
|
137
196
|
- `sseEndpoint`: SSE endpoint path (default: "/sse", set to null to disable)
|
|
138
197
|
- `streamEndpoint`: Streamable HTTP endpoint path (default: "/mcp", set to null to disable)
|
|
139
198
|
- `stateless`: Enable stateless mode for HTTP streamable transport (default: false)
|
|
199
|
+
- `apiKey`: API key for authenticating requests (optional)
|
|
140
200
|
- `onConnect`: Callback when a server connects (optional)
|
|
141
201
|
- `onClose`: Callback when a server disconnects (optional)
|
|
142
202
|
- `onUnhandledRequest`: Callback for unhandled HTTP requests (optional)
|
package/dist/bin/mcp-proxy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Client, InMemoryEventStore, ReadBuffer, Server, __commonJS, __toESM, proxyServer, serializeMessage, startHTTPServer } from "../stdio-
|
|
2
|
+
import { Client, InMemoryEventStore, ReadBuffer, Server, __commonJS, __toESM, proxyServer, serializeMessage, startHTTPServer } from "../stdio-Cm2W-uxV.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { basename, dirname, extname, join, normalize, relative, resolve } from "path";
|
|
5
5
|
import { format, inspect } from "util";
|
|
@@ -5057,6 +5057,10 @@ const argv = await yargs_default(hideBin(process.argv)).scriptName("mcp-proxy").
|
|
|
5057
5057
|
describe: "The arguments to pass to the command",
|
|
5058
5058
|
type: "string"
|
|
5059
5059
|
}).env("MCP_PROXY").parserConfiguration({ "populate--": true }).options({
|
|
5060
|
+
apiKey: {
|
|
5061
|
+
describe: "API key for authenticating requests (uses X-API-Key header)",
|
|
5062
|
+
type: "string"
|
|
5063
|
+
},
|
|
5060
5064
|
debug: {
|
|
5061
5065
|
default: false,
|
|
5062
5066
|
describe: "Enable debug logging",
|
|
@@ -5142,6 +5146,7 @@ const proxy = async () => {
|
|
|
5142
5146
|
return server$1;
|
|
5143
5147
|
};
|
|
5144
5148
|
const server = await startHTTPServer({
|
|
5149
|
+
apiKey: argv.apiKey,
|
|
5145
5150
|
createServer,
|
|
5146
5151
|
eventStore: new InMemoryEventStore(),
|
|
5147
5152
|
host: argv.host,
|