@mcpc-tech/core 0.2.7-beta.3 → 0.2.9
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/index.mjs
CHANGED
|
@@ -847,6 +847,7 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
|
847
847
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
848
848
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
849
849
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
850
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
850
851
|
|
|
851
852
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/registory.js
|
|
852
853
|
function connectToSmitheryServer(smitheryConfig) {
|
|
@@ -882,54 +883,75 @@ var mcpClientPool = /* @__PURE__ */ new Map();
|
|
|
882
883
|
var mcpClientConnecting = /* @__PURE__ */ new Map();
|
|
883
884
|
var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
|
|
884
885
|
function defSignature(def) {
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
pooled.refCount += 1;
|
|
891
|
-
return pooled.client;
|
|
886
|
+
const defCopy = {
|
|
887
|
+
...def
|
|
888
|
+
};
|
|
889
|
+
if (defCopy.transportType === "memory" || defCopy.transport) {
|
|
890
|
+
return `memory:${Date.now()}:${Math.random()}`;
|
|
892
891
|
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
892
|
+
return JSON.stringify(defCopy);
|
|
893
|
+
}
|
|
894
|
+
function createTransport(def) {
|
|
895
|
+
const defAny = def;
|
|
896
|
+
const explicitType = defAny.transportType || defAny.type;
|
|
897
|
+
if (explicitType === "memory") {
|
|
898
|
+
if (!defAny.server) {
|
|
899
|
+
throw new Error("In-memory transport requires a 'server' field with a Server instance");
|
|
900
|
+
}
|
|
901
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
902
|
+
defAny.server.connect(serverTransport).catch((err) => {
|
|
903
|
+
console.error("Error connecting in-memory server:", err);
|
|
904
|
+
});
|
|
905
|
+
return clientTransport;
|
|
899
906
|
}
|
|
900
|
-
|
|
901
|
-
if (typeof def.transportType === "string" && def.transportType === "sse") {
|
|
907
|
+
if (explicitType === "sse") {
|
|
902
908
|
const options = {};
|
|
903
|
-
if (
|
|
909
|
+
if (defAny.headers) {
|
|
904
910
|
options.requestInit = {
|
|
905
|
-
headers:
|
|
911
|
+
headers: defAny.headers
|
|
906
912
|
};
|
|
907
913
|
options.eventSourceInit = {
|
|
908
|
-
headers:
|
|
914
|
+
headers: defAny.headers
|
|
909
915
|
};
|
|
910
916
|
}
|
|
911
|
-
|
|
912
|
-
}
|
|
917
|
+
return new SSEClientTransport(new URL(defAny.url), options);
|
|
918
|
+
}
|
|
919
|
+
if (defAny.url && typeof defAny.url === "string") {
|
|
913
920
|
const options = {};
|
|
914
|
-
if (
|
|
921
|
+
if (defAny.headers) {
|
|
915
922
|
options.requestInit = {
|
|
916
|
-
headers:
|
|
923
|
+
headers: defAny.headers
|
|
917
924
|
};
|
|
918
925
|
}
|
|
919
|
-
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
926
|
+
return new StreamableHTTPClientTransport(new URL(defAny.url), options);
|
|
927
|
+
}
|
|
928
|
+
if (explicitType === "stdio" || defAny.command) {
|
|
929
|
+
return new StdioClientTransport({
|
|
930
|
+
command: defAny.command,
|
|
931
|
+
args: defAny.args,
|
|
924
932
|
env: {
|
|
925
933
|
...process3.env,
|
|
926
|
-
...
|
|
934
|
+
...defAny.env ?? {}
|
|
927
935
|
},
|
|
928
936
|
cwd: cwd()
|
|
929
937
|
});
|
|
930
|
-
} else {
|
|
931
|
-
throw new Error(`Unsupported transport type: ${JSON.stringify(def)}`);
|
|
932
938
|
}
|
|
939
|
+
throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
|
|
940
|
+
}
|
|
941
|
+
async function getOrCreateMcpClient(defKey, def) {
|
|
942
|
+
const pooled = mcpClientPool.get(defKey);
|
|
943
|
+
if (pooled) {
|
|
944
|
+
pooled.refCount += 1;
|
|
945
|
+
return pooled.client;
|
|
946
|
+
}
|
|
947
|
+
const existingConnecting = mcpClientConnecting.get(defKey);
|
|
948
|
+
if (existingConnecting) {
|
|
949
|
+
const client = await existingConnecting;
|
|
950
|
+
const entry = mcpClientPool.get(defKey);
|
|
951
|
+
if (entry) entry.refCount += 1;
|
|
952
|
+
return client;
|
|
953
|
+
}
|
|
954
|
+
const transport = createTransport(def);
|
|
933
955
|
const connecting = (async () => {
|
|
934
956
|
const client = new Client({
|
|
935
957
|
name: `mcp_${shortHash(defSignature(def))}`,
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sources":["../../../src/service/tools.ts"],"names":[],"mappings":"AAAA,SAAS,CAAC,cAA0B;
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sources":["../../../src/service/tools.ts"],"names":[],"mappings":"AAAA,SAAS,CAAC,cAA0B;AA+CpC,OAAO,cAAM,mBAAmB,EAAE,UAAU,OAAO,MAAM,EAAE,EAAE,aAGxD;AASL,YAAY,aACR,EAAE,aAAa,qBACf,EAAE,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sources":["../../../../src/utils/common/mcp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sources":["../../../../src/utils/common/mcp.ts"],"names":[],"mappings":"AAKA,cACE,iBAAiB,iCAEa;AAChC,YAAY,aAAyB;AA4LrC,OAAO,iBAAe,mBACpB,WACI,EAAE,aAAa,qBACf,EAAE,aAAa,kBAAkB,EACrC,YAAY;EACV,QAAQ,MAAM;EACd,MAAM,GAAG;EACT,SAAS,MAAM;EACf,mBAAmB,MAAM;EACzB,kBAAkB,MAAM;EACxB,QAAQ,MAAM;MACV,OAAO,GACZ,QAAQ,OAAO,MAAM,EAAE,GAAG"}
|