diff-ai-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.
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: diff-ai-mcp
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: AI-powered diff ai MCP server for agents. Supports diff texts, diff summary, word diff. By MEOK AI Labs.
|
|
5
|
+
Project-URL: Homepage, https://meok.ai
|
|
6
|
+
Project-URL: Repository, https://github.com/CSOAI-ORG/diff-ai-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,diff,mcp,meok
|
|
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=ukTLmwmxv2hurFor-fHwdeXw47Zn20K8pdHwZc3Ti0c,8759
|
|
2
|
+
diff_ai_mcp-1.0.0.dist-info/METADATA,sha256=2kNlZgqdRJzUoMni02xa1jx-ch0bGJwnH7-9tQwpNtU,1332
|
|
3
|
+
diff_ai_mcp-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
4
|
+
diff_ai_mcp-1.0.0.dist-info/entry_points.txt,sha256=SKIKEgsE1-hDCBrAlL5gE18tqn9iQwFtEnMUe9mOJdo,44
|
|
5
|
+
diff_ai_mcp-1.0.0.dist-info/licenses/LICENSE,sha256=ibFbFVuWMg3hkFJtLijRTUi6DDoUbdR4oE78M6MKq-I,607
|
|
6
|
+
diff_ai_mcp-1.0.0.dist-info/RECORD,,
|
|
@@ -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.
|
server.py
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Compare texts, generate diffs, and create/apply patches. — MEOK AI Labs."""
|
|
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, difflib, hashlib
|
|
9
|
+
from datetime import datetime, timezone
|
|
10
|
+
from collections import defaultdict
|
|
11
|
+
from mcp.server.fastmcp import FastMCP
|
|
12
|
+
|
|
13
|
+
FREE_DAILY_LIMIT = 30
|
|
14
|
+
_usage = defaultdict(list)
|
|
15
|
+
def _rl(c="anon"):
|
|
16
|
+
now = datetime.now(timezone.utc)
|
|
17
|
+
_usage[c] = [t for t in _usage[c] if (now - t).total_seconds() < 86400]
|
|
18
|
+
if len(_usage[c]) >= FREE_DAILY_LIMIT:
|
|
19
|
+
return json.dumps({"error": f"Limit {FREE_DAILY_LIMIT}/day. Upgrade: meok.ai"})
|
|
20
|
+
_usage[c].append(now)
|
|
21
|
+
return None
|
|
22
|
+
|
|
23
|
+
mcp = FastMCP("diff-ai", instructions="Compare texts, generate unified/context diffs, and create/apply patches. By MEOK AI Labs.")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@mcp.tool()
|
|
27
|
+
def diff_texts(text_a: str, text_b: str, context_lines: int = 3, label_a: str = "original", label_b: str = "modified", api_key: str = "") -> str:
|
|
28
|
+
"""Generate a unified diff between two text inputs."""
|
|
29
|
+
allowed, msg, tier = check_access(api_key)
|
|
30
|
+
if not allowed:
|
|
31
|
+
return json.dumps({"error": msg, "upgrade_url": "https://meok.ai/pricing"})
|
|
32
|
+
if err := _rl():
|
|
33
|
+
return err
|
|
34
|
+
|
|
35
|
+
lines_a = text_a.splitlines(keepends=True)
|
|
36
|
+
lines_b = text_b.splitlines(keepends=True)
|
|
37
|
+
context_lines = max(0, min(context_lines, 20))
|
|
38
|
+
|
|
39
|
+
unified = list(difflib.unified_diff(lines_a, lines_b, fromfile=label_a, tofile=label_b, n=context_lines))
|
|
40
|
+
unified_str = ''.join(unified)
|
|
41
|
+
|
|
42
|
+
additions = sum(1 for line in unified if line.startswith('+') and not line.startswith('+++'))
|
|
43
|
+
deletions = sum(1 for line in unified if line.startswith('-') and not line.startswith('---'))
|
|
44
|
+
|
|
45
|
+
ratio = difflib.SequenceMatcher(None, text_a, text_b).ratio()
|
|
46
|
+
|
|
47
|
+
return json.dumps({
|
|
48
|
+
"diff": unified_str,
|
|
49
|
+
"additions": additions,
|
|
50
|
+
"deletions": deletions,
|
|
51
|
+
"total_changes": additions + deletions,
|
|
52
|
+
"similarity": round(ratio, 4),
|
|
53
|
+
"lines_a": len(lines_a),
|
|
54
|
+
"lines_b": len(lines_b),
|
|
55
|
+
"identical": text_a == text_b,
|
|
56
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@mcp.tool()
|
|
61
|
+
def diff_files(content_a: str, content_b: str, filename_a: str = "file_a", filename_b: str = "file_b", output_format: str = "unified", api_key: str = "") -> str:
|
|
62
|
+
"""Generate a diff between two file contents in unified, context, or ndiff format."""
|
|
63
|
+
allowed, msg, tier = check_access(api_key)
|
|
64
|
+
if not allowed:
|
|
65
|
+
return json.dumps({"error": msg, "upgrade_url": "https://meok.ai/pricing"})
|
|
66
|
+
if err := _rl():
|
|
67
|
+
return err
|
|
68
|
+
|
|
69
|
+
lines_a = content_a.splitlines(keepends=True)
|
|
70
|
+
lines_b = content_b.splitlines(keepends=True)
|
|
71
|
+
output_format = output_format.lower().strip()
|
|
72
|
+
|
|
73
|
+
if output_format == "context":
|
|
74
|
+
diff_lines = list(difflib.context_diff(lines_a, lines_b, fromfile=filename_a, tofile=filename_b))
|
|
75
|
+
elif output_format == "ndiff":
|
|
76
|
+
diff_lines = list(difflib.ndiff(lines_a, lines_b))
|
|
77
|
+
elif output_format == "html":
|
|
78
|
+
differ = difflib.HtmlDiff()
|
|
79
|
+
html_table = differ.make_table(
|
|
80
|
+
lines_a, lines_b,
|
|
81
|
+
fromdesc=filename_a, todesc=filename_b,
|
|
82
|
+
context=True, numlines=3
|
|
83
|
+
)
|
|
84
|
+
return json.dumps({
|
|
85
|
+
"format": "html",
|
|
86
|
+
"html": html_table,
|
|
87
|
+
"lines_a": len(lines_a),
|
|
88
|
+
"lines_b": len(lines_b),
|
|
89
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
90
|
+
})
|
|
91
|
+
else:
|
|
92
|
+
diff_lines = list(difflib.unified_diff(lines_a, lines_b, fromfile=filename_a, tofile=filename_b))
|
|
93
|
+
|
|
94
|
+
diff_str = ''.join(diff_lines)
|
|
95
|
+
hash_a = hashlib.sha256(content_a.encode()).hexdigest()[:16]
|
|
96
|
+
hash_b = hashlib.sha256(content_b.encode()).hexdigest()[:16]
|
|
97
|
+
|
|
98
|
+
hunks = 0
|
|
99
|
+
for line in diff_lines:
|
|
100
|
+
if line.startswith('@@') or line.startswith('***'):
|
|
101
|
+
hunks += 1
|
|
102
|
+
|
|
103
|
+
return json.dumps({
|
|
104
|
+
"format": output_format,
|
|
105
|
+
"diff": diff_str,
|
|
106
|
+
"hunks": hunks,
|
|
107
|
+
"lines_a": len(lines_a),
|
|
108
|
+
"lines_b": len(lines_b),
|
|
109
|
+
"hash_a": hash_a,
|
|
110
|
+
"hash_b": hash_b,
|
|
111
|
+
"identical": content_a == content_b,
|
|
112
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@mcp.tool()
|
|
117
|
+
def generate_patch(original: str, modified: str, filename: str = "file.txt", api_key: str = "") -> str:
|
|
118
|
+
"""Generate a patch file from original and modified text that can be applied with the apply_patch tool."""
|
|
119
|
+
allowed, msg, tier = check_access(api_key)
|
|
120
|
+
if not allowed:
|
|
121
|
+
return json.dumps({"error": msg, "upgrade_url": "https://meok.ai/pricing"})
|
|
122
|
+
if err := _rl():
|
|
123
|
+
return err
|
|
124
|
+
|
|
125
|
+
lines_orig = original.splitlines(keepends=True)
|
|
126
|
+
lines_mod = modified.splitlines(keepends=True)
|
|
127
|
+
|
|
128
|
+
if not lines_orig or not lines_orig[-1].endswith('\n'):
|
|
129
|
+
lines_orig = [l if l.endswith('\n') else l + '\n' for l in original.splitlines()]
|
|
130
|
+
if not lines_mod or not lines_mod[-1].endswith('\n'):
|
|
131
|
+
lines_mod = [l if l.endswith('\n') else l + '\n' for l in modified.splitlines()]
|
|
132
|
+
|
|
133
|
+
patch_lines = list(difflib.unified_diff(
|
|
134
|
+
lines_orig, lines_mod,
|
|
135
|
+
fromfile=f"a/{filename}",
|
|
136
|
+
tofile=f"b/{filename}",
|
|
137
|
+
n=3
|
|
138
|
+
))
|
|
139
|
+
patch_str = ''.join(patch_lines)
|
|
140
|
+
|
|
141
|
+
additions = sum(1 for l in patch_lines if l.startswith('+') and not l.startswith('+++'))
|
|
142
|
+
deletions = sum(1 for l in patch_lines if l.startswith('-') and not l.startswith('---'))
|
|
143
|
+
hunks = sum(1 for l in patch_lines if l.startswith('@@'))
|
|
144
|
+
|
|
145
|
+
return json.dumps({
|
|
146
|
+
"patch": patch_str,
|
|
147
|
+
"filename": filename,
|
|
148
|
+
"hunks": hunks,
|
|
149
|
+
"additions": additions,
|
|
150
|
+
"deletions": deletions,
|
|
151
|
+
"original_lines": len(lines_orig),
|
|
152
|
+
"modified_lines": len(lines_mod),
|
|
153
|
+
"patch_size_bytes": len(patch_str.encode()),
|
|
154
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@mcp.tool()
|
|
159
|
+
def apply_patch(original: str, patch_text: str, api_key: str = "") -> str:
|
|
160
|
+
"""Apply a unified diff patch to the original text and return the result."""
|
|
161
|
+
allowed, msg, tier = check_access(api_key)
|
|
162
|
+
if not allowed:
|
|
163
|
+
return json.dumps({"error": msg, "upgrade_url": "https://meok.ai/pricing"})
|
|
164
|
+
if err := _rl():
|
|
165
|
+
return err
|
|
166
|
+
|
|
167
|
+
original_lines = original.splitlines(keepends=True)
|
|
168
|
+
if original_lines and not original_lines[-1].endswith('\n'):
|
|
169
|
+
original_lines[-1] += '\n'
|
|
170
|
+
|
|
171
|
+
patch_lines = patch_text.splitlines(keepends=True)
|
|
172
|
+
|
|
173
|
+
result_lines = list(original_lines)
|
|
174
|
+
hunks = []
|
|
175
|
+
current_hunk = None
|
|
176
|
+
|
|
177
|
+
for line in patch_lines:
|
|
178
|
+
if line.startswith('@@'):
|
|
179
|
+
import re
|
|
180
|
+
match = re.match(r'^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@', line)
|
|
181
|
+
if match:
|
|
182
|
+
if current_hunk:
|
|
183
|
+
hunks.append(current_hunk)
|
|
184
|
+
current_hunk = {
|
|
185
|
+
"orig_start": int(match.group(1)) - 1,
|
|
186
|
+
"orig_count": int(match.group(2) or 1),
|
|
187
|
+
"new_start": int(match.group(3)) - 1,
|
|
188
|
+
"new_count": int(match.group(4) or 1),
|
|
189
|
+
"removals": [],
|
|
190
|
+
"additions": [],
|
|
191
|
+
}
|
|
192
|
+
elif current_hunk is not None:
|
|
193
|
+
if line.startswith('-') and not line.startswith('---'):
|
|
194
|
+
current_hunk["removals"].append(line[1:])
|
|
195
|
+
elif line.startswith('+') and not line.startswith('+++'):
|
|
196
|
+
current_hunk["additions"].append(line[1:])
|
|
197
|
+
|
|
198
|
+
if current_hunk:
|
|
199
|
+
hunks.append(current_hunk)
|
|
200
|
+
|
|
201
|
+
offset = 0
|
|
202
|
+
applied_hunks = 0
|
|
203
|
+
failed_hunks = 0
|
|
204
|
+
|
|
205
|
+
for hunk in hunks:
|
|
206
|
+
start = hunk["orig_start"] + offset
|
|
207
|
+
removals = hunk["removals"]
|
|
208
|
+
additions = hunk["additions"]
|
|
209
|
+
|
|
210
|
+
can_apply = True
|
|
211
|
+
for i, rem_line in enumerate(removals):
|
|
212
|
+
idx = start + i
|
|
213
|
+
if idx >= len(result_lines):
|
|
214
|
+
can_apply = False
|
|
215
|
+
break
|
|
216
|
+
if result_lines[idx].rstrip('\n') != rem_line.rstrip('\n'):
|
|
217
|
+
can_apply = False
|
|
218
|
+
break
|
|
219
|
+
|
|
220
|
+
if can_apply:
|
|
221
|
+
result_lines[start:start + len(removals)] = additions
|
|
222
|
+
offset += len(additions) - len(removals)
|
|
223
|
+
applied_hunks += 1
|
|
224
|
+
else:
|
|
225
|
+
failed_hunks += 1
|
|
226
|
+
|
|
227
|
+
result_text = ''.join(result_lines)
|
|
228
|
+
|
|
229
|
+
return json.dumps({
|
|
230
|
+
"result": result_text,
|
|
231
|
+
"applied_hunks": applied_hunks,
|
|
232
|
+
"failed_hunks": failed_hunks,
|
|
233
|
+
"total_hunks": len(hunks),
|
|
234
|
+
"success": failed_hunks == 0,
|
|
235
|
+
"original_lines": len(original_lines),
|
|
236
|
+
"result_lines": len(result_lines),
|
|
237
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
if __name__ == "__main__":
|
|
242
|
+
mcp.run()
|