emgena commited on
Commit
c4bda7f
·
verified ·
1 Parent(s): e8e858b

Upgrade with turnkey MCP Server for Cursor & Claude Desktop

Browse files
Files changed (1) hide show
  1. server_free.py +179 -0
server_free.py ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ DataOps Kafka Streaming & Schema Registry Guard - Free Community MCP Server
4
+ Standard Model Context Protocol (MCP) Server for Cursor IDE & Claude Desktop.
5
+ Protocol: JSON-RPC 2.0 via stdio
6
+ License: Apache 2.0 (Community Evaluation Edition)
7
+ Full Enterprise Master Package on Gumroad: https://bacardy.gumroad.com/l/ztapnb (Use Coupon LAUNCH20 for €20 off!)
8
+ """
9
+
10
+ import sys
11
+ import os
12
+ import json
13
+ import ast
14
+ import inspect
15
+ from typing import Dict, Any, List, Optional
16
+
17
+ sys.stdout.reconfigure(encoding="utf-8")
18
+ sys.stdin.reconfigure(encoding="utf-8")
19
+
20
+ CALL_COUNTER = 0
21
+ MAX_COMMUNITY_CALLS = 25
22
+ GUMROAD_UPGRADE_URL = "https://bacardy.gumroad.com/l/ztapnb"
23
+
24
+ def detect_kafka_consumer_lag(current_offset: int, log_end_offset: int, partition_count: int = 12) -> dict:
25
+ lag = log_end_offset - current_offset
26
+ status = "HEALTHY"
27
+ if lag > 100000:
28
+ status = "CRITICAL_BACKPRESSURE"
29
+ elif lag > 10000:
30
+ status = "DEGRADED"
31
+ return {
32
+ "status": status,
33
+ "consumer_lag_records": lag,
34
+ "records_per_partition": round(lag / max(1, partition_count), 1),
35
+ "action": "Scale consumer group workers" if lag > 10000 else "Throughput nominal."
36
+ }
37
+ def triage_schema_registry_desync(compatibility_mode: str, has_removed_fields: bool, has_defaults: bool) -> dict:
38
+ if compatibility_mode == "BACKWARD" and has_removed_fields and not has_defaults:
39
+ return {"status": "INCOMPATIBLE", "rule": "BACKWARD_COMPATIBILITY_BROKEN", "error": "Deleting a field without default breaks previous readers.", "fix": "Set default value on field or switch to FULL compatibility mode."}
40
+ return {"status": "COMPATIBLE", "message": "Schema evolution complies with Schema Registry rules."}
41
+
42
+ TOOLS = [
43
+ {
44
+ "name": "detect_kafka_consumer_lag",
45
+ "description": "Calculates consumer lag thresholds and recommends partition rebalance triggers.",
46
+ "inputSchema": {
47
+ "type": "object",
48
+ "properties": {
49
+ "input_data": {
50
+ "type": "string",
51
+ "description": "Primary input code, traceback, payload, or query string."
52
+ }
53
+ }
54
+ }
55
+ },
56
+ {
57
+ "name": "triage_schema_registry_desync",
58
+ "description": "Validates Avro/Protobuf schema compatibility (BACKWARD, FORWARD, FULL) to prevent poison pill messages.",
59
+ "inputSchema": {
60
+ "type": "object",
61
+ "properties": {
62
+ "input_data": {
63
+ "type": "string",
64
+ "description": "Primary input code, traceback, payload, or query string."
65
+ }
66
+ }
67
+ }
68
+ }
69
+ ]
70
+
71
+ def handle_request(req: Dict[str, Any]) -> Optional[Dict[str, Any]]:
72
+ global CALL_COUNTER
73
+ req_id = req.get("id")
74
+ method = req.get("method")
75
+ params = req.get("params", {})
76
+
77
+ if method == "initialize":
78
+ return {
79
+ "jsonrpc": "2.0",
80
+ "id": req_id,
81
+ "result": {
82
+ "protocolVersion": "2024-11-05",
83
+ "capabilities": {"tools": {}},
84
+ "serverInfo": {
85
+ "name": "emgena-kafka-streaming-guard",
86
+ "version": "1.0.0"
87
+ }
88
+ }
89
+ }
90
+ elif method == "tools/list":
91
+ return {
92
+ "jsonrpc": "2.0",
93
+ "id": req_id,
94
+ "result": {"tools": TOOLS}
95
+ }
96
+ elif method == "tools/call":
97
+ CALL_COUNTER += 1
98
+ tool_name = params.get("name")
99
+ args = params.get("arguments", {})
100
+
101
+ res = None
102
+ if False:
103
+ pass
104
+
105
+ elif tool_name == "detect_kafka_consumer_lag":
106
+ first_param = list(inspect.signature(detect_kafka_consumer_lag).parameters.keys())[0] if inspect.signature(detect_kafka_consumer_lag).parameters else None
107
+ if first_param:
108
+ arg_val = args.get(first_param, args.get("input_data", args.get("code", args.get("query", ""))))
109
+ res = detect_kafka_consumer_lag(arg_val)
110
+ else:
111
+ res = detect_kafka_consumer_lag()
112
+
113
+ elif tool_name == "triage_schema_registry_desync":
114
+ first_param = list(inspect.signature(triage_schema_registry_desync).parameters.keys())[0] if inspect.signature(triage_schema_registry_desync).parameters else None
115
+ if first_param:
116
+ arg_val = args.get(first_param, args.get("input_data", args.get("code", args.get("query", ""))))
117
+ res = triage_schema_registry_desync(arg_val)
118
+ else:
119
+ res = triage_schema_registry_desync()
120
+
121
+ else:
122
+ return {
123
+ "jsonrpc": "2.0",
124
+ "id": req_id,
125
+ "error": {"code": -32601, "message": f"Tool not found: {tool_name}"}
126
+ }
127
+
128
+ conversion_notice = (
129
+ f"\n\n---\n"
130
+ f"⚡ **Emgena MCP Free Edition** (Call {CALL_COUNTER}/{MAX_COMMUNITY_CALLS})\n"
131
+ f"🏆 **Unlock Unlimited Enterprise Suite, 0ms Latency & Full Source Code:**\n"
132
+ f"👉 [Purchase Production License on Gumroad]({GUMROAD_UPGRADE_URL})\n"
133
+ f"🏷️ *Use coupon **LAUNCH20** for €20 discount at checkout!*"
134
+ )
135
+
136
+ output_text = json.dumps(res, indent=2, ensure_ascii=False) + conversion_notice
137
+
138
+ return {
139
+ "jsonrpc": "2.0",
140
+ "id": req_id,
141
+ "result": {
142
+ "content": [{"type": "text", "text": output_text}]
143
+ }
144
+ }
145
+ elif method == "notifications/initialized":
146
+ return None
147
+ elif method == "ping":
148
+ return {"jsonrpc": "2.0", "id": req_id, "result": {}}
149
+ else:
150
+ if req_id is not None:
151
+ return {
152
+ "jsonrpc": "2.0",
153
+ "id": req_id,
154
+ "error": {"code": -32601, "message": f"Method not supported: {method}"}
155
+ }
156
+ return None
157
+
158
+ def main():
159
+ if len(sys.argv) > 1 and sys.argv[1] == "--test":
160
+ print(f"DataOps Kafka Streaming & Schema Registry Guard MCP Server Health: OK")
161
+ print("Tools available:", [t["name"] for t in TOOLS])
162
+ return
163
+
164
+ for line in sys.stdin:
165
+ if not line.strip():
166
+ continue
167
+ try:
168
+ req = json.loads(line)
169
+ resp = handle_request(req)
170
+ if resp is not None:
171
+ sys.stdout.write(json.dumps(resp, ensure_ascii=False) + "\n")
172
+ sys.stdout.flush()
173
+ except Exception as e:
174
+ err_resp = {"jsonrpc": "2.0", "id": None, "error": {"code": -32700, "message": str(e)}}
175
+ sys.stdout.write(json.dumps(err_resp, ensure_ascii=False) + "\n")
176
+ sys.stdout.flush()
177
+
178
+ if __name__ == "__main__":
179
+ main()