import click
import logging
import json
import asyncio
from .client import MCPClient
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@click.group()
def cli():
"""MCP Client CLI"""
pass
@cli.command()
@click.option('--config', help='Path to MCP config file')
def list_servers(config: str):
"""List available MCP servers."""
client = MCPClient(config)
servers = client.list_servers()
if not servers:
logger.info("No servers found. Checking config...")
logger.info(f"Config content: {json.dumps(client.config, indent=2)}")
else:
for server in servers:
config = client.get_server_config(server)
print(f"\nServer: {server}")
print(f"Configuration: {json.dumps(config, indent=2)}")
@cli.command()
@click.option('--config', help='Path to MCP config file')
@click.option('--server', required=True, help='MCP server to use')
@click.option('--tool', help='Tool to use')
@click.argument('message')
def send(config: str, server: str, tool: str, message: str):
"""Send message to MCP server."""
try:
client = MCPClient(config)
response = asyncio.run(client.send_message(server, message, tool))
print(response)
except ConnectionError as e:
logger.error(f"Connection error: {e}")
print(f"Error: {e}")
except Exception as e:
logger.error(f"Error: {e}")
print(f"Error: {e}")
def main():
cli()
if __name__ == "__main__":
main()