This repository provides the `MCPServerManager` class for managing multiple MCP server instances, including lifecycle, connection management, and automatic tool discovery, using a JSON configuration file. This repository provides the `MCPServerManager`
The MCPServerManager
class offers a streamlined approach to managing multiple MCP server instances, encompassing server lifecycle, connection management, and tool discovery.
The code snippet illustrates loading server configurations from a servers.json
file using MCPServersConfig.load
. A MCPServerManager
instance is created to start servers, yielding a dictionary mapping server names to their discovered tools. A client instance for a specific server (e.g., "filesystem") is retrieved to execute tool calls, exemplified by listing a directory. Finally, manager.stopAll()
halts all servers.
The servers.json
example demonstrates configuring a server with its command, arguments, and environment variables.
MCPServersConfig
allows specifying server configurations in a JSON file, loaded via the load
function. Configurations include the server executable, command-line arguments, and environment variables. Each server is uniquely identified by a name used for client retrieval. Server startup failures propagate as an MCPError
, halting the startup process.
eastlondoner/swift-mcp-client
January 27, 2025
February 19, 2025
Swift