meta_mcp.mcp#

Attributes#

Classes#

MetaFastMCPDynamic

FastMCP subclass that manages shared MCP client sessions with dynamic client management.

Module Contents#

class meta_mcp.mcp.MetaFastMCPDynamic(registry_json: str, registry_mcp_json: str, registry_mcp_tools_json: str, connect_on_startup: bool = False, *, name: str = 'meta-mcp', **kwargs: Any)#

Bases: fastmcp.FastMCP

FastMCP subclass that manages shared MCP client sessions with dynamic client management.

_connect_on_startup = False#
_registry_config#
_registry_info#
_registry_mcp_tools#
_servers: dict[str, dict[str, Any]]#
_tools: dict[str, dict[str, dict[str, Any]]]#
_lifespan_clients: dict[str, fastmcp.Client]#
_dynamic_clients: dict[str, fastmcp.Client]#
_dynamic_client_stacks: dict[str, contextlib.AsyncExitStack]#
_filter_and_setup_registry(registry_df)#
async _update_tools_from_client(server_name: str, client: fastmcp.Client) None#

Update tool metadata for a server from a connected client.

async _lifespan(_app: fastmcp.FastMCP)#
async add_client(server_name: str, server_config: dict[str, Any]) None#

Add a new client at runtime.

Args:

server_name: Name to identify this server server_config: MCP server configuration dict (should have ‘mcpServers’ key)

Raises:
  • RuntimeError – If clients are not initialized or server already exists:

  • Exception – If client connection fails:

async remove_client(server_name: str) None#

Remove a dynamically-managed client at runtime.

Args:

server_name: Name of the server to remove

Raises:

RuntimeError – If server doesn’t exist or is lifespan-managed:

async _cleanup_all_dynamic_clients() None#

Clean up all dynamically-managed clients.

get_client(server_name: str) fastmcp.Client#

Get a client by name (from either pool).

Parameters:

server_name (str) – Name of the server.

Returns:

Client instance.

Return type:

Client

Raises:

RuntimeError – If clients are not initialized or server doesn’t exist:

get_clients() dict[str, fastmcp.Client]#

Get all clients (both lifespan and dynamic).

Returns:

Combined dictionary of all clients.

Return type:

dict[str, Client]

Raises:

RuntimeError – If clients are not initialized:

get_lifespan_clients() dict[str, fastmcp.Client]#

Get only lifespan-managed clients.

Returns:

Dictionary of lifespan-managed clients.

Return type:

dict[str, Client]

Raises:

RuntimeError – If clients are not initialized:

get_dynamic_clients() dict[str, fastmcp.Client]#

Get only dynamically-managed clients.

Returns:

Dictionary of dynamically-managed clients.

Return type:

dict[str, Client]

async connect_to_server(server_name: str) None#

Connect to a server from the registry.

async disconnect_from_server(server_name: str) None#

Disconnect from a dynamically-connected server.

meta_mcp.mcp._connect_on_startup#
meta_mcp.mcp._registry_json#
meta_mcp.mcp._registry_mcp_json#
meta_mcp.mcp._registry_mcp_tools_json#
meta_mcp.mcp.mcp: MetaFastMCPDynamic#