@anastops/mcp-server 0.1.0 → 1.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/dist/formatters.d.ts.map +1 -1
- package/dist/formatters.js +12 -3
- package/dist/formatters.js.map +1 -1
- package/dist/handlers/agent-handlers.d.ts +8 -0
- package/dist/handlers/agent-handlers.d.ts.map +1 -0
- package/dist/handlers/agent-handlers.js +184 -0
- package/dist/handlers/agent-handlers.js.map +1 -0
- package/dist/handlers/artifact-handlers.d.ts +8 -0
- package/dist/handlers/artifact-handlers.d.ts.map +1 -0
- package/dist/handlers/artifact-handlers.js +122 -0
- package/dist/handlers/artifact-handlers.js.map +1 -0
- package/dist/handlers/cost-handlers.d.ts +8 -0
- package/dist/handlers/cost-handlers.d.ts.map +1 -0
- package/dist/handlers/cost-handlers.js +140 -0
- package/dist/handlers/cost-handlers.js.map +1 -0
- package/dist/handlers/handlers.agent.d.ts +10 -0
- package/dist/handlers/handlers.agent.d.ts.map +1 -0
- package/dist/handlers/handlers.agent.js +99 -0
- package/dist/handlers/handlers.agent.js.map +1 -0
- package/dist/handlers/handlers.base.d.ts +82 -0
- package/dist/handlers/handlers.base.d.ts.map +1 -0
- package/dist/handlers/handlers.base.js +337 -0
- package/dist/handlers/handlers.base.js.map +1 -0
- package/dist/handlers/handlers.lock.d.ts +8 -0
- package/dist/handlers/handlers.lock.d.ts.map +1 -0
- package/dist/handlers/handlers.lock.js +111 -0
- package/dist/handlers/handlers.lock.js.map +1 -0
- package/dist/handlers/handlers.memory.d.ts +11 -0
- package/dist/handlers/handlers.memory.d.ts.map +1 -0
- package/dist/handlers/handlers.memory.js +122 -0
- package/dist/handlers/handlers.memory.js.map +1 -0
- package/dist/handlers/handlers.monitoring.d.ts +8 -0
- package/dist/handlers/handlers.monitoring.d.ts.map +1 -0
- package/dist/handlers/handlers.monitoring.js +99 -0
- package/dist/handlers/handlers.monitoring.js.map +1 -0
- package/dist/handlers/handlers.orchestration.d.ts +9 -0
- package/dist/handlers/handlers.orchestration.d.ts.map +1 -0
- package/dist/handlers/handlers.orchestration.js +128 -0
- package/dist/handlers/handlers.orchestration.js.map +1 -0
- package/dist/handlers/handlers.session.d.ts +18 -0
- package/dist/handlers/handlers.session.d.ts.map +1 -0
- package/dist/handlers/handlers.session.js +286 -0
- package/dist/handlers/handlers.session.js.map +1 -0
- package/dist/handlers/handlers.task.d.ts +15 -0
- package/dist/handlers/handlers.task.d.ts.map +1 -0
- package/dist/handlers/handlers.task.js +753 -0
- package/dist/handlers/handlers.task.js.map +1 -0
- package/dist/handlers/handlers.utility.d.ts +10 -0
- package/dist/handlers/handlers.utility.d.ts.map +1 -0
- package/dist/handlers/handlers.utility.js +59 -0
- package/dist/handlers/handlers.utility.js.map +1 -0
- package/dist/handlers/index.d.ts +18 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +209 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/lock-handlers.d.ts +8 -0
- package/dist/handlers/lock-handlers.d.ts.map +1 -0
- package/dist/handlers/lock-handlers.js +154 -0
- package/dist/handlers/lock-handlers.js.map +1 -0
- package/dist/handlers/memory-handlers.d.ts +8 -0
- package/dist/handlers/memory-handlers.d.ts.map +1 -0
- package/dist/handlers/memory-handlers.js +76 -0
- package/dist/handlers/memory-handlers.js.map +1 -0
- package/dist/handlers/orchestration-handlers.d.ts +8 -0
- package/dist/handlers/orchestration-handlers.d.ts.map +1 -0
- package/dist/handlers/orchestration-handlers.js +113 -0
- package/dist/handlers/orchestration-handlers.js.map +1 -0
- package/dist/handlers/session-handlers.d.ts +8 -0
- package/dist/handlers/session-handlers.d.ts.map +1 -0
- package/dist/handlers/session-handlers.js +558 -0
- package/dist/handlers/session-handlers.js.map +1 -0
- package/dist/handlers/task-handlers.d.ts +8 -0
- package/dist/handlers/task-handlers.d.ts.map +1 -0
- package/dist/handlers/task-handlers.js +677 -0
- package/dist/handlers/task-handlers.js.map +1 -0
- package/dist/handlers/tool-definitions.d.ts +2626 -0
- package/dist/handlers/tool-definitions.d.ts.map +1 -0
- package/dist/handlers/tool-definitions.js +641 -0
- package/dist/handlers/tool-definitions.js.map +1 -0
- package/dist/handlers/types.d.ts +90 -0
- package/dist/handlers/types.d.ts.map +1 -0
- package/dist/handlers/types.js +5 -0
- package/dist/handlers/types.js.map +1 -0
- package/dist/handlers/utility-handlers.d.ts +8 -0
- package/dist/handlers/utility-handlers.d.ts.map +1 -0
- package/dist/handlers/utility-handlers.js +113 -0
- package/dist/handlers/utility-handlers.js.map +1 -0
- package/dist/handlers/utils.d.ts +30 -0
- package/dist/handlers/utils.d.ts.map +1 -0
- package/dist/handlers/utils.js +95 -0
- package/dist/handlers/utils.js.map +1 -0
- package/dist/handlers.d.ts +17 -2260
- package/dist/handlers.d.ts.map +1 -1
- package/dist/handlers.js +17 -1836
- package/dist/handlers.js.map +1 -1
- package/dist/index.js +41 -7
- package/dist/index.js.map +1 -1
- package/dist/persistence.d.ts.map +1 -1
- package/dist/persistence.js +84 -47
- package/dist/persistence.js.map +1 -1
- package/dist/schemas.d.ts +299 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +334 -0
- package/dist/schemas.js.map +1 -0
- package/package.json +8 -5
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for MCP tool handlers
|
|
3
|
+
*/
|
|
4
|
+
import type { AdapterRegistry } from '@anastops/adapters';
|
|
5
|
+
import type { SessionManager, Agent, Artifact, Session, Task } from '@anastops/core';
|
|
6
|
+
import type { LRUCache } from 'lru-cache';
|
|
7
|
+
/**
|
|
8
|
+
* MCP Tool Definition schema
|
|
9
|
+
*/
|
|
10
|
+
export interface ToolDefinition {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
inputSchema: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Memory store value type
|
|
17
|
+
*/
|
|
18
|
+
export interface MemoryStoreValue {
|
|
19
|
+
value: Record<string, unknown>;
|
|
20
|
+
stored_at: Date;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Session report structure from persistence layer
|
|
24
|
+
*/
|
|
25
|
+
export interface SessionReport {
|
|
26
|
+
session: {
|
|
27
|
+
id: string;
|
|
28
|
+
objective: string;
|
|
29
|
+
status: string;
|
|
30
|
+
created_at: Date;
|
|
31
|
+
updated_at: Date;
|
|
32
|
+
metadata: {
|
|
33
|
+
total_tokens: number;
|
|
34
|
+
total_cost: number;
|
|
35
|
+
agents_used: string[];
|
|
36
|
+
files_affected: string[];
|
|
37
|
+
tasks_completed: number;
|
|
38
|
+
tasks_failed: number;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
tasks: Task[];
|
|
42
|
+
agents: Agent[];
|
|
43
|
+
artifacts: Artifact[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Context passed to all handler functions
|
|
47
|
+
*/
|
|
48
|
+
export interface HandlerContext {
|
|
49
|
+
sessions: Map<string, Session>;
|
|
50
|
+
tasks: Map<string, Task>;
|
|
51
|
+
agents: Map<string, Agent>;
|
|
52
|
+
artifacts: Map<string, Artifact>;
|
|
53
|
+
memoryStore: LRUCache<string, MemoryStoreValue>;
|
|
54
|
+
sessionManager: SessionManager;
|
|
55
|
+
registry: AdapterRegistry;
|
|
56
|
+
getPersistence: () => {
|
|
57
|
+
saveSession: (session: Session) => Promise<void>;
|
|
58
|
+
getTask: (taskId: string) => Promise<Task | null>;
|
|
59
|
+
saveTask: (task: Task) => Promise<void>;
|
|
60
|
+
listTasks: (filters: Record<string, unknown>) => Promise<Task[]>;
|
|
61
|
+
getAgent: (agentId: string) => Promise<Agent | null>;
|
|
62
|
+
saveAgent: (agent: Agent) => Promise<void>;
|
|
63
|
+
listAgents: (filters: Record<string, unknown>) => Promise<Agent[]>;
|
|
64
|
+
getArtifact: (artifactId: string) => Promise<Artifact | null>;
|
|
65
|
+
saveArtifact: (artifact: Artifact) => Promise<void>;
|
|
66
|
+
listArtifacts: (filters: Record<string, unknown>) => Promise<Artifact[]>;
|
|
67
|
+
listSessions: (filters: Record<string, unknown>) => Promise<Session[]>;
|
|
68
|
+
getSessionReport: (sessionId: string) => Promise<SessionReport | null>;
|
|
69
|
+
getAllSessionReports: (filters: Record<string, unknown>) => Promise<SessionReport[]>;
|
|
70
|
+
deleteSession: (sessionId: string) => Promise<boolean>;
|
|
71
|
+
deleteSessions: (filters: Record<string, unknown>) => Promise<{
|
|
72
|
+
deleted_count: number;
|
|
73
|
+
session_ids: string[];
|
|
74
|
+
}>;
|
|
75
|
+
};
|
|
76
|
+
safePersist: (promise: Promise<void>) => void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* TOON-encoded response wrapper type
|
|
80
|
+
*/
|
|
81
|
+
export interface TOONEncodedResponse {
|
|
82
|
+
data: unknown;
|
|
83
|
+
encoding?: 'toon' | 'json';
|
|
84
|
+
token_reduction?: {
|
|
85
|
+
original: number;
|
|
86
|
+
encoded: number;
|
|
87
|
+
savings_percent: number;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA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QACvD,cAAc,EAAE,CACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,OAAO,CAAC;YAAE,aAAa,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAC;KAChE,CAAC;IACF,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;CAC/C;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,eAAe,CAAC,EAAE;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility handlers
|
|
3
|
+
* Handles: health_check, provider_list, metrics_get, config_get, config_set
|
|
4
|
+
*/
|
|
5
|
+
import type { HandlerContext, ToolDefinition } from './types.js';
|
|
6
|
+
export declare const toolDefinitions: ToolDefinition[];
|
|
7
|
+
export declare function handleTool(name: string, args: Record<string, unknown>, context: HandlerContext): Promise<unknown>;
|
|
8
|
+
//# sourceMappingURL=utility-handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility-handlers.d.ts","sourceRoot":"","sources":["../../src/handlers/utility-handlers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjE,eAAO,MAAM,eAAe,EAAE,cAAc,EA8C3C,CAAC;AAEF,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,OAAO,CAAC,CAqElB"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility handlers
|
|
3
|
+
* Handles: health_check, provider_list, metrics_get, config_get, config_set
|
|
4
|
+
*/
|
|
5
|
+
export const toolDefinitions = [
|
|
6
|
+
{
|
|
7
|
+
name: 'health_check',
|
|
8
|
+
description: 'Check system health',
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: { include_providers: { type: 'boolean' } },
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'provider_list',
|
|
16
|
+
description: 'List available AI providers',
|
|
17
|
+
inputSchema: {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
filter_healthy: { type: 'boolean' },
|
|
21
|
+
include_capabilities: { type: 'boolean' },
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'metrics_get',
|
|
27
|
+
description: 'Get system metrics',
|
|
28
|
+
inputSchema: {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: { metric_type: { type: 'string', enum: ['routing', 'tokens', 'costs', 'all'] } },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'config_get',
|
|
35
|
+
description: 'Get configuration value',
|
|
36
|
+
inputSchema: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: { key: { type: 'string' } },
|
|
39
|
+
required: ['key'],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'config_set',
|
|
44
|
+
description: 'Set configuration value',
|
|
45
|
+
inputSchema: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: { key: { type: 'string' }, value: {} },
|
|
48
|
+
required: ['key', 'value'],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
export async function handleTool(name, args, context) {
|
|
53
|
+
switch (name) {
|
|
54
|
+
case 'health_check': {
|
|
55
|
+
const result = {
|
|
56
|
+
status: 'healthy',
|
|
57
|
+
timestamp: new Date(),
|
|
58
|
+
components: { core: 'healthy', router: 'healthy', memory: 'in-memory' },
|
|
59
|
+
};
|
|
60
|
+
if (args['include_providers'] === true) {
|
|
61
|
+
const providerHealth = {};
|
|
62
|
+
for (const adapter of context.registry.list()) {
|
|
63
|
+
const health = await adapter.healthCheck();
|
|
64
|
+
providerHealth[adapter.type] = { healthy: health.healthy, error: health.error };
|
|
65
|
+
}
|
|
66
|
+
result['providers'] = providerHealth;
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
case 'provider_list': {
|
|
71
|
+
const providers = [];
|
|
72
|
+
for (const adapter of context.registry.list()) {
|
|
73
|
+
const health = await adapter.healthCheck();
|
|
74
|
+
if (args['filter_healthy'] === true && !health.healthy)
|
|
75
|
+
continue;
|
|
76
|
+
const info = {
|
|
77
|
+
type: adapter.type,
|
|
78
|
+
name: adapter.name,
|
|
79
|
+
healthy: health.healthy,
|
|
80
|
+
};
|
|
81
|
+
if (args['include_capabilities'] === true) {
|
|
82
|
+
const caps = await adapter.getCapabilities();
|
|
83
|
+
info['capabilities'] = caps;
|
|
84
|
+
}
|
|
85
|
+
providers.push(info);
|
|
86
|
+
}
|
|
87
|
+
return { count: providers.length, providers };
|
|
88
|
+
}
|
|
89
|
+
case 'metrics_get': {
|
|
90
|
+
// Placeholder metrics
|
|
91
|
+
return {
|
|
92
|
+
routing: { tier_distribution: {}, provider_stats: {} },
|
|
93
|
+
tokens: { total: 0, by_provider: {} },
|
|
94
|
+
costs: { total: 0, by_provider: {} },
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
case 'config_get': {
|
|
98
|
+
// Placeholder config
|
|
99
|
+
const config = {
|
|
100
|
+
default_provider: 'claude',
|
|
101
|
+
default_timeout: 600000, // 10 minutes
|
|
102
|
+
context_budget: 1600,
|
|
103
|
+
};
|
|
104
|
+
return { key: args['key'], value: config[args['key']] };
|
|
105
|
+
}
|
|
106
|
+
case 'config_set': {
|
|
107
|
+
return { key: args['key'], value: args['value'], updated: true };
|
|
108
|
+
}
|
|
109
|
+
default:
|
|
110
|
+
throw new Error(`Unknown utility tool: ${name}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=utility-handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility-handlers.js","sourceRoot":"","sources":["../../src/handlers/utility-handlers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,CAAC,MAAM,eAAe,GAAqB;IAC/C;QACE,IAAI,EAAE,cAAc;QACpB,WAAW,EAAE,qBAAqB;QAClC,WAAW,EAAE;YACX,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE,EAAE,iBAAiB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE;SACvD;KACF;IACD;QACE,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,6BAA6B;QAC1C,WAAW,EAAE;YACX,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,cAAc,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;gBACnC,oBAAoB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;aAC1C;SACF;KACF;IACD;QACE,IAAI,EAAE,aAAa;QACnB,WAAW,EAAE,oBAAoB;QACjC,WAAW,EAAE;YACX,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE;SAC7F;KACF;IACD;QACE,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,yBAA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AQ;gBAC1B,eAAe,EAAE,MAAM,EAAE,aAAa;gBACtC,cAAc,EAAE,IAAI;aACrB,CAAC;YACF,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAW,CAAC,EAAE,CAAC;QACpE,CAAC;QAED,KAAK,YAAY,CAAC,CAAC,CAAC;YAClB,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACnE,CAAC;QAED;YACE,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;IACrD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for MCP tool handlers
|
|
3
|
+
* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return
|
|
4
|
+
*/
|
|
5
|
+
import type { Agent, Artifact, Task } from '@anastops/core';
|
|
6
|
+
import type { HandlerContext } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Safe fire-and-forget wrapper for persistence operations
|
|
9
|
+
* Catches errors to prevent uncaught promise rejections from crashing the server
|
|
10
|
+
*/
|
|
11
|
+
export declare function safePersist<T>(operation: Promise<T>): void;
|
|
12
|
+
/**
|
|
13
|
+
* Get task from memory or MongoDB
|
|
14
|
+
* Loads from MongoDB and caches in memory if not found
|
|
15
|
+
*/
|
|
16
|
+
export declare function getTask(taskId: string, context: HandlerContext): Promise<Task | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Get agent from memory or MongoDB
|
|
19
|
+
*/
|
|
20
|
+
export declare function getAgent(agentId: string, context: HandlerContext): Promise<Agent | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Get artifact from memory or MongoDB
|
|
23
|
+
*/
|
|
24
|
+
export declare function getArtifact(artifactId: string, context: HandlerContext): Promise<Artifact | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Sanitize error message for external exposure
|
|
27
|
+
* SECURITY: Never expose internal details like stack traces, paths, or credentials
|
|
28
|
+
*/
|
|
29
|
+
export declare function sanitizeErrorMessage(error: unknown): string;
|
|
30
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/handlers/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAI5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAU1D;AAED;;;GAGG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAgB3F;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAa9F;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC/B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAa1B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAwB3D"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for MCP tool handlers
|
|
3
|
+
* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return
|
|
4
|
+
*/
|
|
5
|
+
import { getLogger } from '@anastops/core';
|
|
6
|
+
import { ZodError } from 'zod';
|
|
7
|
+
/**
|
|
8
|
+
* Safe fire-and-forget wrapper for persistence operations
|
|
9
|
+
* Catches errors to prevent uncaught promise rejections from crashing the server
|
|
10
|
+
*/
|
|
11
|
+
export function safePersist(operation) {
|
|
12
|
+
operation.catch((error) => {
|
|
13
|
+
const logger = getLogger();
|
|
14
|
+
logger.error({
|
|
15
|
+
error: error instanceof Error ? error.message : String(error),
|
|
16
|
+
}, 'Persistence error during tool execution');
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get task from memory or MongoDB
|
|
21
|
+
* Loads from MongoDB and caches in memory if not found
|
|
22
|
+
*/
|
|
23
|
+
export async function getTask(taskId, context) {
|
|
24
|
+
// Check in-memory first
|
|
25
|
+
const memTask = context.tasks.get(taskId);
|
|
26
|
+
if (memTask !== undefined) {
|
|
27
|
+
return memTask;
|
|
28
|
+
}
|
|
29
|
+
// Try to load from MongoDB
|
|
30
|
+
const dbTask = await context.getPersistence().getTask(taskId);
|
|
31
|
+
if (dbTask !== null) {
|
|
32
|
+
// Cache in memory for subsequent access
|
|
33
|
+
context.tasks.set(taskId, dbTask);
|
|
34
|
+
return dbTask;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get agent from memory or MongoDB
|
|
40
|
+
*/
|
|
41
|
+
export async function getAgent(agentId, context) {
|
|
42
|
+
const memAgent = context.agents.get(agentId);
|
|
43
|
+
if (memAgent !== undefined) {
|
|
44
|
+
return memAgent;
|
|
45
|
+
}
|
|
46
|
+
const dbAgent = await context.getPersistence().getAgent(agentId);
|
|
47
|
+
if (dbAgent !== null) {
|
|
48
|
+
context.agents.set(agentId, dbAgent);
|
|
49
|
+
return dbAgent;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get artifact from memory or MongoDB
|
|
55
|
+
*/
|
|
56
|
+
export async function getArtifact(artifactId, context) {
|
|
57
|
+
const memArtifact = context.artifacts.get(artifactId);
|
|
58
|
+
if (memArtifact !== undefined) {
|
|
59
|
+
return memArtifact;
|
|
60
|
+
}
|
|
61
|
+
const dbArtifact = await context.getPersistence().getArtifact(artifactId);
|
|
62
|
+
if (dbArtifact !== null) {
|
|
63
|
+
context.artifacts.set(artifactId, dbArtifact);
|
|
64
|
+
return dbArtifact;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Sanitize error message for external exposure
|
|
70
|
+
* SECURITY: Never expose internal details like stack traces, paths, or credentials
|
|
71
|
+
*/
|
|
72
|
+
export function sanitizeErrorMessage(error) {
|
|
73
|
+
if (error instanceof ZodError) {
|
|
74
|
+
// Return validation errors with field details but no internal info
|
|
75
|
+
const issues = error.issues.map((issue) => ({
|
|
76
|
+
path: issue.path.join('.'),
|
|
77
|
+
message: issue.message,
|
|
78
|
+
}));
|
|
79
|
+
return `Validation error: ${JSON.stringify(issues)}`;
|
|
80
|
+
}
|
|
81
|
+
if (error instanceof Error) {
|
|
82
|
+
const message = error.message;
|
|
83
|
+
// Redact sensitive patterns
|
|
84
|
+
const sensitized = message
|
|
85
|
+
.replace(/mongodb:\/\/[^@]+@/gi, 'mongodb://***@') // MongoDB credentials
|
|
86
|
+
.replace(/redis:\/\/[^@]+@/gi, 'redis://***@') // Redis credentials
|
|
87
|
+
.replace(/password[=:]["']?[^"'\s]+["']?/gi, 'password=***') // Generic passwords
|
|
88
|
+
.replace(/\/Users\/[^/]+\//g, '/****/') // User paths
|
|
89
|
+
.replace(/\/home\/[^/]+\//g, '/****/') // User paths
|
|
90
|
+
.replace(/api[_-]?key[=:]["']?[^"'\s]+["']?/gi, 'api_key=***'); // API keys
|
|
91
|
+
return sensitized;
|
|
92
|
+
}
|
|
93
|
+
return 'An unexpected error occurred';
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/handlers/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAI/B;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAI,SAAqB;IAClD,SAAS,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACxB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;QAC3B,MAAM,CAAC,KAAK,CACV;YACE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,EACD,yCAAyC,CAC1C,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,MAAc,EAAE,OAAuB;IACnE,wBAAwB;IACxB,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,2BAA2B;IAC3B,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9D,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,wCAAwC;QACxC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAClC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GA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