cograph-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/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # cograph-mcp
2
+
3
+ MCP (Model Context Protocol) server for [Cograph](https://cograph.cloud). Gives AI agents tools to query and ingest data into your knowledge graphs.
4
+
5
+ ## Install / run
6
+
7
+ No install needed — use `npx`:
8
+
9
+ ```bash
10
+ npx -y cograph-mcp
11
+ ```
12
+
13
+ ## Claude Desktop / Cursor / Claude Code
14
+
15
+ ```json
16
+ {
17
+ "mcpServers": {
18
+ "cograph": {
19
+ "command": "npx",
20
+ "args": ["-y", "cograph-mcp"],
21
+ "env": {
22
+ "COGRAPH_API_KEY": "your-key",
23
+ "COGRAPH_API_URL": "https://api.cograph.cloud"
24
+ }
25
+ }
26
+ }
27
+ }
28
+ ```
29
+
30
+ ## Tools exposed
31
+
32
+ - `list_knowledge_graphs` — list available KGs and descriptions
33
+ - `ask` — ask a natural language question; returns the answer
34
+ - `ingest_csv` — ingest a CSV file by absolute path into a named KG
35
+ - `view_ontology` — show types, attributes, relationships across KGs
36
+
37
+ ## Environment
38
+
39
+ - `COGRAPH_API_KEY` — required
40
+ - `COGRAPH_API_URL` — default `https://api.cograph.cloud`
41
+ - `COGRAPH_TENANT` — default `demo-tenant`
42
+
43
+ Legacy `OMNIX_*` vars are also accepted.
44
+
45
+ ## License
46
+
47
+ MIT
package/dist/index.js ADDED
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
5
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
+ import { Client, CographError } from "cograph";
7
+ import { z } from "zod";
8
+ var VERSION = "0.1.0";
9
+ var server = new McpServer(
10
+ {
11
+ name: "cograph",
12
+ version: VERSION
13
+ },
14
+ {
15
+ instructions: "Cograph is a knowledge graph platform. Use these tools to query structured data across multiple knowledge graphs using natural language."
16
+ }
17
+ );
18
+ function client() {
19
+ return new Client();
20
+ }
21
+ function textResult(text) {
22
+ return {
23
+ content: [{ type: "text", text }]
24
+ };
25
+ }
26
+ function errorResult(err) {
27
+ const msg = err instanceof CographError ? `Cograph error: ${err.message}` : err instanceof Error ? err.message : String(err);
28
+ return {
29
+ content: [{ type: "text", text: msg }],
30
+ isError: true
31
+ };
32
+ }
33
+ server.registerTool(
34
+ "list_knowledge_graphs",
35
+ {
36
+ description: "List all available knowledge graphs and their descriptions.",
37
+ inputSchema: {}
38
+ },
39
+ async () => {
40
+ try {
41
+ const kgs = await client().listKgs();
42
+ if (!kgs.length) return textResult("No knowledge graphs found.");
43
+ const lines = kgs.map((kg) => {
44
+ const name = String(kg.name ?? "?");
45
+ const desc = kg.description ? `: ${kg.description}` : "";
46
+ return `- ${name}${desc}`;
47
+ });
48
+ return textResult(lines.join("\n"));
49
+ } catch (err) {
50
+ return errorResult(err);
51
+ }
52
+ }
53
+ );
54
+ server.registerTool(
55
+ "ask",
56
+ {
57
+ description: "Ask a natural language question against a knowledge graph. Use list_knowledge_graphs to see available KGs first.",
58
+ inputSchema: {
59
+ question: z.string().describe(
60
+ 'The natural language question to ask (e.g., "How many events are in San Francisco?")'
61
+ ),
62
+ kg_name: z.string().optional().describe(
63
+ "Name of the knowledge graph to query. Use list_knowledge_graphs to see available KGs."
64
+ )
65
+ }
66
+ },
67
+ async ({ question, kg_name }) => {
68
+ try {
69
+ const data = await client().ask(question, { kg: kg_name });
70
+ const answer = data.answer ?? "No answer";
71
+ const explanation = data.explanation;
72
+ let out = `Answer: ${answer}`;
73
+ if (explanation) out += `
74
+ Explanation: ${explanation}`;
75
+ return textResult(out);
76
+ } catch (err) {
77
+ return errorResult(err);
78
+ }
79
+ }
80
+ );
81
+ server.registerTool(
82
+ "ingest_csv",
83
+ {
84
+ description: "Ingest a CSV file into a knowledge graph. The schema is automatically inferred.",
85
+ inputSchema: {
86
+ file_path: z.string().describe("Absolute path to the CSV file to ingest."),
87
+ kg_name: z.string().describe(
88
+ 'Name for the knowledge graph (e.g., "sales-data", "customer-records").'
89
+ )
90
+ }
91
+ },
92
+ async ({ file_path, kg_name }) => {
93
+ try {
94
+ const result = await client().ingest(file_path, { kg: kg_name });
95
+ const entities = Number(result.entities_resolved ?? 0);
96
+ const triples = Number(result.triples_inserted ?? 0);
97
+ return textResult(
98
+ `Ingestion complete: ${entities} entities resolved, ${triples} triples inserted into "${kg_name}".`
99
+ );
100
+ } catch (err) {
101
+ return errorResult(err);
102
+ }
103
+ }
104
+ );
105
+ server.registerTool(
106
+ "view_ontology",
107
+ {
108
+ description: "View the ontology (types, attributes, relationships) across all knowledge graphs.",
109
+ inputSchema: {}
110
+ },
111
+ async () => {
112
+ try {
113
+ const types = await client().ontologyTypes();
114
+ if (!types.length) return textResult("No ontology types defined yet.");
115
+ const lines = [];
116
+ for (const t of types) {
117
+ const name = String(t.name ?? "?");
118
+ lines.push(`Type: ${name}`);
119
+ const attrs = t.attributes ?? [];
120
+ if (attrs.length) {
121
+ lines.push(
122
+ ` Attributes: ${attrs.map((a) => String(a.name ?? "?")).join(", ")}`
123
+ );
124
+ }
125
+ const rels = t.relationships ?? [];
126
+ if (rels.length) {
127
+ lines.push(
128
+ ` Relationships: ${rels.map(
129
+ (r) => `${String(r.predicate ?? "?")} -> ${String(r.target_type ?? "?")}`
130
+ ).join(", ")}`
131
+ );
132
+ }
133
+ }
134
+ return textResult(lines.join("\n"));
135
+ } catch (err) {
136
+ return errorResult(err);
137
+ }
138
+ }
139
+ );
140
+ async function main() {
141
+ const transport = new StdioServerTransport();
142
+ await server.connect(transport);
143
+ }
144
+ main().catch((err) => {
145
+ process.stderr.write(
146
+ `cograph-mcp failed to start: ${err instanceof Error ? err.message : String(err)}
147
+ `
148
+ );
149
+ process.exit(1);
150
+ });
151
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { Client, CographError } from \"cograph\";\nimport { z } from \"zod\";\n\nconst VERSION = \"0.1.0\";\n\nconst server = new McpServer(\n {\n name: \"cograph\",\n version: VERSION,\n },\n {\n instructions:\n \"Cograph is a knowledge graph platform. Use these tools to query \" +\n \"structured data across multiple knowledge graphs using natural language.\",\n },\n);\n\nfunction client(): Client {\n return new Client();\n}\n\nfunction textResult(text: string) {\n return {\n content: [{ type: \"text\" as const, text }],\n };\n}\n\nfunction errorResult(err: unknown) {\n const msg =\n err instanceof CographError\n ? `Cograph error: ${err.message}`\n : err instanceof Error\n ? err.message\n : String(err);\n return {\n content: [{ type: \"text\" as const, text: msg }],\n isError: true,\n };\n}\n\nserver.registerTool(\n \"list_knowledge_graphs\",\n {\n description:\n \"List all available knowledge graphs and their descriptions.\",\n inputSchema: {},\n },\n async () => {\n try {\n const kgs = await client().listKgs();\n if (!kgs.length) return textResult(\"No knowledge graphs found.\");\n const lines = kgs.map((kg) => {\n const name = String(kg.name ?? \"?\");\n const desc = kg.description ? `: ${kg.description}` : \"\";\n return `- ${name}${desc}`;\n });\n return textResult(lines.join(\"\\n\"));\n } catch (err) {\n return errorResult(err);\n }\n },\n);\n\nserver.registerTool(\n \"ask\",\n {\n description:\n \"Ask a natural language question against a knowledge graph. \" +\n 'Use list_knowledge_graphs to see available KGs first.',\n inputSchema: {\n question: z\n .string()\n .describe(\n 'The natural language question to ask (e.g., \"How many events are in San Francisco?\")',\n ),\n kg_name: z\n .string()\n .optional()\n .describe(\n \"Name of the knowledge graph to query. Use list_knowledge_graphs to see available KGs.\",\n ),\n },\n },\n async ({ question, kg_name }) => {\n try {\n const data = await client().ask(question, { kg: kg_name });\n const answer = data.answer ?? \"No answer\";\n const explanation = data.explanation;\n let out = `Answer: ${answer}`;\n if (explanation) out += `\\nExplanation: ${explanation}`;\n return textResult(out);\n } catch (err) {\n return errorResult(err);\n }\n },\n);\n\nserver.registerTool(\n \"ingest_csv\",\n {\n description:\n \"Ingest a CSV file into a knowledge graph. The schema is automatically inferred.\",\n inputSchema: {\n file_path: z\n .string()\n .describe(\"Absolute path to the CSV file to ingest.\"),\n kg_name: z\n .string()\n .describe(\n 'Name for the knowledge graph (e.g., \"sales-data\", \"customer-records\").',\n ),\n },\n },\n async ({ file_path, kg_name }) => {\n try {\n const result = await client().ingest(file_path, { kg: kg_name });\n const entities = Number(result.entities_resolved ?? 0);\n const triples = Number(result.triples_inserted ?? 0);\n return textResult(\n `Ingestion complete: ${entities} entities resolved, ${triples} triples inserted into \"${kg_name}\".`,\n );\n } catch (err) {\n return errorResult(err);\n }\n },\n);\n\nserver.registerTool(\n \"view_ontology\",\n {\n description:\n \"View the ontology (types, attributes, relationships) across all knowledge graphs.\",\n inputSchema: {},\n },\n async () => {\n try {\n const types = await client().ontologyTypes();\n if (!types.length) return textResult(\"No ontology types defined yet.\");\n const lines: string[] = [];\n for (const t of types) {\n const name = String(t.name ?? \"?\");\n lines.push(`Type: ${name}`);\n const attrs = (t.attributes ?? []) as Array<Record<string, unknown>>;\n if (attrs.length) {\n lines.push(\n ` Attributes: ${attrs.map((a) => String(a.name ?? \"?\")).join(\", \")}`,\n );\n }\n const rels = (t.relationships ?? []) as Array<Record<string, unknown>>;\n if (rels.length) {\n lines.push(\n ` Relationships: ${rels\n .map(\n (r) =>\n `${String(r.predicate ?? \"?\")} -> ${String(r.target_type ?? \"?\")}`,\n )\n .join(\", \")}`,\n );\n }\n }\n return textResult(lines.join(\"\\n\"));\n } catch (err) {\n return errorResult(err);\n }\n },\n);\n\nasync function main(): Promise<void> {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n}\n\nmain().catch((err) => {\n process.stderr.write(\n `cograph-mcp failed to start: ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n process.exit(1);\n});\n"],"mappings":";;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,4BAA4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W,KAAK,OAAO;AACrB,cAAM,OAAO,OAAO,EAAE,QAAQ,GAAG;AACjC,cAAM,KAAK,SAAS,IAAI,EAAE;AAC1B,cAAM,QAAS,EAAE,cAAc,CAAC;AAChC,YAAI,MAAM,QAAQ;AAChB,gBAAM;AAAA,YACJ,iBAAiB,MAAM,IAAI,CAAC,MAAM,OAAO,EAAE,QAAQ,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC;AAAA,UACrE;AAAA,QACF;AACA,cAAM,OAAQ,EAAE,iBAAiB,CAAC;AAClC,YAAI,KAAK,QAAQ;AACf,gBAAM;AAAA,YACJ,oBAAoB,KACjB;AAAA,cACC,CAAC,MACC,GAAG,OAAO,EAAE,aAAa,GAAG,CAAC,OAAO,OAAO,EAAE,eAAe,GAAG,CAAC;AAAA,YACpE,EACC,KAAK,IAAI,CAAC;AAAA,UACf;AAAA,QACF;AAAA,MACF;AACA,aAAO,WAAW,MAAM,KAAK,IAAI,CAAC;AAAA,IACpC,SAAS,KAAK;AACZ,aAAO,YAAY,GAAG;AAAA,IACxB;AAAA,EACF;AACF;AAEA,eAAe,OAAsB;AACnC,QAAM,YAAY,IAAI,qBAAqB;AAC3C,QAAM,OAAO,QAAQ,SAAS;AAChC;AAEA,KAAK,EAAE,MAAM,CAAC,QAAQ;AACpB,UAAQ,OAAO;AAAA,IACb,gCAAgC,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;AAAA;AAAA,EAClF;AACA,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "cograph-mcp",
3
+ "version": "0.1.0",
4
+ "description": "Cograph MCP server — expose knowledge graph tools to AI agents",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "bin": {
8
+ "cograph-mcp": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsup",
16
+ "prepack": "node ../../scripts/chmod-bin.js packages/cograph-mcp/dist/index.js"
17
+ },
18
+ "keywords": [
19
+ "knowledge-graph",
20
+ "cograph",
21
+ "mcp",
22
+ "model-context-protocol",
23
+ "ai",
24
+ "llm",
25
+ "agent"
26
+ ],
27
+ "author": "Cograph",
28
+ "license": "MIT",
29
+ "homepage": "https://cograph.cloud",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/git-moeen/cograph-oss.git",
33
+ "directory": "packages/cograph-mcp"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/git-moeen/cograph-oss/issues"
37
+ },
38
+ "dependencies": {
39
+ "cograph": "^0.1.0",
40
+ "@modelcontextprotocol/sdk": "^1.0.4",
41
+ "zod": "^3.23.8"
42
+ },
43
+ "engines": {
44
+ "node": ">=20"
45
+ }
46
+ }