#!/usr/bin/env python3
"""
Chatlog MCP Server CLI
"""
import argparse
import sys
import asyncio
from .server import main as server_main
def main():
"""Main entry point for the CLI"""
parser = argparse.ArgumentParser(
description="Chatlog MCP Server - Analyze chat logs via MCP protocol",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# Start the MCP server
chatlog-mcp
# Start with custom API URL
chatlog-mcp --api-url http://localhost:5030
# Start with debug logging
chatlog-mcp --log-level debug
# Show version
chatlog-mcp --version
"""
)
parser.add_argument(
"--api-url",
type=str,
default="http://127.0.0.1:5030",
help="HTTP API server URL (default: http://127.0.0.1:5030)"
)
parser.add_argument(
"--log-level",
type=str,
choices=["debug", "info", "warning", "error"],
default="info",
help="Logging level (default: info)"
)
parser.add_argument(
"--version",
action="version",
version="%(prog)s 1.0.0"
)
args = parser.parse_args()
# Set environment variables for the server
import os
os.environ["CHATLOG_API_URL"] = args.api_url
os.environ["CHATLOG_LOG_LEVEL"] = args.log_level
# Run the server
try:
asyncio.run(server_main())
except KeyboardInterrupt:
print("\nServer stopped by user")
sys.exit(0)
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()