Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cecli/coders/base_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2766,7 +2766,7 @@ async def get_server_tools(server):
return None

async def get_all_server_tools():
tasks = [get_server_tools(server) for server in self.mcp_manager]
tasks = [get_server_tools(server) for server in self.mcp_manager if server.is_enabled]
results = await asyncio.gather(*tasks)
return [result for result in results if result is not None]

Expand Down
14 changes: 10 additions & 4 deletions cecli/mcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ def __init__(
Initialize the MCP server manager.

Args:
mcp_servers: JSON string containing MCP server configurations
mcp_servers_file: Path to a JSON file containing MCP server configurations
servers: List of MCP Servers to manage
io: InputOutput instance for user interaction
verbose: Whether to output verbose logging
"""
self.io = io
self.verbose = verbose
self._servers = servers

self._server_tools: dict[str, list] = {} # Maps server name to its tools
self._connected_servers: set[McpServer] = set()

Expand Down Expand Up @@ -74,7 +74,7 @@ def get_server(self, name: str) -> McpServer | None:
return None

async def connect_all(self) -> None:
"""Connect to all MCP servers."""
"""Connect to all MCP servers while skipping ones that are not enabled."""
if self.is_connected:
self._log_verbose("Some MCP servers already connected")
return
Expand All @@ -93,7 +93,9 @@ async def connect_server(server: McpServer) -> tuple[McpServer, bool]:
self._log_error(f"Failed to connect to MCP server {server.name}: {e}")
return (server, False)

results = await asyncio.gather(*[connect_server(server) for server in self._servers])
results = await asyncio.gather(
*[connect_server(server) for server in self._servers if server.is_enabled]
)

for server, success in results:
if success:
Expand Down Expand Up @@ -142,6 +144,10 @@ async def connect_server(self, name: str) -> bool:
self._log_warning(f"MCP server not found: {name}")
return False

if not server.is_enabled:
self._log_verbose("MCP is not enabled.")
return False

if server in self._connected_servers:
self._log_verbose(f"MCP server already connected: {name}")
return True
Expand Down
16 changes: 14 additions & 2 deletions cecli/mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self, server_config, io=None, verbose=False):
"""
self.config = server_config
self.name = server_config.get("name", "unnamed-server")
self.is_enabled = server_config.get("enabled", True)
self.io = io
self.verbose = verbose
self.session = None
Expand All @@ -52,8 +53,13 @@ async def connect(self):
Otherwise, establishes a new connection and initializes the session.

Returns:
ClientSession: The active session
ClientSession: The active session if mcp is not disabled
"""
if not self.is_enabled:
if self.verbose and self.io:
self.io.tool_output(f"Enabled option is set to false for MCP server: {self.name}")
return None

if self.session is not None:
if self.verbose and self.io:
self.io.tool_output(f"Using existing session for MCP server: {self.name}")
Expand Down Expand Up @@ -123,7 +129,8 @@ async def _create_oauth_provider(self):
existing_redirect_uri = redirect_uris[0]
if self.verbose and self.io:
self.io.tool_output(
f"Found existing redirect URI: {existing_redirect_uri}", log_only=True
f"Found existing redirect URI: {existing_redirect_uri}",
log_only=True,
)

from .utils import find_available_port
Expand Down Expand Up @@ -187,6 +194,11 @@ def _create_transport(self, url, http_client):
raise NotImplementedError("Subclasses must implement _create_transport")

async def connect(self):
if not self.is_enabled:
if self.verbose and self.io:
self.io.tool_output(f"Enabled option is set to false for MCP server: {self.name}")
return None

if self.session is not None:
if self.verbose and self.io:
self.io.tool_output(f"Using existing session for {self.name}")
Expand Down
6 changes: 5 additions & 1 deletion cecli/website/docs/config/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ mcp-servers-file: /path/to/mcp.json

These options are configurable in any of Aider's config file formats.

Also, you are able to say if you would like an mcp enabled/disabled in the config itself via `"enabled"` key
By default MCP servers are enabled, so you MUST explicitly disable them in the config if you dont wish
for them to be included when cecli starts up

### Flags

You can specify MCP servers directly on the command line using the `--mcp-servers` option with a JSON or YAML string:
Expand Down Expand Up @@ -204,7 +208,7 @@ mcp-servers:
"-i",
"--rm",
"-e",
"GITHUB_PERSONAL_ACCESS_TOKEN=<access_token>",
"GITHUB_PERSONAL_ACCESS_TOKEN=<access_token>",
"ghcr.io/github/github-mcp-server"
]
```