mcp-proxy 6.5.4 → 6.5.5
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 +23 -2
- package/dist/bin/mcp-proxy.mjs +17 -2
- package/dist/bin/mcp-proxy.mjs.map +1 -1
- package/dist/index.d.mts +41 -2
- package/dist/index.mjs +1 -1
- package/dist/{stdio-BQunCFor.mjs → stdio-Be0Fx2iV.mjs} +28 -5
- package/dist/stdio-Be0Fx2iV.mjs.map +1 -0
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/InMemoryEventStore.test.ts +96 -0
- package/src/InMemoryEventStore.ts +51 -0
- package/src/bin/mcp-proxy.ts +21 -2
- package/src/index.ts +2 -1
- package/src/startHTTPServer.test.ts +75 -0
- package/src/startHTTPServer.ts +42 -4
- package/dist/stdio-BQunCFor.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -42,15 +42,31 @@ declare class AuthenticationMiddleware {
|
|
|
42
42
|
}
|
|
43
43
|
//#endregion
|
|
44
44
|
//#region src/InMemoryEventStore.d.ts
|
|
45
|
+
interface InMemoryEventStoreOptions {
|
|
46
|
+
/**
|
|
47
|
+
* Maximum number of events retained across all streams before the oldest
|
|
48
|
+
* are evicted (FIFO). Bounds memory use; older reconnect attempts beyond
|
|
49
|
+
* this window fall back to a fresh (non-resumed) stream instead of a replay.
|
|
50
|
+
*
|
|
51
|
+
* @default 1000
|
|
52
|
+
*/
|
|
53
|
+
maxEvents?: number;
|
|
54
|
+
}
|
|
45
55
|
/**
|
|
46
56
|
* Simple in-memory implementation of the EventStore interface for resumability
|
|
47
57
|
* This is primarily intended for examples and testing, not for production use
|
|
48
58
|
* where a persistent storage solution would be more appropriate.
|
|
49
59
|
*/
|
|
50
60
|
declare class InMemoryEventStore implements EventStore {
|
|
61
|
+
/**
|
|
62
|
+
* The number of events currently retained (for observability/testing).
|
|
63
|
+
*/
|
|
64
|
+
get size(): number;
|
|
51
65
|
private events;
|
|
52
66
|
private lastTimestamp;
|
|
53
67
|
private lastTimestampCounter;
|
|
68
|
+
private readonly maxEvents;
|
|
69
|
+
constructor(options?: InMemoryEventStoreOptions);
|
|
54
70
|
/**
|
|
55
71
|
* Replays events that occurred after a specific event ID
|
|
56
72
|
* Implements EventStore.replayEventsAfter
|
|
@@ -90,6 +106,13 @@ declare const proxyServer: ({
|
|
|
90
106
|
}) => Promise<void>;
|
|
91
107
|
//#endregion
|
|
92
108
|
//#region src/startHTTPServer.d.ts
|
|
109
|
+
/**
|
|
110
|
+
* `false` disables the resumability event store entirely (no replay-on-
|
|
111
|
+
* reconnect, no retained state). Omitted/`undefined` creates a fresh,
|
|
112
|
+
* bounded `InMemoryEventStore` per session - see `eventStoreMaxEvents`.
|
|
113
|
+
* Pass an `EventStore` instance to use a shared or custom-backed store.
|
|
114
|
+
*/
|
|
115
|
+
type EventStoreOption = EventStore | false;
|
|
93
116
|
interface CorsOptions {
|
|
94
117
|
allowedHeaders?: string | string[];
|
|
95
118
|
credentials?: boolean;
|
|
@@ -112,6 +135,7 @@ declare const startHTTPServer: <T extends ServerLike>({
|
|
|
112
135
|
createServer,
|
|
113
136
|
enableJsonResponse,
|
|
114
137
|
eventStore,
|
|
138
|
+
eventStoreMaxEvents,
|
|
115
139
|
host,
|
|
116
140
|
keepAliveTimeout,
|
|
117
141
|
oauth,
|
|
@@ -131,7 +155,22 @@ declare const startHTTPServer: <T extends ServerLike>({
|
|
|
131
155
|
cors?: boolean | CorsOptions;
|
|
132
156
|
createServer: (request: http.IncomingMessage) => Promise<T>;
|
|
133
157
|
enableJsonResponse?: boolean;
|
|
134
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Event store for the streamable HTTP transport's resumability support.
|
|
160
|
+
* Pass `false` to disable resumability entirely (recommended for
|
|
161
|
+
* request/response-only deployments that don't need replay-on-reconnect).
|
|
162
|
+
* Omit to get a fresh, bounded `InMemoryEventStore` per session - see
|
|
163
|
+
* `eventStoreMaxEvents`. Pass an `EventStore` instance to bring your own
|
|
164
|
+
* (e.g. a persistent, cross-process store); it will be shared across all
|
|
165
|
+
* sessions handled by this server.
|
|
166
|
+
*/
|
|
167
|
+
eventStore?: EventStoreOption;
|
|
168
|
+
/**
|
|
169
|
+
* Caps how many events the auto-created per-session `InMemoryEventStore`
|
|
170
|
+
* retains (oldest evicted first) before it's overridden by an explicit
|
|
171
|
+
* `eventStore`. Bounds memory for long-lived sessions. Default: 1000.
|
|
172
|
+
*/
|
|
173
|
+
eventStoreMaxEvents?: number;
|
|
135
174
|
host?: string;
|
|
136
175
|
keepAliveTimeout?: number;
|
|
137
176
|
oauth?: AuthConfig["oauth"];
|
|
@@ -185,5 +224,5 @@ type TransportEvent = {
|
|
|
185
224
|
};
|
|
186
225
|
declare const tapTransport: (transport: Transport, eventHandler: (event: TransportEvent) => void) => Transport;
|
|
187
226
|
//#endregion
|
|
188
|
-
export { type AuthConfig, AuthenticationMiddleware, type CorsOptions, InMemoryEventStore, ServerType, proxyServer, startHTTPServer, startStdioServer, tapTransport };
|
|
227
|
+
export { type AuthConfig, AuthenticationMiddleware, type CorsOptions, type EventStoreOption, InMemoryEventStore, type InMemoryEventStoreOptions, ServerType, proxyServer, startHTTPServer, startStdioServer, tapTransport };
|
|
189
228
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as NEVER, S as _coercedNumber, T as AuthenticationMiddleware, _ as looseObject, a as startHTTPServer, b as string, c as LATEST_PROTOCOL_VERSION, d as isJSONRPCResultResponse, f as ZodNumber, g as literal, h as boolean, i as Client, l as isInitializedNotification, m as array, n as serializeMessage, o as proxyServer, p as any, r as Server, s as JSONRPCMessageSchema, t as ReadBuffer, u as isJSONRPCRequest, v as number$1, w as InMemoryEventStore, x as url, y as object } from "./stdio-
|
|
1
|
+
import { C as NEVER, S as _coercedNumber, T as AuthenticationMiddleware, _ as looseObject, a as startHTTPServer, b as string, c as LATEST_PROTOCOL_VERSION, d as isJSONRPCResultResponse, f as ZodNumber, g as literal, h as boolean, i as Client, l as isInitializedNotification, m as array, n as serializeMessage, o as proxyServer, p as any, r as Server, s as JSONRPCMessageSchema, t as ReadBuffer, u as isJSONRPCRequest, v as number$1, w as InMemoryEventStore, x as url, y as object } from "./stdio-Be0Fx2iV.mjs";
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
|
|
4
4
|
//#region node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/classic/compat.js
|
|
@@ -113,15 +113,28 @@ var AuthenticationMiddleware = class {
|
|
|
113
113
|
|
|
114
114
|
//#endregion
|
|
115
115
|
//#region src/InMemoryEventStore.ts
|
|
116
|
+
const DEFAULT_MAX_EVENTS = 1e3;
|
|
116
117
|
/**
|
|
117
118
|
* Simple in-memory implementation of the EventStore interface for resumability
|
|
118
119
|
* This is primarily intended for examples and testing, not for production use
|
|
119
120
|
* where a persistent storage solution would be more appropriate.
|
|
120
121
|
*/
|
|
121
122
|
var InMemoryEventStore = class {
|
|
123
|
+
/**
|
|
124
|
+
* The number of events currently retained (for observability/testing).
|
|
125
|
+
*/
|
|
126
|
+
get size() {
|
|
127
|
+
return this.events.size;
|
|
128
|
+
}
|
|
122
129
|
events = /* @__PURE__ */ new Map();
|
|
123
130
|
lastTimestamp = 0;
|
|
124
131
|
lastTimestampCounter = 0;
|
|
132
|
+
maxEvents;
|
|
133
|
+
constructor(options = {}) {
|
|
134
|
+
const maxEvents = options.maxEvents ?? DEFAULT_MAX_EVENTS;
|
|
135
|
+
if (!(maxEvents >= 1)) throw new Error("maxEvents must be at least 1");
|
|
136
|
+
this.maxEvents = maxEvents;
|
|
137
|
+
}
|
|
125
138
|
/**
|
|
126
139
|
* Replays events that occurred after a specific event ID
|
|
127
140
|
* Implements EventStore.replayEventsAfter
|
|
@@ -152,6 +165,11 @@ var InMemoryEventStore = class {
|
|
|
152
165
|
message,
|
|
153
166
|
streamId
|
|
154
167
|
});
|
|
168
|
+
while (this.events.size > this.maxEvents) {
|
|
169
|
+
const oldestEventId = this.events.keys().next().value;
|
|
170
|
+
if (oldestEventId === void 0) break;
|
|
171
|
+
this.events.delete(oldestEventId);
|
|
172
|
+
}
|
|
155
173
|
return eventId;
|
|
156
174
|
}
|
|
157
175
|
/**
|
|
@@ -15857,6 +15875,10 @@ var StreamableHTTPServerTransport = class {
|
|
|
15857
15875
|
//#endregion
|
|
15858
15876
|
//#region src/startHTTPServer.ts
|
|
15859
15877
|
const DEFAULT_KEEP_ALIVE_TIMEOUT = 3e5;
|
|
15878
|
+
const resolveEventStore = (eventStore, maxEvents) => {
|
|
15879
|
+
if (eventStore === false) return;
|
|
15880
|
+
return eventStore ?? new InMemoryEventStore({ maxEvents });
|
|
15881
|
+
};
|
|
15860
15882
|
const getBody = (request) => {
|
|
15861
15883
|
return new Promise((resolve$2) => {
|
|
15862
15884
|
const bodyParts = [];
|
|
@@ -15998,7 +16020,7 @@ const applyCorsHeaders = (req, res, corsOptions) => {
|
|
|
15998
16020
|
console.error("[mcp-proxy] error parsing origin", error$1);
|
|
15999
16021
|
}
|
|
16000
16022
|
};
|
|
16001
|
-
const handleStreamRequest = async ({ activeTransports, authenticate, authMiddleware, createServer, enableJsonResponse, endpoint, eventStore, oauth, onClose, onConnect, req, res, stateless }) => {
|
|
16023
|
+
const handleStreamRequest = async ({ activeTransports, authenticate, authMiddleware, createServer, enableJsonResponse, endpoint, eventStore, eventStoreMaxEvents, oauth, onClose, onConnect, req, res, stateless }) => {
|
|
16002
16024
|
if (req.method === "POST" && new URL(req.url, "http://localhost").pathname === endpoint) {
|
|
16003
16025
|
let body;
|
|
16004
16026
|
try {
|
|
@@ -16068,7 +16090,7 @@ const handleStreamRequest = async ({ activeTransports, authenticate, authMiddlew
|
|
|
16068
16090
|
} else if (!sessionId && isInitializeRequest(body)) {
|
|
16069
16091
|
transport = new StreamableHTTPServerTransport({
|
|
16070
16092
|
enableJsonResponse,
|
|
16071
|
-
eventStore: eventStore
|
|
16093
|
+
eventStore: resolveEventStore(eventStore, eventStoreMaxEvents),
|
|
16072
16094
|
onsessioninitialized: (_sessionId) => {
|
|
16073
16095
|
if (!stateless && _sessionId) activeTransports[_sessionId] = {
|
|
16074
16096
|
server,
|
|
@@ -16119,7 +16141,7 @@ const handleStreamRequest = async ({ activeTransports, authenticate, authMiddlew
|
|
|
16119
16141
|
} else if (stateless && !sessionId && !isInitializeRequest(body)) {
|
|
16120
16142
|
transport = new StreamableHTTPServerTransport({
|
|
16121
16143
|
enableJsonResponse,
|
|
16122
|
-
eventStore: eventStore
|
|
16144
|
+
eventStore: resolveEventStore(eventStore, eventStoreMaxEvents),
|
|
16123
16145
|
onsessioninitialized: () => {},
|
|
16124
16146
|
sessionIdGenerator: void 0
|
|
16125
16147
|
});
|
|
@@ -16308,7 +16330,7 @@ const handleSSERequest = async ({ activeTransports, createServer, endpoint, onCl
|
|
|
16308
16330
|
}
|
|
16309
16331
|
return false;
|
|
16310
16332
|
};
|
|
16311
|
-
const startHTTPServer = async ({ apiKey, authenticate, cors, createServer, enableJsonResponse, eventStore, host = "::", keepAliveTimeout = DEFAULT_KEEP_ALIVE_TIMEOUT, oauth, onClose, onConnect, onUnhandledRequest, port, sseEndpoint = "/sse", sslCa, sslCert, sslKey, stateless, streamEndpoint = "/mcp" }) => {
|
|
16333
|
+
const startHTTPServer = async ({ apiKey, authenticate, cors, createServer, enableJsonResponse, eventStore, eventStoreMaxEvents, host = "::", keepAliveTimeout = DEFAULT_KEEP_ALIVE_TIMEOUT, oauth, onClose, onConnect, onUnhandledRequest, port, sseEndpoint = "/sse", sslCa, sslCert, sslKey, stateless, streamEndpoint = "/mcp" }) => {
|
|
16312
16334
|
const activeSSETransports = {};
|
|
16313
16335
|
const activeStreamTransports = {};
|
|
16314
16336
|
const authMiddleware = new AuthenticationMiddleware({
|
|
@@ -16364,6 +16386,7 @@ const startHTTPServer = async ({ apiKey, authenticate, cors, createServer, enabl
|
|
|
16364
16386
|
enableJsonResponse,
|
|
16365
16387
|
endpoint: streamEndpoint,
|
|
16366
16388
|
eventStore,
|
|
16389
|
+
eventStoreMaxEvents,
|
|
16367
16390
|
oauth,
|
|
16368
16391
|
onClose,
|
|
16369
16392
|
onConnect,
|
|
@@ -24895,4 +24918,4 @@ function serializeMessage(message) {
|
|
|
24895
24918
|
|
|
24896
24919
|
//#endregion
|
|
24897
24920
|
export { NEVER as C, __toESM as D, __commonJSMin as E, _coercedNumber as S, AuthenticationMiddleware as T, looseObject as _, startHTTPServer as a, string as b, LATEST_PROTOCOL_VERSION as c, isJSONRPCResultResponse as d, ZodNumber as f, literal as g, boolean as h, Client as i, isInitializedNotification as l, array as m, serializeMessage as n, proxyServer as o, any as p, Server as r, JSONRPCMessageSchema as s, ReadBuffer as t, isJSONRPCRequest as u, number as v, InMemoryEventStore as w, url as x, object as y };
|
|
24898
|
-
//# sourceMappingURL=stdio-
|
|
24921
|
+
//# sourceMappingURL=stdio-Be0Fx2iV.mjs.map
|