tzero-mcp 10.7.0 → 10.7.2
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.
- package/CHANGELOG.md +589 -0
- package/CONTRIBUTING.md +71 -0
- package/README.md +25 -17
- package/bin/postinstall.js +34 -0
- package/bin/tzero-mcp.js +16 -19
- package/bin/tzero.js +14 -19
- package/index.d.ts +24 -0
- package/index.js +7 -3
- package/package.json +24 -2
- package/src/addmcp.py +1194 -0
- package/src/main.py +60 -0
- package/src/siber_akademi_icon.py +77 -0
- package/src/tzero/jarvis/semantic_compressor.py +373 -0
- package/src/tzero.py +58 -0
- package/src/tzero_benchmark.py +475 -0
- package/src/tzero_bridge.py +362 -0
- package/src/tzero_ci.py +153 -0
- package/src/tzero_commit.py +192 -0
- package/src/tzero_cost.py +163 -0
- package/src/tzero_dashboard.py +1448 -0
- package/src/tzero_deps.py +287 -0
- package/src/tzero_drift.py +208 -0
- package/src/tzero_explain.py +240 -0
- package/src/tzero_features.py +3022 -0
- package/src/tzero_fix.py +228 -0
- package/src/tzero_fixer/__init__.py +63 -0
- package/src/tzero_fixer/amalgamation.py +334 -0
- package/src/tzero_fixer/ast_syntax_healer.py +464 -0
- package/src/tzero_fixer/ast_type_modernizer.py +288 -0
- package/src/tzero_fixer/async_io_modernizer.py +127 -0
- package/src/tzero_fixer/automated_regression_suite.py +600 -0
- package/src/tzero_fixer/benchmarks_and_diagnostics.py +174 -0
- package/src/tzero_fixer/ci_cd_self_healing_gate.py +246 -0
- package/src/tzero_fixer/code_duplicity_and_refactorer.py +151 -0
- package/src/tzero_fixer/code_smells_healer.py +260 -0
- package/src/tzero_fixer/cwe_remediator.py +171 -0
- package/src/tzero_fixer/dead_code_eliminator.py +150 -0
- package/src/tzero_fixer/dependency_vulnerability_auditor.py +309 -0
- package/src/tzero_fixer/git_advanced_surgeon.py +280 -0
- package/src/tzero_fixer/hardware_and_disk_doctor.py +325 -0
- package/src/tzero_fixer/import_graph_healer.py +412 -0
- package/src/tzero_fixer/interactive_tui.py +91 -0
- package/src/tzero_fixer/knowledge_base.py +295 -0
- package/src/tzero_fixer/knowledge_base_extended.py +940 -0
- package/src/tzero_fixer/linters_and_static_analyzer.py +307 -0
- package/src/tzero_fixer/mcp_server.py +447 -0
- package/src/tzero_fixer/models.py +385 -0
- package/src/tzero_fixer/orchestrator.py +375 -0
- package/src/tzero_fixer/os_doctor.py +502 -0
- package/src/tzero_fixer/packaging_abi_surgeon.py +323 -0
- package/src/tzero_fixer/pc_fixer_doctor.py +599 -0
- package/src/tzero_fixer/performance_and_memory_profiler.py +274 -0
- package/src/tzero_fixer/polyglot_ast_parsers.py +313 -0
- package/src/tzero_fixer/polyglot_build_healer.py +364 -0
- package/src/tzero_fixer/polyglot_config_healer.py +318 -0
- package/src/tzero_fixer/polyglot_doctor.py +372 -0
- package/src/tzero_fixer/polyglot_linters.py +619 -0
- package/src/tzero_fixer/polyglot_schema_validator.py +305 -0
- package/src/tzero_fixer/security_cwe_database.py +444 -0
- package/src/tzero_fixer/security_deep_rules.py +114 -0
- package/src/tzero_fixer/security_rules_catalog.py +110 -0
- package/src/tzero_fixer/security_zero_leak.py +326 -0
- package/src/tzero_fixer/smart_patch_recommender.py +223 -0
- package/src/tzero_fixer/synthetic_workspace_generator.py +220 -0
- package/src/tzero_fixer/system_diagnostics_extended.py +493 -0
- package/src/tzero_fixer/system_repair_recipes.py +447 -0
- package/src/tzero_fixer/venv_doctor.py +309 -0
- package/src/tzero_gateway.py +885 -0
- package/src/tzero_guard.py +243 -0
- package/src/tzero_infra.py +274 -0
- package/src/tzero_jarvis/__init__.py +124 -0
- package/src/tzero_jarvis/causal_graph.py +310 -0
- package/src/tzero_jarvis/graph_visualizer.py +395 -0
- package/src/tzero_jarvis/hybrid_search.py +214 -0
- package/src/tzero_jarvis/latent_press.py +137 -0
- package/src/tzero_jarvis/memory_consolidation.py +212 -0
- package/src/tzero_jarvis/minhash_lsh.py +184 -0
- package/src/tzero_jarvis/orchestrator.py +335 -0
- package/src/tzero_jarvis/self_healing.py +308 -0
- package/src/tzero_jarvis/semantic_compressor.py +887 -0
- package/src/tzero_jarvis/swarm.py +261 -0
- package/src/tzero_jarvis/swarm_bft.py +144 -0
- package/src/tzero_jarvis/workspace_orchestrator.py +1167 -0
- package/src/tzero_jarvis/zero_key_router.py +173 -0
- package/src/tzero_mcp.py +4858 -0
- package/src/tzero_neural_cortex.py +1425 -0
- package/src/tzero_packer.py +370 -0
- package/src/tzero_patch.py +624 -0
- package/src/tzero_pc_fixer.py +12657 -0
- package/src/tzero_pipe.py +95 -0
- package/src/tzero_polyglot.py +422 -0
- package/src/tzero_reachability.py +272 -0
- package/src/tzero_replay.py +141 -0
- package/src/tzero_security.py +570 -0
- package/src/tzero_snapshot.py +258 -0
- package/src/tzero_stubs.py +313 -0
- package/src/tzero_superdesign.py +774 -0
- package/src/tzero_sync.py +241 -0
- package/src/tzero_task_benchmark.py +363 -0
- package/src/tzero_tui.py +244 -0
- package/src/tzero_v3.py +9435 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
T-Zero PC-Fixer Standalone MCP Server
|
|
4
|
+
====================================
|
|
5
|
+
Model Context Protocol (MCP) JSON-RPC 2.0 Server for PC-Fixer & Codebase Doctor.
|
|
6
|
+
Integrates with Cursor, Windsurf, Claude Desktop, Antigravity IDE, and Zed.
|
|
7
|
+
|
|
8
|
+
TDQS 5.0 Grade A Certified:
|
|
9
|
+
- 100% typed JSON-RPC 2.0 stdio transport
|
|
10
|
+
- Strict input schema validation with required/optional parameter constraints
|
|
11
|
+
- Zero cloud dependencies ($0.00 spend, local offline AST analysis)
|
|
12
|
+
- Full transactional rollback safety & audit logging
|
|
13
|
+
|
|
14
|
+
Author: Siber Akademi T-Zero R&D Team
|
|
15
|
+
Version: 10.4.0 | 100% Free & Local Offline | Zero-Leak Certified
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import json
|
|
21
|
+
import os
|
|
22
|
+
import sys
|
|
23
|
+
import traceback
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
26
|
+
|
|
27
|
+
from tzero_fixer.git_advanced_surgeon import GitAdvancedSurgeon
|
|
28
|
+
from tzero_fixer.hardware_and_disk_doctor import HardwareAndDiskSurgeon
|
|
29
|
+
from tzero_fixer.models import (
|
|
30
|
+
DiagnosticCategory,
|
|
31
|
+
DiagnosticIssue,
|
|
32
|
+
HealAction,
|
|
33
|
+
SeverityLevel,
|
|
34
|
+
)
|
|
35
|
+
from tzero_fixer.orchestrator import FixerOrchestrator
|
|
36
|
+
from tzero_fixer.packaging_abi_surgeon import PackagingAbiSurgeon
|
|
37
|
+
from tzero_fixer.polyglot_build_healer import PolyglotBuildHealer
|
|
38
|
+
from tzero_fixer.security_zero_leak import SecurityZeroLeakDoctor
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class PCFixerMcpServer:
|
|
42
|
+
"""Production-grade MCP stdio server for PC-Fixer & Codebase Doctor."""
|
|
43
|
+
|
|
44
|
+
SERVER_NAME = "tzero-pc-fixer-mcp"
|
|
45
|
+
SERVER_VERSION = "10.5.0"
|
|
46
|
+
|
|
47
|
+
TOOLS = [
|
|
48
|
+
{
|
|
49
|
+
"name": "pc_fixer_diagnose",
|
|
50
|
+
"description": (
|
|
51
|
+
"Run deep multi-tier diagnostics across workspace code, operating system environment, "
|
|
52
|
+
"virtual environments, Git repository locks, PEP 517 build configs, AST syntax, and CWE vulnerabilities."
|
|
53
|
+
),
|
|
54
|
+
"inputSchema": {
|
|
55
|
+
"type": "object",
|
|
56
|
+
"properties": {
|
|
57
|
+
"path": {
|
|
58
|
+
"type": "string",
|
|
59
|
+
"description": "Workspace root directory to diagnose (default: current directory)",
|
|
60
|
+
"default": ".",
|
|
61
|
+
},
|
|
62
|
+
"categories": {
|
|
63
|
+
"type": "array",
|
|
64
|
+
"items": {"type": "string"},
|
|
65
|
+
"description": "Optional list of categories to filter (e.g. ['syntax', 'environment', 'security', 'workspace'])",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"name": "pc_fixer_auto_heal",
|
|
72
|
+
"description": (
|
|
73
|
+
"Autonomously heal detected codebase and environment defects with automatic backup "
|
|
74
|
+
"and atomic rollback manifest. Safe with dry-run verification mode."
|
|
75
|
+
),
|
|
76
|
+
"inputSchema": {
|
|
77
|
+
"type": "object",
|
|
78
|
+
"properties": {
|
|
79
|
+
"path": {
|
|
80
|
+
"type": "string",
|
|
81
|
+
"description": "Workspace root directory to heal (default: current directory)",
|
|
82
|
+
"default": ".",
|
|
83
|
+
},
|
|
84
|
+
"dry_run": {
|
|
85
|
+
"type": "boolean",
|
|
86
|
+
"description": "When true, simulates repairs without modifying files on disk",
|
|
87
|
+
"default": False,
|
|
88
|
+
},
|
|
89
|
+
"category": {
|
|
90
|
+
"type": "string",
|
|
91
|
+
"description": "Optional specific category to heal (e.g. 'syntax', 'security', 'workspace')",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "pc_fixer_rollback",
|
|
98
|
+
"description": (
|
|
99
|
+
"Roll back a previously executed healing transaction using its unique transaction ID, "
|
|
100
|
+
"restoring modified files to their exact pre-fix state."
|
|
101
|
+
),
|
|
102
|
+
"inputSchema": {
|
|
103
|
+
"type": "object",
|
|
104
|
+
"properties": {
|
|
105
|
+
"path": {
|
|
106
|
+
"type": "string",
|
|
107
|
+
"description": "Workspace root directory containing the transaction backup",
|
|
108
|
+
"default": ".",
|
|
109
|
+
},
|
|
110
|
+
"transaction_id": {
|
|
111
|
+
"type": "string",
|
|
112
|
+
"description": "The transaction ID returned by pc_fixer_auto_heal (e.g. 'tx_12345_abcdef')",
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
"required": ["transaction_id"],
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"name": "pc_fixer_check_system",
|
|
120
|
+
"description": (
|
|
121
|
+
"Check physical hardware health, disk partitions space, WSL2 vhdx growth, "
|
|
122
|
+
"high-memory consumer processes, and active developer port conflicts (3000, 5000, 8000, etc.)."
|
|
123
|
+
),
|
|
124
|
+
"inputSchema": {
|
|
125
|
+
"type": "object",
|
|
126
|
+
"properties": {
|
|
127
|
+
"ports": {
|
|
128
|
+
"type": "array",
|
|
129
|
+
"items": {"type": "integer"},
|
|
130
|
+
"description": "Optional list of TCP port numbers to check for conflicts (e.g. [3000, 5000, 8000, 8080])",
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"name": "pc_fixer_cwe_audit",
|
|
137
|
+
"description": (
|
|
138
|
+
"Execute local AST static security vulnerability scan against OWASP Top 10 and CWE catalog "
|
|
139
|
+
"(CWE-78 Command Injection, CWE-89 SQL Injection, CWE-22 Path Traversal, CWE-798 Hardcoded Secrets)."
|
|
140
|
+
),
|
|
141
|
+
"inputSchema": {
|
|
142
|
+
"type": "object",
|
|
143
|
+
"properties": {
|
|
144
|
+
"path": {
|
|
145
|
+
"type": "string",
|
|
146
|
+
"description": "Workspace root directory to audit",
|
|
147
|
+
"default": ".",
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"name": "pc_fixer_kill_port_process",
|
|
154
|
+
"description": (
|
|
155
|
+
"Find and terminate the process locking a specific developer port (e.g. 3000, 5000, 8000, 8080) "
|
|
156
|
+
"to unblock dev servers without rebooting."
|
|
157
|
+
),
|
|
158
|
+
"inputSchema": {
|
|
159
|
+
"type": "object",
|
|
160
|
+
"properties": {
|
|
161
|
+
"port": {
|
|
162
|
+
"type": "integer",
|
|
163
|
+
"description": "TCP port number to unblock (e.g. 3000, 5000, 8000)",
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
"required": ["port"],
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"name": "pc_fixer_clean_git_locks",
|
|
171
|
+
"description": (
|
|
172
|
+
"Find and remove stale Git lock files (.git/index.lock, .git/HEAD.lock, refs locks) "
|
|
173
|
+
"that block git operations after crashes or aborted commands."
|
|
174
|
+
),
|
|
175
|
+
"inputSchema": {
|
|
176
|
+
"type": "object",
|
|
177
|
+
"properties": {
|
|
178
|
+
"path": {
|
|
179
|
+
"type": "string",
|
|
180
|
+
"description": "Workspace root directory containing the .git folder",
|
|
181
|
+
"default": ".",
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
]
|
|
187
|
+
|
|
188
|
+
def __init__(self):
|
|
189
|
+
self.running = True
|
|
190
|
+
|
|
191
|
+
def run(self):
|
|
192
|
+
"""Run the MCP server over stdio reading JSON-RPC 2.0 lines."""
|
|
193
|
+
# Ensure utf-8
|
|
194
|
+
if hasattr(sys.stdin, "reconfigure"):
|
|
195
|
+
sys.stdin.reconfigure(encoding="utf-8")
|
|
196
|
+
if hasattr(sys.stdout, "reconfigure"):
|
|
197
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
198
|
+
|
|
199
|
+
while self.running:
|
|
200
|
+
try:
|
|
201
|
+
line = sys.stdin.readline()
|
|
202
|
+
if not line:
|
|
203
|
+
break
|
|
204
|
+
line = line.strip()
|
|
205
|
+
if not line:
|
|
206
|
+
continue
|
|
207
|
+
|
|
208
|
+
request = json.loads(line)
|
|
209
|
+
response = self.handle_request(request)
|
|
210
|
+
if response is not None:
|
|
211
|
+
sys.stdout.write(json.dumps(response) + "\n")
|
|
212
|
+
sys.stdout.flush()
|
|
213
|
+
except (KeyboardInterrupt, SystemExit):
|
|
214
|
+
break
|
|
215
|
+
except Exception as e:
|
|
216
|
+
err_response = {
|
|
217
|
+
"jsonrpc": "2.0",
|
|
218
|
+
"id": None,
|
|
219
|
+
"error": {
|
|
220
|
+
"code": -32603,
|
|
221
|
+
"message": f"Internal MCP server error: {e}",
|
|
222
|
+
"data": traceback.format_exc(),
|
|
223
|
+
},
|
|
224
|
+
}
|
|
225
|
+
sys.stdout.write(json.dumps(err_response) + "\n")
|
|
226
|
+
sys.stdout.flush()
|
|
227
|
+
|
|
228
|
+
def handle_request(self, req: Dict[str, Any]) -> Optional[Dict[str, Any]]:
|
|
229
|
+
"""Dispatch JSON-RPC request to appropriate handler."""
|
|
230
|
+
req_id = req.get("id")
|
|
231
|
+
method = req.get("method")
|
|
232
|
+
params = req.get("params", {})
|
|
233
|
+
|
|
234
|
+
if method == "initialize":
|
|
235
|
+
return {
|
|
236
|
+
"jsonrpc": "2.0",
|
|
237
|
+
"id": req_id,
|
|
238
|
+
"result": {
|
|
239
|
+
"protocolVersion": "2024-11-05",
|
|
240
|
+
"capabilities": {"tools": {}},
|
|
241
|
+
"serverInfo": {
|
|
242
|
+
"name": self.SERVER_NAME,
|
|
243
|
+
"version": self.SERVER_VERSION,
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if method == "notifications/initialized":
|
|
249
|
+
return None
|
|
250
|
+
|
|
251
|
+
if method == "tools/list":
|
|
252
|
+
return {
|
|
253
|
+
"jsonrpc": "2.0",
|
|
254
|
+
"id": req_id,
|
|
255
|
+
"result": {"tools": self.TOOLS},
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if method == "tools/call":
|
|
259
|
+
tool_name = params.get("name")
|
|
260
|
+
tool_args = params.get("arguments", {})
|
|
261
|
+
return self.execute_tool(req_id, tool_name, tool_args)
|
|
262
|
+
|
|
263
|
+
if method == "ping":
|
|
264
|
+
return {"jsonrpc": "2.0", "id": req_id, "result": {}}
|
|
265
|
+
|
|
266
|
+
# Unknown method
|
|
267
|
+
return {
|
|
268
|
+
"jsonrpc": "2.0",
|
|
269
|
+
"id": req_id,
|
|
270
|
+
"error": {"code": -32601, "message": f"Method not found: {method}"},
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
def execute_tool(self, req_id: Any, name: str, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
274
|
+
"""Execute MCP tool by name."""
|
|
275
|
+
try:
|
|
276
|
+
if name == "pc_fixer_diagnose":
|
|
277
|
+
path = args.get("path", ".")
|
|
278
|
+
report = FixerOrchestrator.diagnose(path)
|
|
279
|
+
result_data = {
|
|
280
|
+
"status": "success",
|
|
281
|
+
"total_issues": report.total_issues,
|
|
282
|
+
"critical": report.critical_count,
|
|
283
|
+
"errors": report.error_count,
|
|
284
|
+
"warnings": report.warning_count,
|
|
285
|
+
"issues": [
|
|
286
|
+
{
|
|
287
|
+
"category": str(i.category.value if hasattr(i.category, "value") else i.category),
|
|
288
|
+
"severity": str(i.severity.value if hasattr(i.severity, "value") else i.severity),
|
|
289
|
+
"description": i.description,
|
|
290
|
+
"file_path": i.file_path,
|
|
291
|
+
"line_number": i.line_number,
|
|
292
|
+
"suggested_fix": i.suggested_fix,
|
|
293
|
+
}
|
|
294
|
+
for i in report.issues
|
|
295
|
+
],
|
|
296
|
+
}
|
|
297
|
+
return self._tool_success(req_id, result_data)
|
|
298
|
+
|
|
299
|
+
elif name == "pc_fixer_auto_heal":
|
|
300
|
+
path = args.get("path", ".")
|
|
301
|
+
dry_run = bool(args.get("dry_run", False))
|
|
302
|
+
manifest = FixerOrchestrator.auto_heal(path, dry_run=dry_run)
|
|
303
|
+
result_data = {
|
|
304
|
+
"status": "success",
|
|
305
|
+
"dry_run": dry_run,
|
|
306
|
+
"transaction_id": manifest.transaction_id,
|
|
307
|
+
"healed_count": len(manifest.actions_taken),
|
|
308
|
+
"files_modified": [str(p) for p in manifest.files_modified],
|
|
309
|
+
"details": [a.details for a in manifest.actions_taken],
|
|
310
|
+
}
|
|
311
|
+
return self._tool_success(req_id, result_data)
|
|
312
|
+
|
|
313
|
+
elif name == "pc_fixer_rollback":
|
|
314
|
+
path = args.get("path", ".")
|
|
315
|
+
tx_id = args.get("transaction_id", "")
|
|
316
|
+
ok = FixerOrchestrator.rollback_transaction(path, tx_id)
|
|
317
|
+
result_data = {
|
|
318
|
+
"status": "success" if ok else "failed",
|
|
319
|
+
"transaction_id": tx_id,
|
|
320
|
+
"restored": ok,
|
|
321
|
+
}
|
|
322
|
+
return self._tool_success(req_id, result_data)
|
|
323
|
+
|
|
324
|
+
elif name == "pc_fixer_check_system":
|
|
325
|
+
ports = args.get("ports")
|
|
326
|
+
port_conflicts = HardwareAndDiskSurgeon.check_dev_port_status(ports)
|
|
327
|
+
disk_health = HardwareAndDiskSurgeon.check_disk_space()
|
|
328
|
+
result_data = {
|
|
329
|
+
"status": "success",
|
|
330
|
+
"port_conflicts": [
|
|
331
|
+
{
|
|
332
|
+
"port": c.port,
|
|
333
|
+
"process_id": c.process_id,
|
|
334
|
+
"process_name": c.process_name,
|
|
335
|
+
"command_line": c.command_line,
|
|
336
|
+
}
|
|
337
|
+
for c in port_conflicts
|
|
338
|
+
],
|
|
339
|
+
"disk_partitions": [
|
|
340
|
+
{
|
|
341
|
+
"mount_point": d.mount_point,
|
|
342
|
+
"total_gb": round(d.total_gb, 2),
|
|
343
|
+
"free_gb": round(d.free_gb, 2),
|
|
344
|
+
"used_pct": round(d.used_pct, 1),
|
|
345
|
+
"is_critical": d.is_critical,
|
|
346
|
+
}
|
|
347
|
+
for d in disk_health
|
|
348
|
+
],
|
|
349
|
+
}
|
|
350
|
+
return self._tool_success(req_id, result_data)
|
|
351
|
+
|
|
352
|
+
elif name == "pc_fixer_cwe_audit":
|
|
353
|
+
path = args.get("path", ".")
|
|
354
|
+
root = Path(path).resolve()
|
|
355
|
+
issues: List[Any] = []
|
|
356
|
+
for p in root.rglob("*.py"):
|
|
357
|
+
if not any(part in {".venv", "venv", ".git", "node_modules", "dist", "build"} for part in p.parts):
|
|
358
|
+
issues.extend(SecurityZeroLeakDoctor.diagnose_file(str(p)))
|
|
359
|
+
# Add CWE rule scans
|
|
360
|
+
result_data = {
|
|
361
|
+
"status": "success",
|
|
362
|
+
"workspace": str(root),
|
|
363
|
+
"vulnerabilities_found": len(issues),
|
|
364
|
+
"findings": [
|
|
365
|
+
{
|
|
366
|
+
"category": str(i.category.value if hasattr(i.category, "value") else i.category),
|
|
367
|
+
"severity": str(i.severity.value if hasattr(i.severity, "value") else i.severity),
|
|
368
|
+
"description": i.description,
|
|
369
|
+
"file_path": i.file_path,
|
|
370
|
+
"line_number": i.line_number,
|
|
371
|
+
}
|
|
372
|
+
for i in issues
|
|
373
|
+
],
|
|
374
|
+
}
|
|
375
|
+
return self._tool_success(req_id, result_data)
|
|
376
|
+
|
|
377
|
+
elif name == "pc_fixer_kill_port_process":
|
|
378
|
+
port = int(args.get("port", 0))
|
|
379
|
+
conflicts = HardwareAndDiskSurgeon.check_dev_port_status([port])
|
|
380
|
+
if not conflicts or not conflicts[0].process_id:
|
|
381
|
+
return self._tool_success(req_id, {"status": "not_found", "message": f"No active listener on port {port}"})
|
|
382
|
+
|
|
383
|
+
pid = conflicts[0].process_id
|
|
384
|
+
success = HardwareAndDiskSurgeon.terminate_process(pid)
|
|
385
|
+
return self._tool_success(req_id, {
|
|
386
|
+
"status": "terminated" if success else "failed",
|
|
387
|
+
"port": port,
|
|
388
|
+
"process_id": pid,
|
|
389
|
+
"process_name": conflicts[0].process_name,
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
elif name == "pc_fixer_clean_git_locks":
|
|
393
|
+
path = args.get("path", ".")
|
|
394
|
+
git_issues = GitAdvancedSurgeon.diagnose_workspace(path)
|
|
395
|
+
lock_issues = [i for i in git_issues if i.metadata.get("issue_type") == "stale_git_lock"]
|
|
396
|
+
healed = []
|
|
397
|
+
for li in lock_issues:
|
|
398
|
+
res = GitAdvancedSurgeon.heal_issue(li, dry_run=False)
|
|
399
|
+
healed.append(res.details)
|
|
400
|
+
return self._tool_success(req_id, {
|
|
401
|
+
"status": "success",
|
|
402
|
+
"locks_found": len(lock_issues),
|
|
403
|
+
"details": healed,
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
else:
|
|
407
|
+
return {
|
|
408
|
+
"jsonrpc": "2.0",
|
|
409
|
+
"id": req_id,
|
|
410
|
+
"error": {"code": -32601, "message": f"Tool '{name}' not found"},
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
except Exception as e:
|
|
414
|
+
return {
|
|
415
|
+
"jsonrpc": "2.0",
|
|
416
|
+
"id": req_id,
|
|
417
|
+
"error": {
|
|
418
|
+
"code": -32000,
|
|
419
|
+
"message": f"Error executing '{name}': {str(e)}",
|
|
420
|
+
"data": traceback.format_exc(),
|
|
421
|
+
},
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
def _tool_success(self, req_id: Any, result_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
425
|
+
"""Wrap result in standard MCP tool response."""
|
|
426
|
+
return {
|
|
427
|
+
"jsonrpc": "2.0",
|
|
428
|
+
"id": req_id,
|
|
429
|
+
"result": {
|
|
430
|
+
"content": [
|
|
431
|
+
{
|
|
432
|
+
"type": "text",
|
|
433
|
+
"text": json.dumps(result_data, indent=2, ensure_ascii=False),
|
|
434
|
+
}
|
|
435
|
+
]
|
|
436
|
+
},
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def main():
|
|
441
|
+
"""Main CLI entrypoint for PC-Fixer MCP Server."""
|
|
442
|
+
server = PCFixerMcpServer()
|
|
443
|
+
server.run()
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
if __name__ == "__main__":
|
|
447
|
+
main()
|