Skip to content

Commit 4caa4bb

Browse files
StuartF303claude
andcommitted
fix: Initialize AgentRegistry and TaskManager in server startup
- Create AgentRegistry instance with timeout checking enabled - Create TaskManager instance for queue management - Register current agent instance on startup - Pass both dependencies to CommandRegistry - Fix Capability type usage in DiscoveryCommands - Use correct AgentStatus enum values Fixes "Agent registry not available" error when using commands. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent dd4057d commit 4caa4bb

2 files changed

Lines changed: 50 additions & 11 deletions

File tree

packages/mcp-server/src/commands/handlers/DiscoveryCommands.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ export async function agentStatus(
153153
// Add capability information if available
154154
if (agent.capabilities) {
155155
const caps = agent.capabilities;
156-
if (caps.canExecuteCode !== undefined) {
157-
sections['Can Execute Code'] = caps.canExecuteCode ? 'Yes' : 'No';
156+
if (caps.tools && caps.tools.length > 0) {
157+
sections['Tools'] = caps.tools.join(', ');
158158
}
159-
if (caps.canReadFiles !== undefined) {
160-
sections['Can Read Files'] = caps.canReadFiles ? 'Yes' : 'No';
159+
if (caps.languages && caps.languages.length > 0) {
160+
sections['Languages'] = caps.languages.join(', ');
161161
}
162-
if (caps.canWriteFiles !== undefined) {
163-
sections['Can Write Files'] = caps.canWriteFiles ? 'Yes' : 'No';
162+
if (caps.apiAccess && caps.apiAccess.length > 0) {
163+
sections['API Access'] = caps.apiAccess.join(', ');
164164
}
165165
}
166166

packages/mcp-server/src/index.ts

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,46 @@ async function main() {
4949
});
5050
});
5151

52-
// Initialize CommandRegistry for command-based interaction
52+
// Initialize command infrastructure
5353
const { CommandRegistry } = await import('./commands/CommandRegistry.js');
54-
const registry = new CommandRegistry(channel);
54+
const { AgentRegistry } = await import('./agents/AgentRegistry.js');
55+
const { AgentStatus } = await import('./agents/Agent.js');
56+
const { TaskManager } = await import('./tasks/TaskManager.js');
57+
58+
// Create agent registry and task manager
59+
const agentRegistry = new AgentRegistry({ enableTimeoutChecking: true });
60+
const taskManager = new TaskManager();
61+
62+
// Register this agent instance
63+
const agentId = process.env.AGENT_ID || 'default-agent';
64+
const agentRole = process.env.AGENT_ROLE || 'developer';
65+
66+
// Determine platform
67+
let platform: 'Linux' | 'Windows' | 'macOS' = 'Linux';
68+
if (process.platform === 'win32') platform = 'Windows';
69+
else if (process.platform === 'darwin') platform = 'macOS';
70+
71+
await agentRegistry.add({
72+
id: agentId,
73+
role: agentRole,
74+
platform,
75+
environment: 'local',
76+
capabilities: {
77+
agentId,
78+
roleType: agentRole,
79+
platform,
80+
environmentType: 'local',
81+
tools: ['slack', 'node', 'typescript'],
82+
languages: ['typescript', 'javascript'],
83+
},
84+
status: AgentStatus.CONNECTED,
85+
currentTask: null,
86+
registeredAt: new Date(),
87+
lastSeenAt: new Date(),
88+
});
89+
90+
// Create command registry with full dependencies
91+
const commandRegistry = new CommandRegistry(channel, agentRegistry, taskManager);
5592

5693
// Set up text message handler (for plain text messages)
5794
channel.onTextMessage(async (text, userId) => {
@@ -79,7 +116,7 @@ async function main() {
79116

80117
// Route all other messages to CommandRegistry
81118
try {
82-
await registry.handleCommand(text, userId);
119+
await commandRegistry.handleCommand(text, userId);
83120
} catch (error) {
84121
console.error('❌ Command handling error:', error);
85122
}
@@ -100,8 +137,10 @@ async function main() {
100137
await channel.connect();
101138
console.log('✅ Connected successfully!');
102139
console.log(`📍 Channel ID: ${process.env.SLACK_CHANNEL_ID}`);
103-
console.log(`🤖 Agent ID: ${process.env.AGENT_ID || 'default-agent'}`);
104-
console.log(`👤 Agent Role: ${process.env.AGENT_ROLE || 'developer'}`);
140+
console.log(`🤖 Agent ID: ${agentId}`);
141+
console.log(`👤 Agent Role: ${agentRole}`);
142+
console.log(`📊 Agent Registry: ${agentRegistry.getAll().length} agent(s) registered`);
143+
console.log(`📝 Commands available: 30+ (type "help" in Slack)`);
105144
console.log('\n💬 Waiting for messages...\n');
106145
} catch (error) {
107146
console.error('❌ Failed to connect:', error);

0 commit comments

Comments
 (0)