neuroverse 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/LICENSE +19 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +12 -0
- package/dist/constants.js.map +1 -0
- package/dist/core/intent.d.ts +18 -0
- package/dist/core/intent.d.ts.map +1 -0
- package/dist/core/intent.js +85 -0
- package/dist/core/intent.js.map +1 -0
- package/dist/core/language.d.ts +24 -0
- package/dist/core/language.d.ts.map +1 -0
- package/dist/core/language.js +120 -0
- package/dist/core/language.js.map +1 -0
- package/dist/core/memory.d.ts +29 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +119 -0
- package/dist/core/memory.js.map +1 -0
- package/dist/core/router.d.ts +22 -0
- package/dist/core/router.d.ts.map +1 -0
- package/dist/core/router.js +118 -0
- package/dist/core/router.js.map +1 -0
- package/dist/core/safety.d.ts +23 -0
- package/dist/core/safety.d.ts.map +1 -0
- package/dist/core/safety.js +147 -0
- package/dist/core/safety.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +355 -0
- package/dist/index.js.map +1 -0
- package/dist/services/agent-router.d.ts +12 -0
- package/dist/services/agent-router.d.ts.map +1 -0
- package/dist/services/agent-router.js +36 -0
- package/dist/services/agent-router.js.map +1 -0
- package/dist/services/executor.d.ts +9 -0
- package/dist/services/executor.d.ts.map +1 -0
- package/dist/services/executor.js +63 -0
- package/dist/services/executor.js.map +1 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +32 -0
- package/dist/types.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kavach — 3-Layer Safety Engine.
|
|
3
|
+
*
|
|
4
|
+
* Layer 1: Rule-based blocklist (keywords + regex) — zero tokens, < 1ms
|
|
5
|
+
* Layer 2: Intent risk classification (deterministic map)
|
|
6
|
+
* Layer 3: Optional LLM judge (async, costs tokens)
|
|
7
|
+
*
|
|
8
|
+
* Action Guard:
|
|
9
|
+
* CRITICAL / HIGH → always block
|
|
10
|
+
* MEDIUM + strict mode → block
|
|
11
|
+
* LOW → always allow
|
|
12
|
+
*/
|
|
13
|
+
import { RiskLevel } from "../types.js";
|
|
14
|
+
import type { ExtractedIntent, SafetyVerdict, LLMCall } from "../types.js";
|
|
15
|
+
export declare function setStrictMode(enabled: boolean): void;
|
|
16
|
+
declare function checkBlocklist(rawText: string, intent: ExtractedIntent): SafetyVerdict | null;
|
|
17
|
+
declare function classifyRisk(intent: ExtractedIntent): RiskLevel;
|
|
18
|
+
/**
|
|
19
|
+
* Run the full 3-layer safety pipeline.
|
|
20
|
+
*/
|
|
21
|
+
export declare function checkSafety(intent: ExtractedIntent, rawText?: string, llmCall?: LLMCall): Promise<SafetyVerdict>;
|
|
22
|
+
export { checkBlocklist as _checkBlocklist, classifyRisk as _classifyRisk };
|
|
23
|
+
//# sourceMappingURL=safety.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safety.d.ts","sourceRoot":"","sources":["../../src/core/safety.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAM3E,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAEpD;AA0BD,iBAAS,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,aAAa,GAAG,IAAI,CA0BtF;AAiBD,iBAAS,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,CAExD;AAqCD;;GAEG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,MAAW,EACpB,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,aAAa,CAAC,CAsCxB;AAGD,OAAO,EAAE,cAAc,IAAI,eAAe,EAAE,YAAY,IAAI,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kavach — 3-Layer Safety Engine.
|
|
3
|
+
*
|
|
4
|
+
* Layer 1: Rule-based blocklist (keywords + regex) — zero tokens, < 1ms
|
|
5
|
+
* Layer 2: Intent risk classification (deterministic map)
|
|
6
|
+
* Layer 3: Optional LLM judge (async, costs tokens)
|
|
7
|
+
*
|
|
8
|
+
* Action Guard:
|
|
9
|
+
* CRITICAL / HIGH → always block
|
|
10
|
+
* MEDIUM + strict mode → block
|
|
11
|
+
* LOW → always allow
|
|
12
|
+
*/
|
|
13
|
+
import { RiskLevel } from "../types.js";
|
|
14
|
+
// ─── Configuration ──────────────────────────────────────────────────────
|
|
15
|
+
let strictMode = false;
|
|
16
|
+
export function setStrictMode(enabled) {
|
|
17
|
+
strictMode = enabled;
|
|
18
|
+
}
|
|
19
|
+
// ─── Layer 1: Blocklist ─────────────────────────────────────────────────
|
|
20
|
+
const BLOCKED_KEYWORDS = [
|
|
21
|
+
"delete_all_data",
|
|
22
|
+
"drop_database",
|
|
23
|
+
"drop_table",
|
|
24
|
+
"system_shutdown",
|
|
25
|
+
"format_disk",
|
|
26
|
+
"rm -rf",
|
|
27
|
+
"truncate",
|
|
28
|
+
"shutdown",
|
|
29
|
+
"reboot",
|
|
30
|
+
"erase_all",
|
|
31
|
+
"destroy",
|
|
32
|
+
];
|
|
33
|
+
const BLOCKED_PATTERNS = [
|
|
34
|
+
/\bdrop\s+(database|table|schema)\b/i,
|
|
35
|
+
/\bdelete\s+from\s+\*/i,
|
|
36
|
+
/\btruncate\s+table\b/i,
|
|
37
|
+
/\bformat\s+[a-z]:/i,
|
|
38
|
+
/\brm\s+(-rf|--force)\b/i,
|
|
39
|
+
];
|
|
40
|
+
function checkBlocklist(rawText, intent) {
|
|
41
|
+
const combined = `${rawText} ${intent.intent}`.toLowerCase();
|
|
42
|
+
for (const kw of BLOCKED_KEYWORDS) {
|
|
43
|
+
if (combined.includes(kw)) {
|
|
44
|
+
return {
|
|
45
|
+
allowed: false,
|
|
46
|
+
riskLevel: RiskLevel.CRITICAL,
|
|
47
|
+
reason: `Blocked keyword detected: '${kw}'`,
|
|
48
|
+
blockedBy: "rule",
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
for (const pattern of BLOCKED_PATTERNS) {
|
|
53
|
+
if (pattern.test(combined)) {
|
|
54
|
+
return {
|
|
55
|
+
allowed: false,
|
|
56
|
+
riskLevel: RiskLevel.CRITICAL,
|
|
57
|
+
reason: `Blocked pattern matched: ${pattern.source}`,
|
|
58
|
+
blockedBy: "rule",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null; // no match
|
|
63
|
+
}
|
|
64
|
+
// ─── Layer 2: Intent risk map ───────────────────────────────────────────
|
|
65
|
+
const INTENT_RISK_MAP = {
|
|
66
|
+
delete_data: RiskLevel.HIGH,
|
|
67
|
+
drop_database: RiskLevel.CRITICAL,
|
|
68
|
+
system_shutdown: RiskLevel.CRITICAL,
|
|
69
|
+
send_message: RiskLevel.MEDIUM,
|
|
70
|
+
convert_format: RiskLevel.LOW,
|
|
71
|
+
summarize: RiskLevel.LOW,
|
|
72
|
+
generate_report: RiskLevel.LOW,
|
|
73
|
+
query_data: RiskLevel.LOW,
|
|
74
|
+
explain: RiskLevel.LOW,
|
|
75
|
+
unknown: RiskLevel.MEDIUM,
|
|
76
|
+
};
|
|
77
|
+
function classifyRisk(intent) {
|
|
78
|
+
return INTENT_RISK_MAP[intent.intent] ?? RiskLevel.MEDIUM;
|
|
79
|
+
}
|
|
80
|
+
// ─── Layer 3: Optional LLM judge ────────────────────────────────────────
|
|
81
|
+
async function modelSafetyCheck(intent, rawText, llmCall) {
|
|
82
|
+
const prompt = `You are a safety classifier. Given the following user request and ` +
|
|
83
|
+
`extracted intent, respond with ONLY a JSON object:\n` +
|
|
84
|
+
`{"safe": true/false, "reason": "..."}\n\n` +
|
|
85
|
+
`User request: ${rawText}\n` +
|
|
86
|
+
`Intent: ${intent.intent}\n` +
|
|
87
|
+
`Parameters: ${JSON.stringify(intent.parameters)}\n`;
|
|
88
|
+
try {
|
|
89
|
+
const raw = await llmCall(prompt);
|
|
90
|
+
const result = JSON.parse(raw.trim());
|
|
91
|
+
if (!result.safe) {
|
|
92
|
+
return {
|
|
93
|
+
allowed: false,
|
|
94
|
+
riskLevel: RiskLevel.HIGH,
|
|
95
|
+
reason: result.reason ?? "Model-based check flagged this action.",
|
|
96
|
+
blockedBy: "model",
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// If model fails, default to allowing (layers 1+2 already passed)
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
// ─── Public API ─────────────────────────────────────────────────────────
|
|
106
|
+
/**
|
|
107
|
+
* Run the full 3-layer safety pipeline.
|
|
108
|
+
*/
|
|
109
|
+
export async function checkSafety(intent, rawText = "", llmCall) {
|
|
110
|
+
// Layer 1: Blocklist
|
|
111
|
+
const blocklistVerdict = checkBlocklist(rawText, intent);
|
|
112
|
+
if (blocklistVerdict)
|
|
113
|
+
return blocklistVerdict;
|
|
114
|
+
// Layer 2: Risk classification
|
|
115
|
+
const risk = classifyRisk(intent);
|
|
116
|
+
if (risk === RiskLevel.HIGH || risk === RiskLevel.CRITICAL) {
|
|
117
|
+
return {
|
|
118
|
+
allowed: false,
|
|
119
|
+
riskLevel: risk,
|
|
120
|
+
reason: `Intent '${intent.intent}' classified as ${risk} risk.`,
|
|
121
|
+
blockedBy: "intent_risk",
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (risk === RiskLevel.MEDIUM && strictMode) {
|
|
125
|
+
return {
|
|
126
|
+
allowed: false,
|
|
127
|
+
riskLevel: risk,
|
|
128
|
+
reason: `Intent '${intent.intent}' is medium risk; strict mode is enabled.`,
|
|
129
|
+
blockedBy: "intent_risk",
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// Layer 3: Optional model check
|
|
133
|
+
if (llmCall) {
|
|
134
|
+
const modelVerdict = await modelSafetyCheck(intent, rawText, llmCall);
|
|
135
|
+
if (modelVerdict)
|
|
136
|
+
return modelVerdict;
|
|
137
|
+
}
|
|
138
|
+
// All clear
|
|
139
|
+
return {
|
|
140
|
+
allowed: true,
|
|
141
|
+
riskLevel: risk,
|
|
142
|
+
reason: "All safety checks passed.",
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
// Re-export helpers for testing
|
|
146
|
+
export { checkBlocklist as _checkBlocklist, classifyRisk as _classifyRisk };
|
|
147
|
+
//# sourceMappingURL=safety.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safety.js","sourceRoot":"","sources":["../../src/core/safety.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,2EAA2E;AAE3E,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,UAAU,GAAG,OAAO,CAAC;AACvB,CAAC;AAED,2EAA2E;AAE3E,MAAM,gBAAgB,GAAa;IACjC,iBAAiB;IACjB,eAAe;IACf,YAAY;IACZ,iBAAiB;IACjB,aAAa;IACb,QAAQ;IACR,UAAU;IACV,UAAU;IACV,QAAQ;IACR,WAAW;IACX,SAAS;CACV,CAAC;AAEF,MAAM,gBAAgB,GAAa;IACjC,qCAAqC;IACrC,uBAAuB;IACvB,uBAAuB;IACvB,oBAAoB;IACpB,yBAAyB;CAC1B,CAAC;AAEF,SAAS,cAAc,CAAC,OAAe,EAAE,MAAuB;IAC9D,MAAM,QA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AAE,IAAI;YACf,MAAM,EAAE,WAAW,MAAM,CAAC,MAAM,mBAAmB,IAAI,QAAQ;YAC/D,SAAS,EAAE,aAAa;SACzB,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,KAAK,SAAS,CAAC,MAAM,IAAI,UAAU,EAAE,CAAC;QAC5C,OAAO;YACL,OAAO,EAAE,KAAK;YACd,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,WAAW,MAAM,CAAC,MAAM,2CAA2C;YAC3E,SAAS,EAAE,aAAa;SACzB,CAAC;IACJ,CAAC;IAED,gCAAgC;IAChC,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,YAAY,GAAG,MAAM,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACtE,IAAI,YAAY;YAAE,OAAO,YAAY,CAAC;IACxC,CAAC;IAED,YAAY;IACZ,OAAO;QACL,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,2BAA2B;KACpC,CAAC;AACJ,CAAC;AAED,gCAAgC;AAChC,OAAO,EAAE,cAAc,IAAI,eAAe,EAAE,YAAY,IAAI,aAAa,EAAE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* NeuroVerse — India-First Multilingual MCP Server (npm edition).
|
|
4
|
+
*
|
|
5
|
+
* Exposes 6 tools via Model Context Protocol:
|
|
6
|
+
* 1. neuroverse_process — Full multilingual pipeline
|
|
7
|
+
* 2. neuroverse_store — Store memory
|
|
8
|
+
* 3. neuroverse_recall — Recall memories
|
|
9
|
+
* 4. neuroverse_execute — Safe end-to-end execution
|
|
10
|
+
* 5. neuroverse_route — Route to downstream agent
|
|
11
|
+
* 6. neuroverse_model — Query multi-model router
|
|
12
|
+
*
|
|
13
|
+
* Install: npm install neuroverse
|
|
14
|
+
* Run: npx neuroverse (or node dist/index.js)
|
|
15
|
+
*
|
|
16
|
+
* Built by Joshua Ragiland M — Joshuaragiland.com
|
|
17
|
+
*/
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;GAeG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* NeuroVerse — India-First Multilingual MCP Server (npm edition).
|
|
4
|
+
*
|
|
5
|
+
* Exposes 6 tools via Model Context Protocol:
|
|
6
|
+
* 1. neuroverse_process — Full multilingual pipeline
|
|
7
|
+
* 2. neuroverse_store — Store memory
|
|
8
|
+
* 3. neuroverse_recall — Recall memories
|
|
9
|
+
* 4. neuroverse_execute — Safe end-to-end execution
|
|
10
|
+
* 5. neuroverse_route — Route to downstream agent
|
|
11
|
+
* 6. neuroverse_model — Query multi-model router
|
|
12
|
+
*
|
|
13
|
+
* Install: npm install neuroverse
|
|
14
|
+
* Run: npx neuroverse (or node dist/index.js)
|
|
15
|
+
*
|
|
16
|
+
* Built by Joshua Ragiland M — Joshuaragiland.com
|
|
17
|
+
*/
|
|
18
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
19
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
import { detectLanguage } from "./core/language.js";
|
|
22
|
+
import { extractIntent } from "./core/intent.js";
|
|
23
|
+
import { checkSafety, setStrictMode } from "./core/safety.js";
|
|
24
|
+
import { storeMemory, recallMemory } from "./core/memory.js";
|
|
25
|
+
import { routeTask, callLLM, configureRouter } from "./core/router.js";
|
|
26
|
+
import { executeIntent } from "./services/executor.js";
|
|
27
|
+
import { routeToAgent } from "./services/agent-router.js";
|
|
28
|
+
// ─── Configuration from environment ────────────────────────────────────
|
|
29
|
+
configureRouter({
|
|
30
|
+
openaiApiKey: process.env["OPENAI_API_KEY"],
|
|
31
|
+
anthropicApiKey: process.env["ANTHROPIC_API_KEY"],
|
|
32
|
+
sarvamApiKey: process.env["SARVAM_API_KEY"],
|
|
33
|
+
ollamaBaseUrl: process.env["OLLAMA_BASE_URL"] ?? "http://localhost:11434",
|
|
34
|
+
});
|
|
35
|
+
if (process.env["SAFETY_STRICT_MODE"] === "true") {
|
|
36
|
+
setStrictMode(true);
|
|
37
|
+
}
|
|
38
|
+
// ─── Create MCP server ─────────────────────────────────────────────────
|
|
39
|
+
const server = new McpServer({
|
|
40
|
+
name: "neuroverse-mcp-server",
|
|
41
|
+
version: "1.0.0",
|
|
42
|
+
});
|
|
43
|
+
// ─── Tool 1: neuroverse_process ─────────────────────────────────────────
|
|
44
|
+
const ProcessInputSchema = z
|
|
45
|
+
.object({
|
|
46
|
+
text: z
|
|
47
|
+
.string()
|
|
48
|
+
.min(1, "Text is required")
|
|
49
|
+
.max(5000, "Text must not exceed 5000 characters")
|
|
50
|
+
.describe("Raw user input (may be code-switched, e.g. Tamil+English)"),
|
|
51
|
+
user_id: z
|
|
52
|
+
.string()
|
|
53
|
+
.default("anonymous")
|
|
54
|
+
.describe("Identifier for the user / agent"),
|
|
55
|
+
execute: z
|
|
56
|
+
.boolean()
|
|
57
|
+
.default(true)
|
|
58
|
+
.describe("If true, also execute the extracted intent after safety check"),
|
|
59
|
+
})
|
|
60
|
+
.strict();
|
|
61
|
+
server.registerTool("neuroverse_process", {
|
|
62
|
+
title: "Process Multilingual Input",
|
|
63
|
+
description: `Process mixed-language input through the full NeuroVerse pipeline.
|
|
64
|
+
|
|
65
|
+
Pipeline: Language Detect → Normalise → Intent Extract → Safety Check → (optional) Execute
|
|
66
|
+
|
|
67
|
+
Supported languages: Tamil, Hindi, Telugu, Kannada + English (code-switched).
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
- text (string): Raw user input, possibly code-switched
|
|
71
|
+
- user_id (string): User / agent identifier (default: "anonymous")
|
|
72
|
+
- execute (boolean): Whether to also execute the intent (default: true)
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
JSON with keys: language, intent, safety, execution (if execute=true)
|
|
76
|
+
|
|
77
|
+
Examples:
|
|
78
|
+
- "anna indha file ah csv convert pannu" → detects Tamil+English, extracts convert_format
|
|
79
|
+
- "report banao sales ka" → detects Hindi+English, extracts generate_report
|
|
80
|
+
- "drop database production" → BLOCKED by safety layer`,
|
|
81
|
+
inputSchema: ProcessInputSchema,
|
|
82
|
+
annotations: {
|
|
83
|
+
readOnlyHint: false,
|
|
84
|
+
destructiveHint: false,
|
|
85
|
+
idempotentHint: true,
|
|
86
|
+
openWorldHint: true,
|
|
87
|
+
},
|
|
88
|
+
}, async (params) => {
|
|
89
|
+
const lang = detectLanguage(params.text);
|
|
90
|
+
const intent = await extractIntent(lang.normalizedText);
|
|
91
|
+
const safety = await checkSafety(intent, params.text);
|
|
92
|
+
const result = {
|
|
93
|
+
language: lang,
|
|
94
|
+
intent,
|
|
95
|
+
safety,
|
|
96
|
+
};
|
|
97
|
+
if (params.execute) {
|
|
98
|
+
const exec = await executeIntent(intent, safety);
|
|
99
|
+
result["execution"] = exec;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
// ─── Tool 2: neuroverse_store ───────────────────────────────────────────
|
|
106
|
+
const StoreMemorySchema = z
|
|
107
|
+
.object({
|
|
108
|
+
user_id: z.string().min(1).describe("Agent / user identifier"),
|
|
109
|
+
intent: z.string().min(1).describe("Canonical intent this memory relates to"),
|
|
110
|
+
tier: z
|
|
111
|
+
.enum(["short_term", "episodic", "semantic"])
|
|
112
|
+
.default("short_term")
|
|
113
|
+
.describe("Memory tier"),
|
|
114
|
+
language: z.string().default("en").describe("Primary language code"),
|
|
115
|
+
data: z
|
|
116
|
+
.record(z.unknown())
|
|
117
|
+
.default({})
|
|
118
|
+
.describe("Structured memory payload"),
|
|
119
|
+
importance_score: z
|
|
120
|
+
.number()
|
|
121
|
+
.min(0)
|
|
122
|
+
.max(1)
|
|
123
|
+
.default(0.5)
|
|
124
|
+
.describe("Importance score — only above 0.4 are persisted for episodic/semantic"),
|
|
125
|
+
})
|
|
126
|
+
.strict();
|
|
127
|
+
server.registerTool("neuroverse_store", {
|
|
128
|
+
title: "Store Memory",
|
|
129
|
+
description: `Store a memory record in NeuroVerse's tiered memory system.
|
|
130
|
+
|
|
131
|
+
Tiers:
|
|
132
|
+
- short_term: In-process, capped at 50 per user. Lost on restart.
|
|
133
|
+
- episodic: Persisted to JSON file. Recent actions.
|
|
134
|
+
- semantic: Persisted to JSON file. Long-term facts.
|
|
135
|
+
|
|
136
|
+
Only episodic/semantic memories with importance_score ≥ 0.4 are persisted.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
- user_id (string): Agent / user identifier
|
|
140
|
+
- intent (string): Canonical intent name
|
|
141
|
+
- tier (string): short_term | episodic | semantic
|
|
142
|
+
- language (string): Language code (default: "en")
|
|
143
|
+
- data (object): Structured payload
|
|
144
|
+
- importance_score (number): 0.0–1.0
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
JSON of the stored MemoryRecord`,
|
|
148
|
+
inputSchema: StoreMemorySchema,
|
|
149
|
+
annotations: {
|
|
150
|
+
readOnlyHint: false,
|
|
151
|
+
destructiveHint: false,
|
|
152
|
+
idempotentHint: false,
|
|
153
|
+
openWorldHint: false,
|
|
154
|
+
},
|
|
155
|
+
}, async (params) => {
|
|
156
|
+
const record = storeMemory({
|
|
157
|
+
userId: params.user_id,
|
|
158
|
+
intent: params.intent,
|
|
159
|
+
tier: params.tier,
|
|
160
|
+
language: params.language,
|
|
161
|
+
data: params.data,
|
|
162
|
+
importanceScore: params.importance_score,
|
|
163
|
+
});
|
|
164
|
+
return {
|
|
165
|
+
content: [{ type: "text", text: JSON.stringify(record, null, 2) }],
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
// ─── Tool 3: neuroverse_recall ──────────────────────────────────────────
|
|
169
|
+
const RecallMemorySchema = z
|
|
170
|
+
.object({
|
|
171
|
+
user_id: z.string().min(1).describe("Agent / user identifier"),
|
|
172
|
+
intent: z.string().optional().describe("Filter by intent"),
|
|
173
|
+
tier: z
|
|
174
|
+
.enum(["short_term", "episodic", "semantic"])
|
|
175
|
+
.optional()
|
|
176
|
+
.describe("Filter by tier"),
|
|
177
|
+
limit: z.number().int().min(1).max(100).default(10).describe("Max results"),
|
|
178
|
+
})
|
|
179
|
+
.strict();
|
|
180
|
+
server.registerTool("neuroverse_recall", {
|
|
181
|
+
title: "Recall Memory",
|
|
182
|
+
description: `Retrieve memories from NeuroVerse's tiered memory system.
|
|
183
|
+
|
|
184
|
+
Args:
|
|
185
|
+
- user_id (string): Agent / user identifier
|
|
186
|
+
- intent (string, optional): Filter by intent
|
|
187
|
+
- tier (string, optional): Filter by tier
|
|
188
|
+
- limit (number): Max results (1–100, default 10)
|
|
189
|
+
|
|
190
|
+
Returns:
|
|
191
|
+
JSON array of matching MemoryRecords`,
|
|
192
|
+
inputSchema: RecallMemorySchema,
|
|
193
|
+
annotations: {
|
|
194
|
+
readOnlyHint: true,
|
|
195
|
+
destructiveHint: false,
|
|
196
|
+
idempotentHint: true,
|
|
197
|
+
openWorldHint: false,
|
|
198
|
+
},
|
|
199
|
+
}, async (params) => {
|
|
200
|
+
const results = recallMemory({
|
|
201
|
+
userId: params.user_id,
|
|
202
|
+
intent: params.intent,
|
|
203
|
+
tier: params.tier,
|
|
204
|
+
limit: params.limit,
|
|
205
|
+
});
|
|
206
|
+
return {
|
|
207
|
+
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
|
|
208
|
+
};
|
|
209
|
+
});
|
|
210
|
+
// ─── Tool 4: neuroverse_execute ─────────────────────────────────────────
|
|
211
|
+
const SafeExecuteSchema = z
|
|
212
|
+
.object({
|
|
213
|
+
text: z
|
|
214
|
+
.string()
|
|
215
|
+
.min(1)
|
|
216
|
+
.max(5000)
|
|
217
|
+
.describe("Raw user input to parse, safety-check, and execute"),
|
|
218
|
+
user_id: z.string().default("anonymous").describe("User / agent ID"),
|
|
219
|
+
})
|
|
220
|
+
.strict();
|
|
221
|
+
server.registerTool("neuroverse_execute", {
|
|
222
|
+
title: "Safe Execute",
|
|
223
|
+
description: `Parse, safety-check, and execute a user request end-to-end.
|
|
224
|
+
|
|
225
|
+
Convenience tool that chains: Language → Intent → Safety → Execute.
|
|
226
|
+
|
|
227
|
+
Args:
|
|
228
|
+
- text (string): Raw user input
|
|
229
|
+
- user_id (string): User / agent identifier
|
|
230
|
+
|
|
231
|
+
Returns:
|
|
232
|
+
JSON with safety verdict and execution result`,
|
|
233
|
+
inputSchema: SafeExecuteSchema,
|
|
234
|
+
annotations: {
|
|
235
|
+
readOnlyHint: false,
|
|
236
|
+
destructiveHint: false,
|
|
237
|
+
idempotentHint: false,
|
|
238
|
+
openWorldHint: true,
|
|
239
|
+
},
|
|
240
|
+
}, async (params) => {
|
|
241
|
+
const lang = detectLanguage(params.text);
|
|
242
|
+
const intent = await extractIntent(lang.normalizedText);
|
|
243
|
+
const safety = await checkSafety(intent, params.text);
|
|
244
|
+
const exec = await executeIntent(intent, safety);
|
|
245
|
+
return {
|
|
246
|
+
content: [
|
|
247
|
+
{
|
|
248
|
+
type: "text",
|
|
249
|
+
text: JSON.stringify({ intent, safety, execution: exec }, null, 2),
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
};
|
|
253
|
+
});
|
|
254
|
+
// ─── Tool 5: neuroverse_route ───────────────────────────────────────────
|
|
255
|
+
const RouteAgentSchema = z
|
|
256
|
+
.object({
|
|
257
|
+
target_agent: z.string().min(1).describe("Name of the registered agent"),
|
|
258
|
+
task: z.string().min(1).describe("Task description to send"),
|
|
259
|
+
payload: z
|
|
260
|
+
.record(z.unknown())
|
|
261
|
+
.default({})
|
|
262
|
+
.describe("Arbitrary payload for the target"),
|
|
263
|
+
})
|
|
264
|
+
.strict();
|
|
265
|
+
server.registerTool("neuroverse_route", {
|
|
266
|
+
title: "Route to Agent",
|
|
267
|
+
description: `Route a task to a registered downstream agent via HTTP.
|
|
268
|
+
|
|
269
|
+
Args:
|
|
270
|
+
- target_agent (string): Name of the agent
|
|
271
|
+
- task (string): Task description
|
|
272
|
+
- payload (object): Arbitrary payload
|
|
273
|
+
|
|
274
|
+
Returns:
|
|
275
|
+
JSON with the agent's response or a fallback error`,
|
|
276
|
+
inputSchema: RouteAgentSchema,
|
|
277
|
+
annotations: {
|
|
278
|
+
readOnlyHint: false,
|
|
279
|
+
destructiveHint: false,
|
|
280
|
+
idempotentHint: false,
|
|
281
|
+
openWorldHint: true,
|
|
282
|
+
},
|
|
283
|
+
}, async (params) => {
|
|
284
|
+
const result = await routeToAgent({
|
|
285
|
+
targetAgent: params.target_agent,
|
|
286
|
+
task: params.task,
|
|
287
|
+
payload: params.payload,
|
|
288
|
+
});
|
|
289
|
+
return {
|
|
290
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
291
|
+
};
|
|
292
|
+
});
|
|
293
|
+
// ─── Tool 6: neuroverse_model ───────────────────────────────────────────
|
|
294
|
+
const ModelRouteSchema = z
|
|
295
|
+
.object({
|
|
296
|
+
task_type: z
|
|
297
|
+
.enum(["multilingual", "reasoning", "local", "general"])
|
|
298
|
+
.default("general")
|
|
299
|
+
.describe("Task type for routing"),
|
|
300
|
+
prompt: z
|
|
301
|
+
.string()
|
|
302
|
+
.optional()
|
|
303
|
+
.describe("Optional prompt to actually send to the routed model"),
|
|
304
|
+
})
|
|
305
|
+
.strict();
|
|
306
|
+
server.registerTool("neuroverse_model", {
|
|
307
|
+
title: "Model Route",
|
|
308
|
+
description: `Query the multi-model AI router.
|
|
309
|
+
|
|
310
|
+
If a prompt is provided, the prompt is sent to the routed model.
|
|
311
|
+
Otherwise, returns only the routing decision.
|
|
312
|
+
|
|
313
|
+
Supported providers: OpenAI, Anthropic, Sarvam AI, Ollama.
|
|
314
|
+
|
|
315
|
+
Args:
|
|
316
|
+
- task_type (string): multilingual | reasoning | local | general
|
|
317
|
+
- prompt (string, optional): Prompt to send
|
|
318
|
+
|
|
319
|
+
Returns:
|
|
320
|
+
JSON with routing decision and optional model response`,
|
|
321
|
+
inputSchema: ModelRouteSchema,
|
|
322
|
+
annotations: {
|
|
323
|
+
readOnlyHint: true,
|
|
324
|
+
destructiveHint: false,
|
|
325
|
+
idempotentHint: true,
|
|
326
|
+
openWorldHint: true,
|
|
327
|
+
},
|
|
328
|
+
}, async (params) => {
|
|
329
|
+
const taskType = params.task_type;
|
|
330
|
+
const decision = routeTask(taskType);
|
|
331
|
+
const result = { routing: decision };
|
|
332
|
+
if (params.prompt) {
|
|
333
|
+
try {
|
|
334
|
+
const response = await callLLM(params.prompt, taskType);
|
|
335
|
+
result["model_response"] = response;
|
|
336
|
+
}
|
|
337
|
+
catch (e) {
|
|
338
|
+
result["model_response"] = `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
343
|
+
};
|
|
344
|
+
});
|
|
345
|
+
// ─── Boot ───────────────────────────────────────────────────────────────
|
|
346
|
+
async function main() {
|
|
347
|
+
const transport = new StdioServerTransport();
|
|
348
|
+
await server.connect(transport);
|
|
349
|
+
console.error("🧠 NeuroVerse MCP server running via stdio");
|
|
350
|
+
}
|
|
351
|
+
main().catch((error) => {
|
|
352
|
+
console.error("NeuroVerse server error:", error);
|
|
353
|
+
process.exit(1);
|
|
354
|
+
});
|
|
355
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;GAeG;AAEH,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MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACxD,MAAM,CAAC,gBAAgB,CAAC,GAAG,QAAQ,CAAC;QACtC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,gBAAgB,CAAC,GAAG,UAAU,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACpF,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KAC5E,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,2EAA2E;AAE3E,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;AAC9D,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;IACjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Setu — Agent-to-Agent Router.
|
|
3
|
+
*
|
|
4
|
+
* Registry, discovery, and HTTP routing to downstream agents.
|
|
5
|
+
*/
|
|
6
|
+
import type { AgentDefinition, AgentRoutingRequest } from "../types.js";
|
|
7
|
+
export declare function registerAgent(agent: AgentDefinition): void;
|
|
8
|
+
export declare function unregisterAgent(name: string): boolean;
|
|
9
|
+
export declare function listAgents(): AgentDefinition[];
|
|
10
|
+
export declare function getAgent(name: string): AgentDefinition | undefined;
|
|
11
|
+
export declare function routeToAgent(request: AgentRoutingRequest): Promise<Record<string, unknown>>;
|
|
12
|
+
//# sourceMappingURL=agent-router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-router.d.ts","sourceRoot":"","sources":["../../src/services/agent-router.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAMxE,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAE1D;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,wBAAgB,UAAU,IAAI,eAAe,EAAE,CAE9C;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAElE;AAID,wBAAsB,YAAY,CAChC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAiBlC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Setu — Agent-to-Agent Router.
|
|
3
|
+
*
|
|
4
|
+
* Registry, discovery, and HTTP routing to downstream agents.
|
|
5
|
+
*/
|
|
6
|
+
import axios from "axios";
|
|
7
|
+
// ─── Agent registry ─────────────────────────────────────────────────────
|
|
8
|
+
const registry = new Map();
|
|
9
|
+
export function registerAgent(agent) {
|
|
10
|
+
registry.set(agent.agentName, agent);
|
|
11
|
+
}
|
|
12
|
+
export function unregisterAgent(name) {
|
|
13
|
+
return registry.delete(name);
|
|
14
|
+
}
|
|
15
|
+
export function listAgents() {
|
|
16
|
+
return [...registry.values()];
|
|
17
|
+
}
|
|
18
|
+
export function getAgent(name) {
|
|
19
|
+
return registry.get(name);
|
|
20
|
+
}
|
|
21
|
+
// ─── Routing ────────────────────────────────────────────────────────────
|
|
22
|
+
export async function routeToAgent(request) {
|
|
23
|
+
const agent = getAgent(request.targetAgent);
|
|
24
|
+
if (!agent) {
|
|
25
|
+
return { success: false, error: `Agent '${request.targetAgent}' is not registered.`, fallback: true };
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const resp = await axios.post(agent.endpoint, { task: request.task, payload: request.payload }, { headers: { "Content-Type": "application/json" }, timeout: 30000 });
|
|
29
|
+
return { success: true, agent: request.targetAgent, response: resp.data };
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
33
|
+
return { success: false, error: `Agent unreachable: ${msg}`, fallback: true };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=agent-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-router.js","sourceRoot":"","sources":["../../src/services/agent-router.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,2EAA2E;AAE3E,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;AAEpD,MAAM,UAAU,aAAa,CAAC,KAAsB;IAClD,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED,2EAA2E;AAE3E,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAA4B;IAE5B,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,OAAO,CAAC,WAAW,sBAAsB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACxG,CAAC;IAED,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,CAC3B,KAAK,CAAC,QAAQ,EACd,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,EAChD,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CACpE,CAAC;QACF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,WAAW,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5E,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACvD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,sBAAsB,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAChF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Executor — maps intents to registered tool functions with retry logic.
|
|
3
|
+
*/
|
|
4
|
+
import type { ExtractedIntent, SafetyVerdict, ExecutionResult } from "../types.js";
|
|
5
|
+
type ToolFunc = (params: Record<string, string>) => Promise<string>;
|
|
6
|
+
export declare function registerTool(name: string, fn: ToolFunc): void;
|
|
7
|
+
export declare function executeIntent(intent: ExtractedIntent, safety: SafetyVerdict, extraContext?: Record<string, string>): Promise<ExecutionResult>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/services/executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInF,KAAK,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAIpE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,IAAI,CAE7D;AA4CD,wBAAsB,aAAa,CACjC,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,aAAa,EACrB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,OAAO,CAAC,eAAe,CAAC,CAuB1B"}
|