@elizaos/plugin-mcp 1.3.3 → 1.3.5
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/actions/callToolAction.d.ts.map +1 -1
- package/dist/cjs/index.cjs +57 -21
- package/dist/cjs/index.js.map +7 -7
- package/dist/index.js +57 -21
- package/dist/index.js.map +7 -7
- package/dist/service.d.ts.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/processing.d.ts +1 -1
- package/dist/utils/processing.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callToolAction.d.ts","sourceRoot":"","sources":["../../src/actions/callToolAction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EAOZ,MAAM,eAAe,CAAC;AAQvB,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"callToolAction.d.ts","sourceRoot":"","sources":["../../src/actions/callToolAction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EAOZ,MAAM,eAAe,CAAC;AAQvB,eAAO,MAAM,cAAc,EAAE,MAsK5B,CAAC"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -843,7 +843,9 @@ function buildMcpProviderData(servers) {
|
|
|
843
843
|
}
|
|
844
844
|
}
|
|
845
845
|
return {
|
|
846
|
-
values: { mcp: mcpData
|
|
846
|
+
values: { mcp: mcpData, mcpText: `# MCP Configuration
|
|
847
|
+
|
|
848
|
+
${textContent}` },
|
|
847
849
|
data: { mcp: mcpData },
|
|
848
850
|
text: `# MCP Configuration
|
|
849
851
|
|
|
@@ -966,6 +968,7 @@ async function handleToolResponse(runtime2, message, serverName, toolName, toolA
|
|
|
966
968
|
attachments: hasAttachments && attachments.length > 0 ? attachments : undefined
|
|
967
969
|
});
|
|
968
970
|
}
|
|
971
|
+
return replyMemory;
|
|
969
972
|
}
|
|
970
973
|
async function sendInitialResponse(callback) {
|
|
971
974
|
if (callback) {
|
|
@@ -1528,15 +1531,16 @@ var callToolAction = {
|
|
|
1528
1531
|
${JSON.stringify(toolSelectionArgument, null, 2)}`);
|
|
1529
1532
|
const result = await mcpService.callTool(serverName, toolName, toolSelectionArgument.toolArguments);
|
|
1530
1533
|
const { toolOutput, hasAttachments, attachments } = processToolResult(result, serverName, toolName, runtime2, message.entityId);
|
|
1531
|
-
await handleToolResponse(runtime2, message, serverName, toolName, toolSelectionArgument.toolArguments, toolOutput, hasAttachments, attachments, composedState, mcpProvider, callback);
|
|
1534
|
+
const replyMemory = await handleToolResponse(runtime2, message, serverName, toolName, toolSelectionArgument.toolArguments, toolOutput, hasAttachments, attachments, composedState, mcpProvider, callback);
|
|
1532
1535
|
return {
|
|
1533
|
-
text: `Successfully called tool: ${serverName}/${toolName}`,
|
|
1536
|
+
text: `Successfully called tool: ${serverName}/${toolName}. Reasoned response: ${replyMemory.content.text}`,
|
|
1534
1537
|
values: {
|
|
1535
1538
|
success: true,
|
|
1536
1539
|
toolExecuted: true,
|
|
1537
1540
|
serverName,
|
|
1538
1541
|
toolName,
|
|
1539
|
-
hasAttachments
|
|
1542
|
+
hasAttachments,
|
|
1543
|
+
output: toolOutput
|
|
1540
1544
|
},
|
|
1541
1545
|
data: {
|
|
1542
1546
|
actionName: "CALL_MCP_TOOL",
|
|
@@ -1813,7 +1817,7 @@ class McpService extends import_core8.Service {
|
|
|
1813
1817
|
connections = new Map;
|
|
1814
1818
|
connectionStates = new Map;
|
|
1815
1819
|
mcpProvider = {
|
|
1816
|
-
values: { mcp: {} },
|
|
1820
|
+
values: { mcp: {}, mcpText: "" },
|
|
1817
1821
|
data: { mcp: {} },
|
|
1818
1822
|
text: ""
|
|
1819
1823
|
};
|
|
@@ -1860,18 +1864,38 @@ class McpService extends import_core8.Service {
|
|
|
1860
1864
|
import_core8.logger.info(`[McpService] Getting MCP settings... hasSettings=${!!mcpSettings} hasServers=${!!mcpSettings?.servers} serverCount=${serverCount} servers=${JSON.stringify(serverNames)}`);
|
|
1861
1865
|
if (!mcpSettings || !mcpSettings.servers) {
|
|
1862
1866
|
import_core8.logger.info("[McpService] No MCP servers configured.");
|
|
1867
|
+
this.mcpProvider = buildMcpProviderData([]);
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
if (Object.keys(mcpSettings.servers).length === 0) {
|
|
1871
|
+
import_core8.logger.info("[McpService] MCP settings exist but no servers configured.");
|
|
1872
|
+
this.mcpProvider = buildMcpProviderData([]);
|
|
1863
1873
|
return;
|
|
1864
1874
|
}
|
|
1865
|
-
import_core8.logger.info(`[McpService] Connecting to MCP servers: ${JSON.stringify(Object.keys(mcpSettings.servers))}`);
|
|
1875
|
+
import_core8.logger.info(`[McpService] Connecting to ${Object.keys(mcpSettings.servers).length} MCP servers: ${JSON.stringify(Object.keys(mcpSettings.servers))}`);
|
|
1876
|
+
const connectionStartTime = Date.now();
|
|
1866
1877
|
await this.updateServerConnections(mcpSettings.servers);
|
|
1878
|
+
const connectionDuration = Date.now() - connectionStartTime;
|
|
1867
1879
|
const servers = this.getServers();
|
|
1868
|
-
const
|
|
1869
|
-
|
|
1880
|
+
const connectedServers = servers.filter((s) => s.status === "connected");
|
|
1881
|
+
const failedServers = servers.filter((s) => s.status !== "connected");
|
|
1882
|
+
if (connectedServers.length > 0) {
|
|
1883
|
+
const toolCounts = connectedServers.map((s) => `${s.name}:${s.tools?.length || 0}tools`).join(", ");
|
|
1884
|
+
import_core8.logger.info(`[McpService] ✓ Successfully connected ${connectedServers.length}/${servers.length} servers in ${connectionDuration}ms: ${toolCounts}`);
|
|
1885
|
+
}
|
|
1886
|
+
if (failedServers.length > 0) {
|
|
1887
|
+
const failedDetails = failedServers.map((s) => `${s.name}(${s.error || "unknown error"})`).join(", ");
|
|
1888
|
+
import_core8.logger.warn(`[McpService] ⚠️ Failed to connect to ${failedServers.length}/${servers.length} servers: ${failedDetails}`);
|
|
1889
|
+
}
|
|
1890
|
+
if (connectedServers.length === 0 && servers.length > 0) {
|
|
1891
|
+
import_core8.logger.error(`[McpService] ❌ ALL MCP servers failed to connect! MCP tools will NOT be available.`);
|
|
1892
|
+
}
|
|
1870
1893
|
this.mcpProvider = buildMcpProviderData(servers);
|
|
1871
1894
|
const mcpDataKeys = Object.keys(this.mcpProvider.data?.mcp || {});
|
|
1872
|
-
import_core8.logger.info(`[McpService] MCP provider data built:
|
|
1895
|
+
import_core8.logger.info(`[McpService] MCP provider data built: ${mcpDataKeys.length} server(s) available`);
|
|
1873
1896
|
} catch (error) {
|
|
1874
|
-
import_core8.logger.error({ error: error instanceof Error ? error.message : String(error) }, "Failed to initialize MCP servers");
|
|
1897
|
+
import_core8.logger.error({ error: error instanceof Error ? error.message : String(error) }, "❌ Failed to initialize MCP servers - MCP tools will NOT be available");
|
|
1898
|
+
this.mcpProvider = buildMcpProviderData([]);
|
|
1875
1899
|
}
|
|
1876
1900
|
}
|
|
1877
1901
|
getMcpSettings() {
|
|
@@ -1907,24 +1931,27 @@ class McpService extends import_core8.Service {
|
|
|
1907
1931
|
import_core8.logger.info(`Deleted MCP server: ${name}`);
|
|
1908
1932
|
}
|
|
1909
1933
|
}
|
|
1910
|
-
|
|
1934
|
+
const connectionPromises = Object.entries(serverConfigs).map(async ([name, config]) => {
|
|
1911
1935
|
const currentConnection = this.connections.get(name);
|
|
1912
1936
|
if (!currentConnection) {
|
|
1913
1937
|
try {
|
|
1914
1938
|
await this.initializeConnection(name, config);
|
|
1939
|
+
import_core8.logger.info(`✓ Connected to MCP server: ${name}`);
|
|
1915
1940
|
} catch (error) {
|
|
1916
|
-
import_core8.logger.error({ error: error instanceof Error ? error.message : String(error), serverName: name },
|
|
1941
|
+
import_core8.logger.error({ error: error instanceof Error ? error.message : String(error), serverName: name }, `✗ Failed to connect to new MCP server ${name}`);
|
|
1917
1942
|
}
|
|
1918
1943
|
} else if (JSON.stringify(config) !== currentConnection.server.config) {
|
|
1919
1944
|
try {
|
|
1920
1945
|
await this.deleteConnection(name);
|
|
1921
1946
|
await this.initializeConnection(name, config);
|
|
1922
|
-
import_core8.logger.info(
|
|
1947
|
+
import_core8.logger.info(`✓ Reconnected MCP server with updated config: ${name}`);
|
|
1923
1948
|
} catch (error) {
|
|
1924
|
-
import_core8.logger.error({ error: error instanceof Error ? error.message : String(error), serverName: name },
|
|
1949
|
+
import_core8.logger.error({ error: error instanceof Error ? error.message : String(error), serverName: name }, `✗ Failed to reconnect MCP server ${name}`);
|
|
1925
1950
|
}
|
|
1926
1951
|
}
|
|
1927
|
-
}
|
|
1952
|
+
});
|
|
1953
|
+
await Promise.allSettled(connectionPromises);
|
|
1954
|
+
import_core8.logger.info(`[McpService] All server connection attempts completed`);
|
|
1928
1955
|
}
|
|
1929
1956
|
async initializeConnection(name, config) {
|
|
1930
1957
|
await this.deleteConnection(name);
|
|
@@ -1980,16 +2007,25 @@ class McpService extends import_core8.Service {
|
|
|
1980
2007
|
const config = JSON.parse(connection.server.config);
|
|
1981
2008
|
const isHttpTransport = config.type !== "stdio";
|
|
1982
2009
|
connection.transport.onerror = async (error) => {
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
2010
|
+
const errorMessage = error?.message || String(error);
|
|
2011
|
+
const isExpectedTimeout = isHttpTransport && (errorMessage === "undefined" || errorMessage === "" || errorMessage.includes("SSE error") || errorMessage.includes("timeout"));
|
|
2012
|
+
if (isExpectedTimeout) {
|
|
2013
|
+
import_core8.logger.debug({ serverName: name }, `SSE connection timeout for "${name}" (expected, will reconnect)`);
|
|
2014
|
+
} else {
|
|
2015
|
+
import_core8.logger.error({ error, serverName: name }, `Transport error for "${name}"`);
|
|
2016
|
+
connection.server.status = "disconnected";
|
|
2017
|
+
this.appendErrorMessage(connection, error.message);
|
|
2018
|
+
}
|
|
1986
2019
|
if (!isHttpTransport) {
|
|
1987
2020
|
this.handleDisconnection(name, error);
|
|
1988
2021
|
}
|
|
1989
2022
|
};
|
|
1990
2023
|
connection.transport.onclose = async () => {
|
|
1991
|
-
|
|
1992
|
-
|
|
2024
|
+
if (isHttpTransport) {
|
|
2025
|
+
import_core8.logger.debug({ serverName: name }, `SSE connection closed for "${name}" (stateless, will reconnect on demand)`);
|
|
2026
|
+
} else {
|
|
2027
|
+
import_core8.logger.warn({ serverName: name }, `Transport closed for "${name}"`);
|
|
2028
|
+
connection.server.status = "disconnected";
|
|
1993
2029
|
this.handleDisconnection(name, new Error("Transport closed"));
|
|
1994
2030
|
}
|
|
1995
2031
|
};
|
|
@@ -2271,4 +2307,4 @@ var mcpPlugin = {
|
|
|
2271
2307
|
};
|
|
2272
2308
|
var src_default = mcpPlugin;
|
|
2273
2309
|
|
|
2274
|
-
//# debugId=
|
|
2310
|
+
//# debugId=06B19883B039D4B264756E2164756E21
|