network-ai 3.9.0 → 4.0.0
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.md +2 -2
- package/bin/mcp-server.ts +266 -0
- package/dist/bin/mcp-server.d.ts +35 -0
- package/dist/bin/mcp-server.d.ts.map +1 -0
- package/dist/bin/mcp-server.js +248 -0
- package/dist/bin/mcp-server.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -6
- package/dist/index.js.map +1 -1
- package/dist/lib/mcp-tools-control.d.ts +90 -0
- package/dist/lib/mcp-tools-control.d.ts.map +1 -0
- package/dist/lib/mcp-tools-control.js +377 -0
- package/dist/lib/mcp-tools-control.js.map +1 -0
- package/dist/lib/mcp-tools-extended.d.ts +113 -0
- package/dist/lib/mcp-tools-extended.d.ts.map +1 -0
- package/dist/lib/mcp-tools-extended.js +371 -0
- package/dist/lib/mcp-tools-extended.js.map +1 -0
- package/dist/lib/mcp-transport-sse.d.ts +172 -0
- package/dist/lib/mcp-transport-sse.d.ts.map +1 -0
- package/dist/lib/mcp-transport-sse.js +445 -0
- package/dist/lib/mcp-transport-sse.js.map +1 -0
- package/package.json +6 -1
- package/dist/run-tests.d.ts +0 -9
- package/dist/run-tests.d.ts.map +0 -1
- package/dist/run-tests.js +0 -77
- package/dist/run-tests.js.map +0 -1
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Control-Plane MCP Tools — Phase 6 Part 4
|
|
4
|
+
*
|
|
5
|
+
* Exposes orchestrator configuration and agent lifecycle operations as MCP
|
|
6
|
+
* tools, giving an external AI agent full control-plane access to Network-AI.
|
|
7
|
+
*
|
|
8
|
+
* Tools exposed:
|
|
9
|
+
* config_get — read current CONFIG values
|
|
10
|
+
* config_set — update any CONFIG field at runtime
|
|
11
|
+
* agent_list — list all currently registered agents and their status
|
|
12
|
+
* agent_spawn — dispatch a task to a named agent
|
|
13
|
+
* agent_stop — mark a running agent as stopped
|
|
14
|
+
* fsm_transition — write an FSM state transition to the blackboard
|
|
15
|
+
* orchestrator_info — get orchestrator version, adapter count, blackboard stats
|
|
16
|
+
*
|
|
17
|
+
* @module mcp-tools-control
|
|
18
|
+
* @version 1.0.0
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.ControlMcpTools = void 0;
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// TOOL DEFINITIONS
|
|
24
|
+
// ============================================================================
|
|
25
|
+
const CONTROL_TOOL_DEFINITIONS = [
|
|
26
|
+
{
|
|
27
|
+
name: 'config_get',
|
|
28
|
+
description: 'Read the current Network-AI orchestrator configuration (maxParallelAgents, defaultTimeout, enableTracing, etc.).',
|
|
29
|
+
inputSchema: {
|
|
30
|
+
type: 'object',
|
|
31
|
+
properties: {
|
|
32
|
+
key: { type: 'string', description: 'Specific config key to read. Omit to return all values.' },
|
|
33
|
+
},
|
|
34
|
+
required: [],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'config_set',
|
|
39
|
+
description: 'Update a Network-AI configuration value at runtime. Changes take effect immediately for all subsequent operations.',
|
|
40
|
+
inputSchema: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
properties: {
|
|
43
|
+
key: { type: 'string', description: 'Config key to update (e.g. "maxParallelAgents", "defaultTimeout", "enableTracing")' },
|
|
44
|
+
value: { type: 'string', description: 'New value (JSON-encoded). E.g. "10" for a number, "true" for boolean, \'"string"\' for string.' },
|
|
45
|
+
},
|
|
46
|
+
required: ['key', 'value'],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'agent_list',
|
|
51
|
+
description: 'List all agents currently registered with the orchestrator, including their status and last activity.',
|
|
52
|
+
inputSchema: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
status_filter: { type: 'string', description: 'Filter by status (optional): active, idle, stopped, error' },
|
|
56
|
+
},
|
|
57
|
+
required: [],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'agent_spawn',
|
|
62
|
+
description: 'Dispatch a task to a named agent by writing a task record to the blackboard. The agent will pick it up on its next poll cycle.',
|
|
63
|
+
inputSchema: {
|
|
64
|
+
type: 'object',
|
|
65
|
+
properties: {
|
|
66
|
+
agent_id: { type: 'string', description: 'ID of the agent to assign the task to (e.g. "code_writer", "data_analyst")' },
|
|
67
|
+
task_key: { type: 'string', description: 'Blackboard key for the task (e.g. "task:write:auth_module")' },
|
|
68
|
+
instruction: { type: 'string', description: 'Natural language instruction for the agent' },
|
|
69
|
+
payload_json: { type: 'string', description: 'Optional JSON-encoded extra payload for the agent' },
|
|
70
|
+
ttl: { type: 'string', description: 'Time-to-live for the task entry in seconds (default: 3600)' },
|
|
71
|
+
},
|
|
72
|
+
required: ['agent_id', 'task_key', 'instruction'],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'agent_stop',
|
|
77
|
+
description: 'Signal an agent to stop by writing a stop record to the blackboard and updating its status.',
|
|
78
|
+
inputSchema: {
|
|
79
|
+
type: 'object',
|
|
80
|
+
properties: {
|
|
81
|
+
agent_id: { type: 'string', description: 'ID of the agent to stop' },
|
|
82
|
+
reason: { type: 'string', description: 'Reason for stopping (optional, for audit)' },
|
|
83
|
+
},
|
|
84
|
+
required: ['agent_id'],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: 'fsm_transition',
|
|
89
|
+
description: 'Manually advance an FSM (Finite State Machine) to a new state by writing the transition to the blackboard.',
|
|
90
|
+
inputSchema: {
|
|
91
|
+
type: 'object',
|
|
92
|
+
properties: {
|
|
93
|
+
fsm_id: { type: 'string', description: 'FSM identifier (e.g. "order_pipeline", "code_review_workflow")' },
|
|
94
|
+
new_state: { type: 'string', description: 'The state to transition to' },
|
|
95
|
+
metadata_json: { type: 'string', description: 'Optional JSON metadata to attach to the transition' },
|
|
96
|
+
agent_id: { type: 'string', description: 'Agent performing the transition (for audit)' },
|
|
97
|
+
},
|
|
98
|
+
required: ['fsm_id', 'new_state', 'agent_id'],
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'orchestrator_info',
|
|
103
|
+
description: 'Get a snapshot of the entire orchestrator: version, config, agent count, blackboard key count, and system health.',
|
|
104
|
+
inputSchema: {
|
|
105
|
+
type: 'object',
|
|
106
|
+
properties: {},
|
|
107
|
+
required: [],
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
// ============================================================================
|
|
112
|
+
// CONTROL MCP TOOLS
|
|
113
|
+
// ============================================================================
|
|
114
|
+
/**
|
|
115
|
+
* MCP tool provider for orchestrator control-plane operations.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* import { ControlMcpTools } from 'network-ai';
|
|
120
|
+
*
|
|
121
|
+
* const controlTools = new ControlMcpTools({
|
|
122
|
+
* config: CONFIG, // live reference — mutations take effect immediately
|
|
123
|
+
* agentRegistry: agentMap,
|
|
124
|
+
* blackboard: orchestrator.getBlackboard(),
|
|
125
|
+
* systemToken: 'system-orchestrator-token',
|
|
126
|
+
* });
|
|
127
|
+
*
|
|
128
|
+
* combined.register(controlTools);
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
class ControlMcpTools {
|
|
132
|
+
_config;
|
|
133
|
+
_agentRegistry;
|
|
134
|
+
_blackboard;
|
|
135
|
+
_systemToken;
|
|
136
|
+
_stoppedAgents = new Map(); // agentId -> reason
|
|
137
|
+
constructor(options) {
|
|
138
|
+
this._config = options.config;
|
|
139
|
+
this._agentRegistry = options.agentRegistry;
|
|
140
|
+
this._blackboard = options.blackboard;
|
|
141
|
+
this._systemToken = options.systemToken ?? 'system-orchestrator-token';
|
|
142
|
+
}
|
|
143
|
+
getDefinitions() {
|
|
144
|
+
return CONTROL_TOOL_DEFINITIONS;
|
|
145
|
+
}
|
|
146
|
+
async call(toolName, args) {
|
|
147
|
+
try {
|
|
148
|
+
switch (toolName) {
|
|
149
|
+
case 'config_get': return this._configGet(args);
|
|
150
|
+
case 'config_set': return this._configSet(args);
|
|
151
|
+
case 'agent_list': return this._agentList(args);
|
|
152
|
+
case 'agent_spawn': return this._agentSpawn(args);
|
|
153
|
+
case 'agent_stop': return this._agentStop(args);
|
|
154
|
+
case 'fsm_transition': return this._fsmTransition(args);
|
|
155
|
+
case 'orchestrator_info': return this._orchestratorInfo();
|
|
156
|
+
default:
|
|
157
|
+
return { ok: false, tool: toolName, error: `Unknown control tool: "${toolName}"` };
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
return { ok: false, tool: toolName, error: err instanceof Error ? err.message : String(err) };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// --------------------------------------------------------------------------
|
|
165
|
+
// Config tools
|
|
166
|
+
// --------------------------------------------------------------------------
|
|
167
|
+
_configGet(args) {
|
|
168
|
+
const key = args['key'] ? String(args['key']) : null;
|
|
169
|
+
if (key) {
|
|
170
|
+
if (!(key in this._config)) {
|
|
171
|
+
return { ok: false, tool: 'config_get', error: `Unknown config key: "${key}". Known keys: ${Object.keys(this._config).join(', ')}` };
|
|
172
|
+
}
|
|
173
|
+
return { ok: true, tool: 'config_get', data: { [key]: this._config[key] } };
|
|
174
|
+
}
|
|
175
|
+
// Return entire config (exclude any function values)
|
|
176
|
+
const snapshot = {};
|
|
177
|
+
for (const [k, v] of Object.entries(this._config)) {
|
|
178
|
+
if (typeof v !== 'function')
|
|
179
|
+
snapshot[k] = v;
|
|
180
|
+
}
|
|
181
|
+
return { ok: true, tool: 'config_get', data: snapshot };
|
|
182
|
+
}
|
|
183
|
+
_configSet(args) {
|
|
184
|
+
const key = String(args['key'] ?? '');
|
|
185
|
+
const rawValue = String(args['value'] ?? '');
|
|
186
|
+
if (!key)
|
|
187
|
+
return { ok: false, tool: 'config_set', error: 'key is required' };
|
|
188
|
+
if (!rawValue && rawValue !== '0')
|
|
189
|
+
return { ok: false, tool: 'config_set', error: 'value is required' };
|
|
190
|
+
let parsed;
|
|
191
|
+
try {
|
|
192
|
+
parsed = JSON.parse(rawValue);
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// Treat as raw string if not valid JSON
|
|
196
|
+
parsed = rawValue;
|
|
197
|
+
}
|
|
198
|
+
const previous = this._config[key];
|
|
199
|
+
this._config[key] = parsed;
|
|
200
|
+
return {
|
|
201
|
+
ok: true,
|
|
202
|
+
tool: 'config_set',
|
|
203
|
+
data: { key, previous, current: parsed, applied: true },
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
// --------------------------------------------------------------------------
|
|
207
|
+
// Agent tools
|
|
208
|
+
// --------------------------------------------------------------------------
|
|
209
|
+
_agentList(args) {
|
|
210
|
+
const statusFilter = args['status_filter'] ? String(args['status_filter']).toLowerCase() : null;
|
|
211
|
+
const agents = [];
|
|
212
|
+
if (this._agentRegistry) {
|
|
213
|
+
for (const [id, status] of this._agentRegistry) {
|
|
214
|
+
const entry = { ...status };
|
|
215
|
+
entry.agentId = id; // map key takes precedence
|
|
216
|
+
// Mark stopped agents
|
|
217
|
+
if (this._stoppedAgents.has(id)) {
|
|
218
|
+
entry.status = 'stopped';
|
|
219
|
+
entry.stopReason = this._stoppedAgents.get(id);
|
|
220
|
+
}
|
|
221
|
+
if (!statusFilter || String(entry.status).toLowerCase() === statusFilter) {
|
|
222
|
+
agents.push(entry);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// Also include stopped agents that may not be in the registry
|
|
227
|
+
for (const [id, reason] of this._stoppedAgents) {
|
|
228
|
+
if (!agents.find(a => a.agentId === id)) {
|
|
229
|
+
const entry = { agentId: id, status: 'stopped', stopReason: reason };
|
|
230
|
+
if (!statusFilter || statusFilter === 'stopped') {
|
|
231
|
+
agents.push(entry);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return { ok: true, tool: 'agent_list', data: { agents, count: agents.length } };
|
|
236
|
+
}
|
|
237
|
+
_agentSpawn(args) {
|
|
238
|
+
const agentId = String(args['agent_id'] ?? '');
|
|
239
|
+
const taskKey = String(args['task_key'] ?? '');
|
|
240
|
+
const instruction = String(args['instruction'] ?? '');
|
|
241
|
+
const ttl = Number(args['ttl']) || 3600;
|
|
242
|
+
if (!agentId)
|
|
243
|
+
return { ok: false, tool: 'agent_spawn', error: 'agent_id is required' };
|
|
244
|
+
if (!taskKey)
|
|
245
|
+
return { ok: false, tool: 'agent_spawn', error: 'task_key is required' };
|
|
246
|
+
if (!instruction)
|
|
247
|
+
return { ok: false, tool: 'agent_spawn', error: 'instruction is required' };
|
|
248
|
+
let extraPayload = undefined;
|
|
249
|
+
if (args['payload_json']) {
|
|
250
|
+
try {
|
|
251
|
+
extraPayload = JSON.parse(String(args['payload_json']));
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
return { ok: false, tool: 'agent_spawn', error: 'payload_json must be valid JSON' };
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const task = {
|
|
258
|
+
agentId,
|
|
259
|
+
instruction,
|
|
260
|
+
payload: extraPayload,
|
|
261
|
+
spawnedAt: new Date().toISOString(),
|
|
262
|
+
spawnedBy: 'mcp-control',
|
|
263
|
+
status: 'pending',
|
|
264
|
+
};
|
|
265
|
+
if (this._blackboard) {
|
|
266
|
+
this._blackboard.write(taskKey, JSON.stringify(task), 'mcp-control', ttl, this._systemToken);
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
ok: true,
|
|
270
|
+
tool: 'agent_spawn',
|
|
271
|
+
data: {
|
|
272
|
+
agentId,
|
|
273
|
+
taskKey,
|
|
274
|
+
task,
|
|
275
|
+
blackboardWritten: !!this._blackboard,
|
|
276
|
+
message: this._blackboard
|
|
277
|
+
? `Task written to blackboard at key "${taskKey}". Agent "${agentId}" will pick it up on next poll.`
|
|
278
|
+
: `No blackboard configured — task object returned but NOT persisted. Configure blackboard in ControlMcpTools.`,
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
_agentStop(args) {
|
|
283
|
+
const agentId = String(args['agent_id'] ?? '');
|
|
284
|
+
const reason = String(args['reason'] ?? 'stopped via MCP control tool');
|
|
285
|
+
if (!agentId)
|
|
286
|
+
return { ok: false, tool: 'agent_stop', error: 'agent_id is required' };
|
|
287
|
+
this._stoppedAgents.set(agentId, reason);
|
|
288
|
+
const stopKey = `agent:stop:${agentId}`;
|
|
289
|
+
if (this._blackboard) {
|
|
290
|
+
this._blackboard.write(stopKey, JSON.stringify({ agentId, reason, stoppedAt: new Date().toISOString() }), 'mcp-control', 300, this._systemToken);
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
ok: true,
|
|
294
|
+
tool: 'agent_stop',
|
|
295
|
+
data: { agentId, reason, stopped: true, blackboardWritten: !!this._blackboard },
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
// --------------------------------------------------------------------------
|
|
299
|
+
// FSM tool
|
|
300
|
+
// --------------------------------------------------------------------------
|
|
301
|
+
_fsmTransition(args) {
|
|
302
|
+
const fsmId = String(args['fsm_id'] ?? '');
|
|
303
|
+
const newState = String(args['new_state'] ?? '');
|
|
304
|
+
const agentId = String(args['agent_id'] ?? '');
|
|
305
|
+
if (!fsmId)
|
|
306
|
+
return { ok: false, tool: 'fsm_transition', error: 'fsm_id is required' };
|
|
307
|
+
if (!newState)
|
|
308
|
+
return { ok: false, tool: 'fsm_transition', error: 'new_state is required' };
|
|
309
|
+
if (!agentId)
|
|
310
|
+
return { ok: false, tool: 'fsm_transition', error: 'agent_id is required' };
|
|
311
|
+
let metadata = undefined;
|
|
312
|
+
if (args['metadata_json']) {
|
|
313
|
+
try {
|
|
314
|
+
metadata = JSON.parse(String(args['metadata_json']));
|
|
315
|
+
}
|
|
316
|
+
catch {
|
|
317
|
+
return { ok: false, tool: 'fsm_transition', error: 'metadata_json must be valid JSON' };
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const stateKey = `fsm:${fsmId}:state`;
|
|
321
|
+
const historyKey = `fsm:${fsmId}:history`;
|
|
322
|
+
let previousState = null;
|
|
323
|
+
if (this._blackboard) {
|
|
324
|
+
previousState = this._blackboard.read(stateKey)?.value ?? null;
|
|
325
|
+
}
|
|
326
|
+
const transition = {
|
|
327
|
+
from: previousState,
|
|
328
|
+
to: newState,
|
|
329
|
+
by: agentId,
|
|
330
|
+
at: new Date().toISOString(),
|
|
331
|
+
metadata,
|
|
332
|
+
};
|
|
333
|
+
if (this._blackboard) {
|
|
334
|
+
this._blackboard.write(stateKey, newState, agentId, undefined, this._systemToken);
|
|
335
|
+
// Append to history (read existing, push new entry)
|
|
336
|
+
const existing = this._blackboard.read(historyKey);
|
|
337
|
+
const history = existing ? JSON.parse(String(existing.value)) : [];
|
|
338
|
+
history.push(transition);
|
|
339
|
+
this._blackboard.write(historyKey, JSON.stringify(history), agentId, undefined, this._systemToken);
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
ok: true,
|
|
343
|
+
tool: 'fsm_transition',
|
|
344
|
+
data: { fsmId, transition, blackboardWritten: !!this._blackboard },
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
// --------------------------------------------------------------------------
|
|
348
|
+
// Info
|
|
349
|
+
// --------------------------------------------------------------------------
|
|
350
|
+
_orchestratorInfo() {
|
|
351
|
+
const snapshot = {};
|
|
352
|
+
for (const [k, v] of Object.entries(this._config)) {
|
|
353
|
+
if (typeof v !== 'function')
|
|
354
|
+
snapshot[k] = v;
|
|
355
|
+
}
|
|
356
|
+
const bbSnapshot = this._blackboard?.getSnapshot() ?? {};
|
|
357
|
+
return {
|
|
358
|
+
ok: true,
|
|
359
|
+
tool: 'orchestrator_info',
|
|
360
|
+
data: {
|
|
361
|
+
version: '4.0.0',
|
|
362
|
+
config: snapshot,
|
|
363
|
+
agents: {
|
|
364
|
+
registered: this._agentRegistry?.size ?? 0,
|
|
365
|
+
stopped: this._stoppedAgents.size,
|
|
366
|
+
},
|
|
367
|
+
blackboard: {
|
|
368
|
+
keys: Object.keys(bbSnapshot).length,
|
|
369
|
+
available: !!this._blackboard,
|
|
370
|
+
},
|
|
371
|
+
ts: new Date().toISOString(),
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
exports.ControlMcpTools = ControlMcpTools;
|
|
377
|
+
//# sourceMappingURL=mcp-tools-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tools-control.js","sourceRoot":"","sources":["../../lib/mcp-tools-control.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AA6CH,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E,MAAM,wBAAwB,GAAwB;IACpD;QACE,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,kHAAkH;QAC/H,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,yDAAyD,EAAE;aAChG;YACD,QAAQ,EAAE,EAAE;SACb;KACF;IACD;QACE,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,oHAAoH;QACjI,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,oFAAoF,EAAE;gBAC1H,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,gGAAgG,EAAE;aACzI;YACD,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC;SAC3B;KACF;IACD;QACE,IAAI,EAAE,YAAY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,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;QAEzD,OAAO;YACL,EAAE,EAAE,IAAI;YACR,IAAI,EAAE,mBAAmB;YACzB,IAAI,EAAE;gBACJ,OAAO,EAAE,OAAO;gBAChB,MAAM,EAAE,QAAQ;gBAChB,MAAM,EAAE;oBACN,UAAU,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,IAAI,CAAC;oBAC1C,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI;iBAClC;gBACD,UAAU,EAAE;oBACV,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM;oBACpC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW;iBAC9B;gBACD,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aAC7B;SACF,CAAC;IACJ,CAAC;CACF;AA7QD,0CA6QC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extended MCP Tools — Phase 6 Part 2
|
|
3
|
+
*
|
|
4
|
+
* Exposes budget, token, and audit operations as MCP-compatible tools so
|
|
5
|
+
* an external AI agent can manage Network-AI's security and resource planes
|
|
6
|
+
* without any code changes.
|
|
7
|
+
*
|
|
8
|
+
* Tool groups:
|
|
9
|
+
* Budget — budget_status, budget_spend, budget_reset, budget_set_ceiling, budget_get_log
|
|
10
|
+
* Token — token_validate, token_revoke, token_create
|
|
11
|
+
* Audit — audit_query, audit_tail
|
|
12
|
+
*
|
|
13
|
+
* @module mcp-tools-extended
|
|
14
|
+
* @version 1.0.0
|
|
15
|
+
*/
|
|
16
|
+
import type { MCPToolDefinition, BlackboardToolResult } from './mcp-blackboard-tools';
|
|
17
|
+
import type { McpToolProvider } from './mcp-transport-sse';
|
|
18
|
+
/** Minimal FederatedBudget surface needed by the tools. */
|
|
19
|
+
export interface IBudget {
|
|
20
|
+
spend(agentId: string, tokens: number): {
|
|
21
|
+
allowed: boolean;
|
|
22
|
+
remaining: number;
|
|
23
|
+
deniedReason?: string;
|
|
24
|
+
};
|
|
25
|
+
remaining(): number;
|
|
26
|
+
getTotalSpent(): number;
|
|
27
|
+
getCeiling(): number;
|
|
28
|
+
getSpendLog(): Record<string, number>;
|
|
29
|
+
getTransactionLog(): Array<{
|
|
30
|
+
agentId: string;
|
|
31
|
+
tokens: number;
|
|
32
|
+
timestamp: string;
|
|
33
|
+
}>;
|
|
34
|
+
setCeiling(ceiling: number): void;
|
|
35
|
+
reset(): void;
|
|
36
|
+
}
|
|
37
|
+
/** Minimal SecureTokenManager surface needed by the tools. */
|
|
38
|
+
export interface ITokenManager {
|
|
39
|
+
generateToken(agentId: string, resourceType: string, scope: string): {
|
|
40
|
+
tokenId: string;
|
|
41
|
+
agentId: string;
|
|
42
|
+
resourceType: string;
|
|
43
|
+
scope: string;
|
|
44
|
+
issuedAt: number;
|
|
45
|
+
expiresAt: number;
|
|
46
|
+
signature: string;
|
|
47
|
+
};
|
|
48
|
+
validateToken(token: {
|
|
49
|
+
tokenId: string;
|
|
50
|
+
agentId: string;
|
|
51
|
+
resourceType: string;
|
|
52
|
+
scope: string;
|
|
53
|
+
issuedAt: number;
|
|
54
|
+
expiresAt: number;
|
|
55
|
+
signature: string;
|
|
56
|
+
}): {
|
|
57
|
+
valid: boolean;
|
|
58
|
+
reason?: string;
|
|
59
|
+
};
|
|
60
|
+
revokeToken(tokenId: string): void;
|
|
61
|
+
}
|
|
62
|
+
/** Options for `ExtendedMcpTools`. All dependencies are optional. */
|
|
63
|
+
export interface ExtendedMcpToolsOptions {
|
|
64
|
+
/** FederatedBudget instance. Budget tools are disabled if not provided. */
|
|
65
|
+
budget?: IBudget;
|
|
66
|
+
/** SecureTokenManager instance. Token tools are disabled if not provided. */
|
|
67
|
+
tokenManager?: ITokenManager;
|
|
68
|
+
/** Absolute path to the audit log JSONL file. Defaults to `./data/audit_log.jsonl`. */
|
|
69
|
+
auditLogPath?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* MCP tool provider for budget, token, and audit operations.
|
|
73
|
+
*
|
|
74
|
+
* All three categories are optional — only provide the services you need.
|
|
75
|
+
* Tools for missing services return a clear `{ ok: false, error }` response.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* import { FederatedBudget, SecureTokenManager } from 'network-ai';
|
|
80
|
+
* import { ExtendedMcpTools } from 'network-ai';
|
|
81
|
+
*
|
|
82
|
+
* const tools = new ExtendedMcpTools({
|
|
83
|
+
* budget: new FederatedBudget({ ceiling: 100_000 }),
|
|
84
|
+
* tokenManager: new SecureTokenManager(),
|
|
85
|
+
* auditLogPath: './data/audit_log.jsonl',
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* // Register with McpCombinedBridge
|
|
89
|
+
* combined.register(tools);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare class ExtendedMcpTools implements McpToolProvider {
|
|
93
|
+
private readonly _budget?;
|
|
94
|
+
private readonly _tokenManager?;
|
|
95
|
+
private readonly _auditLogPath;
|
|
96
|
+
constructor(options?: ExtendedMcpToolsOptions);
|
|
97
|
+
getDefinitions(): MCPToolDefinition[];
|
|
98
|
+
call(toolName: string, args: Record<string, unknown>): Promise<BlackboardToolResult>;
|
|
99
|
+
private _budgetStatus;
|
|
100
|
+
private _budgetSpend;
|
|
101
|
+
private _budgetReset;
|
|
102
|
+
private _budgetSetCeiling;
|
|
103
|
+
private _budgetGetLog;
|
|
104
|
+
private _noBudget;
|
|
105
|
+
private _tokenCreate;
|
|
106
|
+
private _tokenValidate;
|
|
107
|
+
private _tokenRevoke;
|
|
108
|
+
private _noTokenManager;
|
|
109
|
+
private _auditQuery;
|
|
110
|
+
private _auditTail;
|
|
111
|
+
private _readAuditLog;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=mcp-tools-extended.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tools-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