Files
HealthTracking/scripts/fix_mcp_json.py
T
evandro 86a4949751 wip: snapshot das alterações não commitadas (2026-10-20)
Origem: D:/Documents/Github/HealthTracking
Arquivos omitidos (segredos, bancos de dados, logs, >50 MB): 1
2026-10-20 00:49:37 -03:00

65 lines
2.1 KiB
Python

"""Just rewrite the mcp.json cleanly with the new whisper path"""
import json
import os
import sys
path = 'C:/Users/Evandro/.pi/agent/mcp.json'
with open(path, 'r', encoding='utf-8') as f:
raw = f.read()
# Find the whisper block
start_marker = '"whisper": {'
start_idx = raw.find(start_marker)
if start_idx == -1:
print("Not found")
sys.exit(1)
# Find the matching closing brace
depth = 0
i = start_idx + len(start_marker) - 1
in_string = False
escape = False
while i < len(raw):
c = raw[i]
if escape:
escape = False
i += 1
continue
if c == chr(92): # backslash
escape = True
i += 1
continue
if c == '"':
in_string = not in_string
i += 1
continue
if in_string:
i += 1
continue
if c == '{':
depth += 1
elif c == '}':
depth -= 1
if depth == 0:
end_idx = i + 1
break
i += 1
else:
print("No matching close brace found")
sys.exit(1)
print(f"start={start_idx}, end={end_idx}")
new_whisper = '"whisper": {\n "command": "C:\\\\Users\\\\Evandro\\\\AppData\\\\Local\\\\Programs\\\\Python\\\\Python312\\\\python.exe",\n "args": [\n "D:/Documents/GitHub/whisper-mcp/server.py"\n ],\n "description": "Whisper transcription via local Speaches/Whisper (faster-whisper-large-v3-turbo). v2.0 with SSRF guard, size limit, retry, structured errors.",\n "timeout": 180,\n "lifecycle": "lazy",\n "idleTimeout": 10,\n "directTools": true,\n "environment": {\n "WHISPER_BASE_URL": "http://localhost:8000",\n "WHISPER_MODEL": "deepdml/faster-whisper-large-v3-turbo-ct2",\n "WHISPER_TIMEOUT": "120",\n "WHISPER_MAX_BYTES": "26214400"\n }\n }'
new_raw = raw[:start_idx] + new_whisper + raw[end_idx:]
try:
parsed = json.loads(new_raw)
print("JSON valid")
with open(path, 'w', encoding='utf-8') as f:
f.write(new_raw)
print("Saved")
except json.JSONDecodeError as e:
print(f"Still invalid: {e}")
start = max(0, e.pos - 100)
end = min(len(new_raw), e.pos + 100)
print(f"Context: {new_raw[start:end]!r}")