debug_mcp.py•1.74 kB
#!/usr/bin/env python3
"""
Debug script to test MCP server functionality
"""
import asyncio
import json
from fastmcp import FastMCP
# Initialize FastMCP server
mcp = FastMCP("Debug Test Server")
@mcp.tool()
def test_tool(message: str = "Hello") -> str:
"""
A simple test tool that echoes a message.
Args:
message: The message to echo
Returns:
The echoed message with a prefix
"""
return f"Echo: {message}"
@mcp.tool()
def get_info() -> str:
"""
Get information about this MCP server.
Returns:
Server information as JSON string
"""
return json.dumps({
"server_name": "Debug Test Server",
"tools": ["test_tool", "get_info"],
"status": "running"
})
async def test_server():
"""Test the server functionality"""
print("Testing MCP server...")
# Get tools
tools = await mcp.get_tools()
print(f"Tools type: {type(tools)}")
print(f"Tools content: {tools}")
# Check if tools is a list or dict
if isinstance(tools, list):
print(f"Number of tools: {len(tools)}")
for i, tool in enumerate(tools):
print(f"Tool {i}: {type(tool)} - {tool}")
elif isinstance(tools, dict):
print(f"Tools dict keys: {list(tools.keys())}")
for name, tool in tools.items():
print(f"Tool '{name}': {type(tool)} - {tool}")
else:
print(f"Unexpected tools format: {tools}")
if __name__ == "__main__":
print("Starting Debug MCP Server...")
print("Available tools should be: test_tool, get_info")
# Run the async test
asyncio.run(test_server())
# Then start the server
print("\nStarting server...")
mcp.run()