[{'Text': '\n\n# ── ClickHouse ontology tools ────────────────────────────────────────────────\n# Requires CLICKHOUSE_HOST + CLICKHOUSE_PASSWORD env vars,\n# OR will auto-fetch from AWS Secrets Manager (ptserver-secret) if running on\n# the server (109.169.53.90).\n\n# def _clickhouse_available() -> bool:\n#     """True if ClickHouse creds are resolvable (env vars or Secrets Manager)."""\n#     if os.environ.get("CLICKHOUSE_HOST") and os.environ.get("CLICKHOUSE_PASSWORD"):\n#         return True\n#     # Try Secrets Manager silently\n#     try:\n#         import boto3, json as _json\n#         secret = _json.loads(\n#             boto3.client("secretsmanager", region_name="eu-west-1")\n#                 .get_secret_value(SecretId="ptserver-secret")["SecretString"]\n#         )\n#         return bool(secret.get("CLICKHOUSE_HOST") and secret.get("CLICKHOUSE_PASSWORD"))\n#     except Exception:\n#         return False\n\nif False:\n# if check_env_vars(\'clickhouse_tools\', [\'CLICKHOUSE_HOST\', \'CLICKHOUSE_PASSWORD\']) or _clickhouse_available():\n    @dynamic_docstring([("SUMMARY", get_ontology_summary)])\n    def assemble_ontology_context(\n        ctx: Optional[Context] = None,\n    ) -> str:\n        """\n        Assemble the full context (instructions, schema, SQL examples) for the\n        Point Topic Ontology dataset stored in ClickHouse.\n\n        Call this before executing any ontology query so the agent understands\n        the schema, available tables, and correct SQL dialect.\n\n        Returns the complete context needed for querying the ontology.\n\n        Summary: {SUMMARY}\n        """\n        return assemble_context(["ontology"])\n\n    def execute_ontology_query(\n        sql_query: str,\n        ctx: Optional[Context] = None,\n    ) -> str:\n        """\n        Execute a read-only SQL query against the Point Topic Ontology ClickHouse database.\n\n        Only SELECT/WITH/SHOW/DESCRIBE queries are allowed.\n        Call assemble_ontology_context first to understand the schema.\n\n        The ontology database contains UK telecom market data:\n        organisations, networks, ISP-network relationships, broadband services,\n        coverage measurements, and more.\n\n        Args:\n            sql_query: SQL query to run. Table names are unqualified lowercase\n                       (e.g. foaf_organization, cto_uses_network).\n                       Use toDate() for date comparisons and today() for current date.\n\n        Returns:\n            CSV results string, or an error message prefixed with ERROR:/DATABASE ERROR:\n        """\n        from point_topic_mcp.connectors.clickhouse import ClickHouseDB\n\n        db = ClickHouseDB()\n        try:\n            db.connect()\n        except RuntimeError as e:\n            return f"DATABASE ERROR: {e}"\n'}]