Skip to main content
Glama
debug_mcp_server.pyโ€ข8.82 kB
#!/usr/bin/env python3 # debug/debug_mcp_server.py """ Enhanced debug script to check what methods are available on the MCPServer object and analyze the complete chuk-mcp library structure. """ import inspect def analyze_mcp_server(): """Analyze the MCPServer class in detail.""" try: from chuk_mcp.server import MCPServer from chuk_mcp.protocol.types import ServerCapabilities print("๐Ÿ” Inspecting MCPServer class:") print("=" * 50) # Create a server instance server = MCPServer(name="test", version="1.0.0") # Get all methods and attributes methods = [] attributes = [] for name in dir(server): if not name.startswith("_"): obj = getattr(server, name) if callable(obj): methods.append(name) else: attributes.append(name) print("๐Ÿ“‹ Available Methods:") for method in sorted(methods): try: sig = inspect.signature(getattr(server, method)) print(f" โ€ข {method}{sig}") except: print(f" โ€ข {method}()") print("\n๐Ÿ“‹ Available Attributes:") for attr in sorted(attributes): attr_obj = getattr(server, attr) print(f" โ€ข {attr}: {type(attr_obj)}") # Check for specific methods we need required_methods = [ "run_stdio", "run", "start", "serve", "register_tool", "register_resource", "register_prompt", ] print("\n๐Ÿ” Checking for required methods:") for method in required_methods: if hasattr(server, method): print(f" โœ… {method} - Available") try: sig = inspect.signature(getattr(server, method)) print(f" Signature: {method}{sig}") except: pass else: print(f" โŒ {method} - Missing") # Check the server's class hierarchy print("\n๐Ÿ—๏ธ Class hierarchy:") for cls in server.__class__.__mro__: print(f" โ€ข {cls}") # Check if there are any run-like methods print("\n๐Ÿƒ Run-like methods:") run_methods = [] for method in methods: if any( keyword in method.lower() for keyword in ["run", "start", "serve", "execute", "handle"] ): run_methods.append(method) print(f" โ€ข {method}") if not run_methods: print(" ๐Ÿ“ No run-like methods found") # Analyze the protocol handler in detail print("\n๐Ÿ” Protocol Handler Analysis:") if hasattr(server, "protocol_handler"): handler = server.protocol_handler print(f" โ€ข Type: {type(handler)}") handler_methods = [] for name in dir(handler): if not name.startswith("_") and callable(getattr(handler, name)): handler_methods.append(name) print(f" โ€ข Methods: {', '.join(sorted(handler_methods))}") # Check if handle_message is async if hasattr(handler, "handle_message"): handle_msg = getattr(handler, "handle_message") is_async = inspect.iscoroutinefunction(handle_msg) print(f" โ€ข handle_message is async: {is_async}") try: sig = inspect.signature(handle_msg) print(f" โ€ข handle_message signature: {sig}") except: pass return True except ImportError as e: print(f"โŒ Failed to import chuk_mcp: {e}") return False except Exception as e: print(f"โŒ Error inspecting MCPServer: {e}") import traceback traceback.print_exc() return False def analyze_chuk_mcp_structure(): """Analyze the complete chuk_mcp library structure.""" print("\n๐Ÿ“ฆ Analyzing chuk_mcp library structure:") print("=" * 50) try: import chuk_mcp print(f"๐Ÿ” chuk_mcp version: {getattr(chuk_mcp, '__version__', 'unknown')}") # Get top-level items top_level = {} for attr in dir(chuk_mcp): if not attr.startswith("_"): obj = getattr(chuk_mcp, attr) obj_type = type(obj).__name__ if obj_type not in top_level: top_level[obj_type] = [] top_level[obj_type].append(attr) for obj_type, items in sorted(top_level.items()): print(f"\n๐Ÿ“‹ {obj_type}s ({len(items)}):") for item in sorted(items)[:10]: # Show first 10 print(f" โ€ข {item}") if len(items) > 10: print(f" ... and {len(items) - 10} more") # Check for transport-related items print("\n๐Ÿš› Transport-related items:") transport_items = [] for attr in dir(chuk_mcp): if any( keyword in attr.lower() for keyword in ["transport", "stdio", "http", "client", "server"] ): obj = getattr(chuk_mcp, attr) transport_items.append((attr, type(obj))) if transport_items: for attr, obj_type in transport_items: print(f" โ€ข {attr}: {obj_type}") else: print(" ๐Ÿ“ No obvious transport items found at top level") # Check submodules print("\n๐Ÿ“‚ Checking for submodules:") potential_submodules = ["server", "client", "transport", "protocol", "stdio"] for submodule in potential_submodules: if hasattr(chuk_mcp, submodule): sub = getattr(chuk_mcp, submodule) if hasattr(sub, "__file__") or hasattr(sub, "__path__"): print(f" โœ… {submodule}: {type(sub)}") # List contents of server module specifically if submodule == "server": print(" ๐Ÿ“‹ server module contents:") for item in dir(sub): if not item.startswith("_"): print(f" โ€ข {item}: {type(getattr(sub, item))}") else: print(f" โš ๏ธ {submodule}: {type(sub)} (not a module)") else: print(f" โŒ {submodule}: Not found") return True except Exception as e: print(f"โŒ Error analyzing chuk_mcp: {e}") return False def check_working_solution(): """Document our current working solution.""" print("\nโœ… Current Working Solution Summary:") print("=" * 50) print("๐Ÿ“Š What works:") print(" โ€ข MCPServer.register_tool() - โœ… Working") print(" โ€ข MCPServer.register_resource() - โœ… Working") print(" โ€ข MCPServer.protocol_handler.handle_message() - โœ… Working (async)") print(" โ€ข Manual stdio handling - โœ… Working") print(" โ€ข 286 mathematical functions - โœ… Working") print(" โ€ข Async function execution - โœ… Working") print(" โ€ข JSON-RPC communication - โœ… Working") print("\n๐Ÿ“Š What's missing/not working:") print(" โ€ข MCPServer.run_stdio() - โŒ Missing") print(" โ€ข MCPServer.register_prompt() - โŒ Missing") print(" โ€ข Built-in transport handling - โŒ Missing") print("\n๐Ÿ”ง Our workarounds:") print(" โ€ข Manual stdio loop instead of run_stdio()") print(" โ€ข Skip prompt registration (method doesn't exist)") print(" โ€ข Direct module access for math functions (get_mcp_functions returns 0)") print(" โ€ข Proper async/await handling for protocol_handler.handle_message()") print("\n๐ŸŽฏ Result:") print(" โ€ข Fully functional MCP Math Server with 286 functions") print(" โ€ข Compatible with chuk-mcp v0.4.0") print(" โ€ข Real mathematical computations working correctly") def main(): """Main analysis function.""" print("๐Ÿงฎ Enhanced chuk-mcp Library Analysis") print("=" * 60) # Analyze MCPServer server_success = analyze_mcp_server() # Analyze overall library structure lib_success = analyze_chuk_mcp_structure() # Document our working solution check_working_solution() print("\n๐Ÿ“‹ Analysis Summary:") print(f" โ€ข MCPServer analysis: {'โœ… Success' if server_success else 'โŒ Failed'}") print(f" โ€ข Library analysis: {'โœ… Success' if lib_success else 'โŒ Failed'}") print(" โ€ข Server implementation: โœ… Working with 286 functions") if __name__ == "__main__": main()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/chrishayuk/chuk-mcp-math-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server