MCPServerConfig
Each MCP server is defined with an MCPServerConfig:
from definable.mcp import MCPServerConfig
server = MCPServerConfig(
name = "my-server" ,
transport = "stdio" ,
command = "npx" ,
args = [ "-y" , "@modelcontextprotocol/server-filesystem" , "/home" ],
connect_timeout = 30.0 ,
request_timeout = 60.0 ,
)
Connection Parameters
Unique identifier for this server. Used in tool name prefixes and logs.
Transport type: "stdio", "sse", or "http".
stdio Transport
Command to launch the server process (e.g., "npx", "python", "node").
Command-line arguments for the server process.
SSE / HTTP Transport
Server URL for SSE or HTTP transports.
Custom HTTP headers (e.g., authentication tokens).
Timeouts
Maximum time in seconds to establish the initial connection.
Maximum time in seconds for individual requests (tool calls, resource reads).
Reliability
Automatically reconnect if the connection drops.
Maximum number of reconnection attempts.
Whitelist of tool names. Only these tools will be exposed to the agent.
Blacklist of tool names. These tools will be hidden from the agent.
# Only expose read operations
MCPServerConfig(
name = "filesystem" ,
transport = "stdio" ,
command = "npx" ,
args = [ "-y" , "@modelcontextprotocol/server-filesystem" , "/data" ],
allowed_tools = [ "read_file" , "list_directory" , "search_files" ],
)
# Block dangerous operations
MCPServerConfig(
name = "filesystem" ,
transport = "stdio" ,
command = "npx" ,
args = [ "-y" , "@modelcontextprotocol/server-filesystem" , "/data" ],
blocked_tools = [ "write_file" , "delete_file" , "move_file" ],
)
MCPConfig
Group multiple servers into a single configuration:
from definable.mcp import MCPConfig, MCPServerConfig
config = MCPConfig(
servers = [
MCPServerConfig( name = "filesystem" , transport = "stdio" , command = "npx" , args = [ "..." ]),
MCPServerConfig( name = "github" , transport = "stdio" , command = "npx" , args = [ "..." ]),
MCPServerConfig( name = "api" , transport = "http" , url = "https://mcp.example.com" ),
],
auto_connect = True ,
reconnect_on_failure = True ,
)
servers
List[MCPServerConfig]
required
List of server configurations.
Automatically connect to all servers on initialization.
Global reconnection setting (can be overridden per server).
Loading from a File
Store configuration in a JSON file and load it:
{
"servers" : [
{
"name" : "filesystem" ,
"transport" : "stdio" ,
"command" : "npx" ,
"args" : [ "-y" , "@modelcontextprotocol/server-filesystem" , "/tmp" ]
},
{
"name" : "api" ,
"transport" : "http" ,
"url" : "https://mcp.example.com/mcp" ,
"headers" : { "Authorization" : "Bearer token" }
}
]
}
config = MCPConfig.from_file( "mcp_config.json" )
Save configuration back to a file:
config.to_file( "mcp_config.json" )
Managing Servers
Add or remove servers dynamically:
config = MCPConfig( servers = [])
# Add a server
config.add_server(MCPServerConfig( name = "fs" , transport = "stdio" , command = "npx" , args = [ ... ]))
# Get a specific server
server = config.get_server( "fs" )
# Remove a server
config.remove_server( "fs" )
Transport-Specific Examples
stdio (local)
SSE (remote)
HTTP (streamable)
MCPServerConfig(
name = "sqlite" ,
transport = "stdio" ,
command = "npx" ,
args = [ "-y" , "@modelcontextprotocol/server-sqlite" , "database.db" ],
)