mcp-simple-gateway
Advanced tools
Comparing version
@@ -1,3 +0,4 @@ | ||
import { McpServerProxyConfig, McpSSEServerConfig, McpStdioServerConfig } from '../types/config.js'; | ||
import { McpServerProxyConfig, McpSSEServerConfig, McpStdioServerConfig, McpStreamableHTTPServerConfig } from '../types/config.js'; | ||
export declare const isSSEConfig: (serverConfig: McpServerProxyConfig) => serverConfig is McpSSEServerConfig; | ||
export declare const isStdioConfig: (serverConfig: McpServerProxyConfig) => serverConfig is McpStdioServerConfig; | ||
export declare const isStreamableHTTPConfig: (serverConfig: McpServerProxyConfig) => serverConfig is McpStreamableHTTPServerConfig; |
@@ -0,6 +1,12 @@ | ||
import { TransportType, } from '../types/config.js'; | ||
export const isSSEConfig = (serverConfig) => { | ||
return 'url' in serverConfig; | ||
return (serverConfig.type === TransportType.SSE || | ||
('url' in serverConfig && | ||
serverConfig.type !== TransportType.STREAMABLE_HTTP)); | ||
}; | ||
export const isStdioConfig = (serverConfig) => { | ||
return 'command' in serverConfig; | ||
return serverConfig.type === TransportType.STDIO || 'command' in serverConfig; | ||
}; | ||
export const isStreamableHTTPConfig = (serverConfig) => { | ||
return serverConfig.type === TransportType.STREAMABLE_HTTP; | ||
}; |
@@ -1,4 +0,3 @@ | ||
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; | ||
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'; | ||
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; | ||
import { McpServerProxyConfig } from '../types/config.js'; | ||
export declare const createServerTransport: (serverConfig: McpServerProxyConfig) => StdioClientTransport | SSEClientTransport; | ||
export declare const createServerTransport: (serverConfig: McpServerProxyConfig) => Transport; |
import { getDefaultEnvironment, StdioClientTransport, } from '@modelcontextprotocol/sdk/client/stdio.js'; | ||
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'; | ||
import { isSSEConfig, isStdioConfig } from '../guards/index.js'; | ||
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'; | ||
import { isSSEConfig, isStdioConfig, isStreamableHTTPConfig } from '../guards/index.js'; | ||
const buildHeaders = (config) => { | ||
const headers = {}; | ||
if (config.headers) { | ||
for (const [key, value] of Object.entries(config.headers)) { | ||
headers[key] = value; | ||
} | ||
} | ||
return headers; | ||
}; | ||
export const createServerTransport = (serverConfig) => { | ||
if (isSSEConfig(serverConfig)) { | ||
const url = new URL(serverConfig.url); | ||
const headers = {}; | ||
if (serverConfig.headers) { | ||
for (const [key, value] of Object.entries(serverConfig.headers)) { | ||
headers[key] = value; | ||
} | ||
} | ||
const headers = buildHeaders(serverConfig); | ||
return new SSEClientTransport(url, { | ||
@@ -25,2 +30,11 @@ eventSourceInit: { | ||
} | ||
if (isStreamableHTTPConfig(serverConfig)) { | ||
const url = new URL(serverConfig.url); | ||
const headers = buildHeaders(serverConfig); | ||
return new StreamableHTTPClientTransport(url, { | ||
requestInit: { | ||
headers, | ||
}, | ||
}); | ||
} | ||
if (isStdioConfig(serverConfig)) { | ||
@@ -27,0 +41,0 @@ return new StdioClientTransport({ |
import { FastifyReply } from 'fastify'; | ||
import { BaseLogger } from 'pino'; | ||
import { SSEMcpProxy } from '../services/SSEMcpProxy.js'; | ||
@@ -8,4 +9,5 @@ import { McpServerProxyConfig } from '../types/config.js'; | ||
reply: FastifyReply; | ||
logger?: BaseLogger; | ||
} | ||
export declare const createSSEProxy: ({ serverName, serverConfig, reply }: Params) => SSEMcpProxy; | ||
export declare const createSSEProxy: ({ serverName, serverConfig, reply, logger, }: Params) => SSEMcpProxy; | ||
export {}; |
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js'; | ||
import { SSEMcpProxy } from '../services/SSEMcpProxy.js'; | ||
import { createServerTransport } from './createServerTransport.js'; | ||
export const createSSEProxy = ({ serverName, serverConfig, reply }) => { | ||
export const createSSEProxy = ({ serverName, serverConfig, reply, logger, }) => { | ||
const serverTransport = createServerTransport(serverConfig); | ||
const mcpProxy = new SSEMcpProxy({ | ||
logger, | ||
serverTransport, | ||
@@ -8,0 +9,0 @@ proxyTransport: new SSEServerTransport(`${serverName}/messages`, reply.raw), |
@@ -7,1 +7,2 @@ export * from './createValidator.js'; | ||
export * from './createLogger.js'; | ||
export * from './errors.js'; |
@@ -7,1 +7,2 @@ export * from './createValidator.js'; | ||
export * from './createLogger.js'; | ||
export * from './errors.js'; |
@@ -15,3 +15,8 @@ import { createMcpServerAuthVerifier, createSSEProxy } from '../helpers/index.js'; | ||
} | ||
const mcpProxy = createSSEProxy({ serverName, serverConfig, reply }); | ||
const mcpProxy = createSSEProxy({ | ||
serverName, | ||
serverConfig, | ||
reply, | ||
logger: request.log, | ||
}); | ||
try { | ||
@@ -18,0 +23,0 @@ await mcpProxy.start(); |
import { IncomingMessage } from 'http'; | ||
import { ServerResponse } from 'http'; | ||
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'; | ||
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; | ||
import { BaseLogger } from 'pino'; | ||
import { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js'; | ||
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js'; | ||
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; | ||
export interface McpProxyInitParams { | ||
serverTransport: StdioClientTransport | SSEClientTransport; | ||
serverTransport: Transport; | ||
proxyTransport: SSEServerTransport; | ||
logger?: BaseLogger; | ||
} | ||
@@ -14,2 +15,3 @@ export declare class SSEMcpProxy { | ||
private proxyTransport; | ||
private logger?; | ||
constructor(params: McpProxyInitParams); | ||
@@ -16,0 +18,0 @@ get sessionId(): string; |
@@ -1,8 +0,10 @@ | ||
import { ErrorCode } from '@modelcontextprotocol/sdk/types.js'; | ||
import { getRPCErrorFromError } from '../helpers/index.js'; | ||
export class SSEMcpProxy { | ||
serverTransport; | ||
proxyTransport; | ||
logger; | ||
constructor(params) { | ||
this.serverTransport = params.serverTransport; | ||
this.proxyTransport = params.proxyTransport; | ||
this.logger = params.logger; | ||
} | ||
@@ -18,15 +20,22 @@ get sessionId() { | ||
}; | ||
this.serverTransport.onerror = (err) => { | ||
this.proxyTransport.send({ | ||
jsonrpc: '2.0', | ||
error: { | ||
code: ErrorCode.InternalError, | ||
message: err.message, | ||
data: err.stack, | ||
}, | ||
id: 0, | ||
}); | ||
this.serverTransport.onerror = async (err) => { | ||
const rpcError = getRPCErrorFromError(err); | ||
try { | ||
await this.proxyTransport.send(rpcError); | ||
} | ||
catch (error) { | ||
this.logger?.error(error, 'Failed to send error'); | ||
} | ||
}; | ||
this.proxyTransport.onmessage = (msg) => { | ||
this.serverTransport.send(msg); | ||
this.proxyTransport.onmessage = async (msg) => { | ||
try { | ||
await this.serverTransport.send(msg); | ||
} | ||
catch (error) { | ||
const rpcError = getRPCErrorFromError(error); | ||
await this.proxyTransport.send({ | ||
...rpcError, | ||
id: rpcError.id || msg.id, | ||
}); | ||
} | ||
}; | ||
@@ -38,7 +47,5 @@ }; | ||
close = async () => { | ||
await Promise.all([ | ||
this.serverTransport.close(), | ||
this.proxyTransport.close(), | ||
]); | ||
await this.serverTransport.close(); | ||
await this.proxyTransport.close(); | ||
}; | ||
} |
import { LevelWithSilentOrString } from 'pino'; | ||
export declare enum TransportType { | ||
STDIO = "stdio", | ||
SSE = "sse", | ||
STREAMABLE_HTTP = "streamableHttp" | ||
} | ||
export interface CommonProxyOptions { | ||
@@ -12,2 +17,3 @@ authTokens?: string[]; | ||
export interface McpStdioServerConfig { | ||
type?: TransportType.STDIO; | ||
command: string; | ||
@@ -18,7 +24,13 @@ args: string[]; | ||
} | ||
export type McpServerConfig = McpStdioServerConfig | McpSSEServerConfig; | ||
export interface McpSSEServerConfig { | ||
type?: TransportType.SSE; | ||
url: string; | ||
headers?: Record<string, string>; | ||
} | ||
export interface McpStreamableHTTPServerConfig { | ||
type: TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string>; | ||
} | ||
export type McpServerConfig = McpStdioServerConfig | McpSSEServerConfig | McpStreamableHTTPServerConfig; | ||
export interface McpServerProxyBaseConfig { | ||
@@ -29,3 +41,4 @@ proxyOptions?: CommonProxyOptions; | ||
export type McpSSEServerProxyConfig = McpServerProxyBaseConfig & McpSSEServerConfig; | ||
export type McpServerProxyConfig = McpStdioServerProxyConfig | McpSSEServerProxyConfig; | ||
export type McpStreamableHTTPServerProxyConfig = McpServerProxyBaseConfig & McpStreamableHTTPServerConfig; | ||
export type McpServerProxyConfig = McpStdioServerProxyConfig | McpSSEServerProxyConfig | McpStreamableHTTPServerProxyConfig; | ||
export interface Config { | ||
@@ -32,0 +45,0 @@ proxyServer: ProxyServerConfig; |
@@ -1,1 +0,6 @@ | ||
export {}; | ||
export var TransportType; | ||
(function (TransportType) { | ||
TransportType["STDIO"] = "stdio"; | ||
TransportType["SSE"] = "sse"; | ||
TransportType["STREAMABLE_HTTP"] = "streamableHttp"; | ||
})(TransportType || (TransportType = {})); |
import { z } from 'zod'; | ||
import { TransportType } from './../../types/config.js'; | ||
export declare const transportTypeSchema: z.ZodNativeEnum<typeof TransportType>; | ||
export declare const commonProxyOptionsSchema: z.ZodObject<{ | ||
@@ -10,2 +12,3 @@ authTokens: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; | ||
export declare const mcpStdioServerConfigSchema: z.ZodObject<{ | ||
type: z.ZodOptional<z.ZodLiteral<TransportType.STDIO>>; | ||
command: z.ZodString; | ||
@@ -18,2 +21,3 @@ args: z.ZodArray<z.ZodString, "many">; | ||
args: string[]; | ||
type?: TransportType.STDIO | undefined; | ||
env?: Record<string, string> | undefined; | ||
@@ -24,2 +28,3 @@ cwd?: string | undefined; | ||
args: string[]; | ||
type?: TransportType.STDIO | undefined; | ||
env?: Record<string, string> | undefined; | ||
@@ -29,2 +34,3 @@ cwd?: string | undefined; | ||
export declare const mcpSSEServerConfigSchema: z.ZodObject<{ | ||
type: z.ZodOptional<z.ZodLiteral<TransportType.SSE>>; | ||
url: z.ZodString; | ||
@@ -34,7 +40,65 @@ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; | ||
url: string; | ||
type?: TransportType.SSE | undefined; | ||
headers?: Record<string, string> | undefined; | ||
}, { | ||
url: string; | ||
type?: TransportType.SSE | undefined; | ||
headers?: Record<string, string> | undefined; | ||
}>; | ||
export declare const mcpStreamableHTTPServerConfigSchema: z.ZodObject<{ | ||
type: z.ZodLiteral<TransportType.STREAMABLE_HTTP>; | ||
url: z.ZodString; | ||
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; | ||
}, "strip", z.ZodTypeAny, { | ||
type: TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
}, { | ||
type: TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
}>; | ||
export declare const mcpServerConfigSchema: z.ZodUnion<[z.ZodObject<{ | ||
type: z.ZodOptional<z.ZodLiteral<TransportType.STDIO>>; | ||
command: z.ZodString; | ||
args: z.ZodArray<z.ZodString, "many">; | ||
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; | ||
cwd: z.ZodOptional<z.ZodString>; | ||
}, "strip", z.ZodTypeAny, { | ||
command: string; | ||
args: string[]; | ||
type?: TransportType.STDIO | undefined; | ||
env?: Record<string, string> | undefined; | ||
cwd?: string | undefined; | ||
}, { | ||
command: string; | ||
args: string[]; | ||
type?: TransportType.STDIO | undefined; | ||
env?: Record<string, string> | undefined; | ||
cwd?: string | undefined; | ||
}>, z.ZodObject<{ | ||
type: z.ZodOptional<z.ZodLiteral<TransportType.SSE>>; | ||
url: z.ZodString; | ||
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; | ||
}, "strip", z.ZodTypeAny, { | ||
url: string; | ||
type?: TransportType.SSE | undefined; | ||
headers?: Record<string, string> | undefined; | ||
}, { | ||
url: string; | ||
type?: TransportType.SSE | undefined; | ||
headers?: Record<string, string> | undefined; | ||
}>, z.ZodObject<{ | ||
type: z.ZodLiteral<TransportType.STREAMABLE_HTTP>; | ||
url: z.ZodString; | ||
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; | ||
}, "strip", z.ZodTypeAny, { | ||
type: TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
}, { | ||
type: TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
}>]>; | ||
export declare const mcpServerProxyBaseConfigSchema: z.ZodObject<{ | ||
@@ -74,2 +138,3 @@ proxyOptions: z.ZodOptional<z.ZodObject<{ | ||
}>, z.ZodObject<{ | ||
type: z.ZodOptional<z.ZodLiteral<TransportType.STDIO>>; | ||
command: z.ZodString; | ||
@@ -82,2 +147,3 @@ args: z.ZodArray<z.ZodString, "many">; | ||
args: string[]; | ||
type?: TransportType.STDIO | undefined; | ||
env?: Record<string, string> | undefined; | ||
@@ -88,2 +154,3 @@ cwd?: string | undefined; | ||
args: string[]; | ||
type?: TransportType.STDIO | undefined; | ||
env?: Record<string, string> | undefined; | ||
@@ -109,2 +176,3 @@ cwd?: string | undefined; | ||
}>, z.ZodObject<{ | ||
type: z.ZodOptional<z.ZodLiteral<TransportType.SSE>>; | ||
url: z.ZodString; | ||
@@ -114,7 +182,38 @@ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; | ||
url: string; | ||
type?: TransportType.SSE | undefined; | ||
headers?: Record<string, string> | undefined; | ||
}, { | ||
url: string; | ||
type?: TransportType.SSE | undefined; | ||
headers?: Record<string, string> | undefined; | ||
}>>; | ||
export declare const mcpStreamableHTTPServerProxyConfigSchema: z.ZodIntersection<z.ZodObject<{ | ||
proxyOptions: z.ZodOptional<z.ZodObject<{ | ||
authTokens: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; | ||
}, "strip", z.ZodTypeAny, { | ||
authTokens?: string[] | undefined; | ||
}, { | ||
authTokens?: string[] | undefined; | ||
}>>; | ||
}, "strip", z.ZodTypeAny, { | ||
proxyOptions?: { | ||
authTokens?: string[] | undefined; | ||
} | undefined; | ||
}, { | ||
proxyOptions?: { | ||
authTokens?: string[] | undefined; | ||
} | undefined; | ||
}>, z.ZodObject<{ | ||
type: z.ZodLiteral<TransportType.STREAMABLE_HTTP>; | ||
url: z.ZodString; | ||
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; | ||
}, "strip", z.ZodTypeAny, { | ||
type: TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
}, { | ||
type: TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
}>>; | ||
export declare const mcpServerProxyConfigSchema: z.ZodUnion<[z.ZodIntersection<z.ZodObject<{ | ||
@@ -137,2 +236,3 @@ proxyOptions: z.ZodOptional<z.ZodObject<{ | ||
}>, z.ZodObject<{ | ||
type: z.ZodOptional<z.ZodLiteral<TransportType.STDIO>>; | ||
command: z.ZodString; | ||
@@ -145,2 +245,3 @@ args: z.ZodArray<z.ZodString, "many">; | ||
args: string[]; | ||
type?: TransportType.STDIO | undefined; | ||
env?: Record<string, string> | undefined; | ||
@@ -151,2 +252,3 @@ cwd?: string | undefined; | ||
args: string[]; | ||
type?: TransportType.STDIO | undefined; | ||
env?: Record<string, string> | undefined; | ||
@@ -171,2 +273,3 @@ cwd?: string | undefined; | ||
}>, z.ZodObject<{ | ||
type: z.ZodOptional<z.ZodLiteral<TransportType.SSE>>; | ||
url: z.ZodString; | ||
@@ -176,6 +279,36 @@ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; | ||
url: string; | ||
type?: TransportType.SSE | undefined; | ||
headers?: Record<string, string> | undefined; | ||
}, { | ||
url: string; | ||
type?: TransportType.SSE | undefined; | ||
headers?: Record<string, string> | undefined; | ||
}>>, z.ZodIntersection<z.ZodObject<{ | ||
proxyOptions: z.ZodOptional<z.ZodObject<{ | ||
authTokens: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; | ||
}, "strip", z.ZodTypeAny, { | ||
authTokens?: string[] | undefined; | ||
}, { | ||
authTokens?: string[] | undefined; | ||
}>>; | ||
}, "strip", z.ZodTypeAny, { | ||
proxyOptions?: { | ||
authTokens?: string[] | undefined; | ||
} | undefined; | ||
}, { | ||
proxyOptions?: { | ||
authTokens?: string[] | undefined; | ||
} | undefined; | ||
}>, z.ZodObject<{ | ||
type: z.ZodLiteral<TransportType.STREAMABLE_HTTP>; | ||
url: z.ZodString; | ||
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; | ||
}, "strip", z.ZodTypeAny, { | ||
type: TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
}, { | ||
type: TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
}>>]>; | ||
@@ -214,27 +347,2 @@ export declare const proxyServerConfigSchema: z.ZodObject<{ | ||
}>; | ||
export declare const mcpServerConfigSchema: z.ZodUnion<[z.ZodObject<{ | ||
command: z.ZodString; | ||
args: z.ZodArray<z.ZodString, "many">; | ||
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; | ||
cwd: z.ZodOptional<z.ZodString>; | ||
}, "strip", z.ZodTypeAny, { | ||
command: string; | ||
args: string[]; | ||
env?: Record<string, string> | undefined; | ||
cwd?: string | undefined; | ||
}, { | ||
command: string; | ||
args: string[]; | ||
env?: Record<string, string> | undefined; | ||
cwd?: string | undefined; | ||
}>, z.ZodObject<{ | ||
url: z.ZodString; | ||
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; | ||
}, "strip", z.ZodTypeAny, { | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
}, { | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
}>]>; | ||
export declare const configSchema: z.ZodObject<{ | ||
@@ -290,2 +398,3 @@ proxyServer: z.ZodObject<{ | ||
}>, z.ZodObject<{ | ||
type: z.ZodOptional<z.ZodLiteral<TransportType.STDIO>>; | ||
command: z.ZodString; | ||
@@ -298,2 +407,3 @@ args: z.ZodArray<z.ZodString, "many">; | ||
args: string[]; | ||
type?: TransportType.STDIO | undefined; | ||
env?: Record<string, string> | undefined; | ||
@@ -304,2 +414,3 @@ cwd?: string | undefined; | ||
args: string[]; | ||
type?: TransportType.STDIO | undefined; | ||
env?: Record<string, string> | undefined; | ||
@@ -324,2 +435,3 @@ cwd?: string | undefined; | ||
}>, z.ZodObject<{ | ||
type: z.ZodOptional<z.ZodLiteral<TransportType.SSE>>; | ||
url: z.ZodString; | ||
@@ -329,6 +441,36 @@ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; | ||
url: string; | ||
type?: TransportType.SSE | undefined; | ||
headers?: Record<string, string> | undefined; | ||
}, { | ||
url: string; | ||
type?: TransportType.SSE | undefined; | ||
headers?: Record<string, string> | undefined; | ||
}>>, z.ZodIntersection<z.ZodObject<{ | ||
proxyOptions: z.ZodOptional<z.ZodObject<{ | ||
authTokens: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; | ||
}, "strip", z.ZodTypeAny, { | ||
authTokens?: string[] | undefined; | ||
}, { | ||
authTokens?: string[] | undefined; | ||
}>>; | ||
}, "strip", z.ZodTypeAny, { | ||
proxyOptions?: { | ||
authTokens?: string[] | undefined; | ||
} | undefined; | ||
}, { | ||
proxyOptions?: { | ||
authTokens?: string[] | undefined; | ||
} | undefined; | ||
}>, z.ZodObject<{ | ||
type: z.ZodLiteral<TransportType.STREAMABLE_HTTP>; | ||
url: z.ZodString; | ||
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; | ||
}, "strip", z.ZodTypeAny, { | ||
type: TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
}, { | ||
type: TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
}>>]>>; | ||
@@ -351,2 +493,3 @@ }, "strip", z.ZodTypeAny, { | ||
args: string[]; | ||
type?: TransportType.STDIO | undefined; | ||
env?: Record<string, string> | undefined; | ||
@@ -360,3 +503,12 @@ cwd?: string | undefined; | ||
url: string; | ||
type?: TransportType.SSE | undefined; | ||
headers?: Record<string, string> | undefined; | ||
}) | ({ | ||
proxyOptions?: { | ||
authTokens?: string[] | undefined; | ||
} | undefined; | ||
} & { | ||
type: TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
})>; | ||
@@ -379,2 +531,3 @@ }, { | ||
args: string[]; | ||
type?: TransportType.STDIO | undefined; | ||
env?: Record<string, string> | undefined; | ||
@@ -388,4 +541,13 @@ cwd?: string | undefined; | ||
url: string; | ||
type?: TransportType.SSE | undefined; | ||
headers?: Record<string, string> | undefined; | ||
}) | ({ | ||
proxyOptions?: { | ||
authTokens?: string[] | undefined; | ||
} | undefined; | ||
} & { | ||
type: TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
})>; | ||
}>; |
// Generated by ts-to-zod | ||
import { z } from 'zod'; | ||
import { TransportType } from './../../types/config.js'; | ||
export const transportTypeSchema = z.nativeEnum(TransportType); | ||
export const commonProxyOptionsSchema = z.object({ | ||
@@ -7,2 +9,3 @@ authTokens: z.array(z.string()).optional(), | ||
export const mcpStdioServerConfigSchema = z.object({ | ||
type: z.literal(TransportType.STDIO).optional(), | ||
command: z.string(), | ||
@@ -14,5 +17,16 @@ args: z.array(z.string()), | ||
export const mcpSSEServerConfigSchema = z.object({ | ||
type: z.literal(TransportType.SSE).optional(), | ||
url: z.string(), | ||
headers: z.record(z.string()).optional(), | ||
}); | ||
export const mcpStreamableHTTPServerConfigSchema = z.object({ | ||
type: z.literal(TransportType.STREAMABLE_HTTP), | ||
url: z.string(), | ||
headers: z.record(z.string()).optional(), | ||
}); | ||
export const mcpServerConfigSchema = z.union([ | ||
mcpStdioServerConfigSchema, | ||
mcpSSEServerConfigSchema, | ||
mcpStreamableHTTPServerConfigSchema, | ||
]); | ||
export const mcpServerProxyBaseConfigSchema = z.object({ | ||
@@ -23,5 +37,7 @@ proxyOptions: commonProxyOptionsSchema.optional(), | ||
export const mcpSSEServerProxyConfigSchema = mcpServerProxyBaseConfigSchema.and(mcpSSEServerConfigSchema); | ||
export const mcpStreamableHTTPServerProxyConfigSchema = mcpServerProxyBaseConfigSchema.and(mcpStreamableHTTPServerConfigSchema); | ||
export const mcpServerProxyConfigSchema = z.union([ | ||
mcpStdioServerProxyConfigSchema, | ||
mcpSSEServerProxyConfigSchema, | ||
mcpStreamableHTTPServerProxyConfigSchema, | ||
]); | ||
@@ -37,6 +53,2 @@ const levelWithSilentOrStringSchema = z.any(); | ||
}); | ||
export const mcpServerConfigSchema = z.union([ | ||
mcpStdioServerConfigSchema, | ||
mcpSSEServerConfigSchema, | ||
]); | ||
export const configSchema = z.object({ | ||
@@ -43,0 +55,0 @@ proxyServer: proxyServerConfigSchema, |
@@ -17,2 +17,3 @@ export declare const validateConfig: (data: unknown, errorPrefix?: string) => { | ||
args: string[]; | ||
type?: import("../types/config.js").TransportType.STDIO | undefined; | ||
env?: Record<string, string> | undefined; | ||
@@ -26,4 +27,13 @@ cwd?: string | undefined; | ||
url: string; | ||
type?: import("../types/config.js").TransportType.SSE | undefined; | ||
headers?: Record<string, string> | undefined; | ||
}) | ({ | ||
proxyOptions?: { | ||
authTokens?: string[] | undefined; | ||
} | undefined; | ||
} & { | ||
type: import("../types/config.js").TransportType.STREAMABLE_HTTP; | ||
url: string; | ||
headers?: Record<string, string> | undefined; | ||
})>; | ||
}; |
{ | ||
"name": "mcp-simple-gateway", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "MCP Simple Gateway", | ||
@@ -23,3 +23,3 @@ "author": "Denny K", | ||
"clean": "rimraf ./dist", | ||
"lint": "eslint . --fix", | ||
"lint": "eslint", | ||
"typecheck": "tsc --noEmit", | ||
@@ -30,3 +30,5 @@ "validate": "npm run typecheck && npm run lint", | ||
"prepublishOnly": "npm run build", | ||
"prepack": "npm run build" | ||
"prepack": "npm run build", | ||
"test": "jest", | ||
"test:watch": "jest --watch" | ||
}, | ||
@@ -48,2 +50,3 @@ "license": "MIT", | ||
"@eslint/js": "^8.57.0", | ||
"@types/jest": "^29.5.14", | ||
"@types/node": "^22.15.3", | ||
@@ -55,5 +58,7 @@ "eslint": "^8.57.0", | ||
"husky": "^9.1.7", | ||
"jest": "^29.7.0", | ||
"lint-staged": "^15.5.1", | ||
"prettier": "^3.2.5", | ||
"rimraf": "^6.0.1", | ||
"ts-jest": "^29.3.2", | ||
"ts-to-zod": "^3.15.0", | ||
@@ -60,0 +65,0 @@ "tsc-alias": "^1.8.15", |
@@ -13,3 +13,3 @@ [](https://www.npmjs.com/package/mcp-simple-gateway) | ||
- 🐳 Docker support | ||
- 🔌 SSE and stdio MCP supported | ||
- 🔌 SSE, stdio and StreamableHTTP MCP supported | ||
@@ -64,2 +64,6 @@ ## Usage | ||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/app/files"] | ||
}, | ||
"echo": { | ||
"type": "streamableHttp", | ||
"url": "http://localhost:8080/mcp" | ||
} | ||
@@ -80,4 +84,6 @@ } | ||
- `[serverName]`: | ||
- `command`: Command to start the server | ||
- `args`: Command arguments | ||
- `command`: Command to start the server (for stdio servers) | ||
- `args`: Command arguments (for stdio servers) | ||
- `url`: URL of the server (for SSE and StreamableHTTP servers) | ||
- `type`: Server type (optional for stdio and SSE, required for StreamableHTTP) | ||
- `proxyOptions`: Proxy options for a specific server | ||
@@ -91,6 +97,7 @@ - `authTokens`: Array of authentication tokens (overrides `proxyServer.options.authTokens` for the specific server) | ||
http://localhost:3000/filesystem/sse | ||
http://localhost:3000/echo/sse | ||
``` | ||
- `localhost:3000` - proxy server address and port (default) | ||
- `/time/sse` and `/filesystem/sse` - paths to corresponding MCP servers that match the keys in the `mcpServers` configuration | ||
- `/time/sse`, `/filesystem/sse`, and `/echo/sse` - paths to corresponding MCP servers that match the keys in the `mcpServers` configuration | ||
@@ -97,0 +104,0 @@ ## Roadmap |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
50827
36.37%47
9.3%1264
38.14%108
6.93%18
20%5
25%