#!/usr/bin/env python3
import json, yaml, urllib.request, urllib.error
PAT = yaml.safe_load(open('/root/.hermes/config.yaml'))['mcp_servers']['airtable']['env']['AIRTABLE_API_KEY']
BASE = 'appE43UvTyARe5oJs'

def req(path):
    r = urllib.request.Request(
        f'https://api.airtable.com/v0/{BASE}/{path}',
        headers={'Authorization': f'Bearer {PAT}'}
    )
    try:
        with urllib.request.urlopen(r, timeout=15) as resp:
            return resp.status, json.loads(resp.read().decode())
    except urllib.error.HTTPError as e:
        return e.code, e.read().decode()[:300]

st, data = req('tables?detailLevel=tableIdentifiersOnly')
print('STATUS:', st)
if st == 200:
    for t in data.get('tables', []):
        print(' -', t.get('id'), t.get('name'))
