Spaces:
Running
Running
File size: 1,069 Bytes
fc7e104 bb0021a fc7e104 09438a8 fc7e104 09438a8 fc7e104 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | """
Simple example showing FastMCP server with command line argument support.
Usage:
fastmcp run examples/config_server.py -- --name MyServer --debug
"""
import argparse
from fastmcp import FastMCP
parser = argparse.ArgumentParser(description="Simple configurable MCP server")
parser.add_argument(
"--name", type=str, default="ConfigurableServer", help="Server name"
)
parser.add_argument("--debug", action="store_true", help="Enable debug mode")
args = parser.parse_args()
server_name = args.name
if args.debug:
server_name += " (Debug)"
mcp = FastMCP(server_name)
@mcp.tool
def get_status() -> dict[str, str | bool]:
"""Get the current server configuration and status."""
return {
"server_name": server_name,
"debug_mode": args.debug,
"original_name": args.name,
}
@mcp.tool
def echo_message(message: str) -> str:
"""Echo a message, with debug info if debug mode is enabled."""
if args.debug:
return f"[DEBUG] Echoing: {message}"
return message
if __name__ == "__main__":
mcp.run()
|