@hashgraphonline/conversational-agent 0.1.206 → 0.1.208

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.
@@ -0,0 +1,14 @@
1
+ import { AgentExecutor } from 'langchain/agents';
2
+
3
+ /**
4
+ * Custom AgentExecutor that intercepts large tool outputs and converts them to content references
5
+ * before they are sent to the LLM to avoid token limit issues.
6
+ *
7
+ * Note: The content reference conversion is already handled in the MCP adapter,
8
+ * so this class currently just extends AgentExecutor without modifications.
9
+ * We keep it as a placeholder for future enhancements.
10
+ */
11
+ export declare class ContentAwareAgentExecutor extends AgentExecutor {
12
+ private logger;
13
+ constructor(config: any);
14
+ }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { AccountBuilder } from "./index18.js";
2
+ import { AccountBuilder } from "./index23.js";
3
3
  import { BaseHederaTransactionTool } from "hedera-agent-kit";
4
4
  const HbarTransferInputSchema = z.object({
5
5
  accountId: z.string().describe('Account ID for the transfer (e.g., "0.0.xxxx").'),
@@ -1,177 +1,12 @@
1
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
- import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
3
- import { MCPContentProcessor } from "./index20.js";
4
- class MCPClientManager {
5
- constructor(logger, contentStorage) {
6
- this.clients = /* @__PURE__ */ new Map();
7
- this.tools = /* @__PURE__ */ new Map();
8
- this.logger = logger;
9
- if (contentStorage) {
10
- this.contentProcessor = new MCPContentProcessor(contentStorage, logger);
11
- }
12
- }
13
- /**
14
- * Connect to an MCP server and discover its tools
15
- */
16
- async connectServer(config) {
17
- try {
18
- if (this.isServerConnected(config.name)) {
19
- return {
20
- serverName: config.name,
21
- connected: false,
22
- error: `Server ${config.name} is already connected`,
23
- tools: []
24
- };
25
- }
26
- if (config.transport && config.transport !== "stdio") {
27
- throw new Error(`Transport ${config.transport} not yet supported`);
28
- }
29
- const transport = new StdioClientTransport({
30
- command: config.command,
31
- args: config.args,
32
- ...config.env && { env: config.env }
33
- });
34
- const client = new Client({
35
- name: `conversational-agent-${config.name}`,
36
- version: "1.0.0"
37
- }, {
38
- capabilities: {}
39
- });
40
- await client.connect(transport);
41
- this.clients.set(config.name, client);
42
- const toolsResponse = await client.listTools();
43
- const toolsWithServer = toolsResponse.tools.map((tool) => ({
44
- ...tool,
45
- serverName: config.name
46
- }));
47
- this.tools.set(config.name, toolsWithServer);
48
- this.logger.info(`Connected to MCP server ${config.name} with ${toolsWithServer.length} tools`);
49
- return {
50
- serverName: config.name,
51
- connected: true,
52
- tools: toolsWithServer
53
- };
54
- } catch (error) {
55
- this.logger.error(`Failed to connect to MCP server ${config.name}:`, error);
56
- return {
57
- serverName: config.name,
58
- connected: false,
59
- error: error instanceof Error ? error.message : "Unknown error",
60
- tools: []
61
- };
62
- }
63
- }
64
- /**
65
- * Execute a tool on a specific MCP server
66
- */
67
- async executeTool(serverName, toolName, args) {
68
- const client = this.clients.get(serverName);
69
- if (!client) {
70
- throw new Error(`MCP server ${serverName} not connected`);
71
- }
72
- this.logger.debug(`Executing MCP tool ${toolName} on server ${serverName}`, args);
73
- try {
74
- const result = await client.callTool({
75
- name: toolName,
76
- arguments: args
77
- });
78
- if (this.contentProcessor) {
79
- const processed = await this.contentProcessor.processResponse(result, serverName, toolName);
80
- if (processed.wasProcessed) {
81
- this.logger.debug(
82
- `Processed MCP response from ${serverName}::${toolName}`,
83
- {
84
- referenceCreated: processed.referenceCreated,
85
- originalSize: processed.originalSize,
86
- errors: processed.errors
87
- }
88
- );
89
- if (processed.errors && processed.errors.length > 0) {
90
- this.logger.warn(`Content processing warnings for ${serverName}::${toolName}:`, processed.errors);
91
- }
92
- }
93
- return processed.content;
94
- }
95
- return result;
96
- } catch (error) {
97
- this.logger.error(`Error executing MCP tool ${toolName}:`, error);
98
- throw error;
99
- }
100
- }
101
- /**
102
- * Disconnect all MCP servers
103
- */
104
- async disconnectAll() {
105
- for (const [name, client] of this.clients) {
106
- try {
107
- await client.close();
108
- this.logger.info(`Disconnected from MCP server ${name}`);
109
- } catch (error) {
110
- this.logger.error(`Error disconnecting MCP server ${name}:`, error);
111
- }
112
- }
113
- this.clients.clear();
114
- this.tools.clear();
115
- }
116
- /**
117
- * Get all discovered tools from all connected servers
118
- */
119
- getAllTools() {
120
- const allTools = [];
121
- for (const tools of this.tools.values()) {
122
- allTools.push(...tools);
123
- }
124
- return allTools;
125
- }
126
- /**
127
- * Get tools from a specific server
128
- */
129
- getServerTools(serverName) {
130
- return this.tools.get(serverName) || [];
131
- }
132
- /**
133
- * Check if a server is connected
134
- */
135
- isServerConnected(serverName) {
136
- return this.clients.has(serverName);
137
- }
138
- /**
139
- * Get list of connected server names
140
- */
141
- getConnectedServers() {
142
- return Array.from(this.clients.keys());
143
- }
144
- /**
145
- * Enable content processing with content storage
146
- */
147
- enableContentProcessing(contentStorage) {
148
- this.contentProcessor = new MCPContentProcessor(contentStorage, this.logger);
149
- this.logger.info("Content processing enabled for MCP responses");
150
- }
151
- /**
152
- * Disable content processing
153
- */
154
- disableContentProcessing() {
155
- delete this.contentProcessor;
156
- this.logger.info("Content processing disabled for MCP responses");
157
- }
158
- /**
159
- * Check if content processing is enabled
160
- */
161
- isContentProcessingEnabled() {
162
- return this.contentProcessor !== void 0;
163
- }
164
- /**
165
- * Analyze a response without processing it (for testing/debugging)
166
- */
167
- analyzeResponseContent(response) {
168
- if (!this.contentProcessor) {
169
- throw new Error("Content processing is not enabled");
170
- }
171
- return this.contentProcessor.analyzeResponse(response);
1
+ import { AgentExecutor } from "langchain/agents";
2
+ import { Logger } from "@hashgraphonline/standards-sdk";
3
+ class ContentAwareAgentExecutor extends AgentExecutor {
4
+ constructor(config) {
5
+ super(config);
6
+ this.logger = new Logger({ module: "ContentAwareAgentExecutor" });
172
7
  }
173
8
  }
174
9
  export {
175
- MCPClientManager
10
+ ContentAwareAgentExecutor
176
11
  };
177
12
  //# sourceMappingURL=index15.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index15.js","sources":["../../src/mcp/MCPClientManager.ts"],"sourcesContent":["import { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';\nimport type { MCPServerConfig, MCPToolInfo, MCPConnectionStatus } from './types';\nimport { Logger } from '@hashgraphonline/standards-sdk';\nimport type { ContentStorage } from '../memory/ContentStorage';\nimport { MCPContentProcessor, ProcessedResponse } from './ContentProcessor';\n\n/**\n * Manages connections to MCP servers and tool discovery\n */\nexport class MCPClientManager {\n private clients: Map<string, Client> = new Map();\n private tools: Map<string, MCPToolInfo[]> = new Map();\n private logger: Logger;\n private contentProcessor?: MCPContentProcessor;\n\n constructor(logger: Logger, contentStorage?: ContentStorage) {\n this.logger = logger;\n if (contentStorage) {\n this.contentProcessor = new MCPContentProcessor(contentStorage, logger);\n }\n }\n\n /**\n * Connect to an MCP server and discover its tools\n */\n async connectServer(config: MCPServerConfig): Promise<MCPConnectionStatus> {\n try {\n if (this.isServerConnected(config.name)) {\n return {\n serverName: config.name,\n connected: false,\n error: `Server ${config.name} is already connected`,\n tools: [],\n };\n }\n\n if (config.transport && config.transport !== 'stdio') {\n throw new Error(`Transport ${config.transport} not yet supported`);\n }\n\n const transport = new StdioClientTransport({\n command: config.command,\n args: config.args,\n ...(config.env && { env: config.env }),\n });\n\n const client = new Client({\n name: `conversational-agent-${config.name}`,\n version: '1.0.0',\n }, {\n capabilities: {},\n });\n\n await client.connect(transport);\n this.clients.set(config.name, client);\n\n const toolsResponse = await client.listTools();\n const toolsWithServer: MCPToolInfo[] = toolsResponse.tools.map(tool => ({\n ...tool,\n serverName: config.name,\n }));\n\n this.tools.set(config.name, toolsWithServer);\n this.logger.info(`Connected to MCP server ${config.name} with ${toolsWithServer.length} tools`);\n\n return {\n serverName: config.name,\n connected: true,\n tools: toolsWithServer,\n };\n } catch (error) {\n this.logger.error(`Failed to connect to MCP server ${config.name}:`, error);\n return {\n serverName: config.name,\n connected: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n tools: [],\n };\n }\n }\n\n /**\n * Execute a tool on a specific MCP server\n */\n async executeTool(serverName: string, toolName: string, args: Record<string, unknown>): Promise<unknown> {\n const client = this.clients.get(serverName);\n if (!client) {\n throw new Error(`MCP server ${serverName} not connected`);\n }\n\n this.logger.debug(`Executing MCP tool ${toolName} on server ${serverName}`, args);\n\n try {\n const result = await client.callTool({\n name: toolName,\n arguments: args,\n });\n\n if (this.contentProcessor) {\n const processed = await this.contentProcessor.processResponse(result, serverName, toolName);\n \n if (processed.wasProcessed) {\n this.logger.debug(\n `Processed MCP response from ${serverName}::${toolName}`,\n {\n referenceCreated: processed.referenceCreated,\n originalSize: processed.originalSize,\n errors: processed.errors\n }\n );\n\n if (processed.errors && processed.errors.length > 0) {\n this.logger.warn(`Content processing warnings for ${serverName}::${toolName}:`, processed.errors);\n }\n }\n\n return processed.content;\n }\n\n return result;\n } catch (error) {\n this.logger.error(`Error executing MCP tool ${toolName}:`, error);\n throw error;\n }\n }\n\n /**\n * Disconnect all MCP servers\n */\n async disconnectAll(): Promise<void> {\n for (const [name, client] of this.clients) {\n try {\n await client.close();\n this.logger.info(`Disconnected from MCP server ${name}`);\n } catch (error) {\n this.logger.error(`Error disconnecting MCP server ${name}:`, error);\n }\n }\n this.clients.clear();\n this.tools.clear();\n }\n\n /**\n * Get all discovered tools from all connected servers\n */\n getAllTools(): MCPToolInfo[] {\n const allTools: MCPToolInfo[] = [];\n for (const tools of this.tools.values()) {\n allTools.push(...tools);\n }\n return allTools;\n }\n\n /**\n * Get tools from a specific server\n */\n getServerTools(serverName: string): MCPToolInfo[] {\n return this.tools.get(serverName) || [];\n }\n\n /**\n * Check if a server is connected\n */\n isServerConnected(serverName: string): boolean {\n return this.clients.has(serverName);\n }\n\n /**\n * Get list of connected server names\n */\n getConnectedServers(): string[] {\n return Array.from(this.clients.keys());\n }\n\n /**\n * Enable content processing with content storage\n */\n enableContentProcessing(contentStorage: ContentStorage): void {\n this.contentProcessor = new MCPContentProcessor(contentStorage, this.logger);\n this.logger.info('Content processing enabled for MCP responses');\n }\n\n /**\n * Disable content processing\n */\n disableContentProcessing(): void {\n delete this.contentProcessor;\n this.logger.info('Content processing disabled for MCP responses');\n }\n\n /**\n * Check if content processing is enabled\n */\n isContentProcessingEnabled(): boolean {\n return this.contentProcessor !== undefined;\n }\n\n /**\n * Analyze a response without processing it (for testing/debugging)\n */\n analyzeResponseContent(response: unknown): unknown {\n if (!this.contentProcessor) {\n throw new Error('Content processing is not enabled');\n }\n return this.contentProcessor.analyzeResponse(response);\n }\n}"],"names":[],"mappings":";;;AAUO,MAAM,iBAAiB;AAAA,EAM5B,YAAY,QAAgB,gBAAiC;AAL7D,SAAQ,8BAAmC,IAAA;AAC3C,SAAQ,4BAAwC,IAAA;AAK9C,SAAK,SAAS;AACd,QAAI,gBAAgB;AAClB,WAAK,mBAAmB,IAAI,oBAAoB,gBAAgB,MAAM;AAAA,IACxE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,QAAuD;AACzE,QAAI;AACF,UAAI,KAAK,kBAAkB,OAAO,IAAI,GAAG;AACvC,eAAO;AAAA,UACL,YAAY,OAAO;AAAA,UACnB,WAAW;AAAA,UACX,OAAO,UAAU,OAAO,IAAI;AAAA,UAC5B,OAAO,CAAA;AAAA,QAAC;AAAA,MAEZ;AAEA,UAAI,OAAO,aAAa,OAAO,cAAc,SAAS;AACpD,cAAM,IAAI,MAAM,aAAa,OAAO,SAAS,oBAAoB;AAAA,MACnE;AAEA,YAAM,YAAY,IAAI,qBAAqB;AAAA,QACzC,SAAS,OAAO;AAAA,QAChB,MAAM,OAAO;AAAA,QACb,GAAI,OAAO,OAAO,EAAE,KAAK,OAAO,IAAA;AAAA,MAAI,CACrC;AAED,YAAM,SAAS,IAAI,OAAO;AAAA,QACxB,MAAM,wBAAwB,OAAO,IAAI;AAAA,QACzC,SAAS;AAAA,MAAA,GACR;AAAA,QACD,cAAc,CAAA;AAAA,MAAC,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oBAAoB,gBAAgB,KAAK,MAAM;AAC3E,SAAK,OAAO,KAAK,8CAA8C;AAAA,EACjE;AAAA;AAAA;AAAA;AAAA,EAKA,2BAAiC;AAC/B,WAAO,KAAK;AACZ,SAAK,OAAO,KAAK,+CAA+C;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA,EAKA,6BAAsC;AACpC,WAAO,KAAK,qBAAqB;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,uBAAuB,UAA4B;AACjD,QAAI,CAAC,KAAK,kBAAkB;AAC1B,YAAM,IAAI,MAAM,mCAAmC;AAAA,IACrD;AACA,WAAO,KAAK,iBAAiB,gBAAgB,QAAQ;AAAA,EACvD;AACF;"}
1
+ {"version":3,"file":"index15.js","sources":["../../src/langchain/ContentAwareAgentExecutor.ts"],"sourcesContent":["import { AgentExecutor } from 'langchain/agents';\nimport type { ChainValues } from '@langchain/core/utils/types';\nimport { Logger } from '@hashgraphonline/standards-sdk';\n\n/**\n * Custom AgentExecutor that intercepts large tool outputs and converts them to content references\n * before they are sent to the LLM to avoid token limit issues.\n * \n * Note: The content reference conversion is already handled in the MCP adapter,\n * so this class currently just extends AgentExecutor without modifications.\n * We keep it as a placeholder for future enhancements.\n */\nexport class ContentAwareAgentExecutor extends AgentExecutor {\n private logger: Logger;\n\n constructor(config: any) {\n super(config);\n this.logger = new Logger({ module: 'ContentAwareAgentExecutor' });\n }\n}"],"names":[],"mappings":";;AAYO,MAAM,kCAAkC,cAAc;AAAA,EAG3D,YAAY,QAAa;AACvB,UAAM,MAAM;AACZ,SAAK,SAAS,IAAI,OAAO,EAAE,QAAQ,6BAA6B;AAAA,EAClE;AACF;"}
@@ -1,136 +1,177 @@
1
- import { DynamicStructuredTool } from "@langchain/core/tools";
2
- import { z } from "zod";
3
- function convertMCPToolToLangChain(tool, mcpManager, serverConfig) {
4
- const zodSchema = jsonSchemaToZod(tool.inputSchema);
5
- const sanitizedName = `${tool.serverName}_${tool.name}`.replace(
6
- /[^a-zA-Z0-9_]/g,
7
- "_"
8
- );
9
- let description = tool.description || `MCP tool ${tool.name} from ${tool.serverName}`;
10
- if (serverConfig?.toolDescriptions?.[tool.name]) {
11
- description = `${description}
12
-
13
- ${serverConfig.toolDescriptions[tool.name]}`;
1
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
3
+ import { MCPContentProcessor } from "./index20.js";
4
+ class MCPClientManager {
5
+ constructor(logger, contentStorage) {
6
+ this.clients = /* @__PURE__ */ new Map();
7
+ this.tools = /* @__PURE__ */ new Map();
8
+ this.logger = logger;
9
+ if (contentStorage) {
10
+ this.contentProcessor = new MCPContentProcessor(contentStorage, logger);
11
+ }
14
12
  }
15
- if (serverConfig?.additionalContext) {
16
- description = `${description}
17
-
18
- Context: ${serverConfig.additionalContext}`;
13
+ /**
14
+ * Connect to an MCP server and discover its tools
15
+ */
16
+ async connectServer(config) {
17
+ try {
18
+ if (this.isServerConnected(config.name)) {
19
+ return {
20
+ serverName: config.name,
21
+ connected: false,
22
+ error: `Server ${config.name} is already connected`,
23
+ tools: []
24
+ };
25
+ }
26
+ if (config.transport && config.transport !== "stdio") {
27
+ throw new Error(`Transport ${config.transport} not yet supported`);
28
+ }
29
+ const transport = new StdioClientTransport({
30
+ command: config.command,
31
+ args: config.args,
32
+ ...config.env && { env: config.env }
33
+ });
34
+ const client = new Client({
35
+ name: `conversational-agent-${config.name}`,
36
+ version: "1.0.0"
37
+ }, {
38
+ capabilities: {}
39
+ });
40
+ await client.connect(transport);
41
+ this.clients.set(config.name, client);
42
+ const toolsResponse = await client.listTools();
43
+ const toolsWithServer = toolsResponse.tools.map((tool) => ({
44
+ ...tool,
45
+ serverName: config.name
46
+ }));
47
+ this.tools.set(config.name, toolsWithServer);
48
+ this.logger.info(`Connected to MCP server ${config.name} with ${toolsWithServer.length} tools`);
49
+ return {
50
+ serverName: config.name,
51
+ connected: true,
52
+ tools: toolsWithServer
53
+ };
54
+ } catch (error) {
55
+ this.logger.error(`Failed to connect to MCP server ${config.name}:`, error);
56
+ return {
57
+ serverName: config.name,
58
+ connected: false,
59
+ error: error instanceof Error ? error.message : "Unknown error",
60
+ tools: []
61
+ };
62
+ }
19
63
  }
20
- return new DynamicStructuredTool({
21
- name: sanitizedName,
22
- description,
23
- schema: zodSchema,
24
- func: async (input) => {
25
- try {
26
- const result = await mcpManager.executeTool(
27
- tool.serverName,
28
- tool.name,
29
- input
30
- );
31
- let responseText = "";
32
- if (typeof result === "string") {
33
- responseText = result;
34
- } else if (result && typeof result === "object" && "content" in result) {
35
- const content = result.content;
36
- if (Array.isArray(content)) {
37
- const textParts = content.filter(
38
- (item) => typeof item === "object" && item !== null && "type" in item && item.type === "text" && "text" in item
39
- ).map((item) => item.text);
40
- responseText = textParts.join("\n");
41
- } else {
42
- responseText = JSON.stringify(content);
64
+ /**
65
+ * Execute a tool on a specific MCP server
66
+ */
67
+ async executeTool(serverName, toolName, args) {
68
+ const client = this.clients.get(serverName);
69
+ if (!client) {
70
+ throw new Error(`MCP server ${serverName} not connected`);
71
+ }
72
+ this.logger.debug(`Executing MCP tool ${toolName} on server ${serverName}`, args);
73
+ try {
74
+ const result = await client.callTool({
75
+ name: toolName,
76
+ arguments: args
77
+ });
78
+ if (this.contentProcessor) {
79
+ const processed = await this.contentProcessor.processResponse(result, serverName, toolName);
80
+ if (processed.wasProcessed) {
81
+ this.logger.debug(
82
+ `Processed MCP response from ${serverName}::${toolName}`,
83
+ {
84
+ referenceCreated: processed.referenceCreated,
85
+ originalSize: processed.originalSize,
86
+ errors: processed.errors
87
+ }
88
+ );
89
+ if (processed.errors && processed.errors.length > 0) {
90
+ this.logger.warn(`Content processing warnings for ${serverName}::${toolName}:`, processed.errors);
43
91
  }
44
- } else {
45
- responseText = JSON.stringify(result);
46
92
  }
47
- return responseText;
93
+ return processed.content;
94
+ }
95
+ return result;
96
+ } catch (error) {
97
+ this.logger.error(`Error executing MCP tool ${toolName}:`, error);
98
+ throw error;
99
+ }
100
+ }
101
+ /**
102
+ * Disconnect all MCP servers
103
+ */
104
+ async disconnectAll() {
105
+ for (const [name, client] of this.clients) {
106
+ try {
107
+ await client.close();
108
+ this.logger.info(`Disconnected from MCP server ${name}`);
48
109
  } catch (error) {
49
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
50
- return `Error executing MCP tool ${tool.name}: ${errorMessage}`;
110
+ this.logger.error(`Error disconnecting MCP server ${name}:`, error);
51
111
  }
52
112
  }
53
- });
54
- }
55
- function jsonSchemaToZod(schema) {
56
- if (!schema || typeof schema !== "object") {
57
- return z.object({});
113
+ this.clients.clear();
114
+ this.tools.clear();
115
+ }
116
+ /**
117
+ * Get all discovered tools from all connected servers
118
+ */
119
+ getAllTools() {
120
+ const allTools = [];
121
+ for (const tools of this.tools.values()) {
122
+ allTools.push(...tools);
123
+ }
124
+ return allTools;
58
125
  }
59
- const schemaObj = schema;
60
- if (schemaObj.type && schemaObj.type !== "object") {
61
- return convertType(schemaObj);
126
+ /**
127
+ * Get tools from a specific server
128
+ */
129
+ getServerTools(serverName) {
130
+ return this.tools.get(serverName) || [];
62
131
  }
63
- if (!schemaObj.properties || typeof schemaObj.properties !== "object") {
64
- return z.object({});
132
+ /**
133
+ * Check if a server is connected
134
+ */
135
+ isServerConnected(serverName) {
136
+ return this.clients.has(serverName);
65
137
  }
66
- const shape = {};
67
- for (const [key, value] of Object.entries(schemaObj.properties)) {
68
- let zodType = convertType(value);
69
- const isRequired = Array.isArray(schemaObj.required) && schemaObj.required.includes(key);
70
- if (!isRequired) {
71
- zodType = zodType.optional();
72
- }
73
- shape[key] = zodType;
138
+ /**
139
+ * Get list of connected server names
140
+ */
141
+ getConnectedServers() {
142
+ return Array.from(this.clients.keys());
74
143
  }
75
- return z.object(shape);
76
- }
77
- function convertType(schema) {
78
- if (!schema || typeof schema !== "object" || !("type" in schema)) {
79
- return z.unknown();
144
+ /**
145
+ * Enable content processing with content storage
146
+ */
147
+ enableContentProcessing(contentStorage) {
148
+ this.contentProcessor = new MCPContentProcessor(contentStorage, this.logger);
149
+ this.logger.info("Content processing enabled for MCP responses");
80
150
  }
81
- const schemaObj = schema;
82
- let zodType;
83
- switch (schemaObj.type) {
84
- case "string":
85
- zodType = z.string();
86
- if (schemaObj.enum && Array.isArray(schemaObj.enum)) {
87
- zodType = z.enum(schemaObj.enum);
88
- }
89
- break;
90
- case "number":
91
- zodType = z.number();
92
- if ("minimum" in schemaObj && typeof schemaObj.minimum === "number") {
93
- zodType = zodType.min(schemaObj.minimum);
94
- }
95
- if ("maximum" in schemaObj && typeof schemaObj.maximum === "number") {
96
- zodType = zodType.max(schemaObj.maximum);
97
- }
98
- break;
99
- case "integer":
100
- zodType = z.number().int();
101
- if ("minimum" in schemaObj && typeof schemaObj.minimum === "number") {
102
- zodType = zodType.min(schemaObj.minimum);
103
- }
104
- if ("maximum" in schemaObj && typeof schemaObj.maximum === "number") {
105
- zodType = zodType.max(schemaObj.maximum);
106
- }
107
- break;
108
- case "boolean":
109
- zodType = z.boolean();
110
- break;
111
- case "array":
112
- if (schemaObj.items) {
113
- zodType = z.array(convertType(schemaObj.items));
114
- } else {
115
- zodType = z.array(z.unknown());
116
- }
117
- break;
118
- case "object":
119
- if ("properties" in schemaObj) {
120
- zodType = jsonSchemaToZod(schemaObj);
121
- } else {
122
- zodType = z.object({}).passthrough();
123
- }
124
- break;
125
- default:
126
- zodType = z.unknown();
151
+ /**
152
+ * Disable content processing
153
+ */
154
+ disableContentProcessing() {
155
+ delete this.contentProcessor;
156
+ this.logger.info("Content processing disabled for MCP responses");
157
+ }
158
+ /**
159
+ * Check if content processing is enabled
160
+ */
161
+ isContentProcessingEnabled() {
162
+ return this.contentProcessor !== void 0;
127
163
  }
128
- if ("description" in schemaObj && typeof schemaObj.description === "string") {
129
- zodType = zodType.describe(schemaObj.description);
164
+ /**
165
+ * Analyze a response without processing it (for testing/debugging)
166
+ */
167
+ analyzeResponseContent(response) {
168
+ if (!this.contentProcessor) {
169
+ throw new Error("Content processing is not enabled");
170
+ }
171
+ return this.contentProcessor.analyzeResponse(response);
130
172
  }
131
- return zodType;
132
173
  }
133
174
  export {
134
- convertMCPToolToLangChain
175
+ MCPClientManager
135
176
  };
136
177
  //# sourceMappingURL=index16.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index16.js","sources":["../../src/mcp/adapters/langchain.ts"],"sourcesContent":["import { DynamicStructuredTool } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport type { MCPToolInfo, MCPServerConfig } from '../types';\nimport type { MCPClientManager } from '../MCPClientManager';\n\n/**\n * Convert an MCP tool to a LangChain DynamicStructuredTool\n */\nexport function convertMCPToolToLangChain(\n tool: MCPToolInfo,\n mcpManager: MCPClientManager,\n serverConfig?: MCPServerConfig\n): DynamicStructuredTool {\n const zodSchema = jsonSchemaToZod(tool.inputSchema);\n\n const sanitizedName = `${tool.serverName}_${tool.name}`.replace(\n /[^a-zA-Z0-9_]/g,\n '_'\n );\n\n let description = tool.description || `MCP tool ${tool.name} from ${tool.serverName}`;\n \n if (serverConfig?.toolDescriptions?.[tool.name]) {\n description = `${description}\\n\\n${serverConfig.toolDescriptions[tool.name]}`;\n }\n \n if (serverConfig?.additionalContext) {\n description = `${description}\\n\\nContext: ${serverConfig.additionalContext}`;\n }\n\n return new DynamicStructuredTool({\n name: sanitizedName,\n description,\n schema: zodSchema,\n func: async (input) => {\n try {\n const result = await mcpManager.executeTool(\n tool.serverName,\n tool.name,\n input\n );\n\n let responseText = '';\n \n if (typeof result === 'string') {\n responseText = result;\n } else if (\n result &&\n typeof result === 'object' &&\n 'content' in result\n ) {\n const content = (result as { content: unknown }).content;\n if (Array.isArray(content)) {\n const textParts = content\n .filter(\n (item): item is { type: string; text: string } =>\n typeof item === 'object' &&\n item !== null &&\n 'type' in item &&\n item.type === 'text' &&\n 'text' in item\n )\n .map((item) => item.text);\n responseText = textParts.join('\\n');\n } else {\n responseText = JSON.stringify(content);\n }\n } else {\n responseText = JSON.stringify(result);\n }\n\n return responseText;\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n return `Error executing MCP tool ${tool.name}: ${errorMessage}`;\n }\n },\n });\n}\n\n/**\n * Convert JSON Schema to Zod schema\n * This is a simplified converter that handles common cases\n */\nfunction jsonSchemaToZod(schema: unknown): z.ZodTypeAny {\n if (!schema || typeof schema !== 'object') {\n return z.object({});\n }\n\n const schemaObj = schema as Record<string, unknown>;\n\n if (schemaObj.type && schemaObj.type !== 'object') {\n return convertType(schemaObj);\n }\n\n if (!schemaObj.properties || typeof schemaObj.properties !== 'object') {\n return z.object({});\n }\n\n const shape: Record<string, z.ZodTypeAny> = {};\n\n for (const [key, value] of Object.entries(schemaObj.properties)) {\n let zodType = convertType(value);\n\n const isRequired =\n Array.isArray(schemaObj.required) && schemaObj.required.includes(key);\n if (!isRequired) {\n zodType = zodType.optional();\n }\n\n shape[key] = zodType;\n }\n\n return z.object(shape);\n}\n\n/**\n * Convert a single JSON Schema type to Zod\n */\nfunction convertType(schema: unknown): z.ZodTypeAny {\n if (!schema || typeof schema !== 'object' || !('type' in schema)) {\n return z.unknown();\n }\n\n const schemaObj = schema as {\n type: string;\n enum?: unknown[];\n items?: unknown;\n };\n let zodType: z.ZodTypeAny;\n\n switch (schemaObj.type) {\n case 'string':\n zodType = z.string();\n if (schemaObj.enum && Array.isArray(schemaObj.enum)) {\n zodType = z.enum(schemaObj.enum as [string, ...string[]]);\n }\n break;\n\n case 'number':\n zodType = z.number();\n if ('minimum' in schemaObj && typeof schemaObj.minimum === 'number') {\n zodType = (zodType as z.ZodNumber).min(schemaObj.minimum);\n }\n if ('maximum' in schemaObj && typeof schemaObj.maximum === 'number') {\n zodType = (zodType as z.ZodNumber).max(schemaObj.maximum);\n }\n break;\n\n case 'integer':\n zodType = z.number().int();\n if ('minimum' in schemaObj && typeof schemaObj.minimum === 'number') {\n zodType = (zodType as z.ZodNumber).min(schemaObj.minimum);\n }\n if ('maximum' in schemaObj && typeof schemaObj.maximum === 'number') {\n zodType = (zodType as z.ZodNumber).max(schemaObj.maximum);\n }\n break;\n\n case 'boolean':\n zodType = z.boolean();\n break;\n\n case 'array':\n if (schemaObj.items) {\n zodType = z.array(convertType(schemaObj.items));\n } else {\n zodType = z.array(z.unknown());\n }\n break;\n\n case 'object':\n if ('properties' in schemaObj) {\n zodType = jsonSchemaToZod(schemaObj);\n } else {\n zodType = z.object({}).passthrough();\n }\n break;\n\n default:\n zodType = z.unknown();\n }\n\n if ('description' in schemaObj && typeof schemaObj.description === 'string') {\n zodType = zodType.describe(schemaObj.description);\n }\n\n return zodType;\n}\n"],"names":[],"mappings":";;AAQO,SAAS,0BACd,MACA,YACA,cACuB;AACvB,QAAM,YAAY,gBAAgB,KAAK,WAAW;AAElD,QAAM,gBAAgB,GAAG,KAAK,UAAU,IAAI,KAAK,IAAI,GAAG;AAAA,IACtD;AAAA,IACA;AAAA,EAAA;AAGF,MAAI,cAAc,KAAK,eAAe,YAAY,KAAK,IAAI,SAAS,KAAK,UAAU;AAEnF,MAAI,cAAc,mBAAmB,KAAK,IAAI,GAAG;AAC/C,kBAAc,GAAG,WAAW;AAAA;AAAA,EAAO,aAAa,iBAAiB,KAAK,IAAI,CAAC;AAAA,EAC7E;AAEA,MAAI,cAAc,mBAAmB;AACnC,kBAAc,GAAG,WAAW;AAAA;AAAA,WAAgB,aAAa,iBAAiB;AAAA,EAC5E;AAEA,SAAO,IAAI,sBAAsB;AAAA,IAC/B,MAAM;AAAA,IACN;AAAA,IACA,QAAQ;AAAA,IACR,MAAM,OAAO,UAAU;AACrB,UAAI;AACF,cAAM,SAAS,MAAM,WAAW;AAAA,UAC9B,KAAK;AAAA,UACL,KAAK;AAAA,UACL;AAAA,QAAA;AAGF,YAAI,eAAe;AAEnB,YAAI,OAAO,WAAW,UAAU;AAC9B,yBAAe;AAAA,QACjB,WACE,UACA,OAAO,WAAW,YAClB,aAAa,QACb;AACA,gBAAM,UAAW,OAAgC;AACjD,cAAI,MAAM,Q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AAQ,SAAS,UAAU,WAAW;AAAA,EAClD;AAEA,SAAO;AACT;"}
1
+ {"version":3,"file":"index16.js","sources":["../../src/mcp/MCPClientManager.ts"],"sourcesContent":["import { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';\nimport type { MCPServerConfig, MCPToolInfo, MCPConnectionStatus } from './types';\nimport { Logger } from '@hashgraphonline/standards-sdk';\nimport type { ContentStorage } from '../memory/ContentStorage';\nimport { MCPContentProcessor, ProcessedResponse } from './ContentProcessor';\n\n/**\n * Manages connections to MCP servers and tool discovery\n */\nexport class MCPClientManager {\n private clients: Map<string, Client> = new Map();\n private tools: Map<string, MCPToolInfo[]> = new Map();\n private logger: Logger;\n private contentProcessor?: MCPContentProcessor;\n\n constructor(logger: Logger, contentStorage?: ContentStorage) {\n this.logger = logger;\n if (contentStorage) {\n this.contentProcessor = new MCPContentProcessor(contentStorage, logger);\n }\n }\n\n /**\n * Connect to an MCP server and discover its tools\n */\n async connectServer(config: MCPServerConfig): Promise<MCPConnectionStatus> {\n try {\n if (this.isServerConnected(config.name)) {\n return {\n serverName: config.name,\n connected: false,\n error: `Server ${config.name} is already connected`,\n tools: [],\n };\n }\n\n if (config.transport && config.transport !== 'stdio') {\n throw new Error(`Transport ${config.transport} not yet supported`);\n }\n\n const transport = new StdioClientTransport({\n command: config.command,\n args: config.args,\n ...(config.env && { env: config.env }),\n });\n\n const client = new Client({\n name: `conversational-agent-${config.name}`,\n version: '1.0.0',\n }, {\n capabilities: {},\n });\n\n await client.connect(transport);\n this.clients.set(config.name, client);\n\n const toolsResponse = await client.listTools();\n const toolsWithServer: MCPToolInfo[] = toolsResponse.tools.map(tool => ({\n ...tool,\n serverName: config.name,\n }));\n\n this.tools.set(config.name, toolsWithServer);\n this.logger.info(`Connected to MCP server ${config.name} with ${toolsWithServer.length} tools`);\n\n return {\n serverName: config.name,\n connected: true,\n tools: toolsWithServer,\n };\n } catch (error) {\n this.logger.error(`Failed to connect to MCP server ${config.name}:`, error);\n return {\n serverName: config.name,\n connected: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n tools: [],\n };\n }\n }\n\n /**\n * Execute a tool on a specific MCP server\n */\n async executeTool(serverName: string, toolName: string, args: Record<string, unknown>): Promise<unknown> {\n const client = this.clients.get(serverName);\n if (!client) {\n throw new Error(`MCP server ${serverName} not connected`);\n }\n\n this.logger.debug(`Executing MCP tool ${toolName} on server ${serverName}`, args);\n\n try {\n const result = await client.callTool({\n name: toolName,\n arguments: args,\n });\n\n if (this.contentProcessor) {\n const processed = await this.contentProcessor.processResponse(result, serverName, toolName);\n \n if (processed.wasProcessed) {\n this.logger.debug(\n `Processed MCP response from ${serverName}::${toolName}`,\n {\n referenceCreated: processed.referenceCreated,\n originalSize: processed.originalSize,\n errors: processed.errors\n }\n );\n\n if (processed.errors && processed.errors.length > 0) {\n this.logger.warn(`Content processing warnings for ${serverName}::${toolName}:`, processed.errors);\n }\n }\n\n return processed.content;\n }\n\n return result;\n } catch (error) {\n this.logger.error(`Error executing MCP tool ${toolName}:`, error);\n throw error;\n }\n }\n\n /**\n * Disconnect all MCP servers\n */\n async disconnectAll(): Promise<void> {\n for (const [name, client] of this.clients) {\n try {\n await client.close();\n this.logger.info(`Disconnected from MCP server ${name}`);\n } catch (error) {\n this.logger.error(`Error disconnecting MCP server ${name}:`, error);\n }\n }\n this.clients.clear();\n this.tools.clear();\n }\n\n /**\n * Get all discovered tools from all connected servers\n */\n getAllTools(): MCPToolInfo[] {\n const allTools: MCPToolInfo[] = [];\n for (const tools of this.tools.values()) {\n allTools.push(...tools);\n }\n return allTools;\n }\n\n /**\n * Get tools from a specific server\n */\n getServerTools(serverName: string): MCPToolInfo[] {\n return this.tools.get(serverName) || [];\n }\n\n /**\n * Check if a server is connected\n */\n isServerConnected(serverName: string): boolean {\n return this.clients.has(serverName);\n }\n\n /**\n * Get list of connected server names\n */\n getConnectedServers(): string[] {\n return Array.from(this.clients.keys());\n }\n\n /**\n * Enable content processing with content storage\n */\n enableContentProcessing(contentStorage: ContentStorage): void {\n this.contentProcessor = new MCPContentProcessor(contentStorage, this.logger);\n this.logger.info('Content processing enabled for MCP responses');\n }\n\n /**\n * Disable content processing\n */\n disableContentProcessing(): void {\n delete this.contentProcessor;\n this.logger.info('Content processing disabled for MCP responses');\n }\n\n /**\n * Check if content processing is enabled\n */\n isContentProcessingEnabled(): boolean {\n return this.contentProcessor !== undefined;\n }\n\n /**\n * Analyze a response without processing it (for testing/debugging)\n */\n analyzeResponseContent(response: unknown): unknown {\n if (!this.contentProcessor) {\n throw new Error('Content processing is not enabled');\n }\n return this.contentProcessor.analyzeResponse(response);\n }\n}"],"names":[],"mappings":";;;AAUO,MAAM,iBAAiB;AAAA,EAM5B,YAAY,QAAgB,gBAAiC;AAL7D,SAAQ,8BAAmC,IAAA;AAC3C,SAAQ,4BAAwC,IAAA;AAK9C,SAAK,SAAS;AACd,QAAI,gBAAgB;AAClB,WAAK,mBAAmB,IAAI,oBAAoB,gBAAgB,MAAM;AAAA,IACxE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,QAAuD;AACzE,QAAI;AACF,UAAI,KAAK,kBAAkB,OAAO,IAAI,GAAG;AACvC,eAAO;AAAA,UACL,YAAY,OAAO;AAAA,UACnB,WAAW;AAAA,UACX,OAAO,UAAU,OAAO,IAAI;AAAA,UAC5B,OAAO,CAAA;AAAA,QAAC;AAAA,MAEZ;AAEA,UAAI,OAAO,aAAa,OAAO,cAAc,SAAS;AACpD,cAAM,IAAI,MAAM,aAAa,OAAO,SAAS,oBAAoB;AAAA,MACnE;AAEA,YAAM,YAAY,IAAI,qBAAqB;AAAA,QACzC,SAAS,OAAO;AAAA,QAChB,MAAM,OAAO;AAAA,QACb,GAAI,OAAO,OAAO,EAAE,KAAK,OAAO,IAAA;AAAA,MAAI,CACrC;AAED,YAAM,SAAS,IAAI,OAAO;AAAA,QACxB,MAAM,wBAAwB,OAAO,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