#!/usr/bin/env python
"""
Run script for the Sequential Thinking MCP server with SSE transport.
This script makes it easy to run the server in SSE mode from the root directory.
"""
import os
import sys
import argparse
# Set environment variables for proper encoding
os.environ['PYTHONIOENCODING'] = 'utf-8'
os.environ['PYTHONUNBUFFERED'] = '1'
# Ensure stdout is clean before importing any modules
sys.stdout.flush()
# Import and run the server
from mcp_sequential_thinking.server import main
from mcp_sequential_thinking.logging_conf import configure_logging
# Configure logging for this script
logger = configure_logging("sequential-thinking.sse-runner")
def run_sse_server():
"""Run the MCP server in SSE mode with command line arguments."""
# Parse command line arguments
parser = argparse.ArgumentParser(description="Sequential Thinking MCP Server (SSE Mode)")
parser.add_argument(
"--host",
default="0.0.0.0",
help="Host to bind to (default: 0.0.0.0)"
)
parser.add_argument(
"--port",
type=int,
default=8000,
help="Port to bind to (default: 8000)"
)
parser.add_argument(
"--debug",
action="store_true",
help="Enable debug mode"
)
args = parser.parse_args()
# Set sys.argv to simulate command line arguments for the main function
sys.argv = [
"run_sse_server.py",
"--transport", "sse",
"--host", args.host,
"--port", str(args.port)
]
if args.debug:
sys.argv.append("--debug")
try:
logger.info("Starting Sequential Thinking MCP server in SSE mode")
main()
except Exception as e:
logger.error(f"Fatal error in MCP SSE server: {e}", exc_info=True)
sys.exit(1)
if __name__ == "__main__":
run_sse_server()