238 lines
7.3 KiB
JavaScript
238 lines
7.3 KiB
JavaScript
// Metro module 938 (f939).
|
|
import { isValidContentItem } from "./Module936";
|
|
import { getClientInfoForTransport, getSessionDataForTransport, getProtocolVersionForTransport } from "./Module939";
|
|
import { MCP_SERVER_NAME_ATTRIBUTE, MCP_SERVER_TITLE_ATTRIBUTE, MCP_SERVER_VERSION_ATTRIBUTE, MCP_SESSION_ID_ATTRIBUTE, CLIENT_ADDRESS_ATTRIBUTE, CLIENT_PORT_ATTRIBUTE, MCP_TRANSPORT_ATTRIBUTE, NETWORK_TRANSPORT_ATTRIBUTE, NETWORK_PROTOCOL_VERSION_ATTRIBUTE, MCP_PROTOCOL_VERSION_ATTRIBUTE } from "./Module940";
|
|
import { HermesBuiltin } from "../_hermes/prelude";
|
|
const extractClientInfo = function extractClientInfo(a0) {
|
|
let address = (a0 == null ? void 0 : a0.requestInfo?.remoteAddress) || a0?.clientAddress || (a0 == null ? void 0 : a0.request?.ip);
|
|
if (!address) {
|
|
const r13 = a0 == null;
|
|
let r14 = void 0;
|
|
if (!r13) {
|
|
const request = a0.request;
|
|
r14 = request == null ? void 0 : request.connection?.remoteAddress;
|
|
}
|
|
address = r14;
|
|
}
|
|
let port = (a0 == null ? void 0 : a0.requestInfo?.remotePort) || a0?.clientPort;
|
|
if (!port) {
|
|
const r26 = a0 == null;
|
|
let r27 = void 0;
|
|
if (!r26) {
|
|
const request2 = a0.request;
|
|
r27 = request2 == null ? void 0 : request2.connection?.remotePort;
|
|
}
|
|
port = r27;
|
|
}
|
|
return {
|
|
address,
|
|
port
|
|
};
|
|
};
|
|
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
value: "Module"
|
|
});
|
|
export function buildClientAttributesFromInfo(a0) {
|
|
const name = a0?.name;
|
|
const r2 = {};
|
|
if (name) {
|
|
r2["mcp.client.name"] = a0.name;
|
|
}
|
|
if (a0?.title) {
|
|
r2["mcp.client.title"] = a0.title;
|
|
}
|
|
if (a0?.version) {
|
|
r2["mcp.client.version"] = a0.version;
|
|
}
|
|
return r2;
|
|
}
|
|
export function buildServerAttributesFromInfo(a0) {
|
|
const name = a0?.name;
|
|
const r3 = {};
|
|
if (name) {
|
|
r3[MCP_SERVER_NAME_ATTRIBUTE] = a0.name;
|
|
}
|
|
if (a0?.title) {
|
|
r3[MCP_SERVER_TITLE_ATTRIBUTE] = a0.title;
|
|
}
|
|
if (a0?.version) {
|
|
r3[MCP_SERVER_VERSION_ATTRIBUTE] = a0.version;
|
|
}
|
|
return r3;
|
|
}
|
|
export function buildTransportAttributes(a0, a1) {
|
|
let r21;
|
|
const r14 = a0 ? "sessionId" in a0 ? a0.sessionId : void 0 : void 0;
|
|
const r13 = a1 ? extractClientInfo(a1) : {};
|
|
if (a0?.constructor) {
|
|
const mcpTransport2 = typeof a0.constructor?.name === "string" ? a0.constructor.name : "unknown";
|
|
const r12 = mcpTransport2.toLowerCase();
|
|
r21 = {
|
|
mcpTransport: mcpTransport2,
|
|
networkTransport: r12.includes("stdio") ? "pipe" : r12.includes("http") || r12.includes("sse") ? "tcp" : "unknown"
|
|
};
|
|
} else {
|
|
r21 = {
|
|
mcpTransport: "unknown",
|
|
networkTransport: "unknown"
|
|
};
|
|
}
|
|
const { mcpTransport, networkTransport } = r21;
|
|
const clientInfoForTransport = getClientInfoForTransport(a0);
|
|
const name = clientInfoForTransport?.name;
|
|
const r44 = {};
|
|
if (name) {
|
|
r44["mcp.client.name"] = clientInfoForTransport.name;
|
|
}
|
|
if (clientInfoForTransport?.title) {
|
|
r44["mcp.client.title"] = clientInfoForTransport.title;
|
|
}
|
|
if (clientInfoForTransport?.version) {
|
|
r44["mcp.client.version"] = clientInfoForTransport.version;
|
|
}
|
|
const serverInfo = getSessionDataForTransport(a0)?.serverInfo;
|
|
const name2 = serverInfo?.name;
|
|
const r60 = {};
|
|
if (name2) {
|
|
r60[MCP_SERVER_NAME_ATTRIBUTE] = serverInfo.name;
|
|
}
|
|
if (serverInfo?.title) {
|
|
r60[MCP_SERVER_TITLE_ATTRIBUTE] = serverInfo.title;
|
|
}
|
|
if (serverInfo?.version) {
|
|
r60[MCP_SERVER_VERSION_ATTRIBUTE] = serverInfo.version;
|
|
}
|
|
const protocolVersionForTransport = getProtocolVersionForTransport(a0);
|
|
let r81 = r14;
|
|
if (r81) {
|
|
const r82 = {};
|
|
r82[MCP_SESSION_ID_ATTRIBUTE] = r14;
|
|
r81 = r82;
|
|
}
|
|
const r86 = {
|
|
...r81
|
|
};
|
|
let address = r13.address;
|
|
if (address) {
|
|
const r89 = {};
|
|
r89[CLIENT_ADDRESS_ATTRIBUTE] = r13.address;
|
|
address = r89;
|
|
}
|
|
HermesBuiltin.copyDataProperties(r86, address);
|
|
let port = r13.port;
|
|
if (port) {
|
|
const r97 = {};
|
|
r97[CLIENT_PORT_ATTRIBUTE] = r13.port;
|
|
port = r97;
|
|
}
|
|
HermesBuiltin.copyDataProperties(r86, port);
|
|
r86[MCP_TRANSPORT_ATTRIBUTE] = mcpTransport;
|
|
r86[NETWORK_TRANSPORT_ATTRIBUTE] = networkTransport;
|
|
r86[NETWORK_PROTOCOL_VERSION_ATTRIBUTE] = "2.0";
|
|
let r115 = protocolVersionForTransport;
|
|
if (r115) {
|
|
const r116 = {};
|
|
r116[MCP_PROTOCOL_VERSION_ATTRIBUTE] = protocolVersionForTransport;
|
|
r115 = r116;
|
|
}
|
|
HermesBuiltin.copyDataProperties(r86, r115);
|
|
HermesBuiltin.copyDataProperties(r86, r44);
|
|
HermesBuiltin.copyDataProperties(r86, r60);
|
|
return r86;
|
|
}
|
|
export { extractClientInfo };
|
|
export function extractSessionDataFromInitializeRequest(a0) {
|
|
const r1 = {};
|
|
if (isValidContentItem(a0.params)) {
|
|
if (typeof a0.params.protocolVersion === "string") {
|
|
r1.protocolVersion = a0.params.protocolVersion;
|
|
}
|
|
if (a0.params.clientInfo) {
|
|
const clientInfo = a0.params.clientInfo;
|
|
const clientInfo2 = {};
|
|
if (isValidContentItem(clientInfo)) {
|
|
if (typeof clientInfo.name === "string") {
|
|
clientInfo2.name = clientInfo.name;
|
|
}
|
|
if (typeof clientInfo.title === "string") {
|
|
clientInfo2.title = clientInfo.title;
|
|
}
|
|
if (typeof clientInfo.version === "string") {
|
|
clientInfo2.version = clientInfo.version;
|
|
}
|
|
}
|
|
r1.clientInfo = clientInfo2;
|
|
}
|
|
}
|
|
return r1;
|
|
}
|
|
export function extractSessionDataFromInitializeResponse(a0) {
|
|
const r1 = {};
|
|
if (isValidContentItem(a0)) {
|
|
if (typeof a0.protocolVersion === "string") {
|
|
r1.protocolVersion = a0.protocolVersion;
|
|
}
|
|
if (a0.serverInfo) {
|
|
const serverInfo = a0.serverInfo;
|
|
const serverInfo2 = {};
|
|
if (isValidContentItem(serverInfo)) {
|
|
if (typeof serverInfo.name === "string") {
|
|
serverInfo2.name = serverInfo.name;
|
|
}
|
|
if (typeof serverInfo.title === "string") {
|
|
serverInfo2.title = serverInfo.title;
|
|
}
|
|
if (typeof serverInfo.version === "string") {
|
|
serverInfo2.version = serverInfo.version;
|
|
}
|
|
}
|
|
r1.serverInfo = serverInfo2;
|
|
}
|
|
}
|
|
return r1;
|
|
}
|
|
export function getClientAttributes(a0) {
|
|
const clientInfoForTransport = getClientInfoForTransport(a0);
|
|
const name = clientInfoForTransport?.name;
|
|
const r12 = {};
|
|
if (name) {
|
|
r12["mcp.client.name"] = clientInfoForTransport.name;
|
|
}
|
|
if (clientInfoForTransport?.title) {
|
|
r12["mcp.client.title"] = clientInfoForTransport.title;
|
|
}
|
|
if (clientInfoForTransport?.version) {
|
|
r12["mcp.client.version"] = clientInfoForTransport.version;
|
|
}
|
|
return r12;
|
|
}
|
|
export function getServerAttributes(a0) {
|
|
const serverInfo = getSessionDataForTransport(a0)?.serverInfo;
|
|
const name = serverInfo?.name;
|
|
const r15 = {};
|
|
if (name) {
|
|
r15[MCP_SERVER_NAME_ATTRIBUTE] = serverInfo.name;
|
|
}
|
|
if (serverInfo?.title) {
|
|
r15[MCP_SERVER_TITLE_ATTRIBUTE] = serverInfo.title;
|
|
}
|
|
if (serverInfo?.version) {
|
|
r15[MCP_SERVER_VERSION_ATTRIBUTE] = serverInfo.version;
|
|
}
|
|
return r15;
|
|
}
|
|
export function getTransportTypes(a0) {
|
|
if (a0?.constructor) {
|
|
const mcpTransport = typeof a0.constructor?.name === "string" ? a0.constructor.name : "unknown";
|
|
const r8 = mcpTransport.toLowerCase();
|
|
return {
|
|
mcpTransport,
|
|
networkTransport: r8.includes("stdio") ? "pipe" : r8.includes("http") || r8.includes("sse") ? "tcp" : "unknown"
|
|
};
|
|
}
|
|
return {
|
|
mcpTransport: "unknown",
|
|
networkTransport: "unknown"
|
|
};
|
|
}
|