@elizaos/plugin-mcp 1.8.1 → 1.8.2
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/dist/cjs/index.cjs +36 -13
- package/dist/cjs/index.js.map +3 -3
- package/dist/index.js +37 -14
- package/dist/index.js.map +3 -3
- package/dist/service.d.ts +9 -0
- package/dist/service.d.ts.map +1 -1
- package/package.json +5 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -8778,7 +8778,17 @@ class McpService extends import_core8.Service {
|
|
|
8778
8778
|
if (!config.url)
|
|
8779
8779
|
throw new Error(`Missing URL for server ${name}`);
|
|
8780
8780
|
const url = new URL(config.url);
|
|
8781
|
-
const
|
|
8781
|
+
const headers = { ...config.headers };
|
|
8782
|
+
const apiKey = this.runtime.getSetting("ELIZAOS_API_KEY");
|
|
8783
|
+
if (apiKey && typeof apiKey === "string" && !headers["X-API-Key"]) {
|
|
8784
|
+
const baseUrl = process.env.NEXT_PUBLIC_APP_URL || process.env.APP_URL || "http://localhost:3000";
|
|
8785
|
+
try {
|
|
8786
|
+
if (url.origin === new URL(baseUrl).origin) {
|
|
8787
|
+
headers["X-API-Key"] = apiKey;
|
|
8788
|
+
}
|
|
8789
|
+
} catch {}
|
|
8790
|
+
}
|
|
8791
|
+
const opts = Object.keys(headers).length > 0 ? { requestInit: { headers } } : undefined;
|
|
8782
8792
|
return config.type === "sse" ? new import_sse.SSEClientTransport(url, opts) : new import_streamableHttp.StreamableHTTPClientTransport(url, opts);
|
|
8783
8793
|
}
|
|
8784
8794
|
setupTransportHandlers(name, conn, state, isStdio) {
|
|
@@ -8928,25 +8938,38 @@ class McpService extends import_core8.Service {
|
|
|
8928
8938
|
isLazyConnection(serverName) {
|
|
8929
8939
|
return this.lazyConnections.has(serverName);
|
|
8930
8940
|
}
|
|
8941
|
+
getConnectionKey(serverName) {
|
|
8942
|
+
const config = this.lazyConnections.get(serverName);
|
|
8943
|
+
if (config && config.type !== "stdio") {
|
|
8944
|
+
const ctx = import_core8.getRequestContext();
|
|
8945
|
+
if (ctx?.entityId)
|
|
8946
|
+
return `${serverName}:${ctx.entityId}`;
|
|
8947
|
+
}
|
|
8948
|
+
return serverName;
|
|
8949
|
+
}
|
|
8950
|
+
getConnection(serverName) {
|
|
8951
|
+
const key = this.getConnectionKey(serverName);
|
|
8952
|
+
return this.connections.get(key) || this.connections.get(serverName);
|
|
8953
|
+
}
|
|
8931
8954
|
async ensureConnected(serverName) {
|
|
8932
|
-
|
|
8955
|
+
const connectionKey = this.getConnectionKey(serverName);
|
|
8956
|
+
if (this.connections.has(connectionKey) || this.connections.has(serverName))
|
|
8933
8957
|
return;
|
|
8934
8958
|
const config = this.lazyConnections.get(serverName);
|
|
8935
8959
|
if (!config)
|
|
8936
8960
|
throw new Error(`Unknown server: ${serverName}`);
|
|
8937
8961
|
const start = Date.now();
|
|
8938
|
-
await this.connect(
|
|
8939
|
-
this.
|
|
8940
|
-
const server = this.connections.get(serverName)?.server;
|
|
8962
|
+
await this.connect(connectionKey, config);
|
|
8963
|
+
const server = this.connections.get(connectionKey)?.server;
|
|
8941
8964
|
if (this.schemaCache.isEnabled && server?.tools?.length) {
|
|
8942
8965
|
await this.schemaCache.setSchemas(this.runtime.agentId, serverName, this.schemaCache.hashConfig(config), server.tools);
|
|
8943
8966
|
}
|
|
8944
|
-
import_core8.logger.info(`[MCP]
|
|
8967
|
+
import_core8.logger.info(`[MCP] Connected: ${connectionKey} in ${Date.now() - start}ms`);
|
|
8945
8968
|
this.mcpProvider = buildMcpProviderData(this.getServers());
|
|
8946
8969
|
}
|
|
8947
8970
|
async callTool(serverName, toolName, args) {
|
|
8948
8971
|
await this.ensureConnected(serverName);
|
|
8949
|
-
const conn = this.
|
|
8972
|
+
const conn = this.getConnection(serverName);
|
|
8950
8973
|
if (!conn)
|
|
8951
8974
|
throw new Error(`No connection: ${serverName}`);
|
|
8952
8975
|
if (conn.server.disabled)
|
|
@@ -8960,7 +8983,7 @@ class McpService extends import_core8.Service {
|
|
|
8960
8983
|
}
|
|
8961
8984
|
async readResource(serverName, uri) {
|
|
8962
8985
|
await this.ensureConnected(serverName);
|
|
8963
|
-
const conn = this.
|
|
8986
|
+
const conn = this.getConnection(serverName);
|
|
8964
8987
|
if (!conn)
|
|
8965
8988
|
throw new Error(`No connection: ${serverName}`);
|
|
8966
8989
|
if (conn.server.disabled)
|
|
@@ -8968,12 +8991,12 @@ class McpService extends import_core8.Service {
|
|
|
8968
8991
|
return conn.client.readResource({ uri });
|
|
8969
8992
|
}
|
|
8970
8993
|
async restartConnection(serverName) {
|
|
8971
|
-
const
|
|
8994
|
+
const connectionKey = this.getConnectionKey(serverName);
|
|
8995
|
+
const conn = this.getConnection(serverName);
|
|
8972
8996
|
if (!conn)
|
|
8973
8997
|
throw new Error(`No connection: ${serverName}`);
|
|
8974
|
-
|
|
8975
|
-
await this.
|
|
8976
|
-
await this.connect(serverName, JSON.parse(config));
|
|
8998
|
+
await this.disconnect(connectionKey);
|
|
8999
|
+
await this.connect(connectionKey, JSON.parse(conn.server.config));
|
|
8977
9000
|
}
|
|
8978
9001
|
}
|
|
8979
9002
|
|
|
@@ -8990,4 +9013,4 @@ var mcpPlugin = {
|
|
|
8990
9013
|
};
|
|
8991
9014
|
var src_default = mcpPlugin;
|
|
8992
9015
|
|
|
8993
|
-
//# debugId=
|
|
9016
|
+
//# debugId=F7ADF8219C68A3DA64756E2164756E21
|