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 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)
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { Client, InMemoryEventStore, ReadBuffer, Server, __commonJS, __toESM, proxyServer, serializeMessage, startHTTPServer } from "../stdio-CQWnvum1.js";
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,