#!/usr/bin/env python
"""Check for unclosed docstrings in server.py"""

with open(r'C:\ProgramData\Ableton\Live 12 Suite\Resources\MIDI Remote Scripts\AbletonMCP_AI\mcp_server\server.py', 'r', encoding='utf-8') as f:
    lines = f.readlines()

# Check for triple-quote balance
in_docstring = False
docstring_char = None
line_num = 0

for i, line in enumerate(lines, 1):
    if not in_docstring:
        if '"""' in line:
            count = line.count('"""')
            if count % 2 == 1:
                in_docstring = True
                docstring_char = '"""'
                line_num = i
        if "'''" in line:
            count = line.count("'''")
            if count % 2 == 1:
                in_docstring = True
                docstring_char = "'''"
                line_num = i
    else:
        if docstring_char in line:
            count = line.count(docstring_char)
            if count % 2 == 1:
                in_docstring = False

if in_docstring:
    print(f'ERROR: Unclosed docstring starting at line {line_num}')
    # Show context
    print(f'Line {line_num-2}: {repr(lines[line_num-3])}')
    print(f'Line {line_num-1}: {repr(lines[line_num-2])}')
    print(f'Line {line_num}: {repr(lines[line_num-1])}')
else:
    print('All docstrings properly closed')
