🐛 Bug: MCP-spawned agents not registered with Communication/MessageRouter
- Dominant language
- TypeScript
- Stars
- 72.6k
- Forks
- 8.6k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 85
Description
## 🐛 Bug: MCP-spawned agents not registered with Communication/MessageRouter
### Bug Description
Agents spawned via MCP tools (`agent_spawn`, `mcp__claude-flow__agent_spawn`) cannot communicate with each other using `daa_communication`. The tool returns:
```
{ "success": false, "error": "Sender agent agent_xxx not found" }
```
### Reproduction Steps
```javascript
// 1. Initialize swarm
await mcp__claude-flow__swarm_init({ topology: "hierarchical" });
// 2. Spawn two agents
const agent1 = await mcp__claude-flow__agent_spawn({ type: "coder", name: "agent-a" });
const agent2 = await mcp__claude-flow__agent_spawn({ type: "tester", name: "agent-b" });
// 3. Attempt inter-agent communication
await mcp__claude-flow__daa_communication({
from: agent1.agentId,
to: agent2.agentId,
message: { type: "ping", content: "hello" }
});
// Returns: { success: false, error: "Sender agent agent_xxx not found" }
```
### Root Cause
Two issues identified in `src/mcp/mcp-server.js`:
**1. MCP spawn handler doesn't register with Communication system**
In the `agent_spawn` case (lines 1228-1287), the handler:
- ✅ Creates agent data object
- ✅ Stores in `memoryStore`
- ✅ Tracks in `global.agentTracker`
- ❌ Never calls `Communication.addAgent()` or registers with `MessageRouter`
**2. HiveMind pathway works correctly**
Compare to `src/hive-mind/core/HiveMind.ts:232`:
```typescript
this.communication.addAgent(agent);
```
The HiveMind spawn pathway correctly registers agents, but the MCP server has no reference to the `Communication` or `MessageRouter` instances.
### Environment
- claude-flow version: 2.7.42
- Node.js: v20.x
- Platform: Linux (also reproducible on other platforms)
- Usage: MCP tools via Claude Code
### Suggested Fix
**Option A: Inject Communication into MCP server**
```javascript
// In mcp-server.js, after line 1276 (agent tracking)
if (this.communication) {
this.communication.addAgent({
id: agentId,
name: agentData.name,
type: agentData.type,
capabilities: args.capabilities || []
});
}
```
**Option B: Lazy registration in daa_communication handler**
```javascript
// Auto-register from agentTracker if not in Communication
if (!this.communication.hasAgent(from)) {
const agentData = global.agentTracker?.getAgent(from);
if (agentData) {
this.communication.addAgent(agentData);
}
}
```
### Current Workaround
Using `memory_usage` (store/retrieve) for agent coordination instead of direct messaging. Functional but loses Communication benefits (priority queues, channels, latency monitoring).
### Testing
After applying the fix, agents spawned via MCP should be able to exchange messages via `daa_communication` the same way HiveMind-spawned agents can.
---
*Found while integrating claude-flow into a multi-agent coordination project. Happy to submit a PR if the approach looks right.*
Contributor guide
Assessment
This issue has not been assessed yet.