mcp-remote 0.0.8 → 0.0.10-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
@@ -2,7 +2,19 @@
2
2
 
3
3
  Connect an MCP Client that only supports local (stdio) servers to a Remote MCP Server, with auth support:
4
4
 
5
- **Note: this is a working proof-of-concept** but should be considered **experimental**
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 MCP [Authorization specification](https://spec.modelcontextprotocol.io/specification/draft/basic/authorization/) nearing completion, 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
6
18
 
7
19
  E.g: Claude Desktop or Windsurf
8
20
 
@@ -20,3 +32,53 @@ E.g: Claude Desktop or Windsurf
20
32
  Cursor:
21
33
 
22
34
  ![image](https://github.com/user-attachments/assets/14338bfa-a779-4e8a-a477-71f72cc5d99d)
35
+
36
+ ## Building Remote MCP Servers
37
+
38
+ For instructions on building & deploying remote MCP servers, including acting as a valid OAuth client, see the following resources:
39
+
40
+ * https://developers.cloudflare.com/agents/guides/remote-mcp-server/
41
+
42
+ In particular, see:
43
+
44
+ * https://github.com/cloudflare/workers-oauth-provider for defining an MCP-comlpiant OAuth server in Cloudflare Workers
45
+ * https://github.com/cloudflare/agents/tree/main/examples/mcp for defining an `McpAgent` using the [`agents`](https://npmjs.com/package/agents) framework.
46
+
47
+ For more information about testing these servers, see also:
48
+
49
+ * https://developers.cloudflare.com/agents/guides/test-remote-mcp-server/
50
+
51
+ Know of more resources you'd like to share? Please add them to this Readme and send a PR!
52
+
53
+ ## Debugging
54
+
55
+ ### Check your Node version
56
+
57
+ Make sure that the version of Node you have installed is [16 or higher](https://modelcontextprotocol.io/quickstart/server).
58
+
59
+ ### Restart Claude
60
+
61
+ When modifying `claude_desktop_config.json` it can helpful to completely restart Claude
62
+
63
+ ### VPN Certs
64
+
65
+ You may run into issues if you are behind a VPN, you can try setting the `NODE_EXTRA_CA_CERTS`
66
+ environment variable to point to the CA certificate file. If using `claude_desktop_config.json`,
67
+ this might look like:
68
+
69
+ ```json
70
+ {
71
+ "mcpServers": {
72
+ "remote-example": {
73
+ "command": "npx",
74
+ "args": [
75
+ "mcp-remote",
76
+ "https://remote.mcp.server/sse"
77
+ ],
78
+ "env": {
79
+ "NODE_EXTRA_CA_CERTS": "{your CA certificate file path}.pem"
80
+ }
81
+ }
82
+ }
83
+ }
84
+ ```
package/dist/cli/proxy.js CHANGED
@@ -13,6 +13,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
13
13
  // src/lib/utils.ts
14
14
  import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
15
15
  import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
16
+ var pid = process.pid;
16
17
  function mcpProxy({ transportToClient, transportToServer }) {
17
18
  let transportToClientClosed = false;
18
19
  let transportToServerClosed = false;
@@ -48,7 +49,7 @@ function mcpProxy({ transportToClient, transportToServer }) {
48
49
  }
49
50
  }
50
51
  async function connectToRemoteServer(serverUrl, authProvider, waitForAuthCode) {
51
- console.error("Connecting to remote server:", serverUrl);
52
+ console.error(`[${pid}] Connecting to remote server: ${serverUrl}`);
52
53
  const url = new URL(serverUrl);
53
54
  const transport = new SSEClientTransport(url, { authProvider });
54
55
  try {
@@ -109,6 +110,28 @@ async function runProxy(serverUrl, callbackPort) {
109
110
  setupSignalHandlers(cleanup);
110
111
  } catch (error) {
111
112
  console.error("Fatal error:", error);
113
+ if (error instanceof Error && error.message.includes("self-signed certificate in certificate chain")) {
114
+ console.error(`You may be behind a VPN!
115
+
116
+ If you are behind a VPN, you can try setting the NODE_EXTRA_CA_CERTS environment variable to point
117
+ to the CA certificate file. If using claude_desktop_config.json, this might look like:
118
+
119
+ {
120
+ "mcpServers": {
121
+ "\${mcpServerName}": {
122
+ "command": "npx",
123
+ "args": [
124
+ "mcp-remote",
125
+ "https://remote.mcp.server/sse"
126
+ ],
127
+ "env": {
128
+ "NODE_EXTRA_CA_CERTS": "\${your CA certificate file path}.pem"
129
+ }
130
+ }
131
+ }
132
+ }
133
+ `);
134
+ }
112
135
  server.close();
113
136
  process.exit(1);
114
137
  }
@@ -61,6 +61,10 @@ type UseMcpResult = {
61
61
  * @returns Auth URL that can be used to manually open a new window
62
62
  */
63
63
  authenticate: () => Promise<string | undefined>;
64
+ /**
65
+ * Clear all localStorage items for this server
66
+ */
67
+ clearStorage: () => void;
64
68
  };
65
69
  /**
66
70
  * useMcp is a React hook that connects to a remote MCP server, negotiates auth
@@ -36,6 +36,34 @@ var BrowserOAuthClientProvider = class {
36
36
  client_uri: this.clientUri
37
37
  };
38
38
  }
39
+ /**
40
+ * Clears all storage items related to this server
41
+ * @returns The number of items cleared
42
+ */
43
+ clearStorage() {
44
+ const prefix = `${this.storageKeyPrefix}_${this.serverUrlHash}`;
45
+ const keysToRemove = [];
46
+ for (let i = 0; i < localStorage.length; i++) {
47
+ const key = localStorage.key(i);
48
+ if (key && key.startsWith(prefix)) {
49
+ keysToRemove.push(key);
50
+ }
51
+ }
52
+ for (let i = 0; i < localStorage.length; i++) {
53
+ const key = localStorage.key(i);
54
+ if (key && key.startsWith(`${this.storageKeyPrefix}:state_`)) {
55
+ try {
56
+ const state = JSON.parse(localStorage.getItem(key) || "{}");
57
+ if (state.serverUrlHash === this.serverUrlHash) {
58
+ keysToRemove.push(key);
59
+ }
60
+ } catch (e) {
61
+ }
62
+ }
63
+ }
64
+ keysToRemove.forEach((key) => localStorage.removeItem(key));
65
+ return keysToRemove.length;
66
+ }
39
67
  hashString(str) {
40
68
  let hash = 0;
41
69
  for (let i = 0; i < str.length; i++) {
@@ -486,6 +514,18 @@ function useMcp(options) {
486
514
  }
487
515
  };
488
516
  }, [disconnect]);
517
+ const clearStorage = useCallback(() => {
518
+ if (!authProviderRef.current) {
519
+ addLog("warn", "Cannot clear storage: auth provider not initialized");
520
+ return;
521
+ }
522
+ const clearedCount = authProviderRef.current.clearStorage();
523
+ authUrlRef.current = void 0;
524
+ setAuthUrl(void 0);
525
+ metadataRef.current = void 0;
526
+ codeVerifierRef.current = void 0;
527
+ addLog("info", `Cleared ${clearedCount} storage items for server`);
528
+ }, [addLog]);
489
529
  return {
490
530
  state,
491
531
  tools,
@@ -495,7 +535,8 @@ function useMcp(options) {
495
535
  callTool,
496
536
  retry,
497
537
  disconnect,
498
- authenticate
538
+ authenticate,
539
+ clearStorage
499
540
  };
500
541
  }
501
542
  async function onMcpAuthorization(query, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-remote",
3
- "version": "0.0.8",
3
+ "version": "0.0.10-0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mcp-remote": "dist/cli/proxy.js"
@@ -18,6 +18,7 @@
18
18
  }
19
19
  },
20
20
  "scripts": {
21
+ "dev": "tsup --watch",
21
22
  "build": "tsup",
22
23
  "check": "prettier --check . && tsc"
23
24
  },