mcpserver-demo / fastmcp_server.py
alexcpn's picture
corrected client access
711c130
"""
This is much simple MCP server based on FastMCP amd transport streamable-http.
Ref https://github.com/modelcontextprotocol/python-sdk/?tab=readme-ov-file#quickstart
and https://gofastmcp.com/deployment/running-server
Author: Alex Punnen
Status: Demo
"""
from fastmcp import FastMCP
mcp = FastMCP()
# Assume that this is the tool you want to expose
# Give all the types and description
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
if __name__ == "__main__":
# take host and port from command line
import argparse
parser = argparse.ArgumentParser(description="Run FastMCP server")
parser.add_argument("--host", type=str, default="0.0.0.0", help="Host address (default: 0.0.0.0)")
parser.add_argument("--port", type=int, default=7860, help="Port number (default: 7860)")
args = parser.parse_args()
mcp.run(
transport="streamable-http", # https://github.com/modelcontextprotocol/python-sdk/?tab=readme-ov-file#streamable-http-transport
host=args.host,
port=args.port,
path="/mcp",
log_level="debug",
)