@hasna/coders 0.2.2 → 0.2.4
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/LICENSE +104 -19
- package/dist/cli.mjs +1419 -31
- package/dist/cli.mjs.map +4 -4
- package/dist/coders-mcp.js +2 -0
- package/dist/coders-mcp.mjs +109232 -0
- package/dist/coders-mcp.mjs.map +7 -0
- package/package.json +6 -2
package/dist/cli.mjs
CHANGED
|
@@ -9587,7 +9587,7 @@ var init_dist = __esm({
|
|
|
9587
9587
|
module.exports = { signatureAlgorithmHashFromCertificate };
|
|
9588
9588
|
});
|
|
9589
9589
|
require_sasl = __commonJS2((exports, module) => {
|
|
9590
|
-
var
|
|
9590
|
+
var crypto4 = require_utils2();
|
|
9591
9591
|
var { signatureAlgorithmHashFromCertificate } = require_cert_signatures();
|
|
9592
9592
|
function startSession(mechanisms, stream) {
|
|
9593
9593
|
const candidates = ["SCRAM-SHA-256"];
|
|
@@ -9600,7 +9600,7 @@ var init_dist = __esm({
|
|
|
9600
9600
|
if (mechanism === "SCRAM-SHA-256-PLUS" && typeof stream.getPeerCertificate !== "function") {
|
|
9601
9601
|
throw new Error("SASL: Mechanism SCRAM-SHA-256-PLUS requires a certificate");
|
|
9602
9602
|
}
|
|
9603
|
-
const clientNonce =
|
|
9603
|
+
const clientNonce = crypto4.randomBytes(18).toString("base64");
|
|
9604
9604
|
const gs2Header = mechanism === "SCRAM-SHA-256-PLUS" ? "p=tls-server-end-point" : stream ? "y" : "n";
|
|
9605
9605
|
return {
|
|
9606
9606
|
mechanism,
|
|
@@ -9636,20 +9636,20 @@ var init_dist = __esm({
|
|
|
9636
9636
|
let hashName = signatureAlgorithmHashFromCertificate(peerCert);
|
|
9637
9637
|
if (hashName === "MD5" || hashName === "SHA-1")
|
|
9638
9638
|
hashName = "SHA-256";
|
|
9639
|
-
const certHash = await
|
|
9639
|
+
const certHash = await crypto4.hashByName(hashName, peerCert);
|
|
9640
9640
|
const bindingData = Buffer.concat([Buffer.from("p=tls-server-end-point,,"), Buffer.from(certHash)]);
|
|
9641
9641
|
channelBinding = bindingData.toString("base64");
|
|
9642
9642
|
}
|
|
9643
9643
|
const clientFinalMessageWithoutProof = "c=" + channelBinding + ",r=" + sv.nonce;
|
|
9644
9644
|
const authMessage = clientFirstMessageBare + "," + serverFirstMessage + "," + clientFinalMessageWithoutProof;
|
|
9645
9645
|
const saltBytes = Buffer.from(sv.salt, "base64");
|
|
9646
|
-
const saltedPassword = await
|
|
9647
|
-
const clientKey = await
|
|
9648
|
-
const storedKey = await
|
|
9649
|
-
const clientSignature = await
|
|
9646
|
+
const saltedPassword = await crypto4.deriveKey(password, saltBytes, sv.iteration);
|
|
9647
|
+
const clientKey = await crypto4.hmacSha256(saltedPassword, "Client Key");
|
|
9648
|
+
const storedKey = await crypto4.sha256(clientKey);
|
|
9649
|
+
const clientSignature = await crypto4.hmacSha256(storedKey, authMessage);
|
|
9650
9650
|
const clientProof = xorBuffers(Buffer.from(clientKey), Buffer.from(clientSignature)).toString("base64");
|
|
9651
|
-
const serverKey = await
|
|
9652
|
-
const serverSignatureBytes = await
|
|
9651
|
+
const serverKey = await crypto4.hmacSha256(saltedPassword, "Server Key");
|
|
9652
|
+
const serverSignatureBytes = await crypto4.hmacSha256(serverKey, authMessage);
|
|
9653
9653
|
session.message = "SASLResponse";
|
|
9654
9654
|
session.serverSignature = Buffer.from(serverSignatureBytes).toString("base64");
|
|
9655
9655
|
session.response = clientFinalMessageWithoutProof + ",p=" + clientProof;
|
|
@@ -11651,7 +11651,7 @@ See https://www.postgresql.org/docs/current/libpq-ssl.html for libpq SSL mode de
|
|
|
11651
11651
|
var Query2 = require_query();
|
|
11652
11652
|
var defaults2 = require_defaults();
|
|
11653
11653
|
var Connection2 = require_connection();
|
|
11654
|
-
var
|
|
11654
|
+
var crypto4 = require_utils2();
|
|
11655
11655
|
var activeQueryDeprecationNotice = nodeUtils.deprecate(() => {
|
|
11656
11656
|
}, "Client.activeQuery is deprecated and will be removed in pg@9.0");
|
|
11657
11657
|
var queryQueueDeprecationNotice = nodeUtils.deprecate(() => {
|
|
@@ -11871,7 +11871,7 @@ See https://www.postgresql.org/docs/current/libpq-ssl.html for libpq SSL mode de
|
|
|
11871
11871
|
_handleAuthMD5Password(msg) {
|
|
11872
11872
|
this._getPassword(async () => {
|
|
11873
11873
|
try {
|
|
11874
|
-
const hashedPassword = await
|
|
11874
|
+
const hashedPassword = await crypto4.postgresMd5PasswordHash(this.user, this.password, msg.salt);
|
|
11875
11875
|
this.connection.password(hashedPassword);
|
|
11876
11876
|
} catch (e) {
|
|
11877
11877
|
this.emit("error", e);
|
|
@@ -44134,8 +44134,8 @@ var init_wrap_text = __esm({
|
|
|
44134
44134
|
init_cli_truncate();
|
|
44135
44135
|
cache2 = {};
|
|
44136
44136
|
wrapText = (text, maxWidth, wrapType) => {
|
|
44137
|
-
const
|
|
44138
|
-
const cachedText = cache2[
|
|
44137
|
+
const cacheKey2 = text + String(maxWidth) + String(wrapType);
|
|
44138
|
+
const cachedText = cache2[cacheKey2];
|
|
44139
44139
|
if (cachedText) {
|
|
44140
44140
|
return cachedText;
|
|
44141
44141
|
}
|
|
@@ -44156,7 +44156,7 @@ var init_wrap_text = __esm({
|
|
|
44156
44156
|
}
|
|
44157
44157
|
wrappedText = cliTruncate(text, maxWidth, { position });
|
|
44158
44158
|
}
|
|
44159
|
-
cache2[
|
|
44159
|
+
cache2[cacheKey2] = wrappedText;
|
|
44160
44160
|
return wrappedText;
|
|
44161
44161
|
};
|
|
44162
44162
|
wrap_text_default = wrapText;
|
|
@@ -46743,7 +46743,7 @@ var require_websocket = __commonJS({
|
|
|
46743
46743
|
var net = __require("net");
|
|
46744
46744
|
var tls = __require("tls");
|
|
46745
46745
|
var { randomBytes: randomBytes2, createHash: createHash2 } = __require("crypto");
|
|
46746
|
-
var { Duplex, Readable } = __require("stream");
|
|
46746
|
+
var { Duplex, Readable: Readable2 } = __require("stream");
|
|
46747
46747
|
var { URL: URL2 } = __require("url");
|
|
46748
46748
|
var PerMessageDeflate = require_permessage_deflate();
|
|
46749
46749
|
var Receiver2 = require_receiver();
|
|
@@ -76380,9 +76380,9 @@ var require_to_regex_range = __commonJS({
|
|
|
76380
76380
|
let shorthand = String(opts.shorthand);
|
|
76381
76381
|
let capture = String(opts.capture);
|
|
76382
76382
|
let wrap = String(opts.wrap);
|
|
76383
|
-
let
|
|
76384
|
-
if (toRegexRange.cache.hasOwnProperty(
|
|
76385
|
-
return toRegexRange.cache[
|
|
76383
|
+
let cacheKey2 = min + ":" + max + "=" + relax + shorthand + capture + wrap;
|
|
76384
|
+
if (toRegexRange.cache.hasOwnProperty(cacheKey2)) {
|
|
76385
|
+
return toRegexRange.cache[cacheKey2].result;
|
|
76386
76386
|
}
|
|
76387
76387
|
let a = Math.min(min, max);
|
|
76388
76388
|
let b = Math.max(min, max);
|
|
@@ -76420,7 +76420,7 @@ var require_to_regex_range = __commonJS({
|
|
|
76420
76420
|
} else if (opts.wrap !== false && positives.length + negatives.length > 1) {
|
|
76421
76421
|
state.result = `(?:${state.result})`;
|
|
76422
76422
|
}
|
|
76423
|
-
toRegexRange.cache[
|
|
76423
|
+
toRegexRange.cache[cacheKey2] = state;
|
|
76424
76424
|
return state.result;
|
|
76425
76425
|
};
|
|
76426
76426
|
function collatePatterns(neg, pos, options2) {
|
|
@@ -88287,11 +88287,12 @@ var init_v4 = __esm({
|
|
|
88287
88287
|
});
|
|
88288
88288
|
|
|
88289
88289
|
// node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
|
|
88290
|
-
var LATEST_PROTOCOL_VERSION, SUPPORTED_PROTOCOL_VERSIONS, RELATED_TASK_META_KEY, JSONRPC_VERSION, AssertObjectSchema, ProgressTokenSchema, CursorSchema, TaskCreationParamsSchema, TaskMetadataSchema, RelatedTaskMetadataSchema, RequestMetaSchema, BaseRequestParamsSchema, TaskAugmentedRequestParamsSchema, isTaskAugmentedRequestParams, RequestSchema, NotificationsParamsSchema, NotificationSchema, ResultSchema, RequestIdSchema, JSONRPCRequestSchema, isJSONRPCRequest, JSONRPCNotificationSchema, isJSONRPCNotification, JSONRPCResultResponseSchema, isJSONRPCResultResponse, ErrorCode, JSONRPCErrorResponseSchema, isJSONRPCErrorResponse, JSONRPCMessageSchema, JSONRPCResponseSchema, EmptyResultSchema, CancelledNotificationParamsSchema, CancelledNotificationSchema, IconSchema, IconsSchema, BaseMetadataSchema, ImplementationSchema, FormElicitationCapabilitySchema, ElicitationCapabilitySchema, ClientTasksCapabilitySchema, ServerTasksCapabilitySchema, ClientCapabilitiesSchema, InitializeRequestParamsSchema, InitializeRequestSchema, ServerCapabilitiesSchema, InitializeResultSchema, InitializedNotificationSchema, PingRequestSchema, ProgressSchema, ProgressNotificationParamsSchema, ProgressNotificationSchema, PaginatedRequestParamsSchema, PaginatedRequestSchema, PaginatedResultSchema, TaskStatusSchema2, TaskSchema, CreateTaskResultSchema, TaskStatusNotificationParamsSchema, TaskStatusNotificationSchema, GetTaskRequestSchema, GetTaskResultSchema, GetTaskPayloadRequestSchema, GetTaskPayloadResultSchema, ListTasksRequestSchema, ListTasksResultSchema, CancelTaskRequestSchema, CancelTaskResultSchema, ResourceContentsSchema, TextResourceContentsSchema, Base64Schema, BlobResourceContentsSchema, RoleSchema, AnnotationsSchema, ResourceSchema, ResourceTemplateSchema, ListResourcesRequestSchema, ListResourcesResultSchema, ListResourceTemplatesRequestSchema, ListResourceTemplatesResultSchema, ResourceRequestParamsSchema, ReadResourceRequestParamsSchema, ReadResourceRequestSchema, ReadResourceResultSchema, ResourceListChangedNotificationSchema, SubscribeRequestParamsSchema, SubscribeRequestSchema, UnsubscribeRequestParamsSchema, UnsubscribeRequestSchema, ResourceUpdatedNotificationParamsSchema, ResourceUpdatedNotificationSchema, PromptArgumentSchema, PromptSchema, ListPromptsRequestSchema, ListPromptsResultSchema, GetPromptRequestParamsSchema, GetPromptRequestSchema, TextContentSchema, ImageContentSchema, AudioContentSchema, ToolUseContentSchema, EmbeddedResourceSchema, ResourceLinkSchema, ContentBlockSchema, PromptMessageSchema, GetPromptResultSchema, PromptListChangedNotificationSchema, ToolAnnotationsSchema, ToolExecutionSchema, ToolSchema, ListToolsRequestSchema, ListToolsResultSchema, CallToolResultSchema, CompatibilityCallToolResultSchema, CallToolRequestParamsSchema, CallToolRequestSchema, ToolListChangedNotificationSchema, ListChangedOptionsBaseSchema, LoggingLevelSchema, SetLevelRequestParamsSchema, SetLevelRequestSchema, LoggingMessageNotificationParamsSchema, LoggingMessageNotificationSchema, ModelHintSchema, ModelPreferencesSchema, ToolChoiceSchema, ToolResultContentSchema, SamplingContentSchema, SamplingMessageContentBlockSchema, SamplingMessageSchema, CreateMessageRequestParamsSchema, CreateMessageRequestSchema, CreateMessageResultSchema, CreateMessageResultWithToolsSchema, BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema, UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema, LegacyTitledEnumSchemaSchema, SingleSelectEnumSchemaSchema, UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema, EnumSchemaSchema, PrimitiveSchemaDefinitionSchema, ElicitRequestFormParamsSchema, ElicitRequestURLParamsSchema, ElicitRequestParamsSchema, ElicitRequestSchema, ElicitationCompleteNotificationParamsSchema, ElicitationCompleteNotificationSchema, ElicitResultSchema, ResourceTemplateReferenceSchema, PromptReferenceSchema, CompleteRequestParamsSchema, CompleteRequestSchema, CompleteResultSchema, RootSchema, ListRootsRequestSchema, ListRootsResultSchema, RootsListChangedNotificationSchema, ClientRequestSchema, ClientNotificationSchema, ClientResultSchema, ServerRequestSchema, ServerNotificationSchema, ServerResultSchema, McpError, UrlElicitationRequiredError;
|
|
88290
|
+
var LATEST_PROTOCOL_VERSION, DEFAULT_NEGOTIATED_PROTOCOL_VERSION, SUPPORTED_PROTOCOL_VERSIONS, RELATED_TASK_META_KEY, JSONRPC_VERSION, AssertObjectSchema, ProgressTokenSchema, CursorSchema, TaskCreationParamsSchema, TaskMetadataSchema, RelatedTaskMetadataSchema, RequestMetaSchema, BaseRequestParamsSchema, TaskAugmentedRequestParamsSchema, isTaskAugmentedRequestParams, RequestSchema, NotificationsParamsSchema, NotificationSchema, ResultSchema, RequestIdSchema, JSONRPCRequestSchema, isJSONRPCRequest, JSONRPCNotificationSchema, isJSONRPCNotification, JSONRPCResultResponseSchema, isJSONRPCResultResponse, ErrorCode, JSONRPCErrorResponseSchema, isJSONRPCErrorResponse, JSONRPCMessageSchema, JSONRPCResponseSchema, EmptyResultSchema, CancelledNotificationParamsSchema, CancelledNotificationSchema, IconSchema, IconsSchema, BaseMetadataSchema, ImplementationSchema, FormElicitationCapabilitySchema, ElicitationCapabilitySchema, ClientTasksCapabilitySchema, ServerTasksCapabilitySchema, ClientCapabilitiesSchema, InitializeRequestParamsSchema, InitializeRequestSchema, isInitializeRequest, ServerCapabilitiesSchema, InitializeResultSchema, InitializedNotificationSchema, PingRequestSchema, ProgressSchema, ProgressNotificationParamsSchema, ProgressNotificationSchema, PaginatedRequestParamsSchema, PaginatedRequestSchema, PaginatedResultSchema, TaskStatusSchema2, TaskSchema, CreateTaskResultSchema, TaskStatusNotificationParamsSchema, TaskStatusNotificationSchema, GetTaskRequestSchema, GetTaskResultSchema, GetTaskPayloadRequestSchema, GetTaskPayloadResultSchema, ListTasksRequestSchema, ListTasksResultSchema, CancelTaskRequestSchema, CancelTaskResultSchema, ResourceContentsSchema, TextResourceContentsSchema, Base64Schema, BlobResourceContentsSchema, RoleSchema, AnnotationsSchema, ResourceSchema, ResourceTemplateSchema, ListResourcesRequestSchema, ListResourcesResultSchema, ListResourceTemplatesRequestSchema, ListResourceTemplatesResultSchema, ResourceRequestParamsSchema, ReadResourceRequestParamsSchema, ReadResourceRequestSchema, ReadResourceResultSchema, ResourceListChangedNotificationSchema, SubscribeRequestParamsSchema, SubscribeRequestSchema, UnsubscribeRequestParamsSchema, UnsubscribeRequestSchema, ResourceUpdatedNotificationParamsSchema, ResourceUpdatedNotificationSchema, PromptArgumentSchema, PromptSchema, ListPromptsRequestSchema, ListPromptsResultSchema, GetPromptRequestParamsSchema, GetPromptRequestSchema, TextContentSchema, ImageContentSchema, AudioContentSchema, ToolUseContentSchema, EmbeddedResourceSchema, ResourceLinkSchema, ContentBlockSchema, PromptMessageSchema, GetPromptResultSchema, PromptListChangedNotificationSchema, ToolAnnotationsSchema, ToolExecutionSchema, ToolSchema, ListToolsRequestSchema, ListToolsResultSchema, CallToolResultSchema, CompatibilityCallToolResultSchema, CallToolRequestParamsSchema, CallToolRequestSchema, ToolListChangedNotificationSchema, ListChangedOptionsBaseSchema, LoggingLevelSchema, SetLevelRequestParamsSchema, SetLevelRequestSchema, LoggingMessageNotificationParamsSchema, LoggingMessageNotificationSchema, ModelHintSchema, ModelPreferencesSchema, ToolChoiceSchema, ToolResultContentSchema, SamplingContentSchema, SamplingMessageContentBlockSchema, SamplingMessageSchema, CreateMessageRequestParamsSchema, CreateMessageRequestSchema, CreateMessageResultSchema, CreateMessageResultWithToolsSchema, BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema, UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema, LegacyTitledEnumSchemaSchema, SingleSelectEnumSchemaSchema, UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema, EnumSchemaSchema, PrimitiveSchemaDefinitionSchema, ElicitRequestFormParamsSchema, ElicitRequestURLParamsSchema, ElicitRequestParamsSchema, ElicitRequestSchema, ElicitationCompleteNotificationParamsSchema, ElicitationCompleteNotificationSchema, ElicitResultSchema, ResourceTemplateReferenceSchema, PromptReferenceSchema, CompleteRequestParamsSchema, CompleteRequestSchema, CompleteResultSchema, RootSchema, ListRootsRequestSchema, ListRootsResultSchema, RootsListChangedNotificationSchema, ClientRequestSchema, ClientNotificationSchema, ClientResultSchema, ServerRequestSchema, ServerNotificationSchema, ServerResultSchema, McpError, UrlElicitationRequiredError;
|
|
88291
88291
|
var init_types3 = __esm({
|
|
88292
88292
|
"node_modules/@modelcontextprotocol/sdk/dist/esm/types.js"() {
|
|
88293
88293
|
init_v4();
|
|
88294
88294
|
LATEST_PROTOCOL_VERSION = "2025-11-25";
|
|
88295
|
+
DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26";
|
|
88295
88296
|
SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"];
|
|
88296
88297
|
RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
88297
88298
|
JSONRPC_VERSION = "2.0";
|
|
@@ -88616,6 +88617,7 @@ var init_types3 = __esm({
|
|
|
88616
88617
|
method: literal("initialize"),
|
|
88617
88618
|
params: InitializeRequestParamsSchema
|
|
88618
88619
|
});
|
|
88620
|
+
isInitializeRequest = (value) => InitializeRequestSchema.safeParse(value).success;
|
|
88619
88621
|
ServerCapabilitiesSchema = object2({
|
|
88620
88622
|
/**
|
|
88621
88623
|
* Experimental, non-standard capabilities that the server supports.
|
|
@@ -95258,8 +95260,8 @@ var require_core = __commonJS({
|
|
|
95258
95260
|
return this;
|
|
95259
95261
|
}
|
|
95260
95262
|
case "object": {
|
|
95261
|
-
const
|
|
95262
|
-
this._cache.delete(
|
|
95263
|
+
const cacheKey2 = schemaKeyRef;
|
|
95264
|
+
this._cache.delete(cacheKey2);
|
|
95263
95265
|
let id = schemaKeyRef[this.opts.schemaId];
|
|
95264
95266
|
if (id) {
|
|
95265
95267
|
id = (0, resolve_1.normalizeId)(id);
|
|
@@ -99841,7 +99843,7 @@ var init_transport = __esm({
|
|
|
99841
99843
|
|
|
99842
99844
|
// node_modules/pkce-challenge/dist/index.node.js
|
|
99843
99845
|
async function getRandomValues(size) {
|
|
99844
|
-
return (await
|
|
99846
|
+
return (await crypto2).getRandomValues(new Uint8Array(size));
|
|
99845
99847
|
}
|
|
99846
99848
|
async function random(size) {
|
|
99847
99849
|
const mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
|
|
@@ -99861,7 +99863,7 @@ async function generateVerifier(length) {
|
|
|
99861
99863
|
return await random(length);
|
|
99862
99864
|
}
|
|
99863
99865
|
async function generateChallenge(code_verifier) {
|
|
99864
|
-
const buffer = await (await
|
|
99866
|
+
const buffer = await (await crypto2).subtle.digest("SHA-256", new TextEncoder().encode(code_verifier));
|
|
99865
99867
|
return btoa(String.fromCharCode(...new Uint8Array(buffer))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
|
|
99866
99868
|
}
|
|
99867
99869
|
async function pkceChallenge(length) {
|
|
@@ -99877,10 +99879,10 @@ async function pkceChallenge(length) {
|
|
|
99877
99879
|
code_challenge: challenge
|
|
99878
99880
|
};
|
|
99879
99881
|
}
|
|
99880
|
-
var
|
|
99882
|
+
var crypto2;
|
|
99881
99883
|
var init_index_node = __esm({
|
|
99882
99884
|
"node_modules/pkce-challenge/dist/index.node.js"() {
|
|
99883
|
-
|
|
99885
|
+
crypto2 = globalThis.crypto?.webcrypto ?? // Node.js [18-16] REPL
|
|
99884
99886
|
globalThis.crypto ?? // Node.js >18
|
|
99885
99887
|
import("node:crypto").then((m) => m.webcrypto);
|
|
99886
99888
|
}
|
|
@@ -104722,6 +104724,1280 @@ var init_app = __esm({
|
|
|
104722
104724
|
}
|
|
104723
104725
|
});
|
|
104724
104726
|
|
|
104727
|
+
// node_modules/@hono/node-server/dist/index.mjs
|
|
104728
|
+
import { createServer as createServerHTTP } from "http";
|
|
104729
|
+
import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
|
|
104730
|
+
import { Http2ServerRequest } from "http2";
|
|
104731
|
+
import { Readable } from "stream";
|
|
104732
|
+
import crypto3 from "crypto";
|
|
104733
|
+
async function readWithoutBlocking(readPromise) {
|
|
104734
|
+
return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(void 0))]);
|
|
104735
|
+
}
|
|
104736
|
+
function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromise) {
|
|
104737
|
+
const cancel = (error2) => {
|
|
104738
|
+
reader.cancel(error2).catch(() => {
|
|
104739
|
+
});
|
|
104740
|
+
};
|
|
104741
|
+
writable.on("close", cancel);
|
|
104742
|
+
writable.on("error", cancel);
|
|
104743
|
+
(currentReadPromise ?? reader.read()).then(flow, handleStreamError);
|
|
104744
|
+
return reader.closed.finally(() => {
|
|
104745
|
+
writable.off("close", cancel);
|
|
104746
|
+
writable.off("error", cancel);
|
|
104747
|
+
});
|
|
104748
|
+
function handleStreamError(error2) {
|
|
104749
|
+
if (error2) {
|
|
104750
|
+
writable.destroy(error2);
|
|
104751
|
+
}
|
|
104752
|
+
}
|
|
104753
|
+
function onDrain() {
|
|
104754
|
+
reader.read().then(flow, handleStreamError);
|
|
104755
|
+
}
|
|
104756
|
+
function flow({ done, value }) {
|
|
104757
|
+
try {
|
|
104758
|
+
if (done) {
|
|
104759
|
+
writable.end();
|
|
104760
|
+
} else if (!writable.write(value)) {
|
|
104761
|
+
writable.once("drain", onDrain);
|
|
104762
|
+
} else {
|
|
104763
|
+
return reader.read().then(flow, handleStreamError);
|
|
104764
|
+
}
|
|
104765
|
+
} catch (e) {
|
|
104766
|
+
handleStreamError(e);
|
|
104767
|
+
}
|
|
104768
|
+
}
|
|
104769
|
+
}
|
|
104770
|
+
function writeFromReadableStream(stream, writable) {
|
|
104771
|
+
if (stream.locked) {
|
|
104772
|
+
throw new TypeError("ReadableStream is locked.");
|
|
104773
|
+
} else if (writable.destroyed) {
|
|
104774
|
+
return;
|
|
104775
|
+
}
|
|
104776
|
+
return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
|
|
104777
|
+
}
|
|
104778
|
+
var RequestError, toRequestError, GlobalRequest, Request, newHeadersFromIncoming, wrapBodyStream, newRequestFromIncoming, getRequestCache, requestCache, incomingKey, urlKey, headersKey, abortControllerKey, getAbortController, requestPrototype, newRequest, responseCache, getResponseCache, cacheKey, GlobalResponse, Response2, buildOutgoingHttpHeaders, X_ALREADY_SENT, outgoingEnded, handleRequestError, handleFetchError, handleResponseError, flushHeaders, responseViaCache, isPromise, responseViaResponseObject, getRequestListener;
|
|
104779
|
+
var init_dist7 = __esm({
|
|
104780
|
+
"node_modules/@hono/node-server/dist/index.mjs"() {
|
|
104781
|
+
RequestError = class extends Error {
|
|
104782
|
+
constructor(message, options2) {
|
|
104783
|
+
super(message, options2);
|
|
104784
|
+
this.name = "RequestError";
|
|
104785
|
+
}
|
|
104786
|
+
};
|
|
104787
|
+
toRequestError = (e) => {
|
|
104788
|
+
if (e instanceof RequestError) {
|
|
104789
|
+
return e;
|
|
104790
|
+
}
|
|
104791
|
+
return new RequestError(e.message, { cause: e });
|
|
104792
|
+
};
|
|
104793
|
+
GlobalRequest = global.Request;
|
|
104794
|
+
Request = class extends GlobalRequest {
|
|
104795
|
+
constructor(input, options2) {
|
|
104796
|
+
if (typeof input === "object" && getRequestCache in input) {
|
|
104797
|
+
input = input[getRequestCache]();
|
|
104798
|
+
}
|
|
104799
|
+
if (typeof options2?.body?.getReader !== "undefined") {
|
|
104800
|
+
;
|
|
104801
|
+
options2.duplex ??= "half";
|
|
104802
|
+
}
|
|
104803
|
+
super(input, options2);
|
|
104804
|
+
}
|
|
104805
|
+
};
|
|
104806
|
+
newHeadersFromIncoming = (incoming) => {
|
|
104807
|
+
const headerRecord = [];
|
|
104808
|
+
const rawHeaders = incoming.rawHeaders;
|
|
104809
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
|
104810
|
+
const { [i]: key, [i + 1]: value } = rawHeaders;
|
|
104811
|
+
if (key.charCodeAt(0) !== /*:*/
|
|
104812
|
+
58) {
|
|
104813
|
+
headerRecord.push([key, value]);
|
|
104814
|
+
}
|
|
104815
|
+
}
|
|
104816
|
+
return new Headers(headerRecord);
|
|
104817
|
+
};
|
|
104818
|
+
wrapBodyStream = Symbol("wrapBodyStream");
|
|
104819
|
+
newRequestFromIncoming = (method, url2, headers, incoming, abortController) => {
|
|
104820
|
+
const init = {
|
|
104821
|
+
method,
|
|
104822
|
+
headers,
|
|
104823
|
+
signal: abortController.signal
|
|
104824
|
+
};
|
|
104825
|
+
if (method === "TRACE") {
|
|
104826
|
+
init.method = "GET";
|
|
104827
|
+
const req = new Request(url2, init);
|
|
104828
|
+
Object.defineProperty(req, "method", {
|
|
104829
|
+
get() {
|
|
104830
|
+
return "TRACE";
|
|
104831
|
+
}
|
|
104832
|
+
});
|
|
104833
|
+
return req;
|
|
104834
|
+
}
|
|
104835
|
+
if (!(method === "GET" || method === "HEAD")) {
|
|
104836
|
+
if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) {
|
|
104837
|
+
init.body = new ReadableStream({
|
|
104838
|
+
start(controller) {
|
|
104839
|
+
controller.enqueue(incoming.rawBody);
|
|
104840
|
+
controller.close();
|
|
104841
|
+
}
|
|
104842
|
+
});
|
|
104843
|
+
} else if (incoming[wrapBodyStream]) {
|
|
104844
|
+
let reader;
|
|
104845
|
+
init.body = new ReadableStream({
|
|
104846
|
+
async pull(controller) {
|
|
104847
|
+
try {
|
|
104848
|
+
reader ||= Readable.toWeb(incoming).getReader();
|
|
104849
|
+
const { done, value } = await reader.read();
|
|
104850
|
+
if (done) {
|
|
104851
|
+
controller.close();
|
|
104852
|
+
} else {
|
|
104853
|
+
controller.enqueue(value);
|
|
104854
|
+
}
|
|
104855
|
+
} catch (error2) {
|
|
104856
|
+
controller.error(error2);
|
|
104857
|
+
}
|
|
104858
|
+
}
|
|
104859
|
+
});
|
|
104860
|
+
} else {
|
|
104861
|
+
init.body = Readable.toWeb(incoming);
|
|
104862
|
+
}
|
|
104863
|
+
}
|
|
104864
|
+
return new Request(url2, init);
|
|
104865
|
+
};
|
|
104866
|
+
getRequestCache = Symbol("getRequestCache");
|
|
104867
|
+
requestCache = Symbol("requestCache");
|
|
104868
|
+
incomingKey = Symbol("incomingKey");
|
|
104869
|
+
urlKey = Symbol("urlKey");
|
|
104870
|
+
headersKey = Symbol("headersKey");
|
|
104871
|
+
abortControllerKey = Symbol("abortControllerKey");
|
|
104872
|
+
getAbortController = Symbol("getAbortController");
|
|
104873
|
+
requestPrototype = {
|
|
104874
|
+
get method() {
|
|
104875
|
+
return this[incomingKey].method || "GET";
|
|
104876
|
+
},
|
|
104877
|
+
get url() {
|
|
104878
|
+
return this[urlKey];
|
|
104879
|
+
},
|
|
104880
|
+
get headers() {
|
|
104881
|
+
return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
|
|
104882
|
+
},
|
|
104883
|
+
[getAbortController]() {
|
|
104884
|
+
this[getRequestCache]();
|
|
104885
|
+
return this[abortControllerKey];
|
|
104886
|
+
},
|
|
104887
|
+
[getRequestCache]() {
|
|
104888
|
+
this[abortControllerKey] ||= new AbortController();
|
|
104889
|
+
return this[requestCache] ||= newRequestFromIncoming(
|
|
104890
|
+
this.method,
|
|
104891
|
+
this[urlKey],
|
|
104892
|
+
this.headers,
|
|
104893
|
+
this[incomingKey],
|
|
104894
|
+
this[abortControllerKey]
|
|
104895
|
+
);
|
|
104896
|
+
}
|
|
104897
|
+
};
|
|
104898
|
+
[
|
|
104899
|
+
"body",
|
|
104900
|
+
"bodyUsed",
|
|
104901
|
+
"cache",
|
|
104902
|
+
"credentials",
|
|
104903
|
+
"destination",
|
|
104904
|
+
"integrity",
|
|
104905
|
+
"mode",
|
|
104906
|
+
"redirect",
|
|
104907
|
+
"referrer",
|
|
104908
|
+
"referrerPolicy",
|
|
104909
|
+
"signal",
|
|
104910
|
+
"keepalive"
|
|
104911
|
+
].forEach((k) => {
|
|
104912
|
+
Object.defineProperty(requestPrototype, k, {
|
|
104913
|
+
get() {
|
|
104914
|
+
return this[getRequestCache]()[k];
|
|
104915
|
+
}
|
|
104916
|
+
});
|
|
104917
|
+
});
|
|
104918
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
104919
|
+
Object.defineProperty(requestPrototype, k, {
|
|
104920
|
+
value: function() {
|
|
104921
|
+
return this[getRequestCache]()[k]();
|
|
104922
|
+
}
|
|
104923
|
+
});
|
|
104924
|
+
});
|
|
104925
|
+
Object.setPrototypeOf(requestPrototype, Request.prototype);
|
|
104926
|
+
newRequest = (incoming, defaultHostname) => {
|
|
104927
|
+
const req = Object.create(requestPrototype);
|
|
104928
|
+
req[incomingKey] = incoming;
|
|
104929
|
+
const incomingUrl = incoming.url || "";
|
|
104930
|
+
if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
|
|
104931
|
+
(incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
|
|
104932
|
+
if (incoming instanceof Http2ServerRequest) {
|
|
104933
|
+
throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
|
|
104934
|
+
}
|
|
104935
|
+
try {
|
|
104936
|
+
const url22 = new URL(incomingUrl);
|
|
104937
|
+
req[urlKey] = url22.href;
|
|
104938
|
+
} catch (e) {
|
|
104939
|
+
throw new RequestError("Invalid absolute URL", { cause: e });
|
|
104940
|
+
}
|
|
104941
|
+
return req;
|
|
104942
|
+
}
|
|
104943
|
+
const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
|
|
104944
|
+
if (!host) {
|
|
104945
|
+
throw new RequestError("Missing host header");
|
|
104946
|
+
}
|
|
104947
|
+
let scheme;
|
|
104948
|
+
if (incoming instanceof Http2ServerRequest) {
|
|
104949
|
+
scheme = incoming.scheme;
|
|
104950
|
+
if (!(scheme === "http" || scheme === "https")) {
|
|
104951
|
+
throw new RequestError("Unsupported scheme");
|
|
104952
|
+
}
|
|
104953
|
+
} else {
|
|
104954
|
+
scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
|
|
104955
|
+
}
|
|
104956
|
+
const url2 = new URL(`${scheme}://${host}${incomingUrl}`);
|
|
104957
|
+
if (url2.hostname.length !== host.length && url2.hostname !== host.replace(/:\d+$/, "")) {
|
|
104958
|
+
throw new RequestError("Invalid host header");
|
|
104959
|
+
}
|
|
104960
|
+
req[urlKey] = url2.href;
|
|
104961
|
+
return req;
|
|
104962
|
+
};
|
|
104963
|
+
responseCache = Symbol("responseCache");
|
|
104964
|
+
getResponseCache = Symbol("getResponseCache");
|
|
104965
|
+
cacheKey = Symbol("cache");
|
|
104966
|
+
GlobalResponse = global.Response;
|
|
104967
|
+
Response2 = class _Response {
|
|
104968
|
+
#body;
|
|
104969
|
+
#init;
|
|
104970
|
+
[getResponseCache]() {
|
|
104971
|
+
delete this[cacheKey];
|
|
104972
|
+
return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
|
|
104973
|
+
}
|
|
104974
|
+
constructor(body, init) {
|
|
104975
|
+
let headers;
|
|
104976
|
+
this.#body = body;
|
|
104977
|
+
if (init instanceof _Response) {
|
|
104978
|
+
const cachedGlobalResponse = init[responseCache];
|
|
104979
|
+
if (cachedGlobalResponse) {
|
|
104980
|
+
this.#init = cachedGlobalResponse;
|
|
104981
|
+
this[getResponseCache]();
|
|
104982
|
+
return;
|
|
104983
|
+
} else {
|
|
104984
|
+
this.#init = init.#init;
|
|
104985
|
+
headers = new Headers(init.#init.headers);
|
|
104986
|
+
}
|
|
104987
|
+
} else {
|
|
104988
|
+
this.#init = init;
|
|
104989
|
+
}
|
|
104990
|
+
if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
|
|
104991
|
+
;
|
|
104992
|
+
this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
|
|
104993
|
+
}
|
|
104994
|
+
}
|
|
104995
|
+
get headers() {
|
|
104996
|
+
const cache3 = this[cacheKey];
|
|
104997
|
+
if (cache3) {
|
|
104998
|
+
if (!(cache3[2] instanceof Headers)) {
|
|
104999
|
+
cache3[2] = new Headers(
|
|
105000
|
+
cache3[2] || { "content-type": "text/plain; charset=UTF-8" }
|
|
105001
|
+
);
|
|
105002
|
+
}
|
|
105003
|
+
return cache3[2];
|
|
105004
|
+
}
|
|
105005
|
+
return this[getResponseCache]().headers;
|
|
105006
|
+
}
|
|
105007
|
+
get status() {
|
|
105008
|
+
return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
|
|
105009
|
+
}
|
|
105010
|
+
get ok() {
|
|
105011
|
+
const status = this.status;
|
|
105012
|
+
return status >= 200 && status < 300;
|
|
105013
|
+
}
|
|
105014
|
+
};
|
|
105015
|
+
["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
|
|
105016
|
+
Object.defineProperty(Response2.prototype, k, {
|
|
105017
|
+
get() {
|
|
105018
|
+
return this[getResponseCache]()[k];
|
|
105019
|
+
}
|
|
105020
|
+
});
|
|
105021
|
+
});
|
|
105022
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
105023
|
+
Object.defineProperty(Response2.prototype, k, {
|
|
105024
|
+
value: function() {
|
|
105025
|
+
return this[getResponseCache]()[k]();
|
|
105026
|
+
}
|
|
105027
|
+
});
|
|
105028
|
+
});
|
|
105029
|
+
Object.setPrototypeOf(Response2, GlobalResponse);
|
|
105030
|
+
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
|
|
105031
|
+
buildOutgoingHttpHeaders = (headers) => {
|
|
105032
|
+
const res = {};
|
|
105033
|
+
if (!(headers instanceof Headers)) {
|
|
105034
|
+
headers = new Headers(headers ?? void 0);
|
|
105035
|
+
}
|
|
105036
|
+
const cookies = [];
|
|
105037
|
+
for (const [k, v] of headers) {
|
|
105038
|
+
if (k === "set-cookie") {
|
|
105039
|
+
cookies.push(v);
|
|
105040
|
+
} else {
|
|
105041
|
+
res[k] = v;
|
|
105042
|
+
}
|
|
105043
|
+
}
|
|
105044
|
+
if (cookies.length > 0) {
|
|
105045
|
+
res["set-cookie"] = cookies;
|
|
105046
|
+
}
|
|
105047
|
+
res["content-type"] ??= "text/plain; charset=UTF-8";
|
|
105048
|
+
return res;
|
|
105049
|
+
};
|
|
105050
|
+
X_ALREADY_SENT = "x-hono-already-sent";
|
|
105051
|
+
if (typeof global.crypto === "undefined") {
|
|
105052
|
+
global.crypto = crypto3;
|
|
105053
|
+
}
|
|
105054
|
+
outgoingEnded = Symbol("outgoingEnded");
|
|
105055
|
+
handleRequestError = () => new Response(null, {
|
|
105056
|
+
status: 400
|
|
105057
|
+
});
|
|
105058
|
+
handleFetchError = (e) => new Response(null, {
|
|
105059
|
+
status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500
|
|
105060
|
+
});
|
|
105061
|
+
handleResponseError = (e, outgoing) => {
|
|
105062
|
+
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
|
|
105063
|
+
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
105064
|
+
console.info("The user aborted a request.");
|
|
105065
|
+
} else {
|
|
105066
|
+
console.error(e);
|
|
105067
|
+
if (!outgoing.headersSent) {
|
|
105068
|
+
outgoing.writeHead(500, { "Content-Type": "text/plain" });
|
|
105069
|
+
}
|
|
105070
|
+
outgoing.end(`Error: ${err.message}`);
|
|
105071
|
+
outgoing.destroy(err);
|
|
105072
|
+
}
|
|
105073
|
+
};
|
|
105074
|
+
flushHeaders = (outgoing) => {
|
|
105075
|
+
if ("flushHeaders" in outgoing && outgoing.writable) {
|
|
105076
|
+
outgoing.flushHeaders();
|
|
105077
|
+
}
|
|
105078
|
+
};
|
|
105079
|
+
responseViaCache = async (res, outgoing) => {
|
|
105080
|
+
let [status, body, header] = res[cacheKey];
|
|
105081
|
+
let hasContentLength = false;
|
|
105082
|
+
if (!header) {
|
|
105083
|
+
header = { "content-type": "text/plain; charset=UTF-8" };
|
|
105084
|
+
} else if (header instanceof Headers) {
|
|
105085
|
+
hasContentLength = header.has("content-length");
|
|
105086
|
+
header = buildOutgoingHttpHeaders(header);
|
|
105087
|
+
} else if (Array.isArray(header)) {
|
|
105088
|
+
const headerObj = new Headers(header);
|
|
105089
|
+
hasContentLength = headerObj.has("content-length");
|
|
105090
|
+
header = buildOutgoingHttpHeaders(headerObj);
|
|
105091
|
+
} else {
|
|
105092
|
+
for (const key in header) {
|
|
105093
|
+
if (key.length === 14 && key.toLowerCase() === "content-length") {
|
|
105094
|
+
hasContentLength = true;
|
|
105095
|
+
break;
|
|
105096
|
+
}
|
|
105097
|
+
}
|
|
105098
|
+
}
|
|
105099
|
+
if (!hasContentLength) {
|
|
105100
|
+
if (typeof body === "string") {
|
|
105101
|
+
header["Content-Length"] = Buffer.byteLength(body);
|
|
105102
|
+
} else if (body instanceof Uint8Array) {
|
|
105103
|
+
header["Content-Length"] = body.byteLength;
|
|
105104
|
+
} else if (body instanceof Blob) {
|
|
105105
|
+
header["Content-Length"] = body.size;
|
|
105106
|
+
}
|
|
105107
|
+
}
|
|
105108
|
+
outgoing.writeHead(status, header);
|
|
105109
|
+
if (typeof body === "string" || body instanceof Uint8Array) {
|
|
105110
|
+
outgoing.end(body);
|
|
105111
|
+
} else if (body instanceof Blob) {
|
|
105112
|
+
outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
105113
|
+
} else {
|
|
105114
|
+
flushHeaders(outgoing);
|
|
105115
|
+
await writeFromReadableStream(body, outgoing)?.catch(
|
|
105116
|
+
(e) => handleResponseError(e, outgoing)
|
|
105117
|
+
);
|
|
105118
|
+
}
|
|
105119
|
+
;
|
|
105120
|
+
outgoing[outgoingEnded]?.();
|
|
105121
|
+
};
|
|
105122
|
+
isPromise = (res) => typeof res.then === "function";
|
|
105123
|
+
responseViaResponseObject = async (res, outgoing, options2 = {}) => {
|
|
105124
|
+
if (isPromise(res)) {
|
|
105125
|
+
if (options2.errorHandler) {
|
|
105126
|
+
try {
|
|
105127
|
+
res = await res;
|
|
105128
|
+
} catch (err) {
|
|
105129
|
+
const errRes = await options2.errorHandler(err);
|
|
105130
|
+
if (!errRes) {
|
|
105131
|
+
return;
|
|
105132
|
+
}
|
|
105133
|
+
res = errRes;
|
|
105134
|
+
}
|
|
105135
|
+
} else {
|
|
105136
|
+
res = await res.catch(handleFetchError);
|
|
105137
|
+
}
|
|
105138
|
+
}
|
|
105139
|
+
if (cacheKey in res) {
|
|
105140
|
+
return responseViaCache(res, outgoing);
|
|
105141
|
+
}
|
|
105142
|
+
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
105143
|
+
if (res.body) {
|
|
105144
|
+
const reader = res.body.getReader();
|
|
105145
|
+
const values = [];
|
|
105146
|
+
let done = false;
|
|
105147
|
+
let currentReadPromise = void 0;
|
|
105148
|
+
if (resHeaderRecord["transfer-encoding"] !== "chunked") {
|
|
105149
|
+
let maxReadCount = 2;
|
|
105150
|
+
for (let i = 0; i < maxReadCount; i++) {
|
|
105151
|
+
currentReadPromise ||= reader.read();
|
|
105152
|
+
const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
|
|
105153
|
+
console.error(e);
|
|
105154
|
+
done = true;
|
|
105155
|
+
});
|
|
105156
|
+
if (!chunk) {
|
|
105157
|
+
if (i === 1) {
|
|
105158
|
+
await new Promise((resolve8) => setTimeout(resolve8));
|
|
105159
|
+
maxReadCount = 3;
|
|
105160
|
+
continue;
|
|
105161
|
+
}
|
|
105162
|
+
break;
|
|
105163
|
+
}
|
|
105164
|
+
currentReadPromise = void 0;
|
|
105165
|
+
if (chunk.value) {
|
|
105166
|
+
values.push(chunk.value);
|
|
105167
|
+
}
|
|
105168
|
+
if (chunk.done) {
|
|
105169
|
+
done = true;
|
|
105170
|
+
break;
|
|
105171
|
+
}
|
|
105172
|
+
}
|
|
105173
|
+
if (done && !("content-length" in resHeaderRecord)) {
|
|
105174
|
+
resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
|
|
105175
|
+
}
|
|
105176
|
+
}
|
|
105177
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
105178
|
+
values.forEach((value) => {
|
|
105179
|
+
;
|
|
105180
|
+
outgoing.write(value);
|
|
105181
|
+
});
|
|
105182
|
+
if (done) {
|
|
105183
|
+
outgoing.end();
|
|
105184
|
+
} else {
|
|
105185
|
+
if (values.length === 0) {
|
|
105186
|
+
flushHeaders(outgoing);
|
|
105187
|
+
}
|
|
105188
|
+
await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise);
|
|
105189
|
+
}
|
|
105190
|
+
} else if (resHeaderRecord[X_ALREADY_SENT]) {
|
|
105191
|
+
} else {
|
|
105192
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
105193
|
+
outgoing.end();
|
|
105194
|
+
}
|
|
105195
|
+
;
|
|
105196
|
+
outgoing[outgoingEnded]?.();
|
|
105197
|
+
};
|
|
105198
|
+
getRequestListener = (fetchCallback, options2 = {}) => {
|
|
105199
|
+
const autoCleanupIncoming = options2.autoCleanupIncoming ?? true;
|
|
105200
|
+
if (options2.overrideGlobalObjects !== false && global.Request !== Request) {
|
|
105201
|
+
Object.defineProperty(global, "Request", {
|
|
105202
|
+
value: Request
|
|
105203
|
+
});
|
|
105204
|
+
Object.defineProperty(global, "Response", {
|
|
105205
|
+
value: Response2
|
|
105206
|
+
});
|
|
105207
|
+
}
|
|
105208
|
+
return async (incoming, outgoing) => {
|
|
105209
|
+
let res, req;
|
|
105210
|
+
try {
|
|
105211
|
+
req = newRequest(incoming, options2.hostname);
|
|
105212
|
+
let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD";
|
|
105213
|
+
if (!incomingEnded) {
|
|
105214
|
+
;
|
|
105215
|
+
incoming[wrapBodyStream] = true;
|
|
105216
|
+
incoming.on("end", () => {
|
|
105217
|
+
incomingEnded = true;
|
|
105218
|
+
});
|
|
105219
|
+
if (incoming instanceof Http2ServerRequest2) {
|
|
105220
|
+
;
|
|
105221
|
+
outgoing[outgoingEnded] = () => {
|
|
105222
|
+
if (!incomingEnded) {
|
|
105223
|
+
setTimeout(() => {
|
|
105224
|
+
if (!incomingEnded) {
|
|
105225
|
+
setTimeout(() => {
|
|
105226
|
+
incoming.destroy();
|
|
105227
|
+
outgoing.destroy();
|
|
105228
|
+
});
|
|
105229
|
+
}
|
|
105230
|
+
});
|
|
105231
|
+
}
|
|
105232
|
+
};
|
|
105233
|
+
}
|
|
105234
|
+
}
|
|
105235
|
+
outgoing.on("close", () => {
|
|
105236
|
+
const abortController = req[abortControllerKey];
|
|
105237
|
+
if (abortController) {
|
|
105238
|
+
if (incoming.errored) {
|
|
105239
|
+
req[abortControllerKey].abort(incoming.errored.toString());
|
|
105240
|
+
} else if (!outgoing.writableFinished) {
|
|
105241
|
+
req[abortControllerKey].abort("Client connection prematurely closed.");
|
|
105242
|
+
}
|
|
105243
|
+
}
|
|
105244
|
+
if (!incomingEnded) {
|
|
105245
|
+
setTimeout(() => {
|
|
105246
|
+
if (!incomingEnded) {
|
|
105247
|
+
setTimeout(() => {
|
|
105248
|
+
incoming.destroy();
|
|
105249
|
+
});
|
|
105250
|
+
}
|
|
105251
|
+
});
|
|
105252
|
+
}
|
|
105253
|
+
});
|
|
105254
|
+
res = fetchCallback(req, { incoming, outgoing });
|
|
105255
|
+
if (cacheKey in res) {
|
|
105256
|
+
return responseViaCache(res, outgoing);
|
|
105257
|
+
}
|
|
105258
|
+
} catch (e) {
|
|
105259
|
+
if (!res) {
|
|
105260
|
+
if (options2.errorHandler) {
|
|
105261
|
+
res = await options2.errorHandler(req ? e : toRequestError(e));
|
|
105262
|
+
if (!res) {
|
|
105263
|
+
return;
|
|
105264
|
+
}
|
|
105265
|
+
} else if (!req) {
|
|
105266
|
+
res = handleRequestError();
|
|
105267
|
+
} else {
|
|
105268
|
+
res = handleFetchError(e);
|
|
105269
|
+
}
|
|
105270
|
+
} else {
|
|
105271
|
+
return handleResponseError(e, outgoing);
|
|
105272
|
+
}
|
|
105273
|
+
}
|
|
105274
|
+
try {
|
|
105275
|
+
return await responseViaResponseObject(res, outgoing, options2);
|
|
105276
|
+
} catch (e) {
|
|
105277
|
+
return handleResponseError(e, outgoing);
|
|
105278
|
+
}
|
|
105279
|
+
};
|
|
105280
|
+
};
|
|
105281
|
+
}
|
|
105282
|
+
});
|
|
105283
|
+
|
|
105284
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js
|
|
105285
|
+
var WebStandardStreamableHTTPServerTransport;
|
|
105286
|
+
var init_webStandardStreamableHttp = __esm({
|
|
105287
|
+
"node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js"() {
|
|
105288
|
+
init_types3();
|
|
105289
|
+
WebStandardStreamableHTTPServerTransport = class {
|
|
105290
|
+
constructor(options2 = {}) {
|
|
105291
|
+
this._started = false;
|
|
105292
|
+
this._hasHandledRequest = false;
|
|
105293
|
+
this._streamMapping = /* @__PURE__ */ new Map();
|
|
105294
|
+
this._requestToStreamMapping = /* @__PURE__ */ new Map();
|
|
105295
|
+
this._requestResponseMap = /* @__PURE__ */ new Map();
|
|
105296
|
+
this._initialized = false;
|
|
105297
|
+
this._enableJsonResponse = false;
|
|
105298
|
+
this._standaloneSseStreamId = "_GET_stream";
|
|
105299
|
+
this.sessionIdGenerator = options2.sessionIdGenerator;
|
|
105300
|
+
this._enableJsonResponse = options2.enableJsonResponse ?? false;
|
|
105301
|
+
this._eventStore = options2.eventStore;
|
|
105302
|
+
this._onsessioninitialized = options2.onsessioninitialized;
|
|
105303
|
+
this._onsessionclosed = options2.onsessionclosed;
|
|
105304
|
+
this._allowedHosts = options2.allowedHosts;
|
|
105305
|
+
this._allowedOrigins = options2.allowedOrigins;
|
|
105306
|
+
this._enableDnsRebindingProtection = options2.enableDnsRebindingProtection ?? false;
|
|
105307
|
+
this._retryInterval = options2.retryInterval;
|
|
105308
|
+
}
|
|
105309
|
+
/**
|
|
105310
|
+
* Starts the transport. This is required by the Transport interface but is a no-op
|
|
105311
|
+
* for the Streamable HTTP transport as connections are managed per-request.
|
|
105312
|
+
*/
|
|
105313
|
+
async start() {
|
|
105314
|
+
if (this._started) {
|
|
105315
|
+
throw new Error("Transport already started");
|
|
105316
|
+
}
|
|
105317
|
+
this._started = true;
|
|
105318
|
+
}
|
|
105319
|
+
/**
|
|
105320
|
+
* Helper to create a JSON error response
|
|
105321
|
+
*/
|
|
105322
|
+
createJsonErrorResponse(status, code, message, options2) {
|
|
105323
|
+
const error2 = { code, message };
|
|
105324
|
+
if (options2?.data !== void 0) {
|
|
105325
|
+
error2.data = options2.data;
|
|
105326
|
+
}
|
|
105327
|
+
return new Response(JSON.stringify({
|
|
105328
|
+
jsonrpc: "2.0",
|
|
105329
|
+
error: error2,
|
|
105330
|
+
id: null
|
|
105331
|
+
}), {
|
|
105332
|
+
status,
|
|
105333
|
+
headers: {
|
|
105334
|
+
"Content-Type": "application/json",
|
|
105335
|
+
...options2?.headers
|
|
105336
|
+
}
|
|
105337
|
+
});
|
|
105338
|
+
}
|
|
105339
|
+
/**
|
|
105340
|
+
* Validates request headers for DNS rebinding protection.
|
|
105341
|
+
* @returns Error response if validation fails, undefined if validation passes.
|
|
105342
|
+
*/
|
|
105343
|
+
validateRequestHeaders(req) {
|
|
105344
|
+
if (!this._enableDnsRebindingProtection) {
|
|
105345
|
+
return void 0;
|
|
105346
|
+
}
|
|
105347
|
+
if (this._allowedHosts && this._allowedHosts.length > 0) {
|
|
105348
|
+
const hostHeader = req.headers.get("host");
|
|
105349
|
+
if (!hostHeader || !this._allowedHosts.includes(hostHeader)) {
|
|
105350
|
+
const error2 = `Invalid Host header: ${hostHeader}`;
|
|
105351
|
+
this.onerror?.(new Error(error2));
|
|
105352
|
+
return this.createJsonErrorResponse(403, -32e3, error2);
|
|
105353
|
+
}
|
|
105354
|
+
}
|
|
105355
|
+
if (this._allowedOrigins && this._allowedOrigins.length > 0) {
|
|
105356
|
+
const originHeader = req.headers.get("origin");
|
|
105357
|
+
if (originHeader && !this._allowedOrigins.includes(originHeader)) {
|
|
105358
|
+
const error2 = `Invalid Origin header: ${originHeader}`;
|
|
105359
|
+
this.onerror?.(new Error(error2));
|
|
105360
|
+
return this.createJsonErrorResponse(403, -32e3, error2);
|
|
105361
|
+
}
|
|
105362
|
+
}
|
|
105363
|
+
return void 0;
|
|
105364
|
+
}
|
|
105365
|
+
/**
|
|
105366
|
+
* Handles an incoming HTTP request, whether GET, POST, or DELETE
|
|
105367
|
+
* Returns a Response object (Web Standard)
|
|
105368
|
+
*/
|
|
105369
|
+
async handleRequest(req, options2) {
|
|
105370
|
+
if (!this.sessionIdGenerator && this._hasHandledRequest) {
|
|
105371
|
+
throw new Error("Stateless transport cannot be reused across requests. Create a new transport per request.");
|
|
105372
|
+
}
|
|
105373
|
+
this._hasHandledRequest = true;
|
|
105374
|
+
const validationError = this.validateRequestHeaders(req);
|
|
105375
|
+
if (validationError) {
|
|
105376
|
+
return validationError;
|
|
105377
|
+
}
|
|
105378
|
+
switch (req.method) {
|
|
105379
|
+
case "POST":
|
|
105380
|
+
return this.handlePostRequest(req, options2);
|
|
105381
|
+
case "GET":
|
|
105382
|
+
return this.handleGetRequest(req);
|
|
105383
|
+
case "DELETE":
|
|
105384
|
+
return this.handleDeleteRequest(req);
|
|
105385
|
+
default:
|
|
105386
|
+
return this.handleUnsupportedRequest();
|
|
105387
|
+
}
|
|
105388
|
+
}
|
|
105389
|
+
/**
|
|
105390
|
+
* Writes a priming event to establish resumption capability.
|
|
105391
|
+
* Only sends if eventStore is configured (opt-in for resumability) and
|
|
105392
|
+
* the client's protocol version supports empty SSE data (>= 2025-11-25).
|
|
105393
|
+
*/
|
|
105394
|
+
async writePrimingEvent(controller, encoder, streamId, protocolVersion) {
|
|
105395
|
+
if (!this._eventStore) {
|
|
105396
|
+
return;
|
|
105397
|
+
}
|
|
105398
|
+
if (protocolVersion < "2025-11-25") {
|
|
105399
|
+
return;
|
|
105400
|
+
}
|
|
105401
|
+
const primingEventId = await this._eventStore.storeEvent(streamId, {});
|
|
105402
|
+
let primingEvent = `id: ${primingEventId}
|
|
105403
|
+
data:
|
|
105404
|
+
|
|
105405
|
+
`;
|
|
105406
|
+
if (this._retryInterval !== void 0) {
|
|
105407
|
+
primingEvent = `id: ${primingEventId}
|
|
105408
|
+
retry: ${this._retryInterval}
|
|
105409
|
+
data:
|
|
105410
|
+
|
|
105411
|
+
`;
|
|
105412
|
+
}
|
|
105413
|
+
controller.enqueue(encoder.encode(primingEvent));
|
|
105414
|
+
}
|
|
105415
|
+
/**
|
|
105416
|
+
* Handles GET requests for SSE stream
|
|
105417
|
+
*/
|
|
105418
|
+
async handleGetRequest(req) {
|
|
105419
|
+
const acceptHeader = req.headers.get("accept");
|
|
105420
|
+
if (!acceptHeader?.includes("text/event-stream")) {
|
|
105421
|
+
this.onerror?.(new Error("Not Acceptable: Client must accept text/event-stream"));
|
|
105422
|
+
return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept text/event-stream");
|
|
105423
|
+
}
|
|
105424
|
+
const sessionError = this.validateSession(req);
|
|
105425
|
+
if (sessionError) {
|
|
105426
|
+
return sessionError;
|
|
105427
|
+
}
|
|
105428
|
+
const protocolError = this.validateProtocolVersion(req);
|
|
105429
|
+
if (protocolError) {
|
|
105430
|
+
return protocolError;
|
|
105431
|
+
}
|
|
105432
|
+
if (this._eventStore) {
|
|
105433
|
+
const lastEventId = req.headers.get("last-event-id");
|
|
105434
|
+
if (lastEventId) {
|
|
105435
|
+
return this.replayEvents(lastEventId);
|
|
105436
|
+
}
|
|
105437
|
+
}
|
|
105438
|
+
if (this._streamMapping.get(this._standaloneSseStreamId) !== void 0) {
|
|
105439
|
+
this.onerror?.(new Error("Conflict: Only one SSE stream is allowed per session"));
|
|
105440
|
+
return this.createJsonErrorResponse(409, -32e3, "Conflict: Only one SSE stream is allowed per session");
|
|
105441
|
+
}
|
|
105442
|
+
const encoder = new TextEncoder();
|
|
105443
|
+
let streamController;
|
|
105444
|
+
const readable = new ReadableStream({
|
|
105445
|
+
start: (controller) => {
|
|
105446
|
+
streamController = controller;
|
|
105447
|
+
},
|
|
105448
|
+
cancel: () => {
|
|
105449
|
+
this._streamMapping.delete(this._standaloneSseStreamId);
|
|
105450
|
+
}
|
|
105451
|
+
});
|
|
105452
|
+
const headers = {
|
|
105453
|
+
"Content-Type": "text/event-stream",
|
|
105454
|
+
"Cache-Control": "no-cache, no-transform",
|
|
105455
|
+
Connection: "keep-alive"
|
|
105456
|
+
};
|
|
105457
|
+
if (this.sessionId !== void 0) {
|
|
105458
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
105459
|
+
}
|
|
105460
|
+
this._streamMapping.set(this._standaloneSseStreamId, {
|
|
105461
|
+
controller: streamController,
|
|
105462
|
+
encoder,
|
|
105463
|
+
cleanup: () => {
|
|
105464
|
+
this._streamMapping.delete(this._standaloneSseStreamId);
|
|
105465
|
+
try {
|
|
105466
|
+
streamController.close();
|
|
105467
|
+
} catch {
|
|
105468
|
+
}
|
|
105469
|
+
}
|
|
105470
|
+
});
|
|
105471
|
+
return new Response(readable, { headers });
|
|
105472
|
+
}
|
|
105473
|
+
/**
|
|
105474
|
+
* Replays events that would have been sent after the specified event ID
|
|
105475
|
+
* Only used when resumability is enabled
|
|
105476
|
+
*/
|
|
105477
|
+
async replayEvents(lastEventId) {
|
|
105478
|
+
if (!this._eventStore) {
|
|
105479
|
+
this.onerror?.(new Error("Event store not configured"));
|
|
105480
|
+
return this.createJsonErrorResponse(400, -32e3, "Event store not configured");
|
|
105481
|
+
}
|
|
105482
|
+
try {
|
|
105483
|
+
let streamId;
|
|
105484
|
+
if (this._eventStore.getStreamIdForEventId) {
|
|
105485
|
+
streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
|
|
105486
|
+
if (!streamId) {
|
|
105487
|
+
this.onerror?.(new Error("Invalid event ID format"));
|
|
105488
|
+
return this.createJsonErrorResponse(400, -32e3, "Invalid event ID format");
|
|
105489
|
+
}
|
|
105490
|
+
if (this._streamMapping.get(streamId) !== void 0) {
|
|
105491
|
+
this.onerror?.(new Error("Conflict: Stream already has an active connection"));
|
|
105492
|
+
return this.createJsonErrorResponse(409, -32e3, "Conflict: Stream already has an active connection");
|
|
105493
|
+
}
|
|
105494
|
+
}
|
|
105495
|
+
const headers = {
|
|
105496
|
+
"Content-Type": "text/event-stream",
|
|
105497
|
+
"Cache-Control": "no-cache, no-transform",
|
|
105498
|
+
Connection: "keep-alive"
|
|
105499
|
+
};
|
|
105500
|
+
if (this.sessionId !== void 0) {
|
|
105501
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
105502
|
+
}
|
|
105503
|
+
const encoder = new TextEncoder();
|
|
105504
|
+
let streamController;
|
|
105505
|
+
const readable = new ReadableStream({
|
|
105506
|
+
start: (controller) => {
|
|
105507
|
+
streamController = controller;
|
|
105508
|
+
},
|
|
105509
|
+
cancel: () => {
|
|
105510
|
+
}
|
|
105511
|
+
});
|
|
105512
|
+
const replayedStreamId = await this._eventStore.replayEventsAfter(lastEventId, {
|
|
105513
|
+
send: async (eventId, message) => {
|
|
105514
|
+
const success = this.writeSSEEvent(streamController, encoder, message, eventId);
|
|
105515
|
+
if (!success) {
|
|
105516
|
+
this.onerror?.(new Error("Failed replay events"));
|
|
105517
|
+
try {
|
|
105518
|
+
streamController.close();
|
|
105519
|
+
} catch {
|
|
105520
|
+
}
|
|
105521
|
+
}
|
|
105522
|
+
}
|
|
105523
|
+
});
|
|
105524
|
+
this._streamMapping.set(replayedStreamId, {
|
|
105525
|
+
controller: streamController,
|
|
105526
|
+
encoder,
|
|
105527
|
+
cleanup: () => {
|
|
105528
|
+
this._streamMapping.delete(replayedStreamId);
|
|
105529
|
+
try {
|
|
105530
|
+
streamController.close();
|
|
105531
|
+
} catch {
|
|
105532
|
+
}
|
|
105533
|
+
}
|
|
105534
|
+
});
|
|
105535
|
+
return new Response(readable, { headers });
|
|
105536
|
+
} catch (error2) {
|
|
105537
|
+
this.onerror?.(error2);
|
|
105538
|
+
return this.createJsonErrorResponse(500, -32e3, "Error replaying events");
|
|
105539
|
+
}
|
|
105540
|
+
}
|
|
105541
|
+
/**
|
|
105542
|
+
* Writes an event to an SSE stream via controller with proper formatting
|
|
105543
|
+
*/
|
|
105544
|
+
writeSSEEvent(controller, encoder, message, eventId) {
|
|
105545
|
+
try {
|
|
105546
|
+
let eventData = `event: message
|
|
105547
|
+
`;
|
|
105548
|
+
if (eventId) {
|
|
105549
|
+
eventData += `id: ${eventId}
|
|
105550
|
+
`;
|
|
105551
|
+
}
|
|
105552
|
+
eventData += `data: ${JSON.stringify(message)}
|
|
105553
|
+
|
|
105554
|
+
`;
|
|
105555
|
+
controller.enqueue(encoder.encode(eventData));
|
|
105556
|
+
return true;
|
|
105557
|
+
} catch (error2) {
|
|
105558
|
+
this.onerror?.(error2);
|
|
105559
|
+
return false;
|
|
105560
|
+
}
|
|
105561
|
+
}
|
|
105562
|
+
/**
|
|
105563
|
+
* Handles unsupported requests (PUT, PATCH, etc.)
|
|
105564
|
+
*/
|
|
105565
|
+
handleUnsupportedRequest() {
|
|
105566
|
+
this.onerror?.(new Error("Method not allowed."));
|
|
105567
|
+
return new Response(JSON.stringify({
|
|
105568
|
+
jsonrpc: "2.0",
|
|
105569
|
+
error: {
|
|
105570
|
+
code: -32e3,
|
|
105571
|
+
message: "Method not allowed."
|
|
105572
|
+
},
|
|
105573
|
+
id: null
|
|
105574
|
+
}), {
|
|
105575
|
+
status: 405,
|
|
105576
|
+
headers: {
|
|
105577
|
+
Allow: "GET, POST, DELETE",
|
|
105578
|
+
"Content-Type": "application/json"
|
|
105579
|
+
}
|
|
105580
|
+
});
|
|
105581
|
+
}
|
|
105582
|
+
/**
|
|
105583
|
+
* Handles POST requests containing JSON-RPC messages
|
|
105584
|
+
*/
|
|
105585
|
+
async handlePostRequest(req, options2) {
|
|
105586
|
+
try {
|
|
105587
|
+
const acceptHeader = req.headers.get("accept");
|
|
105588
|
+
if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
|
|
105589
|
+
this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
|
|
105590
|
+
return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept both application/json and text/event-stream");
|
|
105591
|
+
}
|
|
105592
|
+
const ct = req.headers.get("content-type");
|
|
105593
|
+
if (!ct || !ct.includes("application/json")) {
|
|
105594
|
+
this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json"));
|
|
105595
|
+
return this.createJsonErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
|
|
105596
|
+
}
|
|
105597
|
+
const requestInfo = {
|
|
105598
|
+
headers: Object.fromEntries(req.headers.entries()),
|
|
105599
|
+
url: new URL(req.url)
|
|
105600
|
+
};
|
|
105601
|
+
let rawMessage;
|
|
105602
|
+
if (options2?.parsedBody !== void 0) {
|
|
105603
|
+
rawMessage = options2.parsedBody;
|
|
105604
|
+
} else {
|
|
105605
|
+
try {
|
|
105606
|
+
rawMessage = await req.json();
|
|
105607
|
+
} catch {
|
|
105608
|
+
this.onerror?.(new Error("Parse error: Invalid JSON"));
|
|
105609
|
+
return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
|
|
105610
|
+
}
|
|
105611
|
+
}
|
|
105612
|
+
let messages;
|
|
105613
|
+
try {
|
|
105614
|
+
if (Array.isArray(rawMessage)) {
|
|
105615
|
+
messages = rawMessage.map((msg) => JSONRPCMessageSchema.parse(msg));
|
|
105616
|
+
} else {
|
|
105617
|
+
messages = [JSONRPCMessageSchema.parse(rawMessage)];
|
|
105618
|
+
}
|
|
105619
|
+
} catch {
|
|
105620
|
+
this.onerror?.(new Error("Parse error: Invalid JSON-RPC message"));
|
|
105621
|
+
return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
|
|
105622
|
+
}
|
|
105623
|
+
const isInitializationRequest = messages.some(isInitializeRequest);
|
|
105624
|
+
if (isInitializationRequest) {
|
|
105625
|
+
if (this._initialized && this.sessionId !== void 0) {
|
|
105626
|
+
this.onerror?.(new Error("Invalid Request: Server already initialized"));
|
|
105627
|
+
return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
|
|
105628
|
+
}
|
|
105629
|
+
if (messages.length > 1) {
|
|
105630
|
+
this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed"));
|
|
105631
|
+
return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
|
|
105632
|
+
}
|
|
105633
|
+
this.sessionId = this.sessionIdGenerator?.();
|
|
105634
|
+
this._initialized = true;
|
|
105635
|
+
if (this.sessionId && this._onsessioninitialized) {
|
|
105636
|
+
await Promise.resolve(this._onsessioninitialized(this.sessionId));
|
|
105637
|
+
}
|
|
105638
|
+
}
|
|
105639
|
+
if (!isInitializationRequest) {
|
|
105640
|
+
const sessionError = this.validateSession(req);
|
|
105641
|
+
if (sessionError) {
|
|
105642
|
+
return sessionError;
|
|
105643
|
+
}
|
|
105644
|
+
const protocolError = this.validateProtocolVersion(req);
|
|
105645
|
+
if (protocolError) {
|
|
105646
|
+
return protocolError;
|
|
105647
|
+
}
|
|
105648
|
+
}
|
|
105649
|
+
const hasRequests = messages.some(isJSONRPCRequest);
|
|
105650
|
+
if (!hasRequests) {
|
|
105651
|
+
for (const message of messages) {
|
|
105652
|
+
this.onmessage?.(message, { authInfo: options2?.authInfo, requestInfo });
|
|
105653
|
+
}
|
|
105654
|
+
return new Response(null, { status: 202 });
|
|
105655
|
+
}
|
|
105656
|
+
const streamId = crypto.randomUUID();
|
|
105657
|
+
const initRequest = messages.find((m) => isInitializeRequest(m));
|
|
105658
|
+
const clientProtocolVersion = initRequest ? initRequest.params.protocolVersion : req.headers.get("mcp-protocol-version") ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
|
|
105659
|
+
if (this._enableJsonResponse) {
|
|
105660
|
+
return new Promise((resolve8) => {
|
|
105661
|
+
this._streamMapping.set(streamId, {
|
|
105662
|
+
resolveJson: resolve8,
|
|
105663
|
+
cleanup: () => {
|
|
105664
|
+
this._streamMapping.delete(streamId);
|
|
105665
|
+
}
|
|
105666
|
+
});
|
|
105667
|
+
for (const message of messages) {
|
|
105668
|
+
if (isJSONRPCRequest(message)) {
|
|
105669
|
+
this._requestToStreamMapping.set(message.id, streamId);
|
|
105670
|
+
}
|
|
105671
|
+
}
|
|
105672
|
+
for (const message of messages) {
|
|
105673
|
+
this.onmessage?.(message, { authInfo: options2?.authInfo, requestInfo });
|
|
105674
|
+
}
|
|
105675
|
+
});
|
|
105676
|
+
}
|
|
105677
|
+
const encoder = new TextEncoder();
|
|
105678
|
+
let streamController;
|
|
105679
|
+
const readable = new ReadableStream({
|
|
105680
|
+
start: (controller) => {
|
|
105681
|
+
streamController = controller;
|
|
105682
|
+
},
|
|
105683
|
+
cancel: () => {
|
|
105684
|
+
this._streamMapping.delete(streamId);
|
|
105685
|
+
}
|
|
105686
|
+
});
|
|
105687
|
+
const headers = {
|
|
105688
|
+
"Content-Type": "text/event-stream",
|
|
105689
|
+
"Cache-Control": "no-cache",
|
|
105690
|
+
Connection: "keep-alive"
|
|
105691
|
+
};
|
|
105692
|
+
if (this.sessionId !== void 0) {
|
|
105693
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
105694
|
+
}
|
|
105695
|
+
for (const message of messages) {
|
|
105696
|
+
if (isJSONRPCRequest(message)) {
|
|
105697
|
+
this._streamMapping.set(streamId, {
|
|
105698
|
+
controller: streamController,
|
|
105699
|
+
encoder,
|
|
105700
|
+
cleanup: () => {
|
|
105701
|
+
this._streamMapping.delete(streamId);
|
|
105702
|
+
try {
|
|
105703
|
+
streamController.close();
|
|
105704
|
+
} catch {
|
|
105705
|
+
}
|
|
105706
|
+
}
|
|
105707
|
+
});
|
|
105708
|
+
this._requestToStreamMapping.set(message.id, streamId);
|
|
105709
|
+
}
|
|
105710
|
+
}
|
|
105711
|
+
await this.writePrimingEvent(streamController, encoder, streamId, clientProtocolVersion);
|
|
105712
|
+
for (const message of messages) {
|
|
105713
|
+
let closeSSEStream;
|
|
105714
|
+
let closeStandaloneSSEStream;
|
|
105715
|
+
if (isJSONRPCRequest(message) && this._eventStore && clientProtocolVersion >= "2025-11-25") {
|
|
105716
|
+
closeSSEStream = () => {
|
|
105717
|
+
this.closeSSEStream(message.id);
|
|
105718
|
+
};
|
|
105719
|
+
closeStandaloneSSEStream = () => {
|
|
105720
|
+
this.closeStandaloneSSEStream();
|
|
105721
|
+
};
|
|
105722
|
+
}
|
|
105723
|
+
this.onmessage?.(message, { authInfo: options2?.authInfo, requestInfo, closeSSEStream, closeStandaloneSSEStream });
|
|
105724
|
+
}
|
|
105725
|
+
return new Response(readable, { status: 200, headers });
|
|
105726
|
+
} catch (error2) {
|
|
105727
|
+
this.onerror?.(error2);
|
|
105728
|
+
return this.createJsonErrorResponse(400, -32700, "Parse error", { data: String(error2) });
|
|
105729
|
+
}
|
|
105730
|
+
}
|
|
105731
|
+
/**
|
|
105732
|
+
* Handles DELETE requests to terminate sessions
|
|
105733
|
+
*/
|
|
105734
|
+
async handleDeleteRequest(req) {
|
|
105735
|
+
const sessionError = this.validateSession(req);
|
|
105736
|
+
if (sessionError) {
|
|
105737
|
+
return sessionError;
|
|
105738
|
+
}
|
|
105739
|
+
const protocolError = this.validateProtocolVersion(req);
|
|
105740
|
+
if (protocolError) {
|
|
105741
|
+
return protocolError;
|
|
105742
|
+
}
|
|
105743
|
+
await Promise.resolve(this._onsessionclosed?.(this.sessionId));
|
|
105744
|
+
await this.close();
|
|
105745
|
+
return new Response(null, { status: 200 });
|
|
105746
|
+
}
|
|
105747
|
+
/**
|
|
105748
|
+
* Validates session ID for non-initialization requests.
|
|
105749
|
+
* Returns Response error if invalid, undefined otherwise
|
|
105750
|
+
*/
|
|
105751
|
+
validateSession(req) {
|
|
105752
|
+
if (this.sessionIdGenerator === void 0) {
|
|
105753
|
+
return void 0;
|
|
105754
|
+
}
|
|
105755
|
+
if (!this._initialized) {
|
|
105756
|
+
this.onerror?.(new Error("Bad Request: Server not initialized"));
|
|
105757
|
+
return this.createJsonErrorResponse(400, -32e3, "Bad Request: Server not initialized");
|
|
105758
|
+
}
|
|
105759
|
+
const sessionId = req.headers.get("mcp-session-id");
|
|
105760
|
+
if (!sessionId) {
|
|
105761
|
+
this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required"));
|
|
105762
|
+
return this.createJsonErrorResponse(400, -32e3, "Bad Request: Mcp-Session-Id header is required");
|
|
105763
|
+
}
|
|
105764
|
+
if (sessionId !== this.sessionId) {
|
|
105765
|
+
this.onerror?.(new Error("Session not found"));
|
|
105766
|
+
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
105767
|
+
}
|
|
105768
|
+
return void 0;
|
|
105769
|
+
}
|
|
105770
|
+
/**
|
|
105771
|
+
* Validates the MCP-Protocol-Version header on incoming requests.
|
|
105772
|
+
*
|
|
105773
|
+
* For initialization: Version negotiation handles unknown versions gracefully
|
|
105774
|
+
* (server responds with its supported version).
|
|
105775
|
+
*
|
|
105776
|
+
* For subsequent requests with MCP-Protocol-Version header:
|
|
105777
|
+
* - Accept if in supported list
|
|
105778
|
+
* - 400 if unsupported
|
|
105779
|
+
*
|
|
105780
|
+
* For HTTP requests without the MCP-Protocol-Version header:
|
|
105781
|
+
* - Accept and default to the version negotiated at initialization
|
|
105782
|
+
*/
|
|
105783
|
+
validateProtocolVersion(req) {
|
|
105784
|
+
const protocolVersion = req.headers.get("mcp-protocol-version");
|
|
105785
|
+
if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
|
|
105786
|
+
this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`));
|
|
105787
|
+
return this.createJsonErrorResponse(400, -32e3, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`);
|
|
105788
|
+
}
|
|
105789
|
+
return void 0;
|
|
105790
|
+
}
|
|
105791
|
+
async close() {
|
|
105792
|
+
this._streamMapping.forEach(({ cleanup }) => {
|
|
105793
|
+
cleanup();
|
|
105794
|
+
});
|
|
105795
|
+
this._streamMapping.clear();
|
|
105796
|
+
this._requestResponseMap.clear();
|
|
105797
|
+
this.onclose?.();
|
|
105798
|
+
}
|
|
105799
|
+
/**
|
|
105800
|
+
* Close an SSE stream for a specific request, triggering client reconnection.
|
|
105801
|
+
* Use this to implement polling behavior during long-running operations -
|
|
105802
|
+
* client will reconnect after the retry interval specified in the priming event.
|
|
105803
|
+
*/
|
|
105804
|
+
closeSSEStream(requestId) {
|
|
105805
|
+
const streamId = this._requestToStreamMapping.get(requestId);
|
|
105806
|
+
if (!streamId)
|
|
105807
|
+
return;
|
|
105808
|
+
const stream = this._streamMapping.get(streamId);
|
|
105809
|
+
if (stream) {
|
|
105810
|
+
stream.cleanup();
|
|
105811
|
+
}
|
|
105812
|
+
}
|
|
105813
|
+
/**
|
|
105814
|
+
* Close the standalone GET SSE stream, triggering client reconnection.
|
|
105815
|
+
* Use this to implement polling behavior for server-initiated notifications.
|
|
105816
|
+
*/
|
|
105817
|
+
closeStandaloneSSEStream() {
|
|
105818
|
+
const stream = this._streamMapping.get(this._standaloneSseStreamId);
|
|
105819
|
+
if (stream) {
|
|
105820
|
+
stream.cleanup();
|
|
105821
|
+
}
|
|
105822
|
+
}
|
|
105823
|
+
async send(message, options2) {
|
|
105824
|
+
let requestId = options2?.relatedRequestId;
|
|
105825
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
|
105826
|
+
requestId = message.id;
|
|
105827
|
+
}
|
|
105828
|
+
if (requestId === void 0) {
|
|
105829
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
|
105830
|
+
throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
|
|
105831
|
+
}
|
|
105832
|
+
let eventId;
|
|
105833
|
+
if (this._eventStore) {
|
|
105834
|
+
eventId = await this._eventStore.storeEvent(this._standaloneSseStreamId, message);
|
|
105835
|
+
}
|
|
105836
|
+
const standaloneSse = this._streamMapping.get(this._standaloneSseStreamId);
|
|
105837
|
+
if (standaloneSse === void 0) {
|
|
105838
|
+
return;
|
|
105839
|
+
}
|
|
105840
|
+
if (standaloneSse.controller && standaloneSse.encoder) {
|
|
105841
|
+
this.writeSSEEvent(standaloneSse.controller, standaloneSse.encoder, message, eventId);
|
|
105842
|
+
}
|
|
105843
|
+
return;
|
|
105844
|
+
}
|
|
105845
|
+
const streamId = this._requestToStreamMapping.get(requestId);
|
|
105846
|
+
if (!streamId) {
|
|
105847
|
+
throw new Error(`No connection established for request ID: ${String(requestId)}`);
|
|
105848
|
+
}
|
|
105849
|
+
const stream = this._streamMapping.get(streamId);
|
|
105850
|
+
if (!this._enableJsonResponse && stream?.controller && stream?.encoder) {
|
|
105851
|
+
let eventId;
|
|
105852
|
+
if (this._eventStore) {
|
|
105853
|
+
eventId = await this._eventStore.storeEvent(streamId, message);
|
|
105854
|
+
}
|
|
105855
|
+
this.writeSSEEvent(stream.controller, stream.encoder, message, eventId);
|
|
105856
|
+
}
|
|
105857
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
|
105858
|
+
this._requestResponseMap.set(requestId, message);
|
|
105859
|
+
const relatedIds = Array.from(this._requestToStreamMapping.entries()).filter(([_, sid]) => sid === streamId).map(([id]) => id);
|
|
105860
|
+
const allResponsesReady = relatedIds.every((id) => this._requestResponseMap.has(id));
|
|
105861
|
+
if (allResponsesReady) {
|
|
105862
|
+
if (!stream) {
|
|
105863
|
+
throw new Error(`No connection established for request ID: ${String(requestId)}`);
|
|
105864
|
+
}
|
|
105865
|
+
if (this._enableJsonResponse && stream.resolveJson) {
|
|
105866
|
+
const headers = {
|
|
105867
|
+
"Content-Type": "application/json"
|
|
105868
|
+
};
|
|
105869
|
+
if (this.sessionId !== void 0) {
|
|
105870
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
105871
|
+
}
|
|
105872
|
+
const responses = relatedIds.map((id) => this._requestResponseMap.get(id));
|
|
105873
|
+
if (responses.length === 1) {
|
|
105874
|
+
stream.resolveJson(new Response(JSON.stringify(responses[0]), { status: 200, headers }));
|
|
105875
|
+
} else {
|
|
105876
|
+
stream.resolveJson(new Response(JSON.stringify(responses), { status: 200, headers }));
|
|
105877
|
+
}
|
|
105878
|
+
} else {
|
|
105879
|
+
stream.cleanup();
|
|
105880
|
+
}
|
|
105881
|
+
for (const id of relatedIds) {
|
|
105882
|
+
this._requestResponseMap.delete(id);
|
|
105883
|
+
this._requestToStreamMapping.delete(id);
|
|
105884
|
+
}
|
|
105885
|
+
}
|
|
105886
|
+
}
|
|
105887
|
+
}
|
|
105888
|
+
};
|
|
105889
|
+
}
|
|
105890
|
+
});
|
|
105891
|
+
|
|
105892
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.js
|
|
105893
|
+
var StreamableHTTPServerTransport;
|
|
105894
|
+
var init_streamableHttp = __esm({
|
|
105895
|
+
"node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.js"() {
|
|
105896
|
+
init_dist7();
|
|
105897
|
+
init_webStandardStreamableHttp();
|
|
105898
|
+
StreamableHTTPServerTransport = class {
|
|
105899
|
+
constructor(options2 = {}) {
|
|
105900
|
+
this._requestContext = /* @__PURE__ */ new WeakMap();
|
|
105901
|
+
this._webStandardTransport = new WebStandardStreamableHTTPServerTransport(options2);
|
|
105902
|
+
this._requestListener = getRequestListener(async (webRequest) => {
|
|
105903
|
+
const context = this._requestContext.get(webRequest);
|
|
105904
|
+
return this._webStandardTransport.handleRequest(webRequest, {
|
|
105905
|
+
authInfo: context?.authInfo,
|
|
105906
|
+
parsedBody: context?.parsedBody
|
|
105907
|
+
});
|
|
105908
|
+
}, { overrideGlobalObjects: false });
|
|
105909
|
+
}
|
|
105910
|
+
/**
|
|
105911
|
+
* Gets the session ID for this transport instance.
|
|
105912
|
+
*/
|
|
105913
|
+
get sessionId() {
|
|
105914
|
+
return this._webStandardTransport.sessionId;
|
|
105915
|
+
}
|
|
105916
|
+
/**
|
|
105917
|
+
* Sets callback for when the transport is closed.
|
|
105918
|
+
*/
|
|
105919
|
+
set onclose(handler) {
|
|
105920
|
+
this._webStandardTransport.onclose = handler;
|
|
105921
|
+
}
|
|
105922
|
+
get onclose() {
|
|
105923
|
+
return this._webStandardTransport.onclose;
|
|
105924
|
+
}
|
|
105925
|
+
/**
|
|
105926
|
+
* Sets callback for transport errors.
|
|
105927
|
+
*/
|
|
105928
|
+
set onerror(handler) {
|
|
105929
|
+
this._webStandardTransport.onerror = handler;
|
|
105930
|
+
}
|
|
105931
|
+
get onerror() {
|
|
105932
|
+
return this._webStandardTransport.onerror;
|
|
105933
|
+
}
|
|
105934
|
+
/**
|
|
105935
|
+
* Sets callback for incoming messages.
|
|
105936
|
+
*/
|
|
105937
|
+
set onmessage(handler) {
|
|
105938
|
+
this._webStandardTransport.onmessage = handler;
|
|
105939
|
+
}
|
|
105940
|
+
get onmessage() {
|
|
105941
|
+
return this._webStandardTransport.onmessage;
|
|
105942
|
+
}
|
|
105943
|
+
/**
|
|
105944
|
+
* Starts the transport. This is required by the Transport interface but is a no-op
|
|
105945
|
+
* for the Streamable HTTP transport as connections are managed per-request.
|
|
105946
|
+
*/
|
|
105947
|
+
async start() {
|
|
105948
|
+
return this._webStandardTransport.start();
|
|
105949
|
+
}
|
|
105950
|
+
/**
|
|
105951
|
+
* Closes the transport and all active connections.
|
|
105952
|
+
*/
|
|
105953
|
+
async close() {
|
|
105954
|
+
return this._webStandardTransport.close();
|
|
105955
|
+
}
|
|
105956
|
+
/**
|
|
105957
|
+
* Sends a JSON-RPC message through the transport.
|
|
105958
|
+
*/
|
|
105959
|
+
async send(message, options2) {
|
|
105960
|
+
return this._webStandardTransport.send(message, options2);
|
|
105961
|
+
}
|
|
105962
|
+
/**
|
|
105963
|
+
* Handles an incoming HTTP request, whether GET or POST.
|
|
105964
|
+
*
|
|
105965
|
+
* This method converts Node.js HTTP objects to Web Standard Request/Response
|
|
105966
|
+
* and delegates to the underlying WebStandardStreamableHTTPServerTransport.
|
|
105967
|
+
*
|
|
105968
|
+
* @param req - Node.js IncomingMessage, optionally with auth property from middleware
|
|
105969
|
+
* @param res - Node.js ServerResponse
|
|
105970
|
+
* @param parsedBody - Optional pre-parsed body from body-parser middleware
|
|
105971
|
+
*/
|
|
105972
|
+
async handleRequest(req, res, parsedBody) {
|
|
105973
|
+
const authInfo = req.auth;
|
|
105974
|
+
const handler = getRequestListener(async (webRequest) => {
|
|
105975
|
+
return this._webStandardTransport.handleRequest(webRequest, {
|
|
105976
|
+
authInfo,
|
|
105977
|
+
parsedBody
|
|
105978
|
+
});
|
|
105979
|
+
}, { overrideGlobalObjects: false });
|
|
105980
|
+
await handler(req, res);
|
|
105981
|
+
}
|
|
105982
|
+
/**
|
|
105983
|
+
* Close an SSE stream for a specific request, triggering client reconnection.
|
|
105984
|
+
* Use this to implement polling behavior during long-running operations -
|
|
105985
|
+
* client will reconnect after the retry interval specified in the priming event.
|
|
105986
|
+
*/
|
|
105987
|
+
closeSSEStream(requestId) {
|
|
105988
|
+
this._webStandardTransport.closeSSEStream(requestId);
|
|
105989
|
+
}
|
|
105990
|
+
/**
|
|
105991
|
+
* Close the standalone GET SSE stream, triggering client reconnection.
|
|
105992
|
+
* Use this to implement polling behavior for server-initiated notifications.
|
|
105993
|
+
*/
|
|
105994
|
+
closeStandaloneSSEStream() {
|
|
105995
|
+
this._webStandardTransport.closeStandaloneSSEStream();
|
|
105996
|
+
}
|
|
105997
|
+
};
|
|
105998
|
+
}
|
|
105999
|
+
});
|
|
106000
|
+
|
|
104725
106001
|
// node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/server.js
|
|
104726
106002
|
var ExperimentalServerTasks;
|
|
104727
106003
|
var init_server = __esm({
|
|
@@ -105403,6 +106679,7 @@ var init_stdio3 = __esm({
|
|
|
105403
106679
|
// src/mcp/server.ts
|
|
105404
106680
|
var server_exports = {};
|
|
105405
106681
|
__export(server_exports, {
|
|
106682
|
+
buildServer: () => buildServer,
|
|
105406
106683
|
createMcpServer: () => createMcpServer,
|
|
105407
106684
|
runMcpServer: () => runMcpServer
|
|
105408
106685
|
});
|
|
@@ -105562,7 +106839,7 @@ function schemaToJsonSchema(schema) {
|
|
|
105562
106839
|
}
|
|
105563
106840
|
return { type: "object", properties: {} };
|
|
105564
106841
|
}
|
|
105565
|
-
var _agentReg;
|
|
106842
|
+
var _agentReg, buildServer;
|
|
105566
106843
|
var init_server3 = __esm({
|
|
105567
106844
|
"src/mcp/server.ts"() {
|
|
105568
106845
|
"use strict";
|
|
@@ -105573,6 +106850,112 @@ var init_server3 = __esm({
|
|
|
105573
106850
|
init_registry2();
|
|
105574
106851
|
init_db();
|
|
105575
106852
|
_agentReg = /* @__PURE__ */ new Map();
|
|
106853
|
+
buildServer = createMcpServer;
|
|
106854
|
+
}
|
|
106855
|
+
});
|
|
106856
|
+
|
|
106857
|
+
// src/mcp/http.ts
|
|
106858
|
+
var http_exports = {};
|
|
106859
|
+
__export(http_exports, {
|
|
106860
|
+
DEFAULT_MCP_HTTP_PORT: () => DEFAULT_MCP_HTTP_PORT,
|
|
106861
|
+
MCP_SERVICE_NAME: () => MCP_SERVICE_NAME,
|
|
106862
|
+
handleStatelessMcpNode: () => handleStatelessMcpNode,
|
|
106863
|
+
healthPayload: () => healthPayload,
|
|
106864
|
+
isHttpMode: () => isHttpMode,
|
|
106865
|
+
parseHttpArgv: () => parseHttpArgv,
|
|
106866
|
+
resolveMcpHttpPort: () => resolveMcpHttpPort,
|
|
106867
|
+
runMcpHttpServer: () => runMcpHttpServer,
|
|
106868
|
+
startMcpHttpServer: () => startMcpHttpServer
|
|
106869
|
+
});
|
|
106870
|
+
import { createServer } from "node:http";
|
|
106871
|
+
function resolveMcpHttpPort(explicit) {
|
|
106872
|
+
if (explicit != null && !Number.isNaN(explicit)) return explicit;
|
|
106873
|
+
const env3 = process.env.MCP_HTTP_PORT;
|
|
106874
|
+
if (env3) {
|
|
106875
|
+
const parsed = parseInt(env3, 10);
|
|
106876
|
+
if (!Number.isNaN(parsed)) return parsed;
|
|
106877
|
+
}
|
|
106878
|
+
return DEFAULT_MCP_HTTP_PORT;
|
|
106879
|
+
}
|
|
106880
|
+
function isHttpMode(argv = process.argv) {
|
|
106881
|
+
return argv.includes("--http") || process.env.MCP_HTTP === "1";
|
|
106882
|
+
}
|
|
106883
|
+
function parseHttpArgv(argv = process.argv) {
|
|
106884
|
+
const http = isHttpMode(argv);
|
|
106885
|
+
let port;
|
|
106886
|
+
const portIdx = argv.indexOf("--port");
|
|
106887
|
+
if (portIdx !== -1 && argv[portIdx + 1]) {
|
|
106888
|
+
port = parseInt(argv[portIdx + 1], 10);
|
|
106889
|
+
}
|
|
106890
|
+
return { http, port };
|
|
106891
|
+
}
|
|
106892
|
+
async function readJsonBody(req) {
|
|
106893
|
+
const chunks = [];
|
|
106894
|
+
for await (const chunk of req) chunks.push(chunk);
|
|
106895
|
+
if (chunks.length === 0) return void 0;
|
|
106896
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
106897
|
+
return text ? JSON.parse(text) : void 0;
|
|
106898
|
+
}
|
|
106899
|
+
async function handleStatelessMcpNode(req, res, getServer = buildServer) {
|
|
106900
|
+
const server = await getServer();
|
|
106901
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: void 0 });
|
|
106902
|
+
await server.connect(transport);
|
|
106903
|
+
const body = req.method === "POST" ? await readJsonBody(req) : void 0;
|
|
106904
|
+
await transport.handleRequest(req, res, body);
|
|
106905
|
+
res.on("close", () => {
|
|
106906
|
+
void transport.close();
|
|
106907
|
+
void server.close();
|
|
106908
|
+
});
|
|
106909
|
+
}
|
|
106910
|
+
function healthPayload(name = MCP_SERVICE_NAME) {
|
|
106911
|
+
return { status: "ok", name };
|
|
106912
|
+
}
|
|
106913
|
+
async function startMcpHttpServer(options2 = {}) {
|
|
106914
|
+
const port = options2.port ?? resolveMcpHttpPort();
|
|
106915
|
+
const host = "127.0.0.1";
|
|
106916
|
+
const getServer = options2.getServer ?? buildServer;
|
|
106917
|
+
const name = options2.name ?? MCP_SERVICE_NAME;
|
|
106918
|
+
const httpServer = createServer(async (req, res) => {
|
|
106919
|
+
const url2 = new URL(req.url ?? "/", `http://${host}:${port}`);
|
|
106920
|
+
if (req.method === "GET" && url2.pathname === "/health") {
|
|
106921
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
106922
|
+
res.end(JSON.stringify(healthPayload(name)));
|
|
106923
|
+
return;
|
|
106924
|
+
}
|
|
106925
|
+
if (url2.pathname === "/mcp") {
|
|
106926
|
+
await handleStatelessMcpNode(req, res, getServer);
|
|
106927
|
+
return;
|
|
106928
|
+
}
|
|
106929
|
+
res.writeHead(404);
|
|
106930
|
+
res.end("Not found");
|
|
106931
|
+
});
|
|
106932
|
+
await new Promise((resolve8, reject) => {
|
|
106933
|
+
httpServer.once("error", reject);
|
|
106934
|
+
httpServer.listen(port, host, () => resolve8());
|
|
106935
|
+
});
|
|
106936
|
+
const address = httpServer.address();
|
|
106937
|
+
const boundPort = typeof address === "object" && address ? address.port : port;
|
|
106938
|
+
return {
|
|
106939
|
+
port: boundPort,
|
|
106940
|
+
close: () => new Promise((resolve8, reject) => {
|
|
106941
|
+
httpServer.close((err) => err ? reject(err) : resolve8());
|
|
106942
|
+
})
|
|
106943
|
+
};
|
|
106944
|
+
}
|
|
106945
|
+
async function runMcpHttpServer(options2 = {}) {
|
|
106946
|
+
const { port } = await startMcpHttpServer(options2);
|
|
106947
|
+
console.error(`coders-mcp listening on http://127.0.0.1:${port}/mcp`);
|
|
106948
|
+
await new Promise(() => {
|
|
106949
|
+
});
|
|
106950
|
+
}
|
|
106951
|
+
var DEFAULT_MCP_HTTP_PORT, MCP_SERVICE_NAME;
|
|
106952
|
+
var init_http = __esm({
|
|
106953
|
+
"src/mcp/http.ts"() {
|
|
106954
|
+
"use strict";
|
|
106955
|
+
init_streamableHttp();
|
|
106956
|
+
init_server3();
|
|
106957
|
+
DEFAULT_MCP_HTTP_PORT = 8805;
|
|
106958
|
+
MCP_SERVICE_NAME = "coders";
|
|
105576
106959
|
}
|
|
105577
106960
|
});
|
|
105578
106961
|
|
|
@@ -106208,7 +107591,7 @@ var server_exports2 = {};
|
|
|
106208
107591
|
__export(server_exports2, {
|
|
106209
107592
|
startDashboard: () => startDashboard
|
|
106210
107593
|
});
|
|
106211
|
-
import { createServer } from "http";
|
|
107594
|
+
import { createServer as createServer2 } from "http";
|
|
106212
107595
|
import { createHash } from "crypto";
|
|
106213
107596
|
function route(method, path, handler) {
|
|
106214
107597
|
routes.push({ method, path, handler });
|
|
@@ -106413,7 +107796,7 @@ function terminalPageHTML() {
|
|
|
106413
107796
|
</html>`;
|
|
106414
107797
|
}
|
|
106415
107798
|
function startDashboard(port = 7077) {
|
|
106416
|
-
const server =
|
|
107799
|
+
const server = createServer2(handleRequest);
|
|
106417
107800
|
server.on("upgrade", (req, socket) => {
|
|
106418
107801
|
if (req.url === "/ws") {
|
|
106419
107802
|
handleUpgrade(req, socket);
|
|
@@ -106710,7 +108093,12 @@ async function main() {
|
|
|
106710
108093
|
}
|
|
106711
108094
|
});
|
|
106712
108095
|
const mcp = program2.command("mcp").description("Configure and manage MCP servers").configureHelp(helpConfig());
|
|
106713
|
-
mcp.command("serve").description("Start the Coders MCP server").option("-d, --debug", "Enable debug mode").option("--verbose", "Override verbose mode").action(async ({ debug, verbose }) => {
|
|
108096
|
+
mcp.command("serve").description("Start the Coders MCP server").option("-d, --debug", "Enable debug mode").option("--verbose", "Override verbose mode").option("--http", "Use Streamable HTTP transport on 127.0.0.1").option("--port <port>", "HTTP port (default 8805 or MCP_HTTP_PORT)").action(async ({ debug, verbose, http, port }) => {
|
|
108097
|
+
if (http || process.env.MCP_HTTP === "1") {
|
|
108098
|
+
const { resolveMcpHttpPort: resolveMcpHttpPort2, runMcpHttpServer: runMcpHttpServer2 } = await Promise.resolve().then(() => (init_http(), http_exports));
|
|
108099
|
+
await runMcpHttpServer2({ port: resolveMcpHttpPort2(port ? parseInt(port, 10) : void 0) });
|
|
108100
|
+
return;
|
|
108101
|
+
}
|
|
106714
108102
|
const { runMcpServer: runMcpServer2 } = await Promise.resolve().then(() => (init_server3(), server_exports));
|
|
106715
108103
|
await runMcpServer2({ debug, verbose });
|
|
106716
108104
|
});
|
|
@@ -107644,7 +109032,7 @@ var VERSION, BUILD_TIME, PACKAGE_NAME, ISSUES_URL, startupTimestamps, originalCw
|
|
|
107644
109032
|
var init_index = __esm({
|
|
107645
109033
|
"src/cli/index.ts"() {
|
|
107646
109034
|
VERSION = "0.1.2";
|
|
107647
|
-
BUILD_TIME = "2026-
|
|
109035
|
+
BUILD_TIME = "2026-05-28T10:04:25.240Z";
|
|
107648
109036
|
PACKAGE_NAME = "@hasna/coders";
|
|
107649
109037
|
ISSUES_URL = "https://github.com/hasnaxyz/open-coders/issues";
|
|
107650
109038
|
startupTimestamps = {};
|