You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to use CPE as a sub-agent within other MCP-compliant environments (like Claude Desktop, another CPE instance, or other AI assistants).
Currently, CPE operates primarily as a CLI tool and MCP client. While it can consume other MCP servers, it cannot easily be consumed by others.
There is an existing issue (#104) for a native subagent tool, but a more composable and standard approach would be to expose CPE itself as an MCP Server. This would allow:
Composition: One CPE instance can call another CPE instance as a tool (sub-agent).
Interoperability: Any MCP client can utilize CPE's powerful "Code Mode" and agentic capabilities.
Structured Data: For CPE to be a useful tool, it often needs to return structured data (JSON) rather than just unstructured text to stdout.
Agent Hierarchies and Specialization: By exposing CPE as an MCP server, users can compose trees of specialized agents. A "root" agent could have access to tools like run_architect (a slow, reasoning-heavy CPE instance) and run_linter (a fast, specialized CPE instance). Since those sub-agents can themselves be CPE instances with their own MCP tools, this enables arbitrarily deep, customized agent trees.
Proposed Solution
1. New Command: cpe mcp serve
Implements the MCP Server protocol (Stdio transport). Exposes the subagent defined in the config as an MCP tool.
2. Subagent Configuration
Each cpe.yaml defines a single subagent. This keeps configs self-contained since each subagent can have drastically different requirements for system prompts, models, and tool configurations.
New top-level field:
# architect.cpe.yaml - specialized architect subagentversion: "1.0"subagent:
toolName: "consult_architect"toolDescription: "Consult an architect agent for high-level design decisions and system architecture planning. Returns structured analysis."outputSchemaPath: "./schemas/architect_response.json"models:
- ref: opusid: claude-opus-4-20250514type: anthropicapi_key_env: ANTHROPIC_API_KEY# ... full model configdefaults:
model: "opus"systemPromptPath: "./prompts/architect.prompt"codeMode:
enabled: falsemcpServers: {} # No tools needed for this agent
When outputSchemaPath is defined, CPE uses a final_answer tool pattern to enforce structured output:
Create a final_answer tool where the input schema = the output schema from the file
Register it with a nil callback (leveraging existing gai behavior where nil callbacks terminate execution immediately)
When the agent calls final_answer(...), generation terminates
Extract the tool call parameters from the returned dialog and return them as the subagent's structured output
This approach:
Avoids parsing unstructured LLM text output
Leverages native tool calling for schema validation
Uses existing gai infrastructure (no new callback machinery needed)
5. Tool Input Schema
Each exposed subagent tool accepts:
prompt (required string): The instruction for the subagent
inputs (optional array of strings): File paths or URLs to include as context
6. Bounded Parallelism Guidance
When code mode is enabled and subagent tools are available, the parent agent's system prompt should include guidance like:
When calling subagent tools, limit concurrent calls to 8 to avoid rate limiting issues.
This enables "wide" or fan-out intelligence patterns where the parent agent can dispatch multiple specialized subagents in parallel.
Alternatives Considered
Native Subagent Tool ([Enhancement]: Native Subagent Tool for Code Mode #104): Building a specific internal tool inside CPE to spawn child processes. While useful, it's specific to CPE. Making CPE an MCP server is more generic and standard.
Multiple subagents per config: Initially considered a subagents (plural) field defining multiple tools in one config. Rejected because each subagent benefits from having its own complete, self-contained configuration file.
Scripting: Wrapping CPE in shell scripts to parse output. This is brittle and doesn't handle structured data well.
Impact Scope
Users with MCP integrations
Additional Context
This aligns with the "Unix philosophy" of small, composable tools, but applied to AI agents. It leverages the existing "Code Mode" strength of CPE, making it available as a service to other agents.
Enhancement Category
New MCP tool/server integration
Problem or Use Case
I want to use CPE as a sub-agent within other MCP-compliant environments (like Claude Desktop, another CPE instance, or other AI assistants).
Currently, CPE operates primarily as a CLI tool and MCP client. While it can consume other MCP servers, it cannot easily be consumed by others.
There is an existing issue (#104) for a native subagent tool, but a more composable and standard approach would be to expose CPE itself as an MCP Server. This would allow:
run_architect(a slow, reasoning-heavy CPE instance) andrun_linter(a fast, specialized CPE instance). Since those sub-agents can themselves be CPE instances with their own MCP tools, this enables arbitrarily deep, customized agent trees.Proposed Solution
1. New Command:
cpe mcp serveImplements the MCP Server protocol (Stdio transport). Exposes the subagent defined in the config as an MCP tool.
2. Subagent Configuration
Each
cpe.yamldefines a single subagent. This keeps configs self-contained since each subagent can have drastically different requirements for system prompts, models, and tool configurations.New top-level field:
3. Parent Agent Configuration
The parent agent configures subagents as MCP servers:
4. Structured Output via
final_answerToolWhen
outputSchemaPathis defined, CPE uses afinal_answertool pattern to enforce structured output:final_answertool where the input schema = the output schema from the filefinal_answer(...), generation terminatesThis approach:
5. Tool Input Schema
Each exposed subagent tool accepts:
prompt(required string): The instruction for the subagentinputs(optional array of strings): File paths or URLs to include as context6. Bounded Parallelism Guidance
When code mode is enabled and subagent tools are available, the parent agent's system prompt should include guidance like:
This enables "wide" or fan-out intelligence patterns where the parent agent can dispatch multiple specialized subagents in parallel.
Alternatives Considered
subagents(plural) field defining multiple tools in one config. Rejected because each subagent benefits from having its own complete, self-contained configuration file.Impact Scope
Users with MCP integrations
Additional Context
This aligns with the "Unix philosophy" of small, composable tools, but applied to AI agents. It leverages the existing "Code Mode" strength of CPE, making it available as a service to other agents.