import json, pathlib, sys, urllib.request
home, output = map(pathlib.Path, sys.argv[1:3])
credential=json.loads((home/'credential.json').read_text())
headers={'Content-Type':'application/json','Accept':'application/json, text/event-stream','Authorization':credential['authorizationHeader']}
def call(payload):
    request=urllib.request.Request(credential['endpoint'], json.dumps(payload).encode(), headers)
    with urllib.request.urlopen(request,timeout=40) as response:
        session=response.headers.get('mcp-session-id')
        if session: headers['mcp-session-id']=session
        raw=response.read().decode()
        try: return json.loads(raw)
        except json.JSONDecodeError:
            return [json.loads(line[6:]) for line in raw.splitlines() if line.startswith('data: ')][-1]
call({'jsonrpc':'2.0','id':1,'method':'initialize','params':{'protocolVersion':'2025-06-18','capabilities':{},'clientInfo':{'name':'snapshot-proof','version':'1'}}})
request={'jsonrpc':'2.0','id':2,'method':'tools/call','params':{'name':'preview_snapshot','arguments':{'tabId':'tab-mcp-alternate','save':True}}}
response=call(request)
transcript={'request':request,'response':response}
output.write_text(json.dumps(transcript,indent=2)+'\n')
print(json.dumps(transcript,indent=2))
