format
This commit is contained in:
parent
65e55c3823
commit
d332273355
8 changed files with 21 additions and 29 deletions
1
.prettierignore
Normal file
1
.prettierignore
Normal file
|
@ -0,0 +1 @@
|
|||
pnpm-lock.yaml
|
|
@ -11,10 +11,7 @@ E.g: Claude Desktop or Windsurf
|
|||
"mcpServers": {
|
||||
"remote-example": {
|
||||
"command": "npx",
|
||||
"args": [
|
||||
"mcp-remote",
|
||||
"https://remote.mcp.server/sse"
|
||||
]
|
||||
"args": ["mcp-remote", "https://remote.mcp.server/sse"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,4 +20,3 @@ E.g: Claude Desktop or Windsurf
|
|||
Cursor:
|
||||
|
||||

|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup"
|
||||
"build": "tsup",
|
||||
"check": "prettier --check . && tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.21.2",
|
||||
|
|
|
@ -11,13 +11,8 @@
|
|||
|
||||
import { EventEmitter } from 'events'
|
||||
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
||||
import {
|
||||
NodeOAuthClientProvider,
|
||||
setupOAuthCallbackServer,
|
||||
parseCommandLineArgs,
|
||||
setupSignalHandlers,
|
||||
} from './shared.js'
|
||||
import {connectToRemoteServer, mcpProxy} from "../lib/utils.js";
|
||||
import { NodeOAuthClientProvider, setupOAuthCallbackServer, parseCommandLineArgs, setupSignalHandlers } from './shared.js'
|
||||
import { connectToRemoteServer, mcpProxy } from '../lib/utils.js'
|
||||
|
||||
/**
|
||||
* Main function to run the proxy
|
||||
|
|
|
@ -10,7 +10,7 @@ import path from 'path'
|
|||
import os from 'os'
|
||||
import crypto from 'crypto'
|
||||
import net from 'net'
|
||||
import {OAuthClientProvider} from '@modelcontextprotocol/sdk/client/auth.js'
|
||||
import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js'
|
||||
import {
|
||||
OAuthClientInformation,
|
||||
OAuthClientInformationFull,
|
||||
|
@ -18,7 +18,7 @@ import {
|
|||
OAuthTokens,
|
||||
OAuthTokensSchema,
|
||||
} from '@modelcontextprotocol/sdk/shared/auth.js'
|
||||
import {OAuthCallbackServerOptions, OAuthProviderOptions} from "../lib/types.js";
|
||||
import { OAuthCallbackServerOptions, OAuthProviderOptions } from '../lib/types.js'
|
||||
|
||||
/**
|
||||
* Implements the OAuthClientProvider interface for Node.js environments.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {EventEmitter} from "events";
|
||||
import { EventEmitter } from 'events'
|
||||
|
||||
/**
|
||||
* Options for creating an OAuth client provider
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
import { OAuthClientProvider, UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
|
||||
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
||||
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
||||
import { OAuthClientProvider, UnauthorizedError } from '@modelcontextprotocol/sdk/client/auth.js'
|
||||
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'
|
||||
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'
|
||||
|
||||
/**
|
||||
* Creates a bidirectional proxy between two transports
|
||||
* @param params The transport connections to proxy between
|
||||
*/
|
||||
export function mcpProxy({transportToClient, transportToServer}: {
|
||||
transportToClient: Transport;
|
||||
transportToServer: Transport
|
||||
}) {
|
||||
export function mcpProxy({ transportToClient, transportToServer }: { transportToClient: Transport; transportToServer: Transport }) {
|
||||
let transportToClientClosed = false
|
||||
let transportToServerClosed = false
|
||||
|
||||
transportToClient.onmessage = (message) => {
|
||||
// @ts-expect-error TODO
|
||||
console.error('[Local→Remote]', message.method || message.id)
|
||||
transportToServer.send(message).catch(onServerError)
|
||||
}
|
||||
|
||||
transportToServer.onmessage = (message) => {
|
||||
// @ts-expect-error TODO: fix this type
|
||||
console.error('[Remote→Local]', message.method || message.id)
|
||||
transportToClient.send(message).catch(onClientError)
|
||||
}
|
||||
|
@ -66,7 +65,7 @@ export async function connectToRemoteServer(
|
|||
): Promise<SSEClientTransport> {
|
||||
console.error('Connecting to remote server:', serverUrl)
|
||||
const url = new URL(serverUrl)
|
||||
const transport = new SSEClientTransport(url, {authProvider})
|
||||
const transport = new SSEClientTransport(url, { authProvider })
|
||||
|
||||
try {
|
||||
await transport.start()
|
||||
|
@ -84,7 +83,7 @@ export async function connectToRemoteServer(
|
|||
await transport.finishAuth(code)
|
||||
|
||||
// Create a new transport after auth
|
||||
const newTransport = new SSEClientTransport(url, {authProvider})
|
||||
const newTransport = new SSEClientTransport(url, { authProvider })
|
||||
await newTransport.start()
|
||||
console.error('Connected to remote server after authentication')
|
||||
return newTransport
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue