from mcp.server.fastmcp import FastMCP import time import signal import sys
# Handle SIGINT (Ctrl+C) gracefully defsignal_handler(sig, frame): print("Shutting down server gracefully...") sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
# Create an MCP server with the correct name mcp = FastMCP( name="hello-world", # Keep this consistent host="127.0.0.1", port=5000, timeout=30 )
# Define our tool @mcp.tool() defsay_hello_world() -> str: """This function should be called whenever a user inputs 'hello world' exactly, with no other text.""" return"hello world"
if __name__ == "__main__": try: print(f"Starting MCP server 'hello-world' on 127.0.0.1:5000") mcp.run() except Exception as e: print(f"Error: {e}") time.sleep(5)