NexusInstruments commited on
Commit
7105ca4
·
verified ·
1 Parent(s): 15d3310

Create mcp_server.py

Browse files
Files changed (1) hide show
  1. mcp_server.py +41 -0
mcp_server.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ from mcp.server import Server
3
+ from utils.file_utils import normalize_log_line, keyword_search
4
+ from utils.summarizer import summarize_text
5
+ from utils.docgen import generate_doc
6
+
7
+ server = Server("omniscient")
8
+
9
+ # ─── Expose Tools ─────────────────────────────────────────────
10
+ @server.tool()
11
+ async def summarize_file(content: str) -> str:
12
+ """Summarize a text or log file."""
13
+ return summarize_text(content)
14
+
15
+ @server.tool()
16
+ async def analyze_log(content: str, query: str = None) -> dict:
17
+ """Normalize and search logs."""
18
+ normalized = [normalize_log_line(line) for line in content.splitlines()]
19
+ result = {
20
+ "total_lines": len(normalized),
21
+ "unique_entries": len(set(normalized)),
22
+ "preview": normalized[:20]
23
+ }
24
+ if query:
25
+ result["matches"] = keyword_search("\n".join(normalized), query)[:20]
26
+ return result
27
+
28
+ @server.tool()
29
+ async def generate_script_doc(name: str, content: str) -> str:
30
+ """Generate README-style documentation for a script."""
31
+ return generate_doc(name, "mcp", content)
32
+
33
+ # ─── Health Check ─────────────────────────────────────────────
34
+ @server.tool()
35
+ async def health() -> dict:
36
+ """Check MCP backend status."""
37
+ return {"ok": True, "message": "Omniscient MCP alive"}
38
+
39
+ # ─── Run Server ───────────────────────────────────────────────
40
+ if __name__ == "__main__":
41
+ asyncio.run(server.run_stdio())