"""Claude Desktop MCP server configuration emitter.

Generates the JSON fragment for Claude Desktop's ``mcpServers`` config
that points at an ARIA MCP Gateway with proper Streamable HTTP transport
semantics, Bearer auth, and protocol version headers.
"""

from __future__ import annotations

from typing import Any

MCP_PROTOCOL_VERSION = "2025-03-26"


def claude_desktop_config(
    server_name: str,
    gateway_url: str,
    token: str,
    *,
    protocol_version: str = MCP_PROTOCOL_VERSION,
) -> dict[str, Any]:
    """Generate a Claude Desktop ``mcpServers`` config entry for ARIA MCP Gateway.

    The returned dict is suitable for merging into
    ``claude_desktop_config.json`` under the ``mcpServers`` key.

    Args:
        server_name: Logical name for the MCP server entry.
        gateway_url: ARIA MCP Gateway URL (e.g. ``https://mcp.example.com/v1/mcp``).
        token: Bearer token for every MCP request.
        protocol_version: MCP protocol version string.

    Returns:
        A dict keyed by ``server_name`` containing the full server config.

    Example::

        config = claude_desktop_config(
            server_name="aria-gateway",
            gateway_url="https://mcp.acme.com/v1/mcp",
            token="eyJ...",
        )
        # Merge into claude_desktop_config.json:
        # { "mcpServers": { **config } }
    """
    if not gateway_url:
        raise ValueError("gateway_url must not be empty")
    if not token:
        raise ValueError("token must not be empty")
    if not server_name:
        raise ValueError("server_name must not be empty")

    return {
        server_name: {
            "url": gateway_url,
            "transport": "streamable-http",
            "headers": {
                "Authorization": f"Bearer {token}",
                "Mcp-Protocol-Version": protocol_version,
            },
        },
    }
