list-servers
Display all active MCP servers connected to the central hub server for easy monitoring and management of distributed resources.
Instructions
List all connected MCP servers
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:290-312 (handler)The handler function for the "list-servers" tool. It calls serverManager.listServers() to get the list of connected servers and returns it formatted as JSON text content in the MCP response format.async (args, extra) => { try { const servers = serverManager.listServers(); return { content: [ { type: "text", text: JSON.stringify({ servers }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error listing servers: ${(error as Error).message}`, }, ], }; } }
- src/index.ts:286-313 (registration)Registration of the "list-servers" tool using the MCP server's tool() method, with an empty schema (no parameters) and an inline handler function.server.tool( "list-servers", "List all connected MCP servers", {}, // No parameters needed async (args, extra) => { try { const servers = serverManager.listServers(); return { content: [ { type: "text", text: JSON.stringify({ servers }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error listing servers: ${(error as Error).message}`, }, ], }; } } );
- src/server-manager.ts:311-313 (helper)Helper method listServers() in McpServerManager class, which delegates to getConnectedServers() to retrieve the list of connected server names.listServers(): string[] { return this.getConnectedServers(); }
- src/server-manager.ts:333-335 (helper)Supporting helper method getConnectedServers() that extracts the names of connected servers from the internal Map of clients.getConnectedServers(): string[] { return Array.from(this.clients.keys()); }