mcptesta/examples/test_server.py
Ryan Malloy fa2983e814 Fix runtime issues discovered during local testing
- Fix circular import in protocol/__init__.py by using lazy import for PingTester
- Fix StdioTransport usage: properly parse command string into command + args
- Fix FastMCP Client connection: use async context manager protocol correctly
- Fix capability discovery: handle FastMCP Client return types (list vs dict)
- Fix enum value handling in validation.py for Pydantic use_enum_values=True
- Fix asyncio.wait_for usage with async context managers
- Add record_test_completion method to MetricsCollector
- Add test server example for testing MCPTesta

Tested locally with 'mcptesta validate' and 'mcptesta ping' - both work correctly
2025-12-08 04:40:10 -07:00

50 lines
946 B
Python

"""
Simple FastMCP Test Server for MCPTesta Testing
This minimal server provides tools, resources, and prompts
for testing MCPTesta functionality.
"""
from fastmcp import FastMCP
mcp = FastMCP("MCPTesta Test Server")
@mcp.tool()
def echo(message: str) -> str:
"""Echo back the provided message"""
return message
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers together"""
return a + b
@mcp.tool()
def greet(name: str = "World") -> str:
"""Generate a greeting message"""
return f"Hello, {name}!"
@mcp.resource("config://server")
def get_server_config() -> str:
"""Server configuration resource"""
return '{"name": "test-server", "version": "1.0.0"}'
@mcp.prompt()
def greeting_prompt(name: str = "User") -> str:
"""A simple greeting prompt"""
return f"Please greet {name} warmly."
def main():
"""Run the test server"""
mcp.run()
if __name__ == "__main__":
main()