mcp-proxy 5.7.0 → 5.8.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/dist/bin/mcp-proxy.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/{stdio-AohZZTMh.js → stdio-so1-I7Pn.js} +32 -5
- package/dist/{stdio-AohZZTMh.js.map → stdio-so1-I7Pn.js.map} +1 -1
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/startHTTPServer.test.ts +480 -0
- package/src/startHTTPServer.ts +42 -2
package/dist/bin/mcp-proxy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Client, InMemoryEventStore, ReadBuffer, Server, __commonJS, __toESM, proxyServer, serializeMessage, startHTTPServer } from "../stdio-
|
|
2
|
+
import { Client, InMemoryEventStore, ReadBuffer, Server, __commonJS, __toESM, proxyServer, serializeMessage, startHTTPServer } from "../stdio-so1-I7Pn.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { basename, dirname, extname, join, normalize, relative, resolve } from "path";
|
|
5
5
|
import { format, inspect } from "util";
|
package/dist/index.d.ts
CHANGED
|
@@ -63,6 +63,7 @@ type ServerLike = {
|
|
|
63
63
|
};
|
|
64
64
|
declare const startHTTPServer: <T extends ServerLike>({
|
|
65
65
|
apiKey,
|
|
66
|
+
authenticate,
|
|
66
67
|
createServer,
|
|
67
68
|
enableJsonResponse,
|
|
68
69
|
eventStore,
|
|
@@ -76,6 +77,7 @@ declare const startHTTPServer: <T extends ServerLike>({
|
|
|
76
77
|
streamEndpoint
|
|
77
78
|
}: {
|
|
78
79
|
apiKey?: string;
|
|
80
|
+
authenticate?: (request: http.IncomingMessage) => Promise<unknown>;
|
|
79
81
|
createServer: (request: http.IncomingMessage) => Promise<T>;
|
|
80
82
|
enableJsonResponse?: boolean;
|
|
81
83
|
eventStore?: EventStore;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client, InMemoryEventStore, JSONRPCMessageSchema, LATEST_PROTOCOL_VERSION, NEVER, ReadBuffer, Server, ZodIssueCode, anyType, arrayType, booleanType, isInitializedNotification, isJSONRPCRequest, isJSONRPCResponse, numberType, objectType, proxyServer, serializeMessage, startHTTPServer, stringType } from "./stdio-
|
|
1
|
+
import { Client, InMemoryEventStore, JSONRPCMessageSchema, LATEST_PROTOCOL_VERSION, NEVER, ReadBuffer, Server, ZodIssueCode, anyType, arrayType, booleanType, isInitializedNotification, isJSONRPCRequest, isJSONRPCResponse, numberType, objectType, proxyServer, serializeMessage, startHTTPServer, stringType } from "./stdio-so1-I7Pn.js";
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
|
|
4
4
|
//#region node_modules/.pnpm/eventsource-parser@3.0.6/node_modules/eventsource-parser/dist/index.js
|
|
@@ -15045,13 +15045,39 @@ const cleanupServer = async (server, onClose) => {
|
|
|
15045
15045
|
console.error("[mcp-proxy] error closing server", error);
|
|
15046
15046
|
}
|
|
15047
15047
|
};
|
|
15048
|
-
const handleStreamRequest = async ({ activeTransports, createServer, enableJsonResponse, endpoint, eventStore, onClose, onConnect, req, res, stateless }) => {
|
|
15048
|
+
const handleStreamRequest = async ({ activeTransports, authenticate, createServer, enableJsonResponse, endpoint, eventStore, onClose, onConnect, req, res, stateless }) => {
|
|
15049
15049
|
if (req.method === "POST" && new URL(req.url, "http://localhost").pathname === endpoint) {
|
|
15050
15050
|
try {
|
|
15051
15051
|
const sessionId = Array.isArray(req.headers["mcp-session-id"]) ? req.headers["mcp-session-id"][0] : req.headers["mcp-session-id"];
|
|
15052
15052
|
let transport;
|
|
15053
15053
|
let server;
|
|
15054
15054
|
const body = await getBody(req);
|
|
15055
|
+
if (stateless && authenticate) try {
|
|
15056
|
+
if (!await authenticate(req)) {
|
|
15057
|
+
res.setHeader("Content-Type", "application/json");
|
|
15058
|
+
res.writeHead(401).end(JSON.stringify({
|
|
15059
|
+
error: {
|
|
15060
|
+
code: -32e3,
|
|
15061
|
+
message: "Unauthorized: Authentication failed"
|
|
15062
|
+
},
|
|
15063
|
+
id: body?.id ?? null,
|
|
15064
|
+
jsonrpc: "2.0"
|
|
15065
|
+
}));
|
|
15066
|
+
return true;
|
|
15067
|
+
}
|
|
15068
|
+
} catch (error) {
|
|
15069
|
+
console.error("Authentication error:", error);
|
|
15070
|
+
res.setHeader("Content-Type", "application/json");
|
|
15071
|
+
res.writeHead(401).end(JSON.stringify({
|
|
15072
|
+
error: {
|
|
15073
|
+
code: -32e3,
|
|
15074
|
+
message: "Unauthorized: Authentication error"
|
|
15075
|
+
},
|
|
15076
|
+
id: body?.id ?? null,
|
|
15077
|
+
jsonrpc: "2.0"
|
|
15078
|
+
}));
|
|
15079
|
+
return true;
|
|
15080
|
+
}
|
|
15055
15081
|
if (sessionId) {
|
|
15056
15082
|
const activeTransport = activeTransports[sessionId];
|
|
15057
15083
|
if (!activeTransport) {
|
|
@@ -15220,7 +15246,7 @@ const handleSSERequest = async ({ activeTransports, createServer, endpoint, onCl
|
|
|
15220
15246
|
}
|
|
15221
15247
|
return false;
|
|
15222
15248
|
};
|
|
15223
|
-
const startHTTPServer = async ({ apiKey, createServer, enableJsonResponse, eventStore, host = "::", onClose, onConnect, onUnhandledRequest, port, sseEndpoint = "/sse", stateless, streamEndpoint = "/mcp" }) => {
|
|
15249
|
+
const startHTTPServer = async ({ apiKey, authenticate, createServer, enableJsonResponse, eventStore, host = "::", onClose, onConnect, onUnhandledRequest, port, sseEndpoint = "/sse", stateless, streamEndpoint = "/mcp" }) => {
|
|
15224
15250
|
const activeSSETransports = {};
|
|
15225
15251
|
const activeStreamTransports = {};
|
|
15226
15252
|
const authMiddleware = new AuthenticationMiddleware({ apiKey });
|
|
@@ -15233,8 +15259,8 @@ const startHTTPServer = async ({ apiKey, createServer, enableJsonResponse, event
|
|
|
15233
15259
|
res.setHeader("Access-Control-Allow-Origin", origin.origin);
|
|
15234
15260
|
res.setHeader("Access-Control-Allow-Credentials", "true");
|
|
15235
15261
|
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
15236
|
-
res.setHeader("Access-Control-Allow-Headers", "
|
|
15237
|
-
res.setHeader("Access-Control-Expose-Headers", "
|
|
15262
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, Mcp-Session-Id, Last-Event-Id");
|
|
15263
|
+
res.setHeader("Access-Control-Expose-Headers", "Mcp-Session-Id");
|
|
15238
15264
|
} catch (error) {
|
|
15239
15265
|
console.error("[mcp-proxy] error parsing origin", error);
|
|
15240
15266
|
}
|
|
@@ -15264,6 +15290,7 @@ const startHTTPServer = async ({ apiKey, createServer, enableJsonResponse, event
|
|
|
15264
15290
|
})) return;
|
|
15265
15291
|
if (streamEndpoint && await handleStreamRequest({
|
|
15266
15292
|
activeTransports: activeStreamTransports,
|
|
15293
|
+
authenticate,
|
|
15267
15294
|
createServer,
|
|
15268
15295
|
enableJsonResponse,
|
|
15269
15296
|
endpoint: streamEndpoint,
|
|
@@ -21483,4 +21510,4 @@ function serializeMessage(message) {
|
|
|
21483
21510
|
|
|
21484
21511
|
//#endregion
|
|
21485
21512
|
export { Client, InMemoryEventStore, JSONRPCMessageSchema, LATEST_PROTOCOL_VERSION, NEVER, ReadBuffer, Server, ZodIssueCode, __commonJS, __toESM, anyType, arrayType, booleanType, isInitializedNotification, isJSONRPCRequest, isJSONRPCResponse, numberType, objectType, proxyServer, serializeMessage, startHTTPServer, stringType };
|
|
21486
|
-
//# sourceMappingURL=stdio-
|
|
21513
|
+
//# sourceMappingURL=stdio-so1-I7Pn.js.map
|