@agentrica/mcp 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +39 -5
- package/README.md +39 -5
- package/agents/ai_business_product_development_agency/00-common-rules.md +1 -0
- package/agents/ai_cybersecurity_agency/00-common-rules.md +1 -0
- package/agents/ai_privacy_compliance_agency/00-common-rules.md +1 -0
- package/agents/ai_software_agency/00-common-rules.md +7 -0
- package/agents/ai_web_design_agency/00-common-rules.md +2 -0
- package/dist/mcp/src/page/app.js +287 -0
- package/dist/mcp/src/page/index.html +44 -0
- package/dist/mcp/src/page/style.css +110 -0
- package/dist/mcp/src/panel.js +220 -0
- package/dist/mcp/src/project.js +192 -0
- package/dist/mcp/src/prompt.js +3 -3
- package/dist/mcp/src/server.js +113 -7
- package/package.json +2 -2
package/dist/mcp/src/server.js
CHANGED
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
// Server MCP di Agentrica su stdio: un prompt per agente e due tool (elenca_agenti, agente).
|
|
3
3
|
// Con --agents (es. --agents aisa,aiwda-08) prompt e tool vedono solo la squadra; senza, tutti gli agenti.
|
|
4
4
|
// Legge solo i file di agents/ all'avvio; non scrive file, non apre connessioni e non registra dati.
|
|
5
|
+
// Con --panel (F14) apre anche il pannello locale su 127.0.0.1 (panel.ts), che legge plan/, audit/ e lo stato di git
|
|
6
|
+
// della cartella corrente e aggiunge i tool open_panel e ask_user; le chiamate agli agenti restano solo in memoria.
|
|
7
|
+
import { realpathSync } from "node:fs";
|
|
5
8
|
import { join } from "node:path";
|
|
6
9
|
import { parseArgs } from "node:util";
|
|
7
10
|
import { loadCatalog } from "../../catalog/src/index.js";
|
|
8
11
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
9
12
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
10
13
|
import { z } from "zod";
|
|
14
|
+
import { openBrowser, startPanel } from "./panel.js";
|
|
11
15
|
import { agentSummary, agentText, codeName, findAgent, selectSquad, VERSION } from "./prompt.js";
|
|
12
16
|
// agents/ è in un punto fisso rispetto a questo file, senza risalire le cartelle: la cartella corrente è il progetto
|
|
13
17
|
// dell'utente e non deve poter fornire un'altra agents/. Tre livelli sopra c'è agents/ sia da un clone
|
|
@@ -24,8 +28,11 @@ function fail(message) {
|
|
|
24
28
|
}
|
|
25
29
|
const reason = (error) => (error instanceof Error ? error.message : String(error));
|
|
26
30
|
let spec;
|
|
31
|
+
let withPanel = false;
|
|
27
32
|
try {
|
|
28
|
-
|
|
33
|
+
const { values } = parseArgs({ options: { agents: { type: "string" }, panel: { type: "boolean" } } });
|
|
34
|
+
spec = values.agents;
|
|
35
|
+
withPanel = values.panel ?? false;
|
|
29
36
|
}
|
|
30
37
|
catch (error) {
|
|
31
38
|
fail(reason(error));
|
|
@@ -48,19 +55,47 @@ catch (error) {
|
|
|
48
55
|
const all = catalog.flatMap((department) => department.agents.map((agent) => ({ department, agent })));
|
|
49
56
|
const count = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
50
57
|
const codes = catalog.map((d) => d.code);
|
|
58
|
+
let panel;
|
|
59
|
+
if (withPanel) {
|
|
60
|
+
try {
|
|
61
|
+
panel = await startPanel(realpathSync(process.cwd()));
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
fail(`pannello non avviato: ${reason(error)}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Registra nel pannello che un agente è stato usato: id, nome in codice, ruolo e l'inizio del compito. */
|
|
68
|
+
function used({ department, agent }, task) {
|
|
69
|
+
const line = (task ?? "").replace(/\s+/g, " ").trim();
|
|
70
|
+
panel?.record({
|
|
71
|
+
id: agent.id,
|
|
72
|
+
codeName: codeName(agent),
|
|
73
|
+
role: agent.role,
|
|
74
|
+
department: department.code,
|
|
75
|
+
task: line.length > 120 ? `${line.slice(0, 119)}…` : line,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
51
78
|
const server = new McpServer({ name: "agentrica", version: VERSION }, {
|
|
52
79
|
instructions: `Agentrica: ${count(all.length, "agente IA", "agenti IA")} in ${count(catalog.length, "reparto", "reparti")} (${codes.join(", ")}). ` +
|
|
53
80
|
"Per scegliere un agente usa elenca_agenti; per lavorare come quell'agente carica le sue istruzioni con agente. " +
|
|
54
|
-
`I prompt hanno il nome dell'id dell'agente, es. ${all[0].agent.id.toLowerCase()}
|
|
81
|
+
`I prompt hanno il nome dell'id dell'agente, es. ${all[0].agent.id.toLowerCase()}.` +
|
|
82
|
+
(panel
|
|
83
|
+
? " Il pannello locale è attivo: per le scelte che spettano all'utente usa ask_user, che mostra la domanda nella pagina; open_panel dà l'URL della pagina."
|
|
84
|
+
: ""),
|
|
55
85
|
});
|
|
56
86
|
const TASK = z.string().max(20_000).optional().describe("Il compito da affidare all'agente nel progetto corrente.");
|
|
57
87
|
const READ_ONLY = { readOnlyHint: true, openWorldHint: false };
|
|
88
|
+
// Id ammesso: una sigla di tutto il catalogo (non solo della squadra, così fuori squadra è «non trovato») e due cifre.
|
|
89
|
+
const ID = new RegExp(`^(?:${full.map((d) => d.code).join("|")})-\\d{2}$`, "i");
|
|
58
90
|
for (const found of all) {
|
|
59
91
|
const title = `${codeName(found.agent)} — ${found.agent.role}`;
|
|
60
|
-
server.registerPrompt(found.agent.id.toLowerCase(), { title, description: agentSummary(found), argsSchema: { compito: TASK } }, ({ compito }) =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
92
|
+
server.registerPrompt(found.agent.id.toLowerCase(), { title, description: agentSummary(found), argsSchema: { compito: TASK } }, ({ compito }) => {
|
|
93
|
+
used(found, compito);
|
|
94
|
+
return {
|
|
95
|
+
description: title,
|
|
96
|
+
messages: [{ role: "user", content: { type: "text", text: agentText(found, compito) } }],
|
|
97
|
+
};
|
|
98
|
+
});
|
|
64
99
|
}
|
|
65
100
|
server.registerTool("elenca_agenti", {
|
|
66
101
|
title: "Elenca gli agenti di Agentrica",
|
|
@@ -82,7 +117,7 @@ server.registerTool("agente", {
|
|
|
82
117
|
title: "Istruzioni di un agente",
|
|
83
118
|
description: "Restituisce le istruzioni complete di un agente (regole comuni del reparto e file di ruolo), da seguire per lavorare come quell'agente.",
|
|
84
119
|
inputSchema: {
|
|
85
|
-
id: z.string().regex(
|
|
120
|
+
id: z.string().regex(ID, "Formato dell'id: SIGLA-NN, es. AISA-02.").describe("Id dell'agente, es. AISA-02."),
|
|
86
121
|
compito: TASK,
|
|
87
122
|
},
|
|
88
123
|
annotations: READ_ONLY,
|
|
@@ -94,6 +129,77 @@ server.registerTool("agente", {
|
|
|
94
129
|
content: [{ type: "text", text: "Agente non trovato: usa elenca_agenti per vedere gli id." }],
|
|
95
130
|
};
|
|
96
131
|
}
|
|
132
|
+
used(found, compito);
|
|
97
133
|
return { content: [{ type: "text", text: agentText(found, compito) }] };
|
|
98
134
|
});
|
|
135
|
+
if (panel)
|
|
136
|
+
registerPanelTools(panel);
|
|
137
|
+
function registerPanelTools(panel) {
|
|
138
|
+
const PROGRESS_MS = 30_000;
|
|
139
|
+
// Claude Code interrompe un tool stdio dopo 30 minuti senza risposta né avanzamento (plan/14-pannello.md, F14-01).
|
|
140
|
+
const WAIT_WITH_PROGRESS_MS = 4 * 60 * 60_000;
|
|
141
|
+
const WAIT_WITHOUT_PROGRESS_MS = 25 * 60_000;
|
|
142
|
+
server.registerTool("open_panel", {
|
|
143
|
+
title: "Apri il pannello di Agentrica",
|
|
144
|
+
description: "Apre nel browser il pannello locale del progetto (fasi, backlog, rilievi, agenti in uso, scelte in attesa) e ne restituisce l'URL.",
|
|
145
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
146
|
+
}, () => {
|
|
147
|
+
openBrowser(panel.url);
|
|
148
|
+
return {
|
|
149
|
+
content: [{ type: "text", text: `Pannello aperto nel browser. Se non si è aperto, l'utente può aprire questo URL, valido solo su questo computer: ${panel.url}` }],
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
const option = z.object({
|
|
153
|
+
label: z.string().min(1).max(80).describe("Etichetta breve dell'opzione."),
|
|
154
|
+
description: z.string().max(500).describe("Cosa comporta l'opzione, con la motivazione."),
|
|
155
|
+
});
|
|
156
|
+
server.registerTool("ask_user", {
|
|
157
|
+
title: "Chiedi una scelta all'utente nel pannello",
|
|
158
|
+
description: "Mostra all'utente, nel pannello locale, una scelta con 2–4 opzioni e aspetta la risposta (le etichette scelte e una nota facoltativa). " +
|
|
159
|
+
"Metti per prima l'opzione consigliata, con « (Consigliata)» alla fine dell'etichetta. Se l'utente non risponde, chiedi nel terminale.",
|
|
160
|
+
inputSchema: {
|
|
161
|
+
question: z.string().min(1).max(2000).describe("La domanda completa, comprensibile da sola."),
|
|
162
|
+
header: z.string().max(40).optional().describe("Titolo breve, es. «Strada»."),
|
|
163
|
+
options: z.array(option).min(2).max(4).describe("Le opzioni, la consigliata per prima."),
|
|
164
|
+
multiple: z.boolean().optional().describe("true se si può scegliere più di un'opzione."),
|
|
165
|
+
},
|
|
166
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
167
|
+
}, async ({ question, header, options, multiple }, extra) => {
|
|
168
|
+
const labels = options.map((o) => o.label);
|
|
169
|
+
if (new Set(labels).size !== labels.length) {
|
|
170
|
+
return { isError: true, content: [{ type: "text", text: "Le etichette delle opzioni devono essere diverse." }] };
|
|
171
|
+
}
|
|
172
|
+
const progressToken = extra._meta?.progressToken;
|
|
173
|
+
const wait = progressToken === undefined ? WAIT_WITHOUT_PROGRESS_MS : WAIT_WITH_PROGRESS_MS;
|
|
174
|
+
let progress = 0;
|
|
175
|
+
const ticker = progressToken === undefined
|
|
176
|
+
? undefined
|
|
177
|
+
: setInterval(() => {
|
|
178
|
+
extra
|
|
179
|
+
.sendNotification({
|
|
180
|
+
method: "notifications/progress",
|
|
181
|
+
params: { progressToken, progress: ++progress, message: "In attesa della risposta nel pannello" },
|
|
182
|
+
})
|
|
183
|
+
.catch(() => { });
|
|
184
|
+
}, PROGRESS_MS);
|
|
185
|
+
if (!panel.hasViewers())
|
|
186
|
+
openBrowser(panel.url);
|
|
187
|
+
try {
|
|
188
|
+
const answer = await panel.ask({ question, header: header ?? "", options, multiple: multiple ?? false }, AbortSignal.any([extra.signal, AbortSignal.timeout(wait)]));
|
|
189
|
+
const chosen = answer.choices.length ? `L'utente ha scelto: ${answer.choices.join("; ")}.` : "L'utente non ha scelto un'opzione.";
|
|
190
|
+
return { content: [{ type: "text", text: answer.note ? `${chosen}\nNota dell'utente: ${answer.note}` : chosen }] };
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
return {
|
|
194
|
+
content: [{ type: "text", text: `Nessuna risposta dal pannello entro ${Math.round(wait / 60_000)} minuti: chiedi all'utente nel terminale.` }],
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
finally {
|
|
198
|
+
clearInterval(ticker);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
99
202
|
await server.connect(new StdioServerTransport());
|
|
203
|
+
// Con il pannello, una pagina aperta tiene vivo il processo: quando il client chiude stdio, il server esce.
|
|
204
|
+
if (panel)
|
|
205
|
+
process.stdin.on("close", () => process.exit(0));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentrica/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"mcpName": "io.github.flgisimone/agentrica",
|
|
5
5
|
"description": "I 56 agenti IA di Agentrica come server MCP locale (stdio): un prompt per agente e due tool in sola lettura.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"node": ">=22"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"prepack": "rm -rf dist agents LICENSE && tsc -p tsconfig.build.json && cp -R ../../agents agents && cp ../../LICENSE LICENSE"
|
|
27
|
+
"prepack": "rm -rf dist agents LICENSE && tsc -p tsconfig.build.json && cp -R src/page dist/mcp/src/page && cp -R ../../agents agents && cp ../../LICENSE LICENSE"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@modelcontextprotocol/sdk": "1.32.2",
|