MCPcopy Create free account
hub / github.com/anus-dev/ANUS / testMCPConnection

Function testMCPConnection

packages/cli/src/commands/mcp/list.ts:46–77  ·  view source on GitHub ↗
(
  serverName: string,
  config: MCPServerConfig,
)

Source from the content-addressed store, hash-verified

44}
45
46async function testMCPConnection(
47 serverName: string,
48 config: MCPServerConfig,
49): Promise<MCPServerStatus> {
50 const client = new Client({
51 name: 'mcp-test-client',
52 version: '0.0.1',
53 });
54
55 let transport;
56 try {
57 // Use the same transport creation logic as core
58 transport = await createTransport(serverName, config, false);
59 } catch (_error) {
60 await client.close();
61 return MCPServerStatus.DISCONNECTED;
62 }
63
64 try {
65 // Attempt actual MCP connection with short timeout
66 await client.connect(transport, { timeout: 5000 }); // 5s timeout
67
68 // Test basic MCP protocol by pinging the server
69 await client.ping();
70
71 await client.close();
72 return MCPServerStatus.CONNECTED;
73 } catch (_error) {
74 await transport.close();
75 return MCPServerStatus.DISCONNECTED;
76 }
77}
78
79async function getServerStatus(
80 serverName: string,

Callers 1

getServerStatusFunction · 0.85

Calls 3

createTransportFunction · 0.85
closeMethod · 0.80
connectMethod · 0.80

Tested by

no test coverage detected