"""CLI command to start the machins MCP server (stdio transport)."""

from __future__ import annotations

import asyncio

import click


@click.command()
def mcp():
    """Start the machins MCP server for LLM tool integration."""
    try:
        from machins.mcp.server import create_mcp_server
        from mcp.server.stdio import stdio_server
    except ImportError:
        click.echo(
            "MCP dependencies not installed. Install with:\n"
            "  pip install machins[mcp]",
            err=True,
        )
        raise SystemExit(1)

    server = create_mcp_server()

    async def run():
        async with stdio_server() as (read_stream, write_stream):
            await server.run(
                read_stream, write_stream,
                server.create_initialization_options(),
            )

    asyncio.run(run())
