@hasna/logs 0.3.21 → 0.3.22

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.
@@ -0,0 +1,1236 @@
1
+ // @bun
2
+ import {
3
+ DEFAULT_NEGOTIATED_PROTOCOL_VERSION,
4
+ JSONRPCMessageSchema,
5
+ SUPPORTED_PROTOCOL_VERSIONS,
6
+ isInitializeRequest,
7
+ isJSONRPCErrorResponse,
8
+ isJSONRPCRequest,
9
+ isJSONRPCResultResponse
10
+ } from "./index-hjzbctgt.js";
11
+ import"./index-re3ntm60.js";
12
+
13
+ // src/mcp/http.ts
14
+ import { createServer } from "http";
15
+
16
+ // node_modules/@hono/node-server/dist/index.mjs
17
+ import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
18
+ import { Http2ServerRequest } from "http2";
19
+ import { Readable } from "stream";
20
+ import crypto2 from "crypto";
21
+ var RequestError = class extends Error {
22
+ constructor(message, options) {
23
+ super(message, options);
24
+ this.name = "RequestError";
25
+ }
26
+ };
27
+ var toRequestError = (e) => {
28
+ if (e instanceof RequestError) {
29
+ return e;
30
+ }
31
+ return new RequestError(e.message, { cause: e });
32
+ };
33
+ var GlobalRequest = global.Request;
34
+ var Request = class extends GlobalRequest {
35
+ constructor(input, options) {
36
+ if (typeof input === "object" && getRequestCache in input) {
37
+ input = input[getRequestCache]();
38
+ }
39
+ if (typeof options?.body?.getReader !== "undefined") {
40
+ options.duplex ??= "half";
41
+ }
42
+ super(input, options);
43
+ }
44
+ };
45
+ var newHeadersFromIncoming = (incoming) => {
46
+ const headerRecord = [];
47
+ const rawHeaders = incoming.rawHeaders;
48
+ for (let i = 0;i < rawHeaders.length; i += 2) {
49
+ const { [i]: key, [i + 1]: value } = rawHeaders;
50
+ if (key.charCodeAt(0) !== 58) {
51
+ headerRecord.push([key, value]);
52
+ }
53
+ }
54
+ return new Headers(headerRecord);
55
+ };
56
+ var wrapBodyStream = Symbol("wrapBodyStream");
57
+ var newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
58
+ const init = {
59
+ method,
60
+ headers,
61
+ signal: abortController.signal
62
+ };
63
+ if (method === "TRACE") {
64
+ init.method = "GET";
65
+ const req = new Request(url, init);
66
+ Object.defineProperty(req, "method", {
67
+ get() {
68
+ return "TRACE";
69
+ }
70
+ });
71
+ return req;
72
+ }
73
+ if (!(method === "GET" || method === "HEAD")) {
74
+ if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) {
75
+ init.body = new ReadableStream({
76
+ start(controller) {
77
+ controller.enqueue(incoming.rawBody);
78
+ controller.close();
79
+ }
80
+ });
81
+ } else if (incoming[wrapBodyStream]) {
82
+ let reader;
83
+ init.body = new ReadableStream({
84
+ async pull(controller) {
85
+ try {
86
+ reader ||= Readable.toWeb(incoming).getReader();
87
+ const { done, value } = await reader.read();
88
+ if (done) {
89
+ controller.close();
90
+ } else {
91
+ controller.enqueue(value);
92
+ }
93
+ } catch (error) {
94
+ controller.error(error);
95
+ }
96
+ }
97
+ });
98
+ } else {
99
+ init.body = Readable.toWeb(incoming);
100
+ }
101
+ }
102
+ return new Request(url, init);
103
+ };
104
+ var getRequestCache = Symbol("getRequestCache");
105
+ var requestCache = Symbol("requestCache");
106
+ var incomingKey = Symbol("incomingKey");
107
+ var urlKey = Symbol("urlKey");
108
+ var headersKey = Symbol("headersKey");
109
+ var abortControllerKey = Symbol("abortControllerKey");
110
+ var getAbortController = Symbol("getAbortController");
111
+ var requestPrototype = {
112
+ get method() {
113
+ return this[incomingKey].method || "GET";
114
+ },
115
+ get url() {
116
+ return this[urlKey];
117
+ },
118
+ get headers() {
119
+ return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
120
+ },
121
+ [getAbortController]() {
122
+ this[getRequestCache]();
123
+ return this[abortControllerKey];
124
+ },
125
+ [getRequestCache]() {
126
+ this[abortControllerKey] ||= new AbortController;
127
+ return this[requestCache] ||= newRequestFromIncoming(this.method, this[urlKey], this.headers, this[incomingKey], this[abortControllerKey]);
128
+ }
129
+ };
130
+ [
131
+ "body",
132
+ "bodyUsed",
133
+ "cache",
134
+ "credentials",
135
+ "destination",
136
+ "integrity",
137
+ "mode",
138
+ "redirect",
139
+ "referrer",
140
+ "referrerPolicy",
141
+ "signal",
142
+ "keepalive"
143
+ ].forEach((k) => {
144
+ Object.defineProperty(requestPrototype, k, {
145
+ get() {
146
+ return this[getRequestCache]()[k];
147
+ }
148
+ });
149
+ });
150
+ ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
151
+ Object.defineProperty(requestPrototype, k, {
152
+ value: function() {
153
+ return this[getRequestCache]()[k]();
154
+ }
155
+ });
156
+ });
157
+ Object.setPrototypeOf(requestPrototype, Request.prototype);
158
+ var newRequest = (incoming, defaultHostname) => {
159
+ const req = Object.create(requestPrototype);
160
+ req[incomingKey] = incoming;
161
+ const incomingUrl = incoming.url || "";
162
+ if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
163
+ if (incoming instanceof Http2ServerRequest) {
164
+ throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
165
+ }
166
+ try {
167
+ const url2 = new URL(incomingUrl);
168
+ req[urlKey] = url2.href;
169
+ } catch (e) {
170
+ throw new RequestError("Invalid absolute URL", { cause: e });
171
+ }
172
+ return req;
173
+ }
174
+ const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
175
+ if (!host) {
176
+ throw new RequestError("Missing host header");
177
+ }
178
+ let scheme;
179
+ if (incoming instanceof Http2ServerRequest) {
180
+ scheme = incoming.scheme;
181
+ if (!(scheme === "http" || scheme === "https")) {
182
+ throw new RequestError("Unsupported scheme");
183
+ }
184
+ } else {
185
+ scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
186
+ }
187
+ const url = new URL(`${scheme}://${host}${incomingUrl}`);
188
+ if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
189
+ throw new RequestError("Invalid host header");
190
+ }
191
+ req[urlKey] = url.href;
192
+ return req;
193
+ };
194
+ var responseCache = Symbol("responseCache");
195
+ var getResponseCache = Symbol("getResponseCache");
196
+ var cacheKey = Symbol("cache");
197
+ var GlobalResponse = global.Response;
198
+ var Response2 = class _Response {
199
+ #body;
200
+ #init;
201
+ [getResponseCache]() {
202
+ delete this[cacheKey];
203
+ return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
204
+ }
205
+ constructor(body, init) {
206
+ let headers;
207
+ this.#body = body;
208
+ if (init instanceof _Response) {
209
+ const cachedGlobalResponse = init[responseCache];
210
+ if (cachedGlobalResponse) {
211
+ this.#init = cachedGlobalResponse;
212
+ this[getResponseCache]();
213
+ return;
214
+ } else {
215
+ this.#init = init.#init;
216
+ headers = new Headers(init.#init.headers);
217
+ }
218
+ } else {
219
+ this.#init = init;
220
+ }
221
+ if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
222
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
223
+ }
224
+ }
225
+ get headers() {
226
+ const cache = this[cacheKey];
227
+ if (cache) {
228
+ if (!(cache[2] instanceof Headers)) {
229
+ cache[2] = new Headers(cache[2] || { "content-type": "text/plain; charset=UTF-8" });
230
+ }
231
+ return cache[2];
232
+ }
233
+ return this[getResponseCache]().headers;
234
+ }
235
+ get status() {
236
+ return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
237
+ }
238
+ get ok() {
239
+ const status = this.status;
240
+ return status >= 200 && status < 300;
241
+ }
242
+ };
243
+ ["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
244
+ Object.defineProperty(Response2.prototype, k, {
245
+ get() {
246
+ return this[getResponseCache]()[k];
247
+ }
248
+ });
249
+ });
250
+ ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
251
+ Object.defineProperty(Response2.prototype, k, {
252
+ value: function() {
253
+ return this[getResponseCache]()[k]();
254
+ }
255
+ });
256
+ });
257
+ Object.setPrototypeOf(Response2, GlobalResponse);
258
+ Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
259
+ async function readWithoutBlocking(readPromise) {
260
+ return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(undefined))]);
261
+ }
262
+ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromise) {
263
+ const cancel = (error) => {
264
+ reader.cancel(error).catch(() => {});
265
+ };
266
+ writable.on("close", cancel);
267
+ writable.on("error", cancel);
268
+ (currentReadPromise ?? reader.read()).then(flow, handleStreamError);
269
+ return reader.closed.finally(() => {
270
+ writable.off("close", cancel);
271
+ writable.off("error", cancel);
272
+ });
273
+ function handleStreamError(error) {
274
+ if (error) {
275
+ writable.destroy(error);
276
+ }
277
+ }
278
+ function onDrain() {
279
+ reader.read().then(flow, handleStreamError);
280
+ }
281
+ function flow({ done, value }) {
282
+ try {
283
+ if (done) {
284
+ writable.end();
285
+ } else if (!writable.write(value)) {
286
+ writable.once("drain", onDrain);
287
+ } else {
288
+ return reader.read().then(flow, handleStreamError);
289
+ }
290
+ } catch (e) {
291
+ handleStreamError(e);
292
+ }
293
+ }
294
+ }
295
+ function writeFromReadableStream(stream, writable) {
296
+ if (stream.locked) {
297
+ throw new TypeError("ReadableStream is locked.");
298
+ } else if (writable.destroyed) {
299
+ return;
300
+ }
301
+ return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
302
+ }
303
+ var buildOutgoingHttpHeaders = (headers) => {
304
+ const res = {};
305
+ if (!(headers instanceof Headers)) {
306
+ headers = new Headers(headers ?? undefined);
307
+ }
308
+ const cookies = [];
309
+ for (const [k, v] of headers) {
310
+ if (k === "set-cookie") {
311
+ cookies.push(v);
312
+ } else {
313
+ res[k] = v;
314
+ }
315
+ }
316
+ if (cookies.length > 0) {
317
+ res["set-cookie"] = cookies;
318
+ }
319
+ res["content-type"] ??= "text/plain; charset=UTF-8";
320
+ return res;
321
+ };
322
+ var X_ALREADY_SENT = "x-hono-already-sent";
323
+ if (typeof global.crypto === "undefined") {
324
+ global.crypto = crypto2;
325
+ }
326
+ var outgoingEnded = Symbol("outgoingEnded");
327
+ var handleRequestError = () => new Response(null, {
328
+ status: 400
329
+ });
330
+ var handleFetchError = (e) => new Response(null, {
331
+ status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500
332
+ });
333
+ var handleResponseError = (e, outgoing) => {
334
+ const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
335
+ if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
336
+ console.info("The user aborted a request.");
337
+ } else {
338
+ console.error(e);
339
+ if (!outgoing.headersSent) {
340
+ outgoing.writeHead(500, { "Content-Type": "text/plain" });
341
+ }
342
+ outgoing.end(`Error: ${err.message}`);
343
+ outgoing.destroy(err);
344
+ }
345
+ };
346
+ var flushHeaders = (outgoing) => {
347
+ if ("flushHeaders" in outgoing && outgoing.writable) {
348
+ outgoing.flushHeaders();
349
+ }
350
+ };
351
+ var responseViaCache = async (res, outgoing) => {
352
+ let [status, body, header] = res[cacheKey];
353
+ let hasContentLength = false;
354
+ if (!header) {
355
+ header = { "content-type": "text/plain; charset=UTF-8" };
356
+ } else if (header instanceof Headers) {
357
+ hasContentLength = header.has("content-length");
358
+ header = buildOutgoingHttpHeaders(header);
359
+ } else if (Array.isArray(header)) {
360
+ const headerObj = new Headers(header);
361
+ hasContentLength = headerObj.has("content-length");
362
+ header = buildOutgoingHttpHeaders(headerObj);
363
+ } else {
364
+ for (const key in header) {
365
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
366
+ hasContentLength = true;
367
+ break;
368
+ }
369
+ }
370
+ }
371
+ if (!hasContentLength) {
372
+ if (typeof body === "string") {
373
+ header["Content-Length"] = Buffer.byteLength(body);
374
+ } else if (body instanceof Uint8Array) {
375
+ header["Content-Length"] = body.byteLength;
376
+ } else if (body instanceof Blob) {
377
+ header["Content-Length"] = body.size;
378
+ }
379
+ }
380
+ outgoing.writeHead(status, header);
381
+ if (typeof body === "string" || body instanceof Uint8Array) {
382
+ outgoing.end(body);
383
+ } else if (body instanceof Blob) {
384
+ outgoing.end(new Uint8Array(await body.arrayBuffer()));
385
+ } else {
386
+ flushHeaders(outgoing);
387
+ await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
388
+ }
389
+ outgoing[outgoingEnded]?.();
390
+ };
391
+ var isPromise = (res) => typeof res.then === "function";
392
+ var responseViaResponseObject = async (res, outgoing, options = {}) => {
393
+ if (isPromise(res)) {
394
+ if (options.errorHandler) {
395
+ try {
396
+ res = await res;
397
+ } catch (err) {
398
+ const errRes = await options.errorHandler(err);
399
+ if (!errRes) {
400
+ return;
401
+ }
402
+ res = errRes;
403
+ }
404
+ } else {
405
+ res = await res.catch(handleFetchError);
406
+ }
407
+ }
408
+ if (cacheKey in res) {
409
+ return responseViaCache(res, outgoing);
410
+ }
411
+ const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
412
+ if (res.body) {
413
+ const reader = res.body.getReader();
414
+ const values = [];
415
+ let done = false;
416
+ let currentReadPromise = undefined;
417
+ if (resHeaderRecord["transfer-encoding"] !== "chunked") {
418
+ let maxReadCount = 2;
419
+ for (let i = 0;i < maxReadCount; i++) {
420
+ currentReadPromise ||= reader.read();
421
+ const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
422
+ console.error(e);
423
+ done = true;
424
+ });
425
+ if (!chunk) {
426
+ if (i === 1) {
427
+ await new Promise((resolve) => setTimeout(resolve));
428
+ maxReadCount = 3;
429
+ continue;
430
+ }
431
+ break;
432
+ }
433
+ currentReadPromise = undefined;
434
+ if (chunk.value) {
435
+ values.push(chunk.value);
436
+ }
437
+ if (chunk.done) {
438
+ done = true;
439
+ break;
440
+ }
441
+ }
442
+ if (done && !("content-length" in resHeaderRecord)) {
443
+ resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
444
+ }
445
+ }
446
+ outgoing.writeHead(res.status, resHeaderRecord);
447
+ values.forEach((value) => {
448
+ outgoing.write(value);
449
+ });
450
+ if (done) {
451
+ outgoing.end();
452
+ } else {
453
+ if (values.length === 0) {
454
+ flushHeaders(outgoing);
455
+ }
456
+ await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise);
457
+ }
458
+ } else if (resHeaderRecord[X_ALREADY_SENT]) {} else {
459
+ outgoing.writeHead(res.status, resHeaderRecord);
460
+ outgoing.end();
461
+ }
462
+ outgoing[outgoingEnded]?.();
463
+ };
464
+ var getRequestListener = (fetchCallback, options = {}) => {
465
+ const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
466
+ if (options.overrideGlobalObjects !== false && global.Request !== Request) {
467
+ Object.defineProperty(global, "Request", {
468
+ value: Request
469
+ });
470
+ Object.defineProperty(global, "Response", {
471
+ value: Response2
472
+ });
473
+ }
474
+ return async (incoming, outgoing) => {
475
+ let res, req;
476
+ try {
477
+ req = newRequest(incoming, options.hostname);
478
+ let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD";
479
+ if (!incomingEnded) {
480
+ incoming[wrapBodyStream] = true;
481
+ incoming.on("end", () => {
482
+ incomingEnded = true;
483
+ });
484
+ if (incoming instanceof Http2ServerRequest2) {
485
+ outgoing[outgoingEnded] = () => {
486
+ if (!incomingEnded) {
487
+ setTimeout(() => {
488
+ if (!incomingEnded) {
489
+ setTimeout(() => {
490
+ incoming.destroy();
491
+ outgoing.destroy();
492
+ });
493
+ }
494
+ });
495
+ }
496
+ };
497
+ }
498
+ }
499
+ outgoing.on("close", () => {
500
+ const abortController = req[abortControllerKey];
501
+ if (abortController) {
502
+ if (incoming.errored) {
503
+ req[abortControllerKey].abort(incoming.errored.toString());
504
+ } else if (!outgoing.writableFinished) {
505
+ req[abortControllerKey].abort("Client connection prematurely closed.");
506
+ }
507
+ }
508
+ if (!incomingEnded) {
509
+ setTimeout(() => {
510
+ if (!incomingEnded) {
511
+ setTimeout(() => {
512
+ incoming.destroy();
513
+ });
514
+ }
515
+ });
516
+ }
517
+ });
518
+ res = fetchCallback(req, { incoming, outgoing });
519
+ if (cacheKey in res) {
520
+ return responseViaCache(res, outgoing);
521
+ }
522
+ } catch (e) {
523
+ if (!res) {
524
+ if (options.errorHandler) {
525
+ res = await options.errorHandler(req ? e : toRequestError(e));
526
+ if (!res) {
527
+ return;
528
+ }
529
+ } else if (!req) {
530
+ res = handleRequestError();
531
+ } else {
532
+ res = handleFetchError(e);
533
+ }
534
+ } else {
535
+ return handleResponseError(e, outgoing);
536
+ }
537
+ }
538
+ try {
539
+ return await responseViaResponseObject(res, outgoing, options);
540
+ } catch (e) {
541
+ return handleResponseError(e, outgoing);
542
+ }
543
+ };
544
+ };
545
+
546
+ // node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js
547
+ class WebStandardStreamableHTTPServerTransport {
548
+ constructor(options = {}) {
549
+ this._started = false;
550
+ this._hasHandledRequest = false;
551
+ this._streamMapping = new Map;
552
+ this._requestToStreamMapping = new Map;
553
+ this._requestResponseMap = new Map;
554
+ this._initialized = false;
555
+ this._enableJsonResponse = false;
556
+ this._standaloneSseStreamId = "_GET_stream";
557
+ this.sessionIdGenerator = options.sessionIdGenerator;
558
+ this._enableJsonResponse = options.enableJsonResponse ?? false;
559
+ this._eventStore = options.eventStore;
560
+ this._onsessioninitialized = options.onsessioninitialized;
561
+ this._onsessionclosed = options.onsessionclosed;
562
+ this._allowedHosts = options.allowedHosts;
563
+ this._allowedOrigins = options.allowedOrigins;
564
+ this._enableDnsRebindingProtection = options.enableDnsRebindingProtection ?? false;
565
+ this._retryInterval = options.retryInterval;
566
+ }
567
+ async start() {
568
+ if (this._started) {
569
+ throw new Error("Transport already started");
570
+ }
571
+ this._started = true;
572
+ }
573
+ createJsonErrorResponse(status, code, message, options) {
574
+ const error = { code, message };
575
+ if (options?.data !== undefined) {
576
+ error.data = options.data;
577
+ }
578
+ return new Response(JSON.stringify({
579
+ jsonrpc: "2.0",
580
+ error,
581
+ id: null
582
+ }), {
583
+ status,
584
+ headers: {
585
+ "Content-Type": "application/json",
586
+ ...options?.headers
587
+ }
588
+ });
589
+ }
590
+ validateRequestHeaders(req) {
591
+ if (!this._enableDnsRebindingProtection) {
592
+ return;
593
+ }
594
+ if (this._allowedHosts && this._allowedHosts.length > 0) {
595
+ const hostHeader = req.headers.get("host");
596
+ if (!hostHeader || !this._allowedHosts.includes(hostHeader)) {
597
+ const error = `Invalid Host header: ${hostHeader}`;
598
+ this.onerror?.(new Error(error));
599
+ return this.createJsonErrorResponse(403, -32000, error);
600
+ }
601
+ }
602
+ if (this._allowedOrigins && this._allowedOrigins.length > 0) {
603
+ const originHeader = req.headers.get("origin");
604
+ if (originHeader && !this._allowedOrigins.includes(originHeader)) {
605
+ const error = `Invalid Origin header: ${originHeader}`;
606
+ this.onerror?.(new Error(error));
607
+ return this.createJsonErrorResponse(403, -32000, error);
608
+ }
609
+ }
610
+ return;
611
+ }
612
+ async handleRequest(req, options) {
613
+ if (!this.sessionIdGenerator && this._hasHandledRequest) {
614
+ throw new Error("Stateless transport cannot be reused across requests. Create a new transport per request.");
615
+ }
616
+ this._hasHandledRequest = true;
617
+ const validationError = this.validateRequestHeaders(req);
618
+ if (validationError) {
619
+ return validationError;
620
+ }
621
+ switch (req.method) {
622
+ case "POST":
623
+ return this.handlePostRequest(req, options);
624
+ case "GET":
625
+ return this.handleGetRequest(req);
626
+ case "DELETE":
627
+ return this.handleDeleteRequest(req);
628
+ default:
629
+ return this.handleUnsupportedRequest();
630
+ }
631
+ }
632
+ async writePrimingEvent(controller, encoder, streamId, protocolVersion) {
633
+ if (!this._eventStore) {
634
+ return;
635
+ }
636
+ if (protocolVersion < "2025-11-25") {
637
+ return;
638
+ }
639
+ const primingEventId = await this._eventStore.storeEvent(streamId, {});
640
+ let primingEvent = `id: ${primingEventId}
641
+ data:
642
+
643
+ `;
644
+ if (this._retryInterval !== undefined) {
645
+ primingEvent = `id: ${primingEventId}
646
+ retry: ${this._retryInterval}
647
+ data:
648
+
649
+ `;
650
+ }
651
+ controller.enqueue(encoder.encode(primingEvent));
652
+ }
653
+ async handleGetRequest(req) {
654
+ const acceptHeader = req.headers.get("accept");
655
+ if (!acceptHeader?.includes("text/event-stream")) {
656
+ this.onerror?.(new Error("Not Acceptable: Client must accept text/event-stream"));
657
+ return this.createJsonErrorResponse(406, -32000, "Not Acceptable: Client must accept text/event-stream");
658
+ }
659
+ const sessionError = this.validateSession(req);
660
+ if (sessionError) {
661
+ return sessionError;
662
+ }
663
+ const protocolError = this.validateProtocolVersion(req);
664
+ if (protocolError) {
665
+ return protocolError;
666
+ }
667
+ if (this._eventStore) {
668
+ const lastEventId = req.headers.get("last-event-id");
669
+ if (lastEventId) {
670
+ return this.replayEvents(lastEventId);
671
+ }
672
+ }
673
+ if (this._streamMapping.get(this._standaloneSseStreamId) !== undefined) {
674
+ this.onerror?.(new Error("Conflict: Only one SSE stream is allowed per session"));
675
+ return this.createJsonErrorResponse(409, -32000, "Conflict: Only one SSE stream is allowed per session");
676
+ }
677
+ const encoder = new TextEncoder;
678
+ let streamController;
679
+ const readable = new ReadableStream({
680
+ start: (controller) => {
681
+ streamController = controller;
682
+ },
683
+ cancel: () => {
684
+ this._streamMapping.delete(this._standaloneSseStreamId);
685
+ }
686
+ });
687
+ const headers = {
688
+ "Content-Type": "text/event-stream",
689
+ "Cache-Control": "no-cache, no-transform",
690
+ Connection: "keep-alive"
691
+ };
692
+ if (this.sessionId !== undefined) {
693
+ headers["mcp-session-id"] = this.sessionId;
694
+ }
695
+ this._streamMapping.set(this._standaloneSseStreamId, {
696
+ controller: streamController,
697
+ encoder,
698
+ cleanup: () => {
699
+ this._streamMapping.delete(this._standaloneSseStreamId);
700
+ try {
701
+ streamController.close();
702
+ } catch {}
703
+ }
704
+ });
705
+ return new Response(readable, { headers });
706
+ }
707
+ async replayEvents(lastEventId) {
708
+ if (!this._eventStore) {
709
+ this.onerror?.(new Error("Event store not configured"));
710
+ return this.createJsonErrorResponse(400, -32000, "Event store not configured");
711
+ }
712
+ try {
713
+ let streamId;
714
+ if (this._eventStore.getStreamIdForEventId) {
715
+ streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
716
+ if (!streamId) {
717
+ this.onerror?.(new Error("Invalid event ID format"));
718
+ return this.createJsonErrorResponse(400, -32000, "Invalid event ID format");
719
+ }
720
+ if (this._streamMapping.get(streamId) !== undefined) {
721
+ this.onerror?.(new Error("Conflict: Stream already has an active connection"));
722
+ return this.createJsonErrorResponse(409, -32000, "Conflict: Stream already has an active connection");
723
+ }
724
+ }
725
+ const headers = {
726
+ "Content-Type": "text/event-stream",
727
+ "Cache-Control": "no-cache, no-transform",
728
+ Connection: "keep-alive"
729
+ };
730
+ if (this.sessionId !== undefined) {
731
+ headers["mcp-session-id"] = this.sessionId;
732
+ }
733
+ const encoder = new TextEncoder;
734
+ let streamController;
735
+ const readable = new ReadableStream({
736
+ start: (controller) => {
737
+ streamController = controller;
738
+ },
739
+ cancel: () => {}
740
+ });
741
+ const replayedStreamId = await this._eventStore.replayEventsAfter(lastEventId, {
742
+ send: async (eventId, message) => {
743
+ const success = this.writeSSEEvent(streamController, encoder, message, eventId);
744
+ if (!success) {
745
+ this.onerror?.(new Error("Failed replay events"));
746
+ try {
747
+ streamController.close();
748
+ } catch {}
749
+ }
750
+ }
751
+ });
752
+ this._streamMapping.set(replayedStreamId, {
753
+ controller: streamController,
754
+ encoder,
755
+ cleanup: () => {
756
+ this._streamMapping.delete(replayedStreamId);
757
+ try {
758
+ streamController.close();
759
+ } catch {}
760
+ }
761
+ });
762
+ return new Response(readable, { headers });
763
+ } catch (error) {
764
+ this.onerror?.(error);
765
+ return this.createJsonErrorResponse(500, -32000, "Error replaying events");
766
+ }
767
+ }
768
+ writeSSEEvent(controller, encoder, message, eventId) {
769
+ try {
770
+ let eventData = `event: message
771
+ `;
772
+ if (eventId) {
773
+ eventData += `id: ${eventId}
774
+ `;
775
+ }
776
+ eventData += `data: ${JSON.stringify(message)}
777
+
778
+ `;
779
+ controller.enqueue(encoder.encode(eventData));
780
+ return true;
781
+ } catch (error) {
782
+ this.onerror?.(error);
783
+ return false;
784
+ }
785
+ }
786
+ handleUnsupportedRequest() {
787
+ this.onerror?.(new Error("Method not allowed."));
788
+ return new Response(JSON.stringify({
789
+ jsonrpc: "2.0",
790
+ error: {
791
+ code: -32000,
792
+ message: "Method not allowed."
793
+ },
794
+ id: null
795
+ }), {
796
+ status: 405,
797
+ headers: {
798
+ Allow: "GET, POST, DELETE",
799
+ "Content-Type": "application/json"
800
+ }
801
+ });
802
+ }
803
+ async handlePostRequest(req, options) {
804
+ try {
805
+ const acceptHeader = req.headers.get("accept");
806
+ if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
807
+ this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
808
+ return this.createJsonErrorResponse(406, -32000, "Not Acceptable: Client must accept both application/json and text/event-stream");
809
+ }
810
+ const ct = req.headers.get("content-type");
811
+ if (!ct || !ct.includes("application/json")) {
812
+ this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json"));
813
+ return this.createJsonErrorResponse(415, -32000, "Unsupported Media Type: Content-Type must be application/json");
814
+ }
815
+ const requestInfo = {
816
+ headers: Object.fromEntries(req.headers.entries()),
817
+ url: new URL(req.url)
818
+ };
819
+ let rawMessage;
820
+ if (options?.parsedBody !== undefined) {
821
+ rawMessage = options.parsedBody;
822
+ } else {
823
+ try {
824
+ rawMessage = await req.json();
825
+ } catch {
826
+ this.onerror?.(new Error("Parse error: Invalid JSON"));
827
+ return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
828
+ }
829
+ }
830
+ let messages;
831
+ try {
832
+ if (Array.isArray(rawMessage)) {
833
+ messages = rawMessage.map((msg) => JSONRPCMessageSchema.parse(msg));
834
+ } else {
835
+ messages = [JSONRPCMessageSchema.parse(rawMessage)];
836
+ }
837
+ } catch {
838
+ this.onerror?.(new Error("Parse error: Invalid JSON-RPC message"));
839
+ return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
840
+ }
841
+ const isInitializationRequest = messages.some(isInitializeRequest);
842
+ if (isInitializationRequest) {
843
+ if (this._initialized && this.sessionId !== undefined) {
844
+ this.onerror?.(new Error("Invalid Request: Server already initialized"));
845
+ return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
846
+ }
847
+ if (messages.length > 1) {
848
+ this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed"));
849
+ return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
850
+ }
851
+ this.sessionId = this.sessionIdGenerator?.();
852
+ this._initialized = true;
853
+ if (this.sessionId && this._onsessioninitialized) {
854
+ await Promise.resolve(this._onsessioninitialized(this.sessionId));
855
+ }
856
+ }
857
+ if (!isInitializationRequest) {
858
+ const sessionError = this.validateSession(req);
859
+ if (sessionError) {
860
+ return sessionError;
861
+ }
862
+ const protocolError = this.validateProtocolVersion(req);
863
+ if (protocolError) {
864
+ return protocolError;
865
+ }
866
+ }
867
+ const hasRequests = messages.some(isJSONRPCRequest);
868
+ if (!hasRequests) {
869
+ for (const message of messages) {
870
+ this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo });
871
+ }
872
+ return new Response(null, { status: 202 });
873
+ }
874
+ const streamId = crypto.randomUUID();
875
+ const initRequest = messages.find((m) => isInitializeRequest(m));
876
+ const clientProtocolVersion = initRequest ? initRequest.params.protocolVersion : req.headers.get("mcp-protocol-version") ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
877
+ if (this._enableJsonResponse) {
878
+ return new Promise((resolve) => {
879
+ this._streamMapping.set(streamId, {
880
+ resolveJson: resolve,
881
+ cleanup: () => {
882
+ this._streamMapping.delete(streamId);
883
+ }
884
+ });
885
+ for (const message of messages) {
886
+ if (isJSONRPCRequest(message)) {
887
+ this._requestToStreamMapping.set(message.id, streamId);
888
+ }
889
+ }
890
+ for (const message of messages) {
891
+ this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo });
892
+ }
893
+ });
894
+ }
895
+ const encoder = new TextEncoder;
896
+ let streamController;
897
+ const readable = new ReadableStream({
898
+ start: (controller) => {
899
+ streamController = controller;
900
+ },
901
+ cancel: () => {
902
+ this._streamMapping.delete(streamId);
903
+ }
904
+ });
905
+ const headers = {
906
+ "Content-Type": "text/event-stream",
907
+ "Cache-Control": "no-cache",
908
+ Connection: "keep-alive"
909
+ };
910
+ if (this.sessionId !== undefined) {
911
+ headers["mcp-session-id"] = this.sessionId;
912
+ }
913
+ for (const message of messages) {
914
+ if (isJSONRPCRequest(message)) {
915
+ this._streamMapping.set(streamId, {
916
+ controller: streamController,
917
+ encoder,
918
+ cleanup: () => {
919
+ this._streamMapping.delete(streamId);
920
+ try {
921
+ streamController.close();
922
+ } catch {}
923
+ }
924
+ });
925
+ this._requestToStreamMapping.set(message.id, streamId);
926
+ }
927
+ }
928
+ await this.writePrimingEvent(streamController, encoder, streamId, clientProtocolVersion);
929
+ for (const message of messages) {
930
+ let closeSSEStream;
931
+ let closeStandaloneSSEStream;
932
+ if (isJSONRPCRequest(message) && this._eventStore && clientProtocolVersion >= "2025-11-25") {
933
+ closeSSEStream = () => {
934
+ this.closeSSEStream(message.id);
935
+ };
936
+ closeStandaloneSSEStream = () => {
937
+ this.closeStandaloneSSEStream();
938
+ };
939
+ }
940
+ this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo, closeSSEStream, closeStandaloneSSEStream });
941
+ }
942
+ return new Response(readable, { status: 200, headers });
943
+ } catch (error) {
944
+ this.onerror?.(error);
945
+ return this.createJsonErrorResponse(400, -32700, "Parse error", { data: String(error) });
946
+ }
947
+ }
948
+ async handleDeleteRequest(req) {
949
+ const sessionError = this.validateSession(req);
950
+ if (sessionError) {
951
+ return sessionError;
952
+ }
953
+ const protocolError = this.validateProtocolVersion(req);
954
+ if (protocolError) {
955
+ return protocolError;
956
+ }
957
+ await Promise.resolve(this._onsessionclosed?.(this.sessionId));
958
+ await this.close();
959
+ return new Response(null, { status: 200 });
960
+ }
961
+ validateSession(req) {
962
+ if (this.sessionIdGenerator === undefined) {
963
+ return;
964
+ }
965
+ if (!this._initialized) {
966
+ this.onerror?.(new Error("Bad Request: Server not initialized"));
967
+ return this.createJsonErrorResponse(400, -32000, "Bad Request: Server not initialized");
968
+ }
969
+ const sessionId = req.headers.get("mcp-session-id");
970
+ if (!sessionId) {
971
+ this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required"));
972
+ return this.createJsonErrorResponse(400, -32000, "Bad Request: Mcp-Session-Id header is required");
973
+ }
974
+ if (sessionId !== this.sessionId) {
975
+ this.onerror?.(new Error("Session not found"));
976
+ return this.createJsonErrorResponse(404, -32001, "Session not found");
977
+ }
978
+ return;
979
+ }
980
+ validateProtocolVersion(req) {
981
+ const protocolVersion = req.headers.get("mcp-protocol-version");
982
+ if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
983
+ this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion}` + ` (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`));
984
+ return this.createJsonErrorResponse(400, -32000, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`);
985
+ }
986
+ return;
987
+ }
988
+ async close() {
989
+ this._streamMapping.forEach(({ cleanup }) => {
990
+ cleanup();
991
+ });
992
+ this._streamMapping.clear();
993
+ this._requestResponseMap.clear();
994
+ this.onclose?.();
995
+ }
996
+ closeSSEStream(requestId) {
997
+ const streamId = this._requestToStreamMapping.get(requestId);
998
+ if (!streamId)
999
+ return;
1000
+ const stream = this._streamMapping.get(streamId);
1001
+ if (stream) {
1002
+ stream.cleanup();
1003
+ }
1004
+ }
1005
+ closeStandaloneSSEStream() {
1006
+ const stream = this._streamMapping.get(this._standaloneSseStreamId);
1007
+ if (stream) {
1008
+ stream.cleanup();
1009
+ }
1010
+ }
1011
+ async send(message, options) {
1012
+ let requestId = options?.relatedRequestId;
1013
+ if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
1014
+ requestId = message.id;
1015
+ }
1016
+ if (requestId === undefined) {
1017
+ if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
1018
+ throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
1019
+ }
1020
+ let eventId;
1021
+ if (this._eventStore) {
1022
+ eventId = await this._eventStore.storeEvent(this._standaloneSseStreamId, message);
1023
+ }
1024
+ const standaloneSse = this._streamMapping.get(this._standaloneSseStreamId);
1025
+ if (standaloneSse === undefined) {
1026
+ return;
1027
+ }
1028
+ if (standaloneSse.controller && standaloneSse.encoder) {
1029
+ this.writeSSEEvent(standaloneSse.controller, standaloneSse.encoder, message, eventId);
1030
+ }
1031
+ return;
1032
+ }
1033
+ const streamId = this._requestToStreamMapping.get(requestId);
1034
+ if (!streamId) {
1035
+ throw new Error(`No connection established for request ID: ${String(requestId)}`);
1036
+ }
1037
+ const stream = this._streamMapping.get(streamId);
1038
+ if (!this._enableJsonResponse && stream?.controller && stream?.encoder) {
1039
+ let eventId;
1040
+ if (this._eventStore) {
1041
+ eventId = await this._eventStore.storeEvent(streamId, message);
1042
+ }
1043
+ this.writeSSEEvent(stream.controller, stream.encoder, message, eventId);
1044
+ }
1045
+ if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
1046
+ this._requestResponseMap.set(requestId, message);
1047
+ const relatedIds = Array.from(this._requestToStreamMapping.entries()).filter(([_, sid]) => sid === streamId).map(([id]) => id);
1048
+ const allResponsesReady = relatedIds.every((id) => this._requestResponseMap.has(id));
1049
+ if (allResponsesReady) {
1050
+ if (!stream) {
1051
+ throw new Error(`No connection established for request ID: ${String(requestId)}`);
1052
+ }
1053
+ if (this._enableJsonResponse && stream.resolveJson) {
1054
+ const headers = {
1055
+ "Content-Type": "application/json"
1056
+ };
1057
+ if (this.sessionId !== undefined) {
1058
+ headers["mcp-session-id"] = this.sessionId;
1059
+ }
1060
+ const responses = relatedIds.map((id) => this._requestResponseMap.get(id));
1061
+ if (responses.length === 1) {
1062
+ stream.resolveJson(new Response(JSON.stringify(responses[0]), { status: 200, headers }));
1063
+ } else {
1064
+ stream.resolveJson(new Response(JSON.stringify(responses), { status: 200, headers }));
1065
+ }
1066
+ } else {
1067
+ stream.cleanup();
1068
+ }
1069
+ for (const id of relatedIds) {
1070
+ this._requestResponseMap.delete(id);
1071
+ this._requestToStreamMapping.delete(id);
1072
+ }
1073
+ }
1074
+ }
1075
+ }
1076
+ }
1077
+
1078
+ // node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.js
1079
+ class StreamableHTTPServerTransport {
1080
+ constructor(options = {}) {
1081
+ this._requestContext = new WeakMap;
1082
+ this._webStandardTransport = new WebStandardStreamableHTTPServerTransport(options);
1083
+ this._requestListener = getRequestListener(async (webRequest) => {
1084
+ const context = this._requestContext.get(webRequest);
1085
+ return this._webStandardTransport.handleRequest(webRequest, {
1086
+ authInfo: context?.authInfo,
1087
+ parsedBody: context?.parsedBody
1088
+ });
1089
+ }, { overrideGlobalObjects: false });
1090
+ }
1091
+ get sessionId() {
1092
+ return this._webStandardTransport.sessionId;
1093
+ }
1094
+ set onclose(handler) {
1095
+ this._webStandardTransport.onclose = handler;
1096
+ }
1097
+ get onclose() {
1098
+ return this._webStandardTransport.onclose;
1099
+ }
1100
+ set onerror(handler) {
1101
+ this._webStandardTransport.onerror = handler;
1102
+ }
1103
+ get onerror() {
1104
+ return this._webStandardTransport.onerror;
1105
+ }
1106
+ set onmessage(handler) {
1107
+ this._webStandardTransport.onmessage = handler;
1108
+ }
1109
+ get onmessage() {
1110
+ return this._webStandardTransport.onmessage;
1111
+ }
1112
+ async start() {
1113
+ return this._webStandardTransport.start();
1114
+ }
1115
+ async close() {
1116
+ return this._webStandardTransport.close();
1117
+ }
1118
+ async send(message, options) {
1119
+ return this._webStandardTransport.send(message, options);
1120
+ }
1121
+ async handleRequest(req, res, parsedBody) {
1122
+ const authInfo = req.auth;
1123
+ const handler = getRequestListener(async (webRequest) => {
1124
+ return this._webStandardTransport.handleRequest(webRequest, {
1125
+ authInfo,
1126
+ parsedBody
1127
+ });
1128
+ }, { overrideGlobalObjects: false });
1129
+ await handler(req, res);
1130
+ }
1131
+ closeSSEStream(requestId) {
1132
+ this._webStandardTransport.closeSSEStream(requestId);
1133
+ }
1134
+ closeStandaloneSSEStream() {
1135
+ this._webStandardTransport.closeStandaloneSSEStream();
1136
+ }
1137
+ }
1138
+
1139
+ // src/mcp/http.ts
1140
+ var MCP_HTTP_SERVICE_NAME = "logs";
1141
+ var DEFAULT_MCP_HTTP_PORT = 8820;
1142
+ function isHttpMode(argv = process.argv, env = process.env) {
1143
+ return argv.includes("--http") || env.MCP_HTTP === "1";
1144
+ }
1145
+ function resolveMcpHttpPort(argv = process.argv, env = process.env) {
1146
+ const portIdx = argv.indexOf("--port");
1147
+ if (portIdx !== -1 && argv[portIdx + 1]) {
1148
+ return parsePort(argv[portIdx + 1], "--port");
1149
+ }
1150
+ if (env.MCP_HTTP_PORT) {
1151
+ return parsePort(env.MCP_HTTP_PORT, "MCP_HTTP_PORT");
1152
+ }
1153
+ return DEFAULT_MCP_HTTP_PORT;
1154
+ }
1155
+ function parsePort(raw, source) {
1156
+ const parsed = Number(raw);
1157
+ if (!Number.isInteger(parsed) || parsed < 0 || parsed > 65535) {
1158
+ throw new Error(`Invalid ${source} value "${raw}". Expected 0-65535.`);
1159
+ }
1160
+ return parsed;
1161
+ }
1162
+ async function readJsonBody(req) {
1163
+ const chunks = [];
1164
+ for await (const chunk of req) {
1165
+ chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
1166
+ }
1167
+ const text = Buffer.concat(chunks).toString("utf8");
1168
+ if (!text)
1169
+ return;
1170
+ return JSON.parse(text);
1171
+ }
1172
+ async function startMcpHttpServer(buildServer, options) {
1173
+ const host = options?.host ?? "127.0.0.1";
1174
+ const requestedPort = options?.port ?? resolveMcpHttpPort();
1175
+ const serviceName = options?.serviceName ?? MCP_HTTP_SERVICE_NAME;
1176
+ const httpServer = createServer(async (req, res) => {
1177
+ try {
1178
+ const url = new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`);
1179
+ if (req.method === "GET" && url.pathname === "/health") {
1180
+ res.writeHead(200, { "Content-Type": "application/json" });
1181
+ res.end(JSON.stringify({ status: "ok", name: serviceName }));
1182
+ return;
1183
+ }
1184
+ if (url.pathname !== "/mcp") {
1185
+ res.writeHead(404, { "Content-Type": "text/plain" });
1186
+ res.end("Not Found");
1187
+ return;
1188
+ }
1189
+ const server = buildServer();
1190
+ const transport = new StreamableHTTPServerTransport({
1191
+ sessionIdGenerator: undefined
1192
+ });
1193
+ await server.connect(transport);
1194
+ let parsedBody;
1195
+ if (req.method === "POST") {
1196
+ parsedBody = await readJsonBody(req);
1197
+ }
1198
+ await transport.handleRequest(req, res, parsedBody);
1199
+ res.on("close", () => {
1200
+ transport.close();
1201
+ server.close();
1202
+ });
1203
+ } catch (error) {
1204
+ console.error(`[${serviceName}-mcp] HTTP error:`, error);
1205
+ if (!res.headersSent) {
1206
+ res.writeHead(500, { "Content-Type": "application/json" });
1207
+ res.end(JSON.stringify({
1208
+ jsonrpc: "2.0",
1209
+ error: { code: -32603, message: "Internal server error" },
1210
+ id: null
1211
+ }));
1212
+ }
1213
+ }
1214
+ });
1215
+ await new Promise((resolve, reject) => {
1216
+ httpServer.once("error", reject);
1217
+ httpServer.listen(requestedPort, host, () => resolve());
1218
+ });
1219
+ const addr = httpServer.address();
1220
+ const port = typeof addr === "object" && addr ? addr.port : requestedPort;
1221
+ console.error(`[${serviceName}-mcp] Streamable HTTP listening on http://${host}:${port}/mcp`);
1222
+ return {
1223
+ port,
1224
+ host,
1225
+ close: () => new Promise((resolve, reject) => {
1226
+ httpServer.close((err) => err ? reject(err) : resolve());
1227
+ })
1228
+ };
1229
+ }
1230
+ export {
1231
+ startMcpHttpServer,
1232
+ resolveMcpHttpPort,
1233
+ isHttpMode,
1234
+ MCP_HTTP_SERVICE_NAME,
1235
+ DEFAULT_MCP_HTTP_PORT
1236
+ };