ma-mcp-remote 0.1.41

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Cloudflare, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,400 @@
1
+ # `mcp-remote`
2
+
3
+ Connect an MCP Client that only supports local (stdio) servers to a Remote MCP Server, with auth support:
4
+
5
+ **Note: this is a working proof-of-concept** but should be considered **experimental**.
6
+
7
+ ## Why is this necessary?
8
+
9
+ So far, the majority of MCP servers in the wild are installed locally, using the stdio transport. This has some benefits: both the client and the server can implicitly trust each other as the user has granted them both permission to run. Adding secrets like API keys can be done using environment variables and never leave your machine. And building on `npx` and `uvx` has allowed users to avoid explicit install steps, too.
10
+
11
+ But there's a reason most software that _could_ be moved to the web _did_ get moved to the web: it's so much easier to find and fix bugs & iterate on new features when you can push updates to all your users with a single deploy.
12
+
13
+ With the latest MCP [Authorization specification](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization), we now have a secure way of sharing our MCP servers with the world _without_ running code on user's laptops. Or at least, you would, if all the popular MCP _clients_ supported it yet. Most are stdio-only, and those that _do_ support HTTP+SSE don't yet support the OAuth flows required.
14
+
15
+ That's where `mcp-remote` comes in. As soon as your chosen MCP client supports remote, authorized servers, you can remove it. Until that time, drop in this one liner and dress for the MCP clients you want!
16
+
17
+ ## Usage
18
+
19
+ All the most popular MCP clients (Claude Desktop, Cursor & Windsurf) use the following config format:
20
+
21
+ ```json
22
+ {
23
+ "mcpServers": {
24
+ "remote-example": {
25
+ "command": "npx",
26
+ "args": [
27
+ "mcp-remote",
28
+ "https://remote.mcp.server/sse"
29
+ ]
30
+ }
31
+ }
32
+ }
33
+ ```
34
+
35
+ ### Custom Headers
36
+
37
+ To bypass authentication, or to emit custom headers on all requests to your remote server, pass `--header` CLI arguments:
38
+
39
+ ```json
40
+ {
41
+ "mcpServers": {
42
+ "remote-example": {
43
+ "command": "npx",
44
+ "args": [
45
+ "mcp-remote",
46
+ "https://remote.mcp.server/sse",
47
+ "--header",
48
+ "Authorization: Bearer ${AUTH_TOKEN}"
49
+ ],
50
+ "env": {
51
+ "AUTH_TOKEN": "..."
52
+ }
53
+ },
54
+ }
55
+ }
56
+ ```
57
+
58
+ **Note:** Cursor and Claude Desktop (Windows) have a bug where spaces inside `args` aren't escaped when it invokes `npx`, which ends up mangling these values. You can work around it using:
59
+
60
+ ```jsonc
61
+ {
62
+ // rest of config...
63
+ "args": [
64
+ "mcp-remote",
65
+ "https://remote.mcp.server/sse",
66
+ "--header",
67
+ "Authorization:${AUTH_HEADER}" // note no spaces around ':'
68
+ ],
69
+ "env": {
70
+ "AUTH_HEADER": "Bearer <auth-token>" // spaces OK in env vars
71
+ }
72
+ },
73
+ ```
74
+
75
+ ### Multiple Instances
76
+
77
+ To run multiple instances of the same remote server with different configurations (e.g., different Atlassian tenants), use the `--resource` flag to isolate OAuth sessions:
78
+
79
+ ```json
80
+ {
81
+ "mcpServers": {
82
+ "atlassian_tenant1": {
83
+ "command": "npx",
84
+ "args": [
85
+ "mcp-remote",
86
+ "https://mcp.atlassian.com/v1/sse",
87
+ "--resource",
88
+ "https://tenant1.atlassian.net/"
89
+ ]
90
+ },
91
+ "atlassian_tenant2": {
92
+ "command": "npx",
93
+ "args": [
94
+ "mcp-remote",
95
+ "https://mcp.atlassian.com/v1/sse",
96
+ "--resource",
97
+ "https://tenant2.atlassian.net/"
98
+ ]
99
+ }
100
+ }
101
+ }
102
+ ```
103
+
104
+ Each unique combination of server URL, resource, and custom headers will maintain separate OAuth sessions and token storage.
105
+
106
+ ### Flags
107
+
108
+ * If `npx` is producing errors, consider adding `-y` as the first argument to auto-accept the installation of the `mcp-remote` package.
109
+
110
+ ```json
111
+ "command": "npx",
112
+ "args": [
113
+ "-y",
114
+ "mcp-remote",
115
+ "https://remote.mcp.server/sse"
116
+ ]
117
+ ```
118
+
119
+ * To force `npx` to always check for an updated version of `mcp-remote`, add the `@latest` flag:
120
+
121
+ ```json
122
+ "args": [
123
+ "mcp-remote@latest",
124
+ "https://remote.mcp.server/sse"
125
+ ]
126
+ ```
127
+
128
+ * To change which port `mcp-remote` listens for an OAuth redirect (by default `3334`), add an additional argument after the server URL. Note that whatever port you specify, if it is unavailable an open port will be chosen at random.
129
+
130
+ ```json
131
+ "args": [
132
+ "mcp-remote",
133
+ "https://remote.mcp.server/sse",
134
+ "9696"
135
+ ]
136
+ ```
137
+
138
+ * To change which host `mcp-remote` registers as the OAuth callback URL (by default `localhost`), add the `--host` flag.
139
+
140
+ ```json
141
+ "args": [
142
+ "mcp-remote",
143
+ "https://remote.mcp.server/sse",
144
+ "--host",
145
+ "127.0.0.1"
146
+ ]
147
+ ```
148
+
149
+ * To allow HTTP connections in trusted private networks, add the `--allow-http` flag. Note: This should only be used in secure private networks where traffic cannot be intercepted.
150
+
151
+ ```json
152
+ "args": [
153
+ "mcp-remote",
154
+ "http://internal-service.vpc/sse",
155
+ "--allow-http"
156
+ ]
157
+ ```
158
+
159
+ * To enable detailed debugging logs, add the `--debug` flag. This will write verbose logs to `~/.mcp-auth/{server_hash}_debug.log` with timestamps and detailed information about the auth process, connections, and token refreshing.
160
+
161
+ ```json
162
+ "args": [
163
+ "mcp-remote",
164
+ "https://remote.mcp.server/sse",
165
+ "--debug"
166
+ ]
167
+ ```
168
+
169
+ * To suppress default logs, add the `--silent` flag. This will prevent logs from being emitted, except in the case where `--debug` is also passed.
170
+
171
+ ```json
172
+ "args": [
173
+ "mcp-remote",
174
+ "https://remote.mcp.server/sse",
175
+ "--silent"
176
+ ]
177
+ ```
178
+
179
+ * To enable an outbound HTTP(S) proxy for mcp-remote, add the `--enable-proxy` flag. When enabled, mcp-remote will use the proxy settings from common environment variables (for example `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY`).
180
+
181
+ ```json
182
+ "args": [
183
+ "mcp-remote",
184
+ "https://remote.mcp.server/sse",
185
+ "--enable-proxy"
186
+ ],
187
+ "env": {
188
+ "HTTPS_PROXY": "http://127.0.0.1:3128",
189
+ "NO_PROXY": "localhost,127.0.0.1"
190
+ }
191
+ ```
192
+
193
+ * To ignore specific tools from the remote server, add the `--ignore-tool` flag. This will filter out tools matching the specified patterns from both `tools/list` responses and block `tools/call` requests. Supports wildcard patterns with `*`.
194
+
195
+ ```json
196
+ "args": [
197
+ "mcp-remote",
198
+ "https://remote.mcp.server/sse",
199
+ "--ignore-tool",
200
+ "delete*",
201
+ "--ignore-tool",
202
+ "remove*"
203
+ ]
204
+ ```
205
+
206
+ You can specify multiple `--ignore-tool` flags to ignore different patterns. Examples:
207
+ - `delete*` - ignores all tools starting with "delete" (e.g., `deleteTask`, `deleteUser`)
208
+ - `*account` - ignores all tools ending with "account" (e.g., `getAccount`, `updateAccount`)
209
+ - `exactTool` - ignores only the tool named exactly "exactTool"
210
+
211
+ * To change the timeout for the OAuth callback (by default `30` seconds), add the `--auth-timeout` flag with a value in seconds. This is useful if the authentication process on the server side takes a long time.
212
+
213
+ ```json
214
+ "args": [
215
+ "mcp-remote",
216
+ "https://remote.mcp.server/sse",
217
+ "--auth-timeout",
218
+ "60"
219
+ ]
220
+ ```
221
+
222
+ ### Transport Strategies
223
+
224
+ MCP Remote supports different transport strategies when connecting to an MCP server. This allows you to control whether it uses Server-Sent Events (SSE) or HTTP transport, and in what order it tries them.
225
+
226
+ Specify the transport strategy with the `--transport` flag:
227
+
228
+ ```bash
229
+ npx mcp-remote https://example.remote/server --transport sse-only
230
+ ```
231
+
232
+ **Available Strategies:**
233
+
234
+ - `http-first` (default): Tries HTTP transport first, falls back to SSE if HTTP fails with a 404 error
235
+ - `sse-first`: Tries SSE transport first, falls back to HTTP if SSE fails with a 405 error
236
+ - `http-only`: Only uses HTTP transport, fails if the server doesn't support it
237
+ - `sse-only`: Only uses SSE transport, fails if the server doesn't support it
238
+
239
+ ### Static OAuth Client Metadata
240
+
241
+ MCP Remote supports providing static OAuth client metadata instead of using the mcp-remote defaults.
242
+ This is useful when connecting to OAuth servers that expect specific client/software IDs or scopes.
243
+
244
+ Provide the client metadata as a JSON string or as a `@` prefixed filepath with the `--static-oauth-client-metadata` flag:
245
+
246
+ ```bash
247
+ npx mcp-remote https://example.remote/server --static-oauth-client-metadata '{ "scope": "space separated scopes" }'
248
+ # uses node readfile, so you probably want to use absolute paths if you're not sure what the cwd is
249
+ npx mcp-remote https://example.remote/server --static-oauth-client-metadata '@/Users/username/Library/Application Support/Claude/oauth_client_metadata.json'
250
+ ```
251
+
252
+ ### Static OAuth Client Information
253
+
254
+ Per the [spec](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization#2-4-dynamic-client-registration),
255
+ servers are encouraged but not required to support [OAuth dynamic client registration](https://datatracker.ietf.org/doc/html/rfc7591).
256
+
257
+ For these servers, MCP Remote supports providing static OAuth client information instead.
258
+ This is useful when connecting to OAuth servers that require pre-registered clients.
259
+
260
+ Provide the client metadata as a JSON string or as a `@` prefixed filepath with the `--static-oauth-client-info` flag:
261
+
262
+ ```bash
263
+ export MCP_REMOTE_CLIENT_ID=xxx
264
+ export MCP_REMOTE_CLIENT_SECRET=yyy
265
+ npx mcp-remote https://example.remote/server --static-oauth-client-info "{ \"client_id\": \"$MCP_REMOTE_CLIENT_ID\", \"client_secret\": \"$MCP_REMOTE_CLIENT_SECRET\" }"
266
+ # uses node readfile, so you probably want to use absolute paths if you're not sure what the cwd is
267
+ npx mcp-remote https://example.remote/server --static-oauth-client-info '@/Users/username/Library/Application Support/Claude/oauth_client_info.json'
268
+ ```
269
+
270
+ ### Claude Desktop
271
+
272
+ [Official Docs](https://modelcontextprotocol.io/quickstart/user)
273
+
274
+ In order to add an MCP server to Claude Desktop you need to edit the configuration file located at:
275
+
276
+ * macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
277
+ * Windows: `%APPDATA%\Claude\claude_desktop_config.json`
278
+
279
+ If it does not exist yet, [you may need to enable it under Settings > Developer](https://modelcontextprotocol.io/quickstart/user#2-add-the-filesystem-mcp-server).
280
+
281
+ Restart Claude Desktop to pick up the changes in the configuration file.
282
+ Upon restarting, you should see a hammer icon in the bottom right corner
283
+ of the input box.
284
+
285
+ ### Cursor
286
+
287
+ [Official Docs](https://docs.cursor.com/context/model-context-protocol). The configuration file is located at `~/.cursor/mcp.json`.
288
+
289
+ As of version `0.48.0`, Cursor supports unauthed SSE servers directly. If your MCP server is using the official MCP OAuth authorization protocol, you still need to add a **"command"** server and call `mcp-remote`.
290
+
291
+ ### Windsurf
292
+
293
+ [Official Docs](https://docs.codeium.com/windsurf/mcp). The configuration file is located at `~/.codeium/windsurf/mcp_config.json`.
294
+
295
+ ## Building Remote MCP Servers
296
+
297
+ For instructions on building & deploying remote MCP servers, including acting as a valid OAuth client, see the following resources:
298
+
299
+ * https://developers.cloudflare.com/agents/guides/remote-mcp-server/
300
+
301
+ In particular, see:
302
+
303
+ * https://github.com/cloudflare/workers-oauth-provider for defining an MCP-comlpiant OAuth server in Cloudflare Workers
304
+ * https://github.com/cloudflare/agents/tree/main/examples/mcp for defining an `McpAgent` using the [`agents`](https://npmjs.com/package/agents) framework.
305
+
306
+ For more information about testing these servers, see also:
307
+
308
+ * https://developers.cloudflare.com/agents/guides/test-remote-mcp-server/
309
+
310
+ Know of more resources you'd like to share? Please add them to this Readme and send a PR!
311
+
312
+ ## Troubleshooting
313
+
314
+ ### Clear your `~/.mcp-auth` directory
315
+
316
+ `mcp-remote` stores all the credential information inside `~/.mcp-auth` (or wherever your `MCP_REMOTE_CONFIG_DIR` points to). If you're having persistent issues, try running:
317
+
318
+ ```sh
319
+ rm -rf ~/.mcp-auth
320
+ ```
321
+
322
+ Then restarting your MCP client.
323
+
324
+ ### Check your Node version
325
+
326
+ Make sure that the version of Node you have installed is [18 or
327
+ higher](https://modelcontextprotocol.io/quickstart/server). Claude
328
+ Desktop will use your system version of Node, even if you have a newer
329
+ version installed elsewhere.
330
+
331
+ ### Restart Claude
332
+
333
+ When modifying `claude_desktop_config.json` it can helpful to completely restart Claude
334
+
335
+ ### VPN Certs
336
+
337
+ You may run into issues if you are behind a VPN, you can try setting the `NODE_EXTRA_CA_CERTS`
338
+ environment variable to point to the CA certificate file. If using `claude_desktop_config.json`,
339
+ this might look like:
340
+
341
+ ```json
342
+ {
343
+ "mcpServers": {
344
+ "remote-example": {
345
+ "command": "npx",
346
+ "args": [
347
+ "mcp-remote",
348
+ "https://remote.mcp.server/sse"
349
+ ],
350
+ "env": {
351
+ "NODE_EXTRA_CA_CERTS": "{your CA certificate file path}.pem"
352
+ }
353
+ }
354
+ }
355
+ }
356
+ ```
357
+
358
+ ### Check the logs
359
+
360
+ * [Follow Claude Desktop logs in real-time](https://modelcontextprotocol.io/docs/tools/debugging#debugging-in-claude-desktop)
361
+ * MacOS / Linux:<br/>`tail -n 20 -F ~/Library/Logs/Claude/mcp*.log`
362
+ * For bash on WSL:<br/>`tail -n 20 -f "C:\Users\YourUsername\AppData\Local\Claude\Logs\mcp.log"`
363
+ * Powershell: <br/>`Get-Content "C:\Users\YourUsername\AppData\Local\Claude\Logs\mcp.log" -Wait -Tail 20`
364
+
365
+ ## Debugging
366
+
367
+ ### Debug Logs
368
+
369
+ For troubleshooting complex issues, especially with token refreshing or authentication problems, use the `--debug` flag:
370
+
371
+ ```json
372
+ "args": [
373
+ "mcp-remote",
374
+ "https://remote.mcp.server/sse",
375
+ "--debug"
376
+ ]
377
+ ```
378
+
379
+ This creates detailed logs in `~/.mcp-auth/{server_hash}_debug.log` with timestamps and complete information about every step of the connection and authentication process. When you find issues with token refreshing, laptop sleep/resume issues, or auth problems, provide these logs when seeking support.
380
+
381
+ ### Authentication Errors
382
+
383
+ If you encounter the following error, returned by the `/callback` URL:
384
+
385
+ ```
386
+ Authentication Error
387
+ Token exchange failed: HTTP 400
388
+ ```
389
+
390
+ You can run `rm -rf ~/.mcp-auth` to clear any locally stored state and tokens.
391
+
392
+ ### "Client" mode
393
+
394
+ Run the following on the command line (not from an MCP server):
395
+
396
+ ```shell
397
+ npx -p mcp-remote@latest mcp-remote-client https://remote.mcp.server/sse
398
+ ```
399
+
400
+ This will run through the entire authorization flow and attempt to list the tools & resources at the remote URL. Try this after running `rm -rf ~/.mcp-auth` to see if stale credentials are your problem, otherwise hopefully the issue will be more obvious in these logs than those in your MCP client.