@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
package/dist/index.js
CHANGED
|
@@ -804,7 +804,9 @@ function buildMcpProviderData(servers) {
|
|
|
804
804
|
}
|
|
805
805
|
}
|
|
806
806
|
return {
|
|
807
|
-
values: { mcp: mcpData
|
|
807
|
+
values: { mcp: mcpData, mcpText: `# MCP Configuration
|
|
808
|
+
|
|
809
|
+
${textContent}` },
|
|
808
810
|
data: { mcp: mcpData },
|
|
809
811
|
text: `# MCP Configuration
|
|
810
812
|
|
|
@@ -927,6 +929,7 @@ async function handleToolResponse(runtime2, message, serverName, toolName, toolA
|
|
|
927
929
|
attachments: hasAttachments && attachments.length > 0 ? attachments : undefined
|
|
928
930
|
});
|
|
929
931
|
}
|
|
932
|
+
return replyMemory;
|
|
930
933
|
}
|
|
931
934
|
async function sendInitialResponse(callback) {
|
|
932
935
|
if (callback) {
|
|
@@ -1496,15 +1499,16 @@ var callToolAction = {
|
|
|
1496
1499
|
${JSON.stringify(toolSelectionArgument, null, 2)}`);
|
|
1497
1500
|
const result = await mcpService.callTool(serverName, toolName, toolSelectionArgument.toolArguments);
|
|
1498
1501
|
const { toolOutput, hasAttachments, attachments } = processToolResult(result, serverName, toolName, runtime2, message.entityId);
|
|
1499
|
-
await handleToolResponse(runtime2, message, serverName, toolName, toolSelectionArgument.toolArguments, toolOutput, hasAttachments, attachments, composedState, mcpProvider, callback);
|
|
1502
|
+
const replyMemory = await handleToolResponse(runtime2, message, serverName, toolName, toolSelectionArgument.toolArguments, toolOutput, hasAttachments, attachments, composedState, mcpProvider, callback);
|
|
1500
1503
|
return {
|
|
1501
|
-
text: `Successfully called tool: ${serverName}/${toolName}`,
|
|
1504
|
+
text: `Successfully called tool: ${serverName}/${toolName}. Reasoned response: ${replyMemory.content.text}`,
|
|
1502
1505
|
values: {
|
|
1503
1506
|
success: true,
|
|
1504
1507
|
toolExecuted: true,
|
|
1505
1508
|
serverName,
|
|
1506
1509
|
toolName,
|
|
1507
|
-
hasAttachments
|
|
1510
|
+
hasAttachments,
|
|
1511
|
+
output: toolOutput
|
|
1508
1512
|
},
|
|
1509
1513
|
data: {
|
|
1510
1514
|
actionName: "CALL_MCP_TOOL",
|
|
@@ -1785,7 +1789,7 @@ class McpService extends Service {
|
|
|
1785
1789
|
connections = new Map;
|
|
1786
1790
|
connectionStates = new Map;
|
|
1787
1791
|
mcpProvider = {
|
|
1788
|
-
values: { mcp: {} },
|
|
1792
|
+
values: { mcp: {}, mcpText: "" },
|
|
1789
1793
|
data: { mcp: {} },
|
|
1790
1794
|
text: ""
|
|
1791
1795
|
};
|
|
@@ -1832,18 +1836,38 @@ class McpService extends Service {
|
|
|
1832
1836
|
logger7.info(`[McpService] Getting MCP settings... hasSettings=${!!mcpSettings} hasServers=${!!mcpSettings?.servers} serverCount=${serverCount} servers=${JSON.stringify(serverNames)}`);
|
|
1833
1837
|
if (!mcpSettings || !mcpSettings.servers) {
|
|
1834
1838
|
logger7.info("[McpService] No MCP servers configured.");
|
|
1839
|
+
this.mcpProvider = buildMcpProviderData([]);
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1842
|
+
if (Object.keys(mcpSettings.servers).length === 0) {
|
|
1843
|
+
logger7.info("[McpService] MCP settings exist but no servers configured.");
|
|
1844
|
+
this.mcpProvider = buildMcpProviderData([]);
|
|
1835
1845
|
return;
|
|
1836
1846
|
}
|
|
1837
|
-
logger7.info(`[McpService] Connecting to MCP servers: ${JSON.stringify(Object.keys(mcpSettings.servers))}`);
|
|
1847
|
+
logger7.info(`[McpService] Connecting to ${Object.keys(mcpSettings.servers).length} MCP servers: ${JSON.stringify(Object.keys(mcpSettings.servers))}`);
|
|
1848
|
+
const connectionStartTime = Date.now();
|
|
1838
1849
|
await this.updateServerConnections(mcpSettings.servers);
|
|
1850
|
+
const connectionDuration = Date.now() - connectionStartTime;
|
|
1839
1851
|
const servers = this.getServers();
|
|
1840
|
-
const
|
|
1841
|
-
|
|
1852
|
+
const connectedServers = servers.filter((s) => s.status === "connected");
|
|
1853
|
+
const failedServers = servers.filter((s) => s.status !== "connected");
|
|
1854
|
+
if (connectedServers.length > 0) {
|
|
1855
|
+
const toolCounts = connectedServers.map((s) => `${s.name}:${s.tools?.length || 0}tools`).join(", ");
|
|
1856
|
+
logger7.info(`[McpService] ✓ Successfully connected ${connectedServers.length}/${servers.length} servers in ${connectionDuration}ms: ${toolCounts}`);
|
|
1857
|
+
}
|
|
1858
|
+
if (failedServers.length > 0) {
|
|
1859
|
+
const failedDetails = failedServers.map((s) => `${s.name}(${s.error || "unknown error"})`).join(", ");
|
|
1860
|
+
logger7.warn(`[McpService] ⚠️ Failed to connect to ${failedServers.length}/${servers.length} servers: ${failedDetails}`);
|
|
1861
|
+
}
|
|
1862
|
+
if (connectedServers.length === 0 && servers.length > 0) {
|
|
1863
|
+
logger7.error(`[McpService] ❌ ALL MCP servers failed to connect! MCP tools will NOT be available.`);
|
|
1864
|
+
}
|
|
1842
1865
|
this.mcpProvider = buildMcpProviderData(servers);
|
|
1843
1866
|
const mcpDataKeys = Object.keys(this.mcpProvider.data?.mcp || {});
|
|
1844
|
-
logger7.info(`[McpService] MCP provider data built:
|
|
1867
|
+
logger7.info(`[McpService] MCP provider data built: ${mcpDataKeys.length} server(s) available`);
|
|
1845
1868
|
} catch (error) {
|
|
1846
|
-
logger7.error({ error: error instanceof Error ? error.message : String(error) }, "Failed to initialize MCP servers");
|
|
1869
|
+
logger7.error({ error: error instanceof Error ? error.message : String(error) }, "❌ Failed to initialize MCP servers - MCP tools will NOT be available");
|
|
1870
|
+
this.mcpProvider = buildMcpProviderData([]);
|
|
1847
1871
|
}
|
|
1848
1872
|
}
|
|
1849
1873
|
getMcpSettings() {
|
|
@@ -1879,24 +1903,27 @@ class McpService extends Service {
|
|
|
1879
1903
|
logger7.info(`Deleted MCP server: ${name}`);
|
|
1880
1904
|
}
|
|
1881
1905
|
}
|
|
1882
|
-
|
|
1906
|
+
const connectionPromises = Object.entries(serverConfigs).map(async ([name, config]) => {
|
|
1883
1907
|
const currentConnection = this.connections.get(name);
|
|
1884
1908
|
if (!currentConnection) {
|
|
1885
1909
|
try {
|
|
1886
1910
|
await this.initializeConnection(name, config);
|
|
1911
|
+
logger7.info(`✓ Connected to MCP server: ${name}`);
|
|
1887
1912
|
} catch (error) {
|
|
1888
|
-
logger7.error({ error: error instanceof Error ? error.message : String(error), serverName: name },
|
|
1913
|
+
logger7.error({ error: error instanceof Error ? error.message : String(error), serverName: name }, `✗ Failed to connect to new MCP server ${name}`);
|
|
1889
1914
|
}
|
|
1890
1915
|
} else if (JSON.stringify(config) !== currentConnection.server.config) {
|
|
1891
1916
|
try {
|
|
1892
1917
|
await this.deleteConnection(name);
|
|
1893
1918
|
await this.initializeConnection(name, config);
|
|
1894
|
-
logger7.info(
|
|
1919
|
+
logger7.info(`✓ Reconnected MCP server with updated config: ${name}`);
|
|
1895
1920
|
} catch (error) {
|
|
1896
|
-
logger7.error({ error: error instanceof Error ? error.message : String(error), serverName: name },
|
|
1921
|
+
logger7.error({ error: error instanceof Error ? error.message : String(error), serverName: name }, `✗ Failed to reconnect MCP server ${name}`);
|
|
1897
1922
|
}
|
|
1898
1923
|
}
|
|
1899
|
-
}
|
|
1924
|
+
});
|
|
1925
|
+
await Promise.allSettled(connectionPromises);
|
|
1926
|
+
logger7.info(`[McpService] All server connection attempts completed`);
|
|
1900
1927
|
}
|
|
1901
1928
|
async initializeConnection(name, config) {
|
|
1902
1929
|
await this.deleteConnection(name);
|
|
@@ -1952,16 +1979,25 @@ class McpService extends Service {
|
|
|
1952
1979
|
const config = JSON.parse(connection.server.config);
|
|
1953
1980
|
const isHttpTransport = config.type !== "stdio";
|
|
1954
1981
|
connection.transport.onerror = async (error) => {
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1982
|
+
const errorMessage = error?.message || String(error);
|
|
1983
|
+
const isExpectedTimeout = isHttpTransport && (errorMessage === "undefined" || errorMessage === "" || errorMessage.includes("SSE error") || errorMessage.includes("timeout"));
|
|
1984
|
+
if (isExpectedTimeout) {
|
|
1985
|
+
logger7.debug({ serverName: name }, `SSE connection timeout for "${name}" (expected, will reconnect)`);
|
|
1986
|
+
} else {
|
|
1987
|
+
logger7.error({ error, serverName: name }, `Transport error for "${name}"`);
|
|
1988
|
+
connection.server.status = "disconnected";
|
|
1989
|
+
this.appendErrorMessage(connection, error.message);
|
|
1990
|
+
}
|
|
1958
1991
|
if (!isHttpTransport) {
|
|
1959
1992
|
this.handleDisconnection(name, error);
|
|
1960
1993
|
}
|
|
1961
1994
|
};
|
|
1962
1995
|
connection.transport.onclose = async () => {
|
|
1963
|
-
|
|
1964
|
-
|
|
1996
|
+
if (isHttpTransport) {
|
|
1997
|
+
logger7.debug({ serverName: name }, `SSE connection closed for "${name}" (stateless, will reconnect on demand)`);
|
|
1998
|
+
} else {
|
|
1999
|
+
logger7.warn({ serverName: name }, `Transport closed for "${name}"`);
|
|
2000
|
+
connection.server.status = "disconnected";
|
|
1965
2001
|
this.handleDisconnection(name, new Error("Transport closed"));
|
|
1966
2002
|
}
|
|
1967
2003
|
};
|
|
@@ -2261,4 +2297,4 @@ export {
|
|
|
2261
2297
|
BACKOFF_MULTIPLIER
|
|
2262
2298
|
};
|
|
2263
2299
|
|
|
2264
|
-
//# debugId=
|
|
2300
|
+
//# debugId=7FE3B98268562B6664756E2164756E21
|