test_mcp_tools.pyโข5.65 kB
#!/usr/bin/env python3
"""
Test script to verify MCP tools are properly registered
This helps debug why Cursor might not see the tools
"""
import sys
import os
# Add current directory to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def test_mcp_tools():
"""Test that MCP tools are properly registered"""
print("๐งช Testing MCP Tool Registration...")
try:
# Import the main module
from main import mcp, get_available_tools
print(f"โ
MCP server imported: {mcp}")
print(f"๐ Server name: {mcp.name}")
# Check available tools using the helper function
tools = get_available_tools()
print(f"๐ง Available tools: {len(tools) if isinstance(tools, dict) else 0}")
if not tools:
print("โ No tools found! This is the problem.")
return False
# List all tools with their details
for tool_name, tool_info in tools.items():
print(f" ๐ {tool_name}:")
if isinstance(tool_info, dict):
print(f" Description: {tool_info.get('description', 'No description')}")
print(f" Parameters: {tool_info.get('parameters', 'No parameters')}")
else:
print(f" Info: {tool_info}")
print()
# Test tool execution (if possible)
print("๐งช Testing tool execution...")
# Test the system status tool
if 'get_system_status' in tools:
print("โ
get_system_status tool found")
else:
print("โ get_system_status tool not found")
# Test the test conversation tracking tool
if 'test_conversation_tracking' in tools:
print("โ
test_conversation_tracking tool found")
else:
print("โ test_conversation_tracking tool not found")
# Test the weather tool
if 'get_current_weather' in tools:
print("โ
get_current_weather tool found")
else:
print("โ get_current_weather tool not found")
print("\n๐ MCP tools are properly registered!")
return True
except Exception as e:
print(f"โ Error testing MCP tools: {e}")
import traceback
traceback.print_exc()
return False
def test_mcp_server_startup():
"""Test that the MCP server can start properly"""
print("\n๐ Testing MCP Server Startup...")
try:
from main import mcp, get_available_tools
# Check if we can access the server object
print(f"โ
MCP server object accessible: {type(mcp)}")
print(f"โ
Server name: {mcp.name}")
# Get available tools
tools = get_available_tools()
tool_names = list(tools.keys()) if isinstance(tools, dict) else []
print(f"โ
Available tools: {tool_names}")
# Test that the server has the right attributes
if hasattr(mcp, 'run'):
print("โ
Server has 'run' method")
else:
print("โ Server missing 'run' method")
# Check for tools-related attributes
tools_attrs = [attr for attr in dir(mcp) if 'tool' in attr.lower()]
if tools_attrs:
print(f"โ
Server has tools-related attributes: {tools_attrs}")
else:
print("โ ๏ธ Server has no obvious tools-related attributes")
return True
except Exception as e:
print(f"โ Error testing MCP server startup: {e}")
return False
def test_tool_execution():
"""Test that tools can actually be executed"""
print("\n๐ง Testing Tool Execution...")
try:
from main import get_system_status, test_conversation_tracking
# Test system status tool
print("๐งช Testing get_system_status...")
status_result = get_system_status()
print(f"โ
get_system_status result: {status_result[:100]}...")
# Test conversation tracking tool
print("๐งช Testing test_conversation_tracking...")
tracking_result = test_conversation_tracking("Test from test script")
print(f"โ
test_conversation_tracking result: {tracking_result}")
return True
except Exception as e:
print(f"โ Error testing tool execution: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
print("๐ MCP Tools Registration Test")
print("=" * 50)
tools_ok = test_mcp_tools()
startup_ok = test_mcp_server_startup()
execution_ok = test_tool_execution()
print("\n" + "=" * 50)
if tools_ok and startup_ok and execution_ok:
print("๐ฏ ALL TESTS PASSED!")
print("โ
MCP tools are properly registered")
print("โ
MCP server can start properly")
print("โ
Tools can be executed successfully")
print("\n๐ก If Cursor still doesn't see the tools, check:")
print(" 1. The .cursor/mcp.json configuration")
print(" 2. That the MCP server is running")
print(" 3. Cursor's MCP server connection")
else:
print("โ SOME TESTS FAILED!")
if not tools_ok:
print("โ MCP tools registration failed")
if not startup_ok:
print("โ MCP server startup failed")
if not execution_ok:
print("โ Tool execution failed")
print("\n๐ง Please fix the issues above before using with Cursor")
print("=" * 50)