vector-knowledge-graph-mcp 1.0.0__py3-none-any.whl

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.
server.py ADDED
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env python3
2
+ """Vector Knowledge Graph MCP Server — Neo4j-style graph + vector hybrid for compliance reasoning."""
3
+
4
+ import sys, os
5
+ sys.path.insert(0, os.path.expanduser('~/clawd/meok-labs-engine/shared'))
6
+ from auth_middleware import check_access
7
+
8
+ import json, hashlib
9
+ from datetime import datetime, timezone
10
+ from collections import defaultdict
11
+ from typing import List, Optional
12
+ from mcp.server.fastmcp import FastMCP
13
+
14
+ FREE_DAILY_LIMIT = 15
15
+ _usage = defaultdict(list)
16
+ def _rl(c="anon"):
17
+ now = datetime.now(timezone.utc)
18
+ _usage[c] = [t for t in _usage[c] if (now-t).total_seconds() < 86400]
19
+ if len(_usage[c]) >= FREE_DAILY_LIMIT: return json.dumps({"error": f"Limit {FREE_DAILY_LIMIT}/day"})
20
+ _usage[c].append(now); return None
21
+
22
+ mcp = FastMCP("vector-knowledge-graph", instructions="MEOK AI Labs MCP Server")
23
+
24
+ _NODES: dict = {}
25
+ _EDGES: list = []
26
+
27
+ def _embed(text: str) -> List[float]:
28
+ h = hashlib.md5(text.lower().encode()).hexdigest()
29
+ return [int(h[i:i+2], 16) / 255.0 for i in range(0, 32, 2)]
30
+
31
+ def _cosine(a, b):
32
+ dot = sum(x*y for x,y in zip(a,b))
33
+ return dot / ((sum(x*x for x in a)**0.5 * sum(y*y for y in b)**0.5) + 1e-9)
34
+
35
+ @mcp.tool()
36
+ def add_node(label: str, properties: dict, node_id: Optional[str] = None, api_key: str = "") -> str:
37
+ """Add a node to the knowledge graph with properties, embeddings, and metadata."""
38
+ allowed, msg, tier = check_access(api_key)
39
+ if not allowed:
40
+ return {"error": msg, "upgrade_url": "https://buy.stripe.com/14A4gB3K4eUWgYR56o8k836"}
41
+ if err := _rl(): return err
42
+
43
+ nid = node_id or hashlib.md5(label.encode()).hexdigest()[:12]
44
+ _NODES[nid] = {"label": label, "properties": properties, "embedding": _embed(label + " " + json.dumps(properties))}
45
+ return {"node_id": nid, "created": True}
46
+
47
+ @mcp.tool()
48
+ def add_edge(from_id: str, to_id: str, relation: str, weight: float = 1.0, api_key: str = "") -> str:
49
+ """Create a directed edge between two nodes with relationship type and weight."""
50
+ allowed, msg, tier = check_access(api_key)
51
+ if not allowed:
52
+ return {"error": msg, "upgrade_url": "https://buy.stripe.com/14A4gB3K4eUWgYR56o8k836"}
53
+ if err := _rl(): return err
54
+
55
+ _EDGES.append({"from": from_id, "to": to_id, "relation": relation, "weight": weight})
56
+ return {"edge_created": True, "relation": relation}
57
+
58
+ @mcp.tool()
59
+ def semantic_node_search(query: str, top_k: int = 5, api_key: str = "") -> str:
60
+ """Search for nodes using semantic similarity matching against stored embeddings."""
61
+ allowed, msg, tier = check_access(api_key)
62
+ if not allowed:
63
+ return {"error": msg, "upgrade_url": "https://buy.stripe.com/14A4gB3K4eUWgYR56o8k836"}
64
+ if err := _rl(): return err
65
+
66
+ q_vec = _embed(query)
67
+ results = []
68
+ for nid, node in _NODES.items():
69
+ score = _cosine(q_vec, node["embedding"])
70
+ results.append({"node_id": nid, "score": round(score, 4), "label": node["label"]})
71
+ results.sort(key=lambda x: x["score"], reverse=True)
72
+ return {"results": results[:top_k]}
73
+
74
+ @mcp.tool()
75
+ def trace_compliance_chain(start_node_id: str, max_depth: int = 3, api_key: str = "") -> str:
76
+ """Trace the compliance chain from a requirement through controls to evidence."""
77
+ allowed, msg, tier = check_access(api_key)
78
+ if not allowed:
79
+ return {"error": msg, "upgrade_url": "https://buy.stripe.com/14A4gB3K4eUWgYR56o8k836"}
80
+ if err := _rl(): return err
81
+
82
+ visited = set()
83
+ paths = []
84
+ def dfs(node, depth, path):
85
+ if depth > max_depth or node in visited:
86
+ return
87
+ visited.add(node)
88
+ for e in _EDGES:
89
+ if e["from"] == node:
90
+ dfs(e["to"], depth + 1, path + [{"relation": e["relation"], "to": e["to"], "weight": e["weight"]}])
91
+ if path:
92
+ paths.append({"from": start_node_id, "path": path})
93
+ dfs(start_node_id, 0, [])
94
+ return {"start": start_node_id, "paths": paths}
95
+
96
+ @mcp.tool()
97
+ def find_gaps(required_frameworks: list, api_key: str = "") -> str:
98
+ """Find gaps in the knowledge graph where expected relationships or nodes are missing."""
99
+ allowed, msg, tier = check_access(api_key)
100
+ if not allowed:
101
+ return {"error": msg, "upgrade_url": "https://buy.stripe.com/14A4gB3K4eUWgYR56o8k836"}
102
+ if err := _rl(): return err
103
+
104
+ present = set()
105
+ for node in _NODES.values():
106
+ for fw in required_frameworks:
107
+ if fw.lower() in node["label"].lower():
108
+ present.add(fw)
109
+ missing = [fw for fw in required_frameworks if fw not in present]
110
+ return {"present": list(present), "missing": missing, "coverage": round(len(present)/len(required_frameworks)*100,1) if required_frameworks else 100}
111
+
112
+ if __name__ == "__main__":
113
+ mcp.run()
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: vector-knowledge-graph-mcp
3
+ Version: 1.0.0
4
+ Summary: AI-powered vector knowledge graph MCP server for agents. Supports add node, add edge, semantic node search. By MEOK AI Labs.
5
+ Project-URL: Homepage, https://meok.ai
6
+ Project-URL: Repository, https://github.com/CSOAI-ORG/vector-knowledge-graph-mcp
7
+ Author-email: MEOK AI Labs <nicholas@meok.ai>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2026 MEOK AI Labs
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+ License-File: LICENSE
22
+ Keywords: ai,graph,knowledge,mcp,meok,vector
23
+ Classifier: License :: OSI Approved :: MIT License
24
+ Classifier: Operating System :: OS Independent
25
+ Classifier: Programming Language :: Python :: 3
26
+ Classifier: Topic :: Software Development :: Libraries
27
+ Requires-Python: >=3.10
28
+ Requires-Dist: mcp>=1.0.0
@@ -0,0 +1,6 @@
1
+ server.py,sha256=-_CU6CUaFyFmUru3ch8Ypd7X2scikDubsb2lcqST22g,4731
2
+ vector_knowledge_graph_mcp-1.0.0.dist-info/METADATA,sha256=vxZwfErYjCO0Zxzmju9OKa9laSL_gJXKfYFqhRMqfko,1400
3
+ vector_knowledge_graph_mcp-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
4
+ vector_knowledge_graph_mcp-1.0.0.dist-info/entry_points.txt,sha256=rtlBZHz2G0Z1Uh5nodEEnRs7zgiar65TW-Rokg6W_pw,59
5
+ vector_knowledge_graph_mcp-1.0.0.dist-info/licenses/LICENSE,sha256=ibFbFVuWMg3hkFJtLijRTUi6DDoUbdR4oE78M6MKq-I,607
6
+ vector_knowledge_graph_mcp-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ vector_knowledge_graph_mcp = server:main
@@ -0,0 +1,13 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MEOK AI Labs
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.