"""{{ display_name }} MCP server — generated by mcpify. Do not hand-edit."""

from __future__ import annotations

import json

from ..auth.auth_manager import AuthManager
from ..core.config import load_config
from ..core.errors import NotFoundError
from ..data.store import cached_store_connection, close_cached_connections, get_endpoint
from ..tools.call_tool import call_operation


async def run(operation_id: str, args_json: str) -> None:
    try:
        config = load_config()
        auth_manager = AuthManager(config.auth_method)
        args = json.loads(args_json)

        conn = await cached_store_connection(config.api_version)
        endpoint = await get_endpoint(conn, operation_id)
        if endpoint is None:
            raise NotFoundError(f"unknown operationId '{operation_id}'")

        result = await call_operation(endpoint, config, auth_manager, operation_id, args, None)
        print(json.dumps(result, indent=2))
    finally:
        await close_cached_connections()
