@cognivia/mcp 0.1.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 +21 -0
- package/README.md +14 -0
- package/package.json +17 -0
- package/server.mjs +108 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Manik Maurya
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @cognivia/mcp
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol server that gives any AI agent Cognivia's learning
|
|
4
|
+
diagnostics as tools: `diagnose_error`, `get_memory_state`, `generate_report`.
|
|
5
|
+
|
|
6
|
+
```jsonc
|
|
7
|
+
{ "mcpServers": { "cognivia": {
|
|
8
|
+
"command": "npx", "args": ["-y", "@cognivia/mcp"],
|
|
9
|
+
"env": { "COGNIVIA_API_KEY": "sk_live_..." } } } }
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
With a key it proxies to the hosted API; otherwise it computes locally.
|
|
13
|
+
|
|
14
|
+
MIT · Manik Maurya
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cognivia/mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Model Context Protocol server for Cognivia. Gives any AI agent learning diagnostics (error type, memory state, session report) as callable tools.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": { "cognivia-mcp": "server.mjs" },
|
|
7
|
+
"main": "server.mjs",
|
|
8
|
+
"files": ["server.mjs", "README.md", "LICENSE"],
|
|
9
|
+
"keywords": ["cognivia", "mcp", "model-context-protocol", "learning", "diagnostics", "ai-agents"],
|
|
10
|
+
"homepage": "https://cognivia-platform.vercel.app/intelligence",
|
|
11
|
+
"repository": { "type": "git", "url": "git+https://github.com/Manik-Maurya/cognivia-platform.git", "directory": "packages/mcp" },
|
|
12
|
+
"engines": { "node": ">=18" },
|
|
13
|
+
"dependencies": { "@cognivia/core": "^0.1.0" },
|
|
14
|
+
"publishConfig": { "access": "public" },
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Manik Maurya"
|
|
17
|
+
}
|
package/server.mjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @cognivia/mcp - a Model Context Protocol server that gives any AI agent
|
|
3
|
+
// Cognivia's learning diagnostics as tools. Zero dependencies: newline-delimited
|
|
4
|
+
// JSON-RPC 2.0 over stdio, which every MCP client speaks.
|
|
5
|
+
//
|
|
6
|
+
// Tools:
|
|
7
|
+
// diagnose_error(subject, question, answer, correct, latencyMs, confidence)
|
|
8
|
+
// get_memory_state(attempts[])
|
|
9
|
+
// generate_report(attempts[])
|
|
10
|
+
//
|
|
11
|
+
// All computed by @cognivia/core - the same engine behind the site, console, CLI.
|
|
12
|
+
//
|
|
13
|
+
// Client config (Claude Desktop / any MCP client):
|
|
14
|
+
// { "mcpServers": { "cognivia": { "command": "node", "args": ["server.mjs"] } } }
|
|
15
|
+
|
|
16
|
+
import * as core from "@cognivia/core";
|
|
17
|
+
import * as client from "@cognivia/core/client";
|
|
18
|
+
import { createInterface } from "node:readline";
|
|
19
|
+
|
|
20
|
+
const send = (msg) => process.stdout.write(JSON.stringify(msg) + "\n");
|
|
21
|
+
const ok = (id, result) => send({ jsonrpc: "2.0", id, result });
|
|
22
|
+
const err = (id, code, message) => send({ jsonrpc: "2.0", id, error: { code, message } });
|
|
23
|
+
|
|
24
|
+
const TOOLS = [
|
|
25
|
+
{
|
|
26
|
+
name: "diagnose_error",
|
|
27
|
+
description: "Diagnose one answered item: the error type, memory state, and next review, each grounded in memory science.",
|
|
28
|
+
inputSchema: {
|
|
29
|
+
type: "object",
|
|
30
|
+
properties: {
|
|
31
|
+
subject: { type: "string" }, question: { type: "string" }, answer: { type: "string" },
|
|
32
|
+
correct: { type: "boolean" }, latencyMs: { type: "number" },
|
|
33
|
+
confidence: { type: "number", description: "1-5 (or 0-100)" },
|
|
34
|
+
},
|
|
35
|
+
required: ["correct"],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "get_memory_state",
|
|
40
|
+
description: "Compute the Learning Genome and per-item memory state for a set of attempts from any learning or quiz app.",
|
|
41
|
+
inputSchema: { type: "object", properties: { attempts: { type: "array" } }, required: ["attempts"] },
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "generate_report",
|
|
45
|
+
description: "Build a full Cognivia Session Report (Learning Genome, per-item diagnosis, recommendation) from a set of attempts.",
|
|
46
|
+
inputSchema: { type: "object", properties: { attempts: { type: "array" } }, required: ["attempts"] },
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
function textResult(obj, text) {
|
|
51
|
+
return { content: [{ type: "text", text: text || JSON.stringify(obj, null, 2) }], structuredContent: obj };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function callTool(name, a = {}) {
|
|
55
|
+
// When COGNIVIA_API_KEY is set, prefer the hosted /v1 API; else compute locally.
|
|
56
|
+
const remote = client.hasKey();
|
|
57
|
+
if (name === "diagnose_error") {
|
|
58
|
+
if (remote) { try { return textResult(await client.diagnoseRemote(a)); } catch (e) { /* fall back */ } }
|
|
59
|
+
const tag = core.classify(!!a.correct, a.confidence);
|
|
60
|
+
return textResult({
|
|
61
|
+
errorType: tag.code, label: tag.label,
|
|
62
|
+
memoryState: core.memoryState(a), diagnosis: core.diagnosis(a),
|
|
63
|
+
nextReview: core.reviewFor(tag, a.confidence),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (name === "get_memory_state") {
|
|
67
|
+
const atts = a.attempts || [];
|
|
68
|
+
return textResult({
|
|
69
|
+
genome: core.computeGenome(atts),
|
|
70
|
+
items: atts.map((x, i) => ({ n: i + 1, subject: x.subject || x.topic, memoryState: core.memoryState(x), diagnosis: core.diagnosis(x) })),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (name === "generate_report") {
|
|
74
|
+
if (remote) { try { const rep = await client.reportRemote(a.attempts || []); return textResult(rep, core.renderText(rep)); } catch (e) { /* fall back */ } }
|
|
75
|
+
const rep = core.buildReport(a.attempts || [], { idPrefix: "CGV-MCP" });
|
|
76
|
+
return textResult(rep, core.renderText(rep));
|
|
77
|
+
}
|
|
78
|
+
throw new Error("unknown tool: " + name);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const rl = createInterface({ input: process.stdin });
|
|
82
|
+
rl.on("line", async (line) => {
|
|
83
|
+
const s = line.trim();
|
|
84
|
+
if (!s) return;
|
|
85
|
+
let msg;
|
|
86
|
+
try { msg = JSON.parse(s); } catch { return; }
|
|
87
|
+
const { id, method, params } = msg;
|
|
88
|
+
try {
|
|
89
|
+
if (method === "initialize") {
|
|
90
|
+
ok(id, {
|
|
91
|
+
protocolVersion: "2024-11-05",
|
|
92
|
+
capabilities: { tools: {} },
|
|
93
|
+
serverInfo: { name: "cognivia", version: "0.1.0" },
|
|
94
|
+
});
|
|
95
|
+
} else if (method === "tools/list") {
|
|
96
|
+
ok(id, { tools: TOOLS });
|
|
97
|
+
} else if (method === "tools/call") {
|
|
98
|
+
const { name, arguments: a } = params || {};
|
|
99
|
+
ok(id, await callTool(name, a || {}));
|
|
100
|
+
} else if (method === "ping") {
|
|
101
|
+
ok(id, {});
|
|
102
|
+
} else if (id !== undefined) {
|
|
103
|
+
err(id, -32601, "Method not found: " + method);
|
|
104
|
+
}
|
|
105
|
+
} catch (e) {
|
|
106
|
+
if (id !== undefined) err(id, -32000, e.message);
|
|
107
|
+
}
|
|
108
|
+
});
|