mcp-proxy 5.7.0 → 5.8.1
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-9KZaSDCW.js} +61 -5
- package/dist/{stdio-AohZZTMh.js.map → stdio-9KZaSDCW.js.map} +1 -1
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/startHTTPServer.test.ts +974 -0
- package/src/startHTTPServer.ts +92 -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-9KZaSDCW.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-9KZaSDCW.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,42 @@ 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
|
+
const authResult = await authenticate(req);
|
|
15057
|
+
if (!authResult || typeof authResult === "object" && "authenticated" in authResult && !authResult.authenticated) {
|
|
15058
|
+
const errorMessage = authResult && typeof authResult === "object" && "error" in authResult && typeof authResult.error === "string" ? authResult.error : "Unauthorized: Authentication failed";
|
|
15059
|
+
res.setHeader("Content-Type", "application/json");
|
|
15060
|
+
res.writeHead(401).end(JSON.stringify({
|
|
15061
|
+
error: {
|
|
15062
|
+
code: -32e3,
|
|
15063
|
+
message: errorMessage
|
|
15064
|
+
},
|
|
15065
|
+
id: body?.id ?? null,
|
|
15066
|
+
jsonrpc: "2.0"
|
|
15067
|
+
}));
|
|
15068
|
+
return true;
|
|
15069
|
+
}
|
|
15070
|
+
} catch (error) {
|
|
15071
|
+
const errorMessage = error instanceof Error ? error.message : "Unauthorized: Authentication error";
|
|
15072
|
+
console.error("Authentication error:", error);
|
|
15073
|
+
res.setHeader("Content-Type", "application/json");
|
|
15074
|
+
res.writeHead(401).end(JSON.stringify({
|
|
15075
|
+
error: {
|
|
15076
|
+
code: -32e3,
|
|
15077
|
+
message: errorMessage
|
|
15078
|
+
},
|
|
15079
|
+
id: body?.id ?? null,
|
|
15080
|
+
jsonrpc: "2.0"
|
|
15081
|
+
}));
|
|
15082
|
+
return true;
|
|
15083
|
+
}
|
|
15055
15084
|
if (sessionId) {
|
|
15056
15085
|
const activeTransport = activeTransports[sessionId];
|
|
15057
15086
|
if (!activeTransport) {
|
|
@@ -15086,6 +15115,19 @@ const handleStreamRequest = async ({ activeTransports, createServer, enableJsonR
|
|
|
15086
15115
|
try {
|
|
15087
15116
|
server = await createServer(req);
|
|
15088
15117
|
} catch (error) {
|
|
15118
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
15119
|
+
if (errorMessage.includes("Authentication") || errorMessage.includes("Invalid JWT") || errorMessage.includes("Token") || errorMessage.includes("Unauthorized")) {
|
|
15120
|
+
res.setHeader("Content-Type", "application/json");
|
|
15121
|
+
res.writeHead(401).end(JSON.stringify({
|
|
15122
|
+
error: {
|
|
15123
|
+
code: -32e3,
|
|
15124
|
+
message: errorMessage
|
|
15125
|
+
},
|
|
15126
|
+
id: body?.id ?? null,
|
|
15127
|
+
jsonrpc: "2.0"
|
|
15128
|
+
}));
|
|
15129
|
+
return true;
|
|
15130
|
+
}
|
|
15089
15131
|
if (handleResponseError(error, res)) return true;
|
|
15090
15132
|
res.writeHead(500).end("Error creating server");
|
|
15091
15133
|
return true;
|
|
@@ -15104,6 +15146,19 @@ const handleStreamRequest = async ({ activeTransports, createServer, enableJsonR
|
|
|
15104
15146
|
try {
|
|
15105
15147
|
server = await createServer(req);
|
|
15106
15148
|
} catch (error) {
|
|
15149
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
15150
|
+
if (errorMessage.includes("Authentication") || errorMessage.includes("Invalid JWT") || errorMessage.includes("Token") || errorMessage.includes("Unauthorized")) {
|
|
15151
|
+
res.setHeader("Content-Type", "application/json");
|
|
15152
|
+
res.writeHead(401).end(JSON.stringify({
|
|
15153
|
+
error: {
|
|
15154
|
+
code: -32e3,
|
|
15155
|
+
message: errorMessage
|
|
15156
|
+
},
|
|
15157
|
+
id: body?.id ?? null,
|
|
15158
|
+
jsonrpc: "2.0"
|
|
15159
|
+
}));
|
|
15160
|
+
return true;
|
|
15161
|
+
}
|
|
15107
15162
|
if (handleResponseError(error, res)) return true;
|
|
15108
15163
|
res.writeHead(500).end("Error creating server");
|
|
15109
15164
|
return true;
|
|
@@ -15220,7 +15275,7 @@ const handleSSERequest = async ({ activeTransports, createServer, endpoint, onCl
|
|
|
15220
15275
|
}
|
|
15221
15276
|
return false;
|
|
15222
15277
|
};
|
|
15223
|
-
const startHTTPServer = async ({ apiKey, createServer, enableJsonResponse, eventStore, host = "::", onClose, onConnect, onUnhandledRequest, port, sseEndpoint = "/sse", stateless, streamEndpoint = "/mcp" }) => {
|
|
15278
|
+
const startHTTPServer = async ({ apiKey, authenticate, createServer, enableJsonResponse, eventStore, host = "::", onClose, onConnect, onUnhandledRequest, port, sseEndpoint = "/sse", stateless, streamEndpoint = "/mcp" }) => {
|
|
15224
15279
|
const activeSSETransports = {};
|
|
15225
15280
|
const activeStreamTransports = {};
|
|
15226
15281
|
const authMiddleware = new AuthenticationMiddleware({ apiKey });
|
|
@@ -15233,8 +15288,8 @@ const startHTTPServer = async ({ apiKey, createServer, enableJsonResponse, event
|
|
|
15233
15288
|
res.setHeader("Access-Control-Allow-Origin", origin.origin);
|
|
15234
15289
|
res.setHeader("Access-Control-Allow-Credentials", "true");
|
|
15235
15290
|
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
15236
|
-
res.setHeader("Access-Control-Allow-Headers", "
|
|
15237
|
-
res.setHeader("Access-Control-Expose-Headers", "
|
|
15291
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, Mcp-Session-Id, Last-Event-Id");
|
|
15292
|
+
res.setHeader("Access-Control-Expose-Headers", "Mcp-Session-Id");
|
|
15238
15293
|
} catch (error) {
|
|
15239
15294
|
console.error("[mcp-proxy] error parsing origin", error);
|
|
15240
15295
|
}
|
|
@@ -15264,6 +15319,7 @@ const startHTTPServer = async ({ apiKey, createServer, enableJsonResponse, event
|
|
|
15264
15319
|
})) return;
|
|
15265
15320
|
if (streamEndpoint && await handleStreamRequest({
|
|
15266
15321
|
activeTransports: activeStreamTransports,
|
|
15322
|
+
authenticate,
|
|
15267
15323
|
createServer,
|
|
15268
15324
|
enableJsonResponse,
|
|
15269
15325
|
endpoint: streamEndpoint,
|
|
@@ -21483,4 +21539,4 @@ function serializeMessage(message) {
|
|
|
21483
21539
|
|
|
21484
21540
|
//#endregion
|
|
21485
21541
|
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-
|
|
21542
|
+
//# sourceMappingURL=stdio-9KZaSDCW.js.map
|