Spaces:
Running
Running
| # server.py | |
| # A tiny mcp server example to show it working on a Huggingface Space | |
| from fastmcp import FastMCP | |
| from starlette.requests import Request | |
| from starlette.responses import PlainTextResponse | |
| import os | |
| mcp = FastMCP("fastmcp-space") | |
| def add(a: int, b: int) -> int: | |
| """Add two numbers""" | |
| return a + b | |
| # Basic dynamic resource returning a string | |
| def get_greeting() -> str: | |
| """Provides a simple greeting message.""" | |
| return "Hello from fastmcp-space" | |
| async def health_check(request: Request) -> PlainTextResponse: | |
| return PlainTextResponse("OK") | |
| # Export an ASGI app for uvicorn; choose a single path for Streamable HTTP (e.g. /mcp) | |
| app = mcp.http_app(path="/mcp") | |
| if __name__ == "__main__": | |
| # No uvicorn, just internal FastMCP server | |
| mcp.run(transport="http", host="0.0.0.0", port=int(os.getenv("PORT", 7860)), path="/mcp") | |