@nahisaho/musubix-ontology-mcp 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.
Files changed (45) hide show
  1. package/dist/index.d.ts +12 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +17 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/inference/index.d.ts +6 -0
  6. package/dist/inference/index.d.ts.map +1 -0
  7. package/dist/inference/index.js +6 -0
  8. package/dist/inference/index.js.map +1 -0
  9. package/dist/inference/rule-engine.d.ts +149 -0
  10. package/dist/inference/rule-engine.d.ts.map +1 -0
  11. package/dist/inference/rule-engine.js +478 -0
  12. package/dist/inference/rule-engine.js.map +1 -0
  13. package/dist/integration/index.d.ts +6 -0
  14. package/dist/integration/index.d.ts.map +1 -0
  15. package/dist/integration/index.js +6 -0
  16. package/dist/integration/index.js.map +1 -0
  17. package/dist/integration/pattern-bridge.d.ts +146 -0
  18. package/dist/integration/pattern-bridge.d.ts.map +1 -0
  19. package/dist/integration/pattern-bridge.js +517 -0
  20. package/dist/integration/pattern-bridge.js.map +1 -0
  21. package/dist/privacy/index.d.ts +6 -0
  22. package/dist/privacy/index.d.ts.map +1 -0
  23. package/dist/privacy/index.js +6 -0
  24. package/dist/privacy/index.js.map +1 -0
  25. package/dist/privacy/privacy-guard.d.ts +43 -0
  26. package/dist/privacy/privacy-guard.d.ts.map +1 -0
  27. package/dist/privacy/privacy-guard.js +59 -0
  28. package/dist/privacy/privacy-guard.js.map +1 -0
  29. package/dist/store/index.d.ts +7 -0
  30. package/dist/store/index.d.ts.map +1 -0
  31. package/dist/store/index.js +7 -0
  32. package/dist/store/index.js.map +1 -0
  33. package/dist/store/n3-store.d.ts +115 -0
  34. package/dist/store/n3-store.d.ts.map +1 -0
  35. package/dist/store/n3-store.js +344 -0
  36. package/dist/store/n3-store.js.map +1 -0
  37. package/dist/store/ontology-store.d.ts +59 -0
  38. package/dist/store/ontology-store.d.ts.map +1 -0
  39. package/dist/store/ontology-store.js +135 -0
  40. package/dist/store/ontology-store.js.map +1 -0
  41. package/dist/types.d.ts +81 -0
  42. package/dist/types.d.ts.map +1 -0
  43. package/dist/types.js +6 -0
  44. package/dist/types.js.map +1 -0
  45. package/package.json +50 -0
@@ -0,0 +1,135 @@
1
+ /**
2
+ * @fileoverview Ontology store with local persistence
3
+ * @traceability TSK-ONTO-001, REQ-ONTO-001-F001
4
+ */
5
+ import { readFile, writeFile, mkdir } from 'node:fs/promises';
6
+ import { dirname } from 'node:path';
7
+ /**
8
+ * Ontology store with local JSON persistence
9
+ *
10
+ * @description
11
+ * Manages ontology storage locally (no external communication).
12
+ * Supports CRUD operations on ontologies and triples.
13
+ */
14
+ export class OntologyStore {
15
+ ontologies = new Map();
16
+ config;
17
+ dirty = false;
18
+ constructor(config = {}) {
19
+ this.config = {
20
+ storagePath: config.storagePath ?? './storage/ontology/store.json',
21
+ enableInference: config.enableInference ?? true,
22
+ maxTriples: config.maxTriples ?? 100000,
23
+ };
24
+ }
25
+ /**
26
+ * Load store from disk
27
+ */
28
+ async load() {
29
+ try {
30
+ const data = await readFile(this.config.storagePath, 'utf-8');
31
+ const parsed = JSON.parse(data);
32
+ this.ontologies.clear();
33
+ for (const onto of parsed.ontologies) {
34
+ this.ontologies.set(onto.id, onto);
35
+ }
36
+ this.dirty = false;
37
+ }
38
+ catch {
39
+ // File doesn't exist yet - start with empty store
40
+ this.ontologies.clear();
41
+ }
42
+ }
43
+ /**
44
+ * Save store to disk
45
+ */
46
+ async save() {
47
+ if (!this.dirty)
48
+ return;
49
+ const dir = dirname(this.config.storagePath);
50
+ await mkdir(dir, { recursive: true });
51
+ const data = {
52
+ version: '1.0.0',
53
+ updatedAt: new Date().toISOString(),
54
+ ontologies: Array.from(this.ontologies.values()),
55
+ };
56
+ await writeFile(this.config.storagePath, JSON.stringify(data, null, 2), 'utf-8');
57
+ this.dirty = false;
58
+ }
59
+ /**
60
+ * Create new ontology
61
+ */
62
+ create(id, namespace, prefixes = {}) {
63
+ const now = new Date().toISOString();
64
+ const ontology = {
65
+ id,
66
+ namespace,
67
+ prefixes,
68
+ triples: [],
69
+ createdAt: now,
70
+ updatedAt: now,
71
+ };
72
+ this.ontologies.set(id, ontology);
73
+ this.dirty = true;
74
+ return ontology;
75
+ }
76
+ /**
77
+ * Get ontology by ID
78
+ */
79
+ get(id) {
80
+ return this.ontologies.get(id);
81
+ }
82
+ /**
83
+ * Delete ontology
84
+ */
85
+ delete(id) {
86
+ const deleted = this.ontologies.delete(id);
87
+ if (deleted) {
88
+ this.dirty = true;
89
+ }
90
+ return deleted;
91
+ }
92
+ /**
93
+ * Add triple to ontology
94
+ */
95
+ addTriple(ontologyId, triple) {
96
+ const ontology = this.ontologies.get(ontologyId);
97
+ if (!ontology)
98
+ return false;
99
+ const totalTriples = Array.from(this.ontologies.values())
100
+ .reduce((sum, o) => sum + o.triples.length, 0);
101
+ if (totalTriples >= this.config.maxTriples) {
102
+ return false;
103
+ }
104
+ ontology.triples.push(triple);
105
+ ontology.updatedAt = new Date().toISOString();
106
+ this.dirty = true;
107
+ return true;
108
+ }
109
+ /**
110
+ * Get all triples from ontology
111
+ */
112
+ getTriples(ontologyId) {
113
+ return this.ontologies.get(ontologyId)?.triples ?? [];
114
+ }
115
+ /**
116
+ * List all ontologies
117
+ */
118
+ list() {
119
+ return Array.from(this.ontologies.values());
120
+ }
121
+ /**
122
+ * Get total triple count
123
+ */
124
+ get tripleCount() {
125
+ return Array.from(this.ontologies.values())
126
+ .reduce((sum, o) => sum + o.triples.length, 0);
127
+ }
128
+ /**
129
+ * Get ontology count
130
+ */
131
+ get size() {
132
+ return this.ontologies.size;
133
+ }
134
+ }
135
+ //# sourceMappingURL=ontology-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ontology-store.js","sourceRoot":"","sources":["../../src/store/ontology-store.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,K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AC,UAAU,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @fileoverview Ontology MCP type definitions
3
+ * @traceability REQ-ONTO-001
4
+ */
5
+ /**
6
+ * RDF Triple
7
+ */
8
+ export interface Triple {
9
+ subject: string;
10
+ predicate: string;
11
+ object: string;
12
+ graph?: string;
13
+ }
14
+ /**
15
+ * Ontology definition
16
+ */
17
+ export interface Ontology {
18
+ id: string;
19
+ namespace: string;
20
+ prefixes: Record<string, string>;
21
+ triples: Triple[];
22
+ createdAt: string;
23
+ updatedAt: string;
24
+ }
25
+ /**
26
+ * Ontology store configuration
27
+ */
28
+ export interface OntologyStoreConfig {
29
+ storagePath: string;
30
+ enableInference: boolean;
31
+ maxTriples: number;
32
+ }
33
+ /**
34
+ * SPARQL query result
35
+ */
36
+ export interface QueryResult {
37
+ type: 'select' | 'ask' | 'construct';
38
+ bindings?: Record<string, string>[];
39
+ boolean?: boolean;
40
+ triples?: Triple[];
41
+ }
42
+ /**
43
+ * Inference result with proof tree
44
+ */
45
+ export interface InferenceResult {
46
+ inferred: Triple[];
47
+ proofTree: ProofNode[];
48
+ }
49
+ /**
50
+ * Proof tree node
51
+ */
52
+ export interface ProofNode {
53
+ conclusion: Triple;
54
+ rule: string;
55
+ premises: ProofNode[];
56
+ }
57
+ /**
58
+ * Consistency check result
59
+ */
60
+ export interface ConsistencyResult {
61
+ consistent: boolean;
62
+ violations: ConsistencyViolation[];
63
+ }
64
+ /**
65
+ * Consistency violation
66
+ */
67
+ export interface ConsistencyViolation {
68
+ type: string;
69
+ message: string;
70
+ triples: Triple[];
71
+ }
72
+ /**
73
+ * Query error with position
74
+ */
75
+ export interface QueryError {
76
+ message: string;
77
+ line: number;
78
+ column: number;
79
+ suggestion?: string;
80
+ }
81
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA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I,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @fileoverview Ontology MCP type definitions
3
+ * @traceability REQ-ONTO-001
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@nahisaho/musubix-ontology-mcp",
3
+ "version": "1.0.0",
4
+ "description": "MUSUBIX Ontology Reasoning MCP - OWL 2 RL inference and SPARQL query",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "test": "vitest run",
20
+ "clean": "rm -rf dist",
21
+ "typecheck": "tsc --noEmit"
22
+ },
23
+ "keywords": [
24
+ "musubix",
25
+ "ontology",
26
+ "mcp",
27
+ "owl",
28
+ "sparql",
29
+ "reasoning"
30
+ ],
31
+ "author": "nahisaho",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/nahisaho/MUSUBIX.git",
36
+ "directory": "packages/ontology-mcp"
37
+ },
38
+ "dependencies": {
39
+ "@modelcontextprotocol/sdk": "^1.0.0",
40
+ "n3": "^1.26.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/n3": "^1.26.1",
44
+ "typescript": "^5.7.0",
45
+ "vitest": "^3.0.0"
46
+ },
47
+ "peerDependencies": {
48
+ "@nahisaho/musubix-core": "^1.2.0"
49
+ }
50
+ }