mcp-proxy 5.5.6 → 5.6.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/README.md +60 -0
- package/dist/bin/mcp-proxy.js +6 -1
- package/dist/bin/mcp-proxy.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/{stdio-CQWnvum1.js → stdio-Cm2W-uxV.js} +36 -2
- package/dist/stdio-Cm2W-uxV.js.map +1 -0
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/authentication.test.ts +117 -0
- package/src/authentication.ts +43 -0
- package/src/bin/mcp-proxy.ts +5 -0
- package/src/startHTTPServer.test.ts +374 -0
- package/src/startHTTPServer.ts +13 -0
- package/dist/stdio-CQWnvum1.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ type ServerLike = {
|
|
|
60
60
|
connect: Server["connect"];
|
|
61
61
|
};
|
|
62
62
|
declare const startHTTPServer: <T extends ServerLike>({
|
|
63
|
+
apiKey,
|
|
63
64
|
createServer,
|
|
64
65
|
enableJsonResponse,
|
|
65
66
|
eventStore,
|
|
@@ -72,6 +73,7 @@ declare const startHTTPServer: <T extends ServerLike>({
|
|
|
72
73
|
stateless,
|
|
73
74
|
streamEndpoint
|
|
74
75
|
}: {
|
|
76
|
+
apiKey?: string;
|
|
75
77
|
createServer: (request: http.IncomingMessage) => Promise<T>;
|
|
76
78
|
enableJsonResponse?: boolean;
|
|
77
79
|
eventStore?: EventStore;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client, InMemoryEventStore, JSONRPCMessageSchema, LATEST_PROTOCOL_VERSION, ReadBuffer, Server, anyType, arrayType, booleanType, isInitializedNotification, isJSONRPCRequest, isJSONRPCResponse, numberType, objectType, proxyServer, serializeMessage, startHTTPServer, stringType } from "./stdio-
|
|
1
|
+
import { Client, InMemoryEventStore, JSONRPCMessageSchema, LATEST_PROTOCOL_VERSION, ReadBuffer, Server, anyType, arrayType, booleanType, isInitializedNotification, isJSONRPCRequest, isJSONRPCResponse, numberType, objectType, proxyServer, serializeMessage, startHTTPServer, stringType } from "./stdio-Cm2W-uxV.js";
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
|
|
4
4
|
//#region node_modules/.pnpm/eventsource-parser@3.0.3/node_modules/eventsource-parser/dist/index.js
|
|
@@ -14948,6 +14948,33 @@ var StreamableHTTPServerTransport = class {
|
|
|
14948
14948
|
}
|
|
14949
14949
|
};
|
|
14950
14950
|
|
|
14951
|
+
//#endregion
|
|
14952
|
+
//#region src/authentication.ts
|
|
14953
|
+
var AuthenticationMiddleware = class {
|
|
14954
|
+
constructor(config = {}) {
|
|
14955
|
+
this.config = config;
|
|
14956
|
+
}
|
|
14957
|
+
getUnauthorizedResponse() {
|
|
14958
|
+
return {
|
|
14959
|
+
body: JSON.stringify({
|
|
14960
|
+
error: {
|
|
14961
|
+
code: 401,
|
|
14962
|
+
message: "Unauthorized: Invalid or missing API key"
|
|
14963
|
+
},
|
|
14964
|
+
id: null,
|
|
14965
|
+
jsonrpc: "2.0"
|
|
14966
|
+
}),
|
|
14967
|
+
headers: { "Content-Type": "application/json" }
|
|
14968
|
+
};
|
|
14969
|
+
}
|
|
14970
|
+
validateRequest(req) {
|
|
14971
|
+
if (!this.config.apiKey) return true;
|
|
14972
|
+
const apiKey = req.headers["x-api-key"];
|
|
14973
|
+
if (!apiKey || typeof apiKey !== "string") return false;
|
|
14974
|
+
return apiKey === this.config.apiKey;
|
|
14975
|
+
}
|
|
14976
|
+
};
|
|
14977
|
+
|
|
14951
14978
|
//#endregion
|
|
14952
14979
|
//#region src/startHTTPServer.ts
|
|
14953
14980
|
const getBody = (request) => {
|
|
@@ -15173,9 +15200,10 @@ const handleSSERequest = async ({ activeTransports, createServer, endpoint, onCl
|
|
|
15173
15200
|
}
|
|
15174
15201
|
return false;
|
|
15175
15202
|
};
|
|
15176
|
-
const startHTTPServer = async ({ createServer, enableJsonResponse, eventStore, host = "::", onClose, onConnect, onUnhandledRequest, port, sseEndpoint = "/sse", stateless, streamEndpoint = "/mcp" }) => {
|
|
15203
|
+
const startHTTPServer = async ({ apiKey, createServer, enableJsonResponse, eventStore, host = "::", onClose, onConnect, onUnhandledRequest, port, sseEndpoint = "/sse", stateless, streamEndpoint = "/mcp" }) => {
|
|
15177
15204
|
const activeSSETransports = {};
|
|
15178
15205
|
const activeStreamTransports = {};
|
|
15206
|
+
const authMiddleware = new AuthenticationMiddleware({ apiKey });
|
|
15179
15207
|
/**
|
|
15180
15208
|
* @author https://dev.classmethod.jp/articles/mcp-sse/
|
|
15181
15209
|
*/
|
|
@@ -15199,6 +15227,12 @@ const startHTTPServer = async ({ createServer, enableJsonResponse, eventStore, h
|
|
|
15199
15227
|
res.writeHead(200).end("pong");
|
|
15200
15228
|
return;
|
|
15201
15229
|
}
|
|
15230
|
+
if (!authMiddleware.validateRequest(req)) {
|
|
15231
|
+
const authResponse = authMiddleware.getUnauthorizedResponse();
|
|
15232
|
+
res.writeHead(401, authResponse.headers);
|
|
15233
|
+
res.end(authResponse.body);
|
|
15234
|
+
return;
|
|
15235
|
+
}
|
|
15202
15236
|
if (sseEndpoint && await handleSSERequest({
|
|
15203
15237
|
activeTransports: activeSSETransports,
|
|
15204
15238
|
createServer,
|
|
@@ -21421,4 +21455,4 @@ function serializeMessage(message) {
|
|
|
21421
21455
|
|
|
21422
21456
|
//#endregion
|
|
21423
21457
|
export { Client, InMemoryEventStore, JSONRPCMessageSchema, LATEST_PROTOCOL_VERSION, ReadBuffer, Server, __commonJS, __toESM, anyType, arrayType, booleanType, isInitializedNotification, isJSONRPCRequest, isJSONRPCResponse, numberType, objectType, proxyServer, serializeMessage, startHTTPServer, stringType };
|
|
21424
|
-
//# sourceMappingURL=stdio-
|
|
21458
|
+
//# sourceMappingURL=stdio-Cm2W-uxV.js.map
|