-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaudit_handlers.py
More file actions
76 lines (61 loc) · 2.48 KB
/
audit_handlers.py
File metadata and controls
76 lines (61 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
"""Audit script to find all missing GitLab client methods"""
import re
import ast
import sys
from pathlib import Path
def extract_handler_calls(handlers_file):
"""Extract all client method calls from tool handlers"""
with open(handlers_file, 'r') as f:
content = f.read()
# Find all return client.method_name(...) calls
pattern = r'return client\.(\w+)\('
calls = re.findall(pattern, content)
# Also find client.method_name calls in other contexts
pattern2 = r'client\.(\w+)\('
calls.extend(re.findall(pattern2, content))
return set(calls)
def extract_client_methods(client_file):
"""Extract all defined methods in GitLabClient"""
with open(client_file, 'r') as f:
tree = ast.parse(f.read())
methods = set()
for node in ast.walk(tree):
if isinstance(node, ast.ClassDef) and node.name == 'GitLabClient':
for item in node.body:
if isinstance(item, ast.FunctionDef):
if not item.name.startswith('_'): # Skip private methods
methods.add(item.name)
return methods
def main():
handlers_file = Path('/home/dev/IdeaProjects/mcp-gitlab/src/mcp_gitlab/tool_handlers.py')
client_file = Path('/home/dev/IdeaProjects/mcp-gitlab/src/mcp_gitlab/gitlab_client.py')
# Get all handler calls and client methods
handler_calls = extract_handler_calls(handlers_file)
client_methods = extract_client_methods(client_file)
# Find missing methods
missing = handler_calls - client_methods
# Sort for better readability
missing = sorted(missing)
handler_calls = sorted(handler_calls)
client_methods = sorted(client_methods)
print("=== AUDIT RESULTS ===\n")
print(f"Total handler calls: {len(handler_calls)}")
print(f"Total client methods: {len(client_methods)}")
print(f"Missing methods: {len(missing)}\n")
if missing:
print("MISSING METHODS:")
for method in missing:
print(f" - {method}")
else:
print("✅ All handler methods are implemented!")
# Also show methods that exist but aren't used
unused = client_methods - handler_calls
if unused:
print(f"\nUNUSED CLIENT METHODS ({len(unused)}):")
for method in sorted(unused)[:10]: # Show first 10
print(f" - {method}")
if len(unused) > 10:
print(f" ... and {len(unused) - 10} more")
if __name__ == "__main__":
main()