""" Debug runner that starts the server and client in the same process for IDE debugging. Set breakpoints in mcp_server.py and they will be hit when you run test requests. """ import asyncio import json import sys from pathlib import Path # Add src to path so imports work sys.path.insert(0, str(Path(__file__).parent)) from mcp.client.stdio import stdio_client, StdioServerParameters from mcp import ClientSession async def debug_test(): """Run a single debug test.""" repo_root = Path(__file__).resolve().parent server_script = repo_root / "src" / "mcp_server.py" print("\n" + "=" * 70) print("๐Ÿ” MCP Server Debug Mode") print("=" * 70) print(f"๐Ÿ“ Server: {server_script}") print(f"โฑ๏ธ Starting server in debugger...") print("=" * 70 + "\n") # Create server parameters server_params = StdioServerParameters( command=sys.executable, args=[str(server_script)] ) try: # Connect to the server via stdio async with stdio_client(server_params) as (read, write): async with ClientSession(read, write) as session: # Initialize print("๐Ÿš€ Initializing session...\n") await session.initialize() print("โœ… Session initialized\n") # Test various tools - set breakpoints in mcp_server.py to debug test_cases = [ # ("list_s3_buckets", {}, "List S3 Buckets"), # ("list_lambda_functions", {}, "List Lambda Functions"), # ("query_mysql", {"sql": "SELECT VERSION()"}, "MySQL Version Test"), # ("get_s3_object", {"bucket": "qa-sr-versions-bucket", "key": "c5072516-6ee0-40a8-9b38-27a81c09e550"}, "Read S3 object"), ("get_lambda_info", {"bucket": "qa-sr-versions-bucket", "function_name": "qa-lambda-sr-add-version"}, "Get lambda function info"), ] for tool_name, arguments, description in test_cases: print("-" * 70) print(f"๐Ÿงช Test: {description}") print(f" Tool: {tool_name}") print(f" Args: {json.dumps(arguments, indent=2)}") print("-" * 70) try: # This call will hit any breakpoints in your tool functions result = await session.call_tool(tool_name, arguments) print("\nโœ… Success!\n") if result.content: for content in result.content: print(content.text) else: print("No result returned") except Exception as e: print(f"\nโŒ Error: {e}") import traceback traceback.print_exc() print("\n") except Exception as e: print(f"โŒ Connection Error: {e}") import traceback traceback.print_exc() sys.exit(1) if __name__ == "__main__": print("\n๐Ÿ’ก How to debug:") print(" 1. Set breakpoints in src/mcp_server.py (any line in a tool function)") print(" 2. Run this script in the IDE debugger") print(" 3. Execution will pause at breakpoints when tools are called\n") asyncio.run(debug_test())