forked from khaoss85/mcp-orchestro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_suggestion_workflow.mjs
More file actions
executable file
·290 lines (241 loc) · 9.99 KB
/
demo_suggestion_workflow.mjs
File metadata and controls
executable file
·290 lines (241 loc) · 9.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/usr/bin/env node
/**
* Demo Completo: Agent & Tool Suggestion Workflow
*
* Questo script dimostra:
* 1. Sync agenti Claude Code → Database
* 2. Inizializzazione MCP tools
* 3. Decomposizione task con AI suggestions
* 4. Enrichment del prompt con agenti e tools suggeriti
*/
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
const transport = new StdioClientTransport({
command: 'node',
args: ['dist/server.js'],
});
const client = new Client(
{ name: 'demo-client', version: '1.0.0' },
{ capabilities: {} }
);
async function main() {
try {
await client.connect(transport);
console.log('🎭 Connesso a Orchestro MCP Server\n');
// ============================================
// STEP 1: Get Project Info
// ============================================
console.log('📋 STEP 1: Recupero informazioni progetto...');
const projectInfo = await client.callTool({
name: 'get_project_info',
arguments: {},
});
const project = JSON.parse(projectInfo.content[0].text);
const projectId = project.id;
console.log(` ✅ Project: ${project.name} (${projectId})\n`);
// ============================================
// STEP 2: Sync Claude Code Agents
// ============================================
console.log('🔄 STEP 2: Sincronizzazione Claude Code agents...');
const syncResult = await client.callTool({
name: 'sync_claude_code_agents',
arguments: { projectId },
});
const syncData = JSON.parse(syncResult.content[0].text);
if (syncData.success) {
console.log(` ✅ Sincronizzati ${syncData.syncedCount} agenti:`);
for (const agent of syncData.agents) {
console.log(` - ${agent.name} (${agent.agentType})`);
}
} else {
console.log(` ❌ Errore sync: ${syncData.error}`);
}
console.log('');
// ============================================
// STEP 3: Initialize Project Configuration
// ============================================
console.log('⚙️ STEP 3: Inizializzazione configurazione progetto...');
const initResult = await client.callTool({
name: 'initialize_project_configuration',
arguments: { projectId },
});
const initData = JSON.parse(initResult.content[0].text);
if (initData.success) {
console.log(` ✅ Configurazione inizializzata:`);
console.log(` - Tech Stack: ${initData.techStack?.length || 0} framework`);
console.log(` - Sub Agents: ${initData.subAgents?.length || 0} agenti`);
console.log(` - MCP Tools: ${initData.mcpTools?.length || 0} tools`);
console.log(` - Guidelines: ${initData.guidelines?.length || 0} regole`);
}
console.log('');
// ============================================
// STEP 4: Decompose User Story con Suggestions
// ============================================
console.log('🎯 STEP 4: Decomposizione user story con AI suggestions...\n');
const userStory = 'Come sviluppatore, voglio implementare un sistema di autenticazione JWT con refresh token e rate limiting per proteggere le API';
console.log(`📝 User Story:\n "${userStory}"\n`);
const decomposeResult = await client.callTool({
name: 'decompose_story',
arguments: { userStory },
});
const decomposition = JSON.parse(decomposeResult.content[0].text);
if (!decomposition.success) {
console.error(` ❌ Decomposition failed: ${decomposition.error}`);
process.exit(1);
}
console.log(`✅ Creati ${decomposition.tasks.length} tasks con suggestions:\n`);
// ============================================
// STEP 5: Mostra Tasks con Agent e Tool Suggestions
// ============================================
console.log('📊 STEP 5: Tasks decomposed con AI suggestions:\n');
console.log('═'.repeat(80));
for (let i = 0; i < decomposition.tasks.length; i++) {
const taskInfo = decomposition.tasks[i];
const task = taskInfo.task;
const metadata = task.storyMetadata || {};
console.log(`\n📌 Task ${i + 1}: ${task.title}`);
console.log('─'.repeat(80));
console.log(` 📝 Description: ${task.description.substring(0, 100)}...`);
console.log(` ⏱️ Complexity: ${metadata.complexity || 'N/A'} (${metadata.estimatedHours || '?'} hours)`);
console.log(` 🏷️ Tags: ${(metadata.tags || []).join(', ') || 'None'}`);
// Agent Suggestion
if (metadata.suggestedAgent) {
const agent = metadata.suggestedAgent;
console.log(`\n 🤖 SUGGESTED AGENT:`);
console.log(` Name: ${agent.agentName}`);
console.log(` Type: ${agent.agentType}`);
console.log(` Confidence: ${(agent.confidence * 100).toFixed(0)}%`);
console.log(` Reason: ${agent.reason}`);
} else {
console.log(`\n 🤖 SUGGESTED AGENT: None`);
}
// Tool Suggestions
if (metadata.suggestedTools && metadata.suggestedTools.length > 0) {
console.log(`\n 🔧 SUGGESTED MCP TOOLS (${metadata.suggestedTools.length}):`);
metadata.suggestedTools.forEach((tool, idx) => {
console.log(` ${idx + 1}. ${tool.toolName} (${tool.category})`);
console.log(` Confidence: ${(tool.confidence * 100).toFixed(0)}%`);
console.log(` Reason: ${tool.reason}`);
});
} else {
console.log(`\n 🔧 SUGGESTED MCP TOOLS: None`);
}
}
console.log('\n' + '═'.repeat(80));
// ============================================
// STEP 6: Esempio Enrichment Prompt per Execution
// ============================================
console.log('\n\n💡 STEP 6: Esempio di prompt enrichment per task execution:\n');
const firstTask = decomposition.tasks[0];
const enrichedPrompt = buildEnrichedPrompt(firstTask, project);
console.log('─'.repeat(80));
console.log(enrichedPrompt);
console.log('─'.repeat(80));
// ============================================
// STEP 7: Configuration Summary
// ============================================
console.log('\n\n📊 STEP 7: Configuration Summary:\n');
const configResult = await client.callTool({
name: 'get_project_configuration',
arguments: { projectId },
});
const config = JSON.parse(configResult.content[0].text);
if (config.success && config.configuration) {
console.log('✅ Active Configuration:');
if (config.configuration.sub_agents?.length > 0) {
console.log(`\n🤖 Sub-Agents (${config.configuration.sub_agents.length}):`);
config.configuration.sub_agents.forEach(agent => {
console.log(` - ${agent.name} (${agent.agent_type})`);
console.log(` Enabled: ${agent.enabled}, Priority: ${agent.priority}`);
if (agent.triggers?.length > 0) {
console.log(` Triggers: ${agent.triggers.join(', ')}`);
}
});
}
if (config.configuration.mcp_tools?.length > 0) {
console.log(`\n🔧 MCP Tools (${config.configuration.mcp_tools.length}):`);
config.configuration.mcp_tools.forEach(tool => {
console.log(` - ${tool.name} (${tool.tool_type})`);
console.log(` Command: ${tool.command}`);
console.log(` When to use: ${(tool.when_to_use || []).join(', ')}`);
});
}
}
console.log('\n\n✅ Demo completata con successo!\n');
} catch (error) {
console.error('❌ Errore:', error.message);
} finally {
await client.close();
process.exit(0);
}
}
/**
* Build enriched prompt with agent and tool suggestions
*/
function buildEnrichedPrompt(taskInfo, project) {
const task = taskInfo.task;
const metadata = task.storyMetadata || {};
let prompt = `
🎯 TASK EXECUTION PROMPT (Enriched with AI Suggestions)
═══════════════════════════════════════════════════════════════════════════
📋 PROJECT: ${project.name}
📌 TASK: ${task.title}
📝 DESCRIPTION:
${task.description}
⏱️ METADATA:
- Complexity: ${metadata.complexity || 'medium'}
- Estimated Hours: ${metadata.estimatedHours || 'unknown'}
- Tags: ${(metadata.tags || []).join(', ') || 'None'}
`;
// Add suggested agent
if (metadata.suggestedAgent) {
const agent = metadata.suggestedAgent;
prompt += `
🤖 RECOMMENDED AGENT:
Name: ${agent.agentName}
Type: ${agent.agentType}
Confidence: ${(agent.confidence * 100).toFixed(0)}%
WHY THIS AGENT?
${agent.reason}
ACTION: Claude Code should invoke this agent via:
/task "Use ${agent.agentName} to: ${task.title}"
`;
}
// Add suggested tools
if (metadata.suggestedTools && metadata.suggestedTools.length > 0) {
prompt += `
🔧 RECOMMENDED MCP TOOLS:
`;
metadata.suggestedTools.forEach((tool, idx) => {
prompt += `
${idx + 1}. ${tool.toolName} (${tool.category}) - ${(tool.confidence * 100).toFixed(0)}% confidence
→ ${tool.reason}
`;
});
prompt += `
ACTION: Use these tools during implementation for optimal results.
`;
}
// Add execution steps
prompt += `
📋 SUGGESTED EXECUTION STEPS:
1. 🔍 ANALYSIS PHASE (use claude-context or sequential-thinking)
- Review existing codebase for similar patterns
- Identify affected files and dependencies
- Check architectural constraints
2. 🛠️ IMPLEMENTATION PHASE (use suggested agent: ${metadata.suggestedAgent?.agentName || 'general-purpose'})
- Follow project guidelines
- Implement according to task description
- Ensure code quality and testing
3. ✅ VALIDATION PHASE (use architecture-guardian, test-maintainer)
- Run guardian validations
- Execute tests
- Verify implementation against requirements
4. 📝 DOCUMENTATION
- Update relevant documentation
- Add code comments
- Record decisions made
`;
return prompt;
}
main().catch(console.error);