60e0ffc959
Upgrade checks / Notify on failure (push) Has been cancelled
Upgrade checks / Close issue on success (push) Has been cancelled
Schema Crash Test / Real-world schema crash test (232K schemas) (push) Has been cancelled
Run static analysis / static_analysis (push) Has been cancelled
Tests / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Tests / Tests with lowest-direct dependencies (push) Has been cancelled
Tests / MCP conformance tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Package install smoke (push) Has been cancelled
Upgrade checks / Static analysis (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Upgrade checks / Integration tests (push) Has been cancelled
Update MCPServerConfig Schema / update-config-schema (push) Has been cancelled
Update SDK Documentation / update-sdk-docs (push) Has been cancelled
47 lines
1.0 KiB
Python
47 lines
1.0 KiB
Python
"""
|
|
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()
|