-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-agno-compatibility.js
More file actions
executable file
Β·291 lines (238 loc) Β· 9.25 KB
/
Copy pathtest-agno-compatibility.js
File metadata and controls
executable file
Β·291 lines (238 loc) Β· 9.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/usr/bin/env node
/**
* Test script to verify BigCommerce MCP server compatibility with Agno
*
* This script demonstrates how to use the BigCommerce MCP server with Agno's MCPTools
* Run with: node test-agno-compatibility.js
*/
import dotenv from 'dotenv';
import { fileURLToPath } from 'url';
import path from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Load environment variables
dotenv.config({ path: path.resolve(__dirname, '.env') });
// Mock Agno MCPTools behavior to test compatibility
class MockMCPTools {
constructor(serverUrl) {
this.serverUrl = serverUrl;
this.isConnected = false;
}
async connect() {
console.log(`π Connecting to MCP server: ${this.serverUrl}`);
try {
// Test health check
const healthResponse = await fetch(`${this.serverUrl.replace('/mcp', '')}/health`);
if (healthResponse.ok) {
const healthData = await healthResponse.json();
console.log(`β
Health check passed:`, healthData);
}
// Test server info
try {
const infoResponse = await fetch(`${this.serverUrl.replace('/mcp', '')}/info`);
if (infoResponse.ok) {
const infoData = await infoResponse.json();
console.log(`βΉοΈ Server info:`, infoData);
}
} catch (e) {
console.log(`β οΈ Server info endpoint not available`);
}
// Test tools listing
const toolsRequest = {
jsonrpc: "2.0",
id: "test-tools",
method: "tools/list",
params: {}
};
const toolsResponse = await fetch(this.serverUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json, text/event-stream',
'Authorization': `Bearer ${process.env.MCP_AUTH_TOKEN}`
},
body: JSON.stringify(toolsRequest)
});
if (!toolsResponse.ok) {
throw new Error(`Tools request failed: ${toolsResponse.status}`);
}
// Parse SSE response
const responseText = await toolsResponse.text();
const toolsData = this.parseSSEResponse(responseText);
console.log(`π οΈ Available tools:`, toolsData.result?.tools?.map(t => t.name) || []);
this.isConnected = true;
console.log(`β
Successfully connected to MCP server`);
return toolsData.result?.tools || [];
} catch (error) {
console.error(`β Failed to connect:`, error.message);
throw error;
}
}
async callTool(toolName, args) {
if (!this.isConnected) {
throw new Error('Not connected to MCP server');
}
console.log(`π§ Calling tool: ${toolName} with args:`, args);
const request = {
jsonrpc: "2.0",
id: `test-${toolName}-${Date.now()}`,
method: "tools/call",
params: {
name: toolName,
arguments: args
}
};
try {
const response = await fetch(this.serverUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json, text/event-stream',
'Authorization': `Bearer ${process.env.MCP_AUTH_TOKEN}`
},
body: JSON.stringify(request)
});
if (!response.ok) {
throw new Error(`Tool call failed: ${response.status}`);
}
// Parse SSE response
const responseText = await response.text();
const data = this.parseSSEResponse(responseText);
if (data.error) {
console.error(`β Tool error:`, data.error);
throw new Error(data.error.message);
}
console.log(`β
Tool result received:`, {
toolName,
hasContent: !!data.result?.content,
contentType: data.result?.content?.[0]?.type,
hasMeta: !!data.result?._meta,
resultKeys: Object.keys(data.result || {})
});
return data.result;
} catch (error) {
console.error(`β Tool call failed:`, error.message);
throw error;
}
}
parseSSEResponse(sseText) {
// Parse Server-Sent Events format
const lines = sseText.split('\n');
let eventType = '';
let data = '';
for (const line of lines) {
if (line.startsWith('event: ')) {
eventType = line.substring(7).trim();
} else if (line.startsWith('data: ')) {
data += line.substring(6);
} else if (line === '' && data) {
// End of event
try {
return JSON.parse(data);
} catch (e) {
console.warn('Failed to parse SSE data as JSON:', data);
return { result: { tools: [] } };
}
}
}
// If no complete event found, try to parse the last data
if (data) {
try {
return JSON.parse(data);
} catch (e) {
console.warn('Failed to parse SSE data as JSON:', data);
return { result: { tools: [] } };
}
}
return { result: { tools: [] } };
}
async close() {
this.isConnected = false;
console.log(`π Disconnected from MCP server`);
}
}
async function testAgnoCompatibility() {
console.log(`π§ͺ Testing BigCommerce MCP Server compatibility with Agno`);
console.log(`=====================================\n`);
const serverUrl = process.env.MCP_SERVER_URL || 'http://localhost:3000/mcp';
const mcpTools = new MockMCPTools(serverUrl);
try {
// Connect to the server
const tools = await mcpTools.connect();
if (tools.length === 0) {
console.log(`β οΈ No tools available. Make sure the server is configured with BigCommerce credentials.`);
return;
}
// Test each available tool with basic parameters
for (const tool of tools) {
console.log(`\nπ Testing tool: ${tool.name}`);
console.log(` Description: ${tool.description}`);
try {
let testArgs = {};
// Add tool-specific test arguments
if (tool.name === 'get_all_products') {
testArgs = { limit: 5 }; // Small limit for testing
} else if (tool.name === 'get_all_customers') {
testArgs = { limit: 5 }; // Small limit for testing
} else if (tool.name === 'get_all_orders') {
testArgs = { limit: 5 }; // Small limit for testing
}
const result = await mcpTools.callTool(tool.name, testArgs);
// Parse the result content
if (result?.content?.[0]?.text) {
const resultText = result.content[0].text;
console.log(` π Result preview: ${resultText.substring(0, 200)}${resultText.length > 200 ? '...' : ''}`);
}
console.log(` β
Tool test passed`);
} catch (error) {
console.log(` β Tool test failed: ${error.message}`);
// Continue testing other tools even if one fails
continue;
}
}
console.log(`\nπ Agno compatibility test completed!`);
console.log(`π Results: ${tools.length} tools tested`);
} catch (error) {
console.error(`β Compatibility test failed:`, error.message);
process.exit(1);
} finally {
await mcpTools.close();
}
}
// Example of how to use the MCP server with Agno
async function demonstrateAgnoUsage() {
console.log(`\nπ Example: How to use with Agno`);
console.log(`=================================`);
const exampleCode = `
// Example Agno integration:
import { MCPTools } from '@agno/mcp';
const bigcommerceMCP = new MCPTools('http://localhost:3000/mcp');
async function getBigCommerceData() {
await bigcommerceMCP.connect();
// Get recent orders
const orders = await bigcommerceMCP.callTool('get_all_orders', {
limit: 10,
sort: 'date_created:desc'
});
// Get product catalog
const products = await bigcommerceMCP.callTool('get_all_products', {
limit: 20,
is_visible: true
});
// Get customer list
const customers = await bigcommerceMCP.callTool('get_all_customers', {
limit: 10
});
await bigcommerceMCP.close();
return { orders, products, customers };
}
`;
console.log(exampleCode);
}
// Main execution
if (import.meta.url === `file://${process.argv[1]}`) {
testAgnoCompatibility()
.then(() => demonstrateAgnoUsage())
.catch(console.error);
}
export { MockMCPTools, testAgnoCompatibility };