# AstraNL core tools with the official MCP Python SDK.  pip install mcp
import asyncio, json
from mcp import ClientSession
try:  # mcp 2.x
    from mcp.client.streamable_http import streamable_http_client as http_client
except ImportError:  # mcp 1.x
    from mcp.client.streamable_http import streamablehttp_client as http_client

async def main():
    async with http_client("https://astranl.com/mcp/streamable?profile=core") as streams:
        read, write = streams[0], streams[1]
        async with ClientSession(read, write) as s:
            await s.initialize()
            print([t.name for t in (await s.list_tools()).tools])
            est = json.loads((await s.call_tool("astranl_renovation_estimate_nl",
                              {"category": "painting", "area_m2": 30, "location": "Utrecht"})).content[0].text)
            print(est["answer_meta"]["range"]["typical"], est["receipt"]["reference"])
            v = json.loads((await s.call_tool("astranl_verify_receipt", {"ref": est["receipt"]["reference"]})).content[0].text)
            print(v["integrity"]["verdict"], v["integrity"]["proof_level"])
            return v["integrity"]["verdict"] in ("PASS", "SIGNED_PENDING_INCLUSION")

raise SystemExit(0 if asyncio.run(main()) else 1)
