From 026caedd3c28905d3079a414825df0880928cc18 Mon Sep 17 00:00:00 2001 From: Fadojutimi Temitayo Olusegun Date: Mon, 5 May 2025 02:37:41 +0100 Subject: [PATCH 01/12] fix: changed the header argument processing from a forEach loop to a while loop to handle array modifications correctly, preventing index errors. --- src/lib/utils.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 9e3e243..c6238b2 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -130,14 +130,14 @@ export async function connectToRemoteServer( const sseTransport = transportStrategy === 'sse-only' || transportStrategy === 'sse-first' const transport = sseTransport ? new SSEClientTransport(url, { - authProvider, - requestInit: { headers }, - eventSourceInit, - }) + authProvider, + requestInit: { headers }, + eventSourceInit, + }) : new StreamableHTTPClientTransport(url, { - authProvider, - requestInit: { headers }, - }) + authProvider, + requestInit: { headers }, + }) try { if (client) { @@ -376,8 +376,9 @@ export async function findAvailablePort(preferredPort?: number): Promise export async function parseCommandLineArgs(args: string[], defaultPort: number, usage: string) { // Process headers const headers: Record = {} - args.forEach((arg, i) => { - if (arg === '--header' && i < args.length - 1) { + let i = 0; + while (i < args.length) { + if (args[i] === '--header' && i < args.length - 1) { const value = args[i + 1] const match = value.match(/^([A-Za-z0-9_-]+):(.*)$/) if (match) { @@ -386,8 +387,11 @@ export async function parseCommandLineArgs(args: string[], defaultPort: number, log(`Warning: ignoring invalid header argument: ${value}`) } args.splice(i, 2) + // Do not increment i, as the array has shifted + continue } - }) + i++ + } const serverUrl = args[0] const specifiedPort = args[1] ? parseInt(args[1]) : undefined From c4a2d4a2425d85c9bc36b0efbc23e10cacff70f9 Mon Sep 17 00:00:00 2001 From: Glen Maddern Date: Mon, 5 May 2025 12:40:27 +1000 Subject: [PATCH 02/12] 0.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bb010a7..341afe2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mcp-remote", - "version": "0.1.1", + "version": "0.1.2", "description": "Remote proxy for Model Context Protocol, allowing local-only clients to connect to remote servers using oAuth", "keywords": [ "mcp", From 67bd63192f41552fe57fe4947d811565fde2c3af Mon Sep 17 00:00:00 2001 From: Glen Maddern Date: Mon, 5 May 2025 15:11:18 +1000 Subject: [PATCH 03/12] Publishing all commits to pkg.pr.new --- .github/workflows/publish.yml | 30 ++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 31 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..dd32058 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,30 @@ +name: Publish Any Commit +on: + pull_request: + push: + branches: + - "**" + tags: + - "!**" + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - run: corepack enable + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - name: Build + run: pnpm build + + - run: pnpm dlx pkg-pr-new publish --compact --bin diff --git a/package.json b/package.json index 341afe2..5ee38e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "mcp-remote", "version": "0.1.2", + "packageManager": "pnpm@8.15.1", "description": "Remote proxy for Model Context Protocol, allowing local-only clients to connect to remote servers using oAuth", "keywords": [ "mcp", From c9e082d9e28098c0d6b9c5a6c48fbe0ca9473c69 Mon Sep 17 00:00:00 2001 From: Glen Maddern Date: Mon, 5 May 2025 16:49:20 +1000 Subject: [PATCH 04/12] Removing traces of react --- package.json | 6 +----- pnpm-lock.yaml | 24 ------------------------ tsconfig.json | 2 +- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 5ee38e5..2d65086 100644 --- a/package.json +++ b/package.json @@ -36,9 +36,7 @@ "@modelcontextprotocol/sdk": "^1.10.2", "@types/express": "^5.0.0", "@types/node": "^22.13.10", - "@types/react": "^19.0.12", "prettier": "^3.5.3", - "react": "^19.0.0", "tsup": "^8.4.0", "tsx": "^4.19.3", "typescript": "^5.8.2" @@ -54,8 +52,6 @@ "dts": true, "clean": true, "outDir": "dist", - "external": [ - "react" - ] + "external": [] } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 48d8491..a987cf4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,15 +24,9 @@ importers: '@types/node': specifier: ^22.13.10 version: 22.13.10 - '@types/react': - specifier: ^19.0.12 - version: 19.0.12 prettier: specifier: ^3.5.3 version: 3.5.3 - react: - specifier: ^19.0.0 - version: 19.0.0 tsup: specifier: ^8.4.0 version: 8.4.0(tsx@4.19.3)(typescript@5.8.2) @@ -350,9 +344,6 @@ packages: '@types/range-parser@1.2.7': resolution: {integrity: sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==} - '@types/react@19.0.12': - resolution: {integrity: sha512-V6Ar115dBDrjbtXSrS+/Oruobc+qVbbUxDFC1RSbRqLt5SYvxxyIDrSC85RWml54g+jfNeEMZhEj7wW07ONQhA==} - '@types/send@0.17.4': resolution: {integrity: sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA==} @@ -479,9 +470,6 @@ packages: resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==} engines: {node: '>= 8'} - csstype@3.1.3: - resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==} - debug@2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} peerDependencies: @@ -899,10 +887,6 @@ packages: resolution: {integrity: sha512-RmkhL8CAyCRPXCE28MMH0z2PNWQBNk2Q09ZdxM9IOOXwxwZbN+qbWaatPkdkWIKL2ZVDImrN/pK5HTRz2PcS4g==} engines: {node: '>= 0.8'} - react@19.0.0: - resolution: {integrity: sha512-V8AVnmPIICiWpGfm6GLzCR/W5FXLchHop40W4nXBmdlEceh16rCN8O8LNWm5bh5XUX91fh7KpA+W0TgMKmgTpQ==} - engines: {node: '>=0.10.0'} - readdirp@4.1.2: resolution: {integrity: sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==} engines: {node: '>= 14.18.0'} @@ -1334,10 +1318,6 @@ snapshots: '@types/range-parser@1.2.7': {} - '@types/react@19.0.12': - dependencies: - csstype: 3.1.3 - '@types/send@0.17.4': dependencies: '@types/mime': 1.3.5 @@ -1474,8 +1454,6 @@ snapshots: shebang-command: 2.0.0 which: 2.0.2 - csstype@3.1.3: {} - debug@2.6.9: dependencies: ms: 2.0.0 @@ -1896,8 +1874,6 @@ snapshots: iconv-lite: 0.6.3 unpipe: 1.0.0 - react@19.0.0: {} - readdirp@4.1.2: {} resolve-from@5.0.0: {} diff --git a/tsconfig.json b/tsconfig.json index cd9cfa1..9bfece1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "esModuleInterop": true, "noEmit": true, "lib": ["ES2022", "DOM"], - "types": ["node", "react"], + "types": ["node"], "forceConsistentCasingInFileNames": true, "resolveJsonModule": true } From 114ee3c4b6983fe6b425a0ab32b2c01a3cba4301 Mon Sep 17 00:00:00 2001 From: shaun smith <1936278+evalstate@users.noreply.github.com> Date: Mon, 5 May 2025 11:53:53 +0100 Subject: [PATCH 05/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c36424c..bc70b15 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ To bypass authentication, or to emit custom headers on all requests to your remo } ``` -**Note:** Cursor has 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: +**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: ```jsonc { From b9105958c1f8c40c10361d8542c647d875b204af Mon Sep 17 00:00:00 2001 From: dp-rufus <73200607+dp-rufus@users.noreply.github.com> Date: Fri, 18 Apr 2025 03:30:43 +0100 Subject: [PATCH 06/12] Attempt auto close --- src/lib/utils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index c6238b2..8843c3f 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -300,7 +300,8 @@ export function setupOAuthCallbackServerWithLongPoll(options: OAuthCallbackServe log('Auth code received, resolving promise') authCompletedResolve(code) - res.send('Authorization successful! You may close this window and return to the CLI.') + res.send('Authorization successful! You may close this window and return to the CLI.' + + '') // Notify main flow that auth code is available options.events.emit('auth-code-received', code) From 5c71b268694635f7687ab35a38144e6ce4e9db6a Mon Sep 17 00:00:00 2001 From: Glen Maddern Date: Mon, 5 May 2025 15:25:49 +1000 Subject: [PATCH 07/12] Added a 2 second delay before closing the browser --- src/lib/utils.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 8843c3f..c88a08b 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -130,14 +130,14 @@ export async function connectToRemoteServer( const sseTransport = transportStrategy === 'sse-only' || transportStrategy === 'sse-first' const transport = sseTransport ? new SSEClientTransport(url, { - authProvider, - requestInit: { headers }, - eventSourceInit, - }) + authProvider, + requestInit: { headers }, + eventSourceInit, + }) : new StreamableHTTPClientTransport(url, { - authProvider, - requestInit: { headers }, - }) + authProvider, + requestInit: { headers }, + }) try { if (client) { @@ -300,8 +300,16 @@ export function setupOAuthCallbackServerWithLongPoll(options: OAuthCallbackServe log('Auth code received, resolving promise') authCompletedResolve(code) - res.send('Authorization successful! You may close this window and return to the CLI.' + - '') + res.send(` + Authorization successful! + You may close this window and return to the CLI. + + `) // Notify main flow that auth code is available options.events.emit('auth-code-received', code) @@ -377,7 +385,7 @@ export async function findAvailablePort(preferredPort?: number): Promise export async function parseCommandLineArgs(args: string[], defaultPort: number, usage: string) { // Process headers const headers: Record = {} - let i = 0; + let i = 0 while (i < args.length) { if (args[i] === '--header' && i < args.length - 1) { const value = args[i + 1] From 45c1739b4c849575458565c8f5feb746c917fc64 Mon Sep 17 00:00:00 2001 From: Glen Maddern Date: Tue, 6 May 2025 11:13:50 +1000 Subject: [PATCH 08/12] Adding (via mcp-remote ) to clientInfo.name on initialize --- .github/workflows/publish.yml | 11 ++++------- package.json | 1 - src/lib/utils.ts | 15 +++++++++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index dd32058..c58f197 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,14 +15,11 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - run: corepack enable - - uses: actions/setup-node@v4 + - name: Setup pnpm & install + uses: wyvox/action-setup-pnpm@v3 with: - node-version: 20 - cache: "pnpm" - - - name: Install dependencies - run: pnpm install + node-version: 22 + pnpm-version: 10 - name: Build run: pnpm build diff --git a/package.json b/package.json index 2d65086..ba21bf7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "name": "mcp-remote", "version": "0.1.2", - "packageManager": "pnpm@8.15.1", "description": "Remote proxy for Model Context Protocol, allowing local-only clients to connect to remote servers using oAuth", "keywords": [ "mcp", diff --git a/src/lib/utils.ts b/src/lib/utils.ts index c88a08b..e86aaac 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -32,14 +32,21 @@ export function mcpProxy({ transportToClient, transportToServer }: { transportTo let transportToClientClosed = false let transportToServerClosed = false - transportToClient.onmessage = (message) => { - // @ts-expect-error TODO + transportToClient.onmessage = (_message) => { + // TODO: fix types + const message = _message as any log('[Local→Remote]', message.method || message.id) + if (message.method === 'initialize') { + const { clientInfo } = message.params + if (clientInfo) clientInfo.name = `${clientInfo.name} (via mcp-remote ${MCP_REMOTE_VERSION})` + log(JSON.stringify(message, null, 2)) + } transportToServer.send(message).catch(onServerError) } - transportToServer.onmessage = (message) => { - // @ts-expect-error TODO: fix this type + transportToServer.onmessage = (_message) => { + // TODO: fix types + const message = _message as any log('[Remote→Local]', message.method || message.id) transportToClient.send(message).catch(onClientError) } From 63e02eef1c11aa4f218ab94906f3ac1e05591198 Mon Sep 17 00:00:00 2001 From: Glen Maddern Date: Tue, 6 May 2025 09:00:58 +1000 Subject: [PATCH 09/12] Use 127.0.0.1 everywhere _except_ as a redirect_uri for the client registration --- src/lib/node-oauth-client-provider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/node-oauth-client-provider.ts b/src/lib/node-oauth-client-provider.ts index 1e58b7e..806f3af 100644 --- a/src/lib/node-oauth-client-provider.ts +++ b/src/lib/node-oauth-client-provider.ts @@ -37,7 +37,7 @@ export class NodeOAuthClientProvider implements OAuthClientProvider { } get redirectUrl(): string { - return `http://127.0.0.1:${this.options.callbackPort}${this.callbackPath}` + return `http://localhost:${this.options.callbackPort}${this.callbackPath}` } get clientMetadata() { From 46e33334164cb75be0b6490f205a7c87e0ae775c Mon Sep 17 00:00:00 2001 From: Glen Maddern Date: Mon, 12 May 2025 15:27:57 +1000 Subject: [PATCH 10/12] 0.1.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ba21bf7..77a21a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mcp-remote", - "version": "0.1.2", + "version": "0.1.3", "description": "Remote proxy for Model Context Protocol, allowing local-only clients to connect to remote servers using oAuth", "keywords": [ "mcp", From 767549412f79bd92d85f07a3c9dfe4f8a2f0cf7b Mon Sep 17 00:00:00 2001 From: Tomer Zait Date: Tue, 6 May 2025 19:00:33 +0300 Subject: [PATCH 11/12] fix issue #64 --- src/lib/utils.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index e86aaac..572550c 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -484,6 +484,11 @@ export function setupSignalHandlers(cleanup: () => Promise) { // Keep the process alive process.stdin.resume() + process.stdin.on('end', async () => { + log('\nShutting down...') + await cleanup() + process.exit(0) + }) } /** From bd75a1cdf026bed04e03ce097293124028c329f1 Mon Sep 17 00:00:00 2001 From: Glen Maddern Date: Mon, 12 May 2025 15:37:49 +1000 Subject: [PATCH 12/12] 0.1.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 77a21a4..4c7a40d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mcp-remote", - "version": "0.1.3", + "version": "0.1.4", "description": "Remote proxy for Model Context Protocol, allowing local-only clients to connect to remote servers using oAuth", "keywords": [ "mcp",