forked from cloudflare/agents-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-mcp-connection.js
More file actions
52 lines (42 loc) · 1.62 KB
/
test-mcp-connection.js
File metadata and controls
52 lines (42 loc) · 1.62 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
// Simple test script to debug MCP connection issues
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
async function testMCPConnection() {
console.log("Testing MCP connection to localhost:64590...");
try {
const transport = new SSEClientTransport(new URL("http://localhost:64590/sse"));
const client = new Client(
{
name: "test-client",
version: "1.0.0",
},
{
capabilities: {
tools: {},
},
}
);
console.log("Creating transport...");
console.log("Connecting to server...");
// Add timeout to prevent hanging
const connectPromise = client.connect(transport);
const timeoutPromise = new Promise((_, reject) => {
setTimeout(() => reject(new Error("Connection timeout after 5 seconds")), 5000);
});
await Promise.race([connectPromise, timeoutPromise]);
console.log("Connected! Listing tools...");
const tools = await client.listTools();
console.log("Available tools:", tools);
await client.close();
console.log("Connection closed successfully");
} catch (error) {
console.error("Connection failed:", error);
console.error("Error details:", {
name: error.name,
message: error.message,
stack: error.stack
});
}
}
// Run the test
testMCPConnection().catch(console.error);