Skip to content

Commit 4e60699

Browse files
author
Your Name
committed
Move MCP and skill management to common ResourceManager tool
1 parent 46fd622 commit 4e60699

28 files changed

Lines changed: 923 additions & 864 deletions

cecli/coders/agent_coder.py

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def _get_agent_config(self):
194194
"todo_list",
195195
"sub_agents",
196196
"skills",
197+
"servers",
197198
},
198199
)
199200
)
@@ -357,6 +358,7 @@ def _calculate_context_block_tokens(self, force=False):
357358
"git_status",
358359
"symbol_outline",
359360
"skills",
361+
"servers",
360362
"sub_agents",
361363
"loaded_skills",
362364
]
@@ -391,6 +393,8 @@ def _generate_context_block(self, block_name):
391393
content = self.get_todo_list()
392394
elif block_name == "skills":
393395
content = self.get_skills_context()
396+
elif block_name == "servers":
397+
content = self.get_servers_context()
394398
elif block_name == "loaded_skills":
395399
content = self.get_skills_content()
396400
elif block_name == "sub_agents" and (
@@ -624,9 +628,8 @@ def get_context_summary(self):
624628
result += f" ({percentage:.1f}% of limit)"
625629
if percentage > 80:
626630
result += "\n\n⚠ **Context is getting full!**\n"
627-
result += "- Remove non-essential files via the `ContextManager` tool.\n"
628-
result += "- Remove unused MCP servers via the `RemoveMcp` tool to free context space.\n"
629-
result += "- Keep only essential files and MCP servers in context for best performance"
631+
result += "- Remove non-essential files, skills and tool servers via the `ResourceManager` tool.\n"
632+
result += "- Keep only essential files, skills, and MCP servers in context for best performance"
630633
result += "\n</context>"
631634
if not hasattr(self, "context_blocks_cache"):
632635
self.context_blocks_cache = {}
@@ -1328,7 +1331,7 @@ async def check_for_file_mentions(self, content):
13281331
13291332
Override parent's method to disable implicit file mention handling in agent mode.
13301333
Files should only be added via explicit tool commands
1331-
(`ContextManager`).
1334+
(`ResourceManager`).
13321335
"""
13331336
pass
13341337

@@ -1482,6 +1485,81 @@ def get_skills_content(self):
14821485
self.io.tool_error(f"Error generating skills content context: {str(e)}")
14831486
return None
14841487

1488+
def get_servers_context(self):
1489+
"""
1490+
Generate a context block for available MCP servers.
1491+
1492+
Categorizes servers as:
1493+
- Active: Connected and passing includelist/excludelist filters
1494+
- Inactive: Connected but filtered out by includelist/excludelist
1495+
- Available (Disconnected): Managed but not currently connected
1496+
1497+
Returns:
1498+
Formatted context block string or None if no servers available
1499+
"""
1500+
if not self.use_enhanced_context:
1501+
return None
1502+
try:
1503+
if not self.mcp_manager:
1504+
return None
1505+
1506+
all_servers = self.mcp_manager.servers
1507+
connected_servers = self.mcp_manager.connected_servers
1508+
connected_server_names = {s.name for s in connected_servers}
1509+
1510+
if not all_servers:
1511+
return None
1512+
1513+
# Apply registered_servers filtering to determine active vs inactive
1514+
incl = self.registered_servers.get("included", set())
1515+
excl = self.registered_servers.get("excluded", set())
1516+
1517+
active_servers = []
1518+
inactive_servers = []
1519+
for server in connected_servers:
1520+
name = server.name
1521+
if incl and name not in incl:
1522+
inactive_servers.append(name)
1523+
elif name in excl:
1524+
inactive_servers.append(name)
1525+
else:
1526+
active_servers.append(name)
1527+
1528+
# Servers managed but not currently connected
1529+
disconnected_servers = [
1530+
server.name for server in all_servers if server.name not in connected_server_names
1531+
]
1532+
1533+
result = '<context name="servers" from="agent">\n'
1534+
result += "## Connected MCP Servers\n\n"
1535+
1536+
if active_servers:
1537+
result += f"Active ({len(active_servers)}):\n"
1538+
for name in sorted(active_servers):
1539+
result += f"- {name}\n"
1540+
result += "\n"
1541+
1542+
if inactive_servers:
1543+
result += f"Inactive (Filtered) ({len(inactive_servers)}):\n"
1544+
for name in sorted(inactive_servers):
1545+
result += f"- {name}\n"
1546+
result += "\n"
1547+
1548+
if disconnected_servers:
1549+
result += f"Available (Disconnected) ({len(disconnected_servers)}):\n"
1550+
for name in sorted(disconnected_servers):
1551+
result += f"- {name}\n"
1552+
result += "\n"
1553+
1554+
if not active_servers and not inactive_servers and not disconnected_servers:
1555+
result += "No MCP servers currently available.\n\n"
1556+
1557+
result += "</context>"
1558+
return result
1559+
except Exception as e:
1560+
self.io.tool_error(f"Error generating servers context: {str(e)}")
1561+
return None
1562+
14851563
def get_sub_agents_context(self):
14861564
"""
14871565
Generate a context block for registered sub-agents.

cecli/helpers/conversation/integration.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ def add_static_context_blocks(self) -> None:
890890
"""
891891
Add static context blocks to conversation (priority 50).
892892
893-
Static blocks include: environment_info, directory_structure, skills
893+
Static blocks include: environment_info, directory_structure, skills, servers, sub_agents
894894
"""
895895
coder = self.get_coder()
896896
if not coder:
@@ -922,6 +922,10 @@ def add_static_context_blocks(self) -> None:
922922
block = coder._generate_context_block("skills")
923923
if block:
924924
message_blocks["skills"] = block
925+
if "servers" in coder.allowed_context_blocks:
926+
block = coder._generate_context_block("servers")
927+
if block:
928+
message_blocks["servers"] = block
925929

926930
# Add static blocks to conversation manager with stable hash keys
927931
for block_type, block_content in message_blocks.items():

cecli/prompts/agent.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ main_system: |
4242
## Core Workflow
4343
1. **Plan**: Start by using `UpdateTodoList` to outline the task.
4444
2. **Explore**: Use discovery tools (`ExploreCode`, `Grep`, `Ls`) to research and gather understanding for you task. Modify search terms when errors are encountered.
45-
3. **Execute**: Mark files as editable with `ContextManager` before attempting edits. Proactively use skills if they are available. Review diff outputs after edit to ensure the proper changes were made.
45+
3. **Execute**: Mark files as editable with `ResourceManager` before attempting edits. Proactively use skills if they are available. Review diff outputs after edit to ensure the proper changes were made.
4646
4. **Verify & Recover**: If an edit fails or introduces linting errors, fix the error immediately. Use `UndoChange` if the errors are too complex to incrementally modify.
4747
5. **Yield**: Use the `Yield` tool after accomplishing the goal and verifying any changes made. Provide helpful summaries of any changes.
4848
@@ -52,7 +52,7 @@ main_system: |
5252
5353
## Operational Rules
5454
- **Scope**: No unrequested refactors. Avoid full-file rewrites. Only modify what you are asked to.
55-
- **Hygiene**: Use `ContextManager`/`RemoveSkill` to evict unneeded files/skills immediately after use.
55+
- **Hygiene**: Use `ResourceManager` to evict unneeded files/skills immediately after use.
5656
- **Outputs**: Tool calls trigger turns. Never include tool syntax in final user summaries.
5757
- **Sandbox**: Perform all verification and temp logic in `.cecli/temp`.
5858
- **Responses**: Reason out loud through the problem but be brief.
@@ -71,7 +71,7 @@ system_reminder: |
7171
7272
{lazy_prompt}
7373
{shell_cmd_reminder}
74-
</context>""
74+
</context>
7575
7676
try_again: |
7777
My previous exploration was insufficient. I will now adjust my strategy, use more specific search patterns, and manage my context more aggressively to find the correct solution.

cecli/prompts/subagent.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ main_system: |
2727
## Core Workflow
2828
1. **Plan**: Start by using `UpdateTodoList` to outline the task.
2929
2. **Explore**: Use discovery tools (`ExploreCode`, `Grep`, `Ls`) to research and gather understanding for you task. Modify search terms when errors are encountered.
30-
3. **Execute**: Mark files as editable with `ContextManager` before attempting edits. Proactively use skills if they are available. Review diff outputs after edit to ensure the proper changes were made.
30+
3. **Execute**: Mark files as editable with `ResourceManager` before attempting edits. Proactively use skills if they are available. Review diff outputs after edit to ensure the proper changes were made.
3131
4. **Verify & Recover**: If an edit fails or introduces linting errors, fix the error immediately. Use `UndoChange` if the errors are too complex to incrementally modify.
3232
5. **Yield**: Use the `Yield` tool after accomplishing the goal and verifying any changes made. Provide helpful summaries of any changes.
3333
@@ -37,7 +37,7 @@ main_system: |
3737
3838
## Operational Rules
3939
- **Scope**: No unrequested refactors. Avoid full-file rewrites. Only modify what you are asked to.
40-
- **Hygiene**: Use `ContextManager`/`RemoveSkill` to evict unneeded files/skills immediately after use.
40+
- **Hygiene**: Use `ResourceManager` to evict unneeded files/skills immediately after use.
4141
- **Outputs**: Tool calls trigger turns. Never include tool syntax in final user summaries.
4242
- **Sandbox**: Perform all verification and temp logic in `.cecli/temp`.
4343
- **Responses**: Reason out loud through the problem but be brief.

cecli/tools/__init__.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
_yield,
77
command,
88
command_interactive,
9-
context_manager,
109
delegate,
1110
edit_text,
1211
explore_code,
@@ -17,13 +16,9 @@
1716
git_show,
1817
git_status,
1918
grep,
20-
list_mcp,
21-
load_mcp,
22-
load_skill,
2319
ls,
2420
read_range,
25-
remove_mcp,
26-
remove_skill,
21+
resource_manager,
2722
thinking,
2823
undo_change,
2924
update_todo_list,
@@ -33,7 +28,6 @@
3328
TOOL_MODULES = [
3429
command,
3530
command_interactive,
36-
context_manager,
3731
delegate,
3832
edit_text,
3933
explore_code,
@@ -45,13 +39,9 @@
4539
git_show,
4640
git_status,
4741
grep,
48-
list_mcp,
49-
load_mcp,
50-
load_skill,
5142
ls,
5243
read_range,
53-
remove_mcp,
54-
remove_skill,
44+
resource_manager,
5545
thinking,
5646
undo_change,
5747
update_todo_list,

cecli/tools/command.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ async def _execute_with_timeout(cls, coder, command_string, timeout, use_pty=Fal
310310
output_content = (
311311
f"[Large Response ({total_size} characters). "
312312
"Output saved to paginated files.]\n"
313-
f"File Aliases (for use with ContextManager):\n{alias_list_str}\n"
314-
"Use the `ContextManager` tool to view these files."
313+
f"File Aliases (for use with ResourceManager):\n{alias_list_str}\n"
314+
"Use the `ResourceManager` tool to view these files."
315315
"Do not use standard cli tools to view these files."
316316
"Remove them from context after taking notes on the relevant information "
317317
"to prevent overfilling stale context."
@@ -397,8 +397,8 @@ async def _execute_foreground(cls, coder, command_string):
397397
output_content = (
398398
f"[Large Response ({total_size} characters). "
399399
"Output saved to paginated files.]\n"
400-
f"File Aliases (for use with ContextManager):\n{alias_list_str}\n"
401-
"Use the `ContextManager` tool to view these files."
400+
f"File Aliases (for use with ResourceManager):\n{alias_list_str}\n"
401+
"Use the `ResourceManager` tool to view these files."
402402
"Do not use standard cli tools to view these files."
403403
"Remove them from context after taking note of the relevant information "
404404
"in the output to prevent overfilling stale context."

0 commit comments

Comments
 (0)