Spaces:
Running
Running
Upload 4 files
Browse files- Dockerfile +7 -0
- README.md +10 -12
- requirements.txt +3 -0
- server.py +34 -0
Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY requirements.txt .
|
| 4 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 5 |
+
COPY server.py .
|
| 6 |
+
EXPOSE 7860
|
| 7 |
+
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -1,12 +1,10 @@
|
|
| 1 |
-
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
short_description: Example fastmcp server as a Space
|
| 10 |
-
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: FastMCP-Space
|
| 3 |
+
sdk: docker
|
| 4 |
+
app_port: 7860
|
| 5 |
+
pinned: true
|
| 6 |
+
emoji: π
|
| 7 |
+
colorFrom: yellow
|
| 8 |
+
colorTo: green
|
| 9 |
+
short_description: Example fastmcp server as a Space
|
| 10 |
+
---
|
|
|
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp==2.11.3
|
| 2 |
+
uvicorn
|
| 3 |
+
starlette
|
server.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# server.py
|
| 2 |
+
# A tiny mcp server example to show it working on a Huggingface Space
|
| 3 |
+
from fastmcp import FastMCP
|
| 4 |
+
from starlette.requests import Request
|
| 5 |
+
from starlette.responses import PlainTextResponse
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
mcp = FastMCP("fastmcp-space")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@mcp.tool
|
| 12 |
+
def add(a: int, b: int) -> int:
|
| 13 |
+
"""Add two numbers"""
|
| 14 |
+
return a + b
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Basic dynamic resource returning a string
|
| 18 |
+
@mcp.resource("resource://greeting")
|
| 19 |
+
def get_greeting() -> str:
|
| 20 |
+
"""Provides a simple greeting message."""
|
| 21 |
+
return "Hello from fastmcp-space"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@mcp.custom_route("/health", methods=["GET"])
|
| 25 |
+
async def health_check(request: Request) -> PlainTextResponse:
|
| 26 |
+
return PlainTextResponse("OK")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Export an ASGI app for uvicorn; choose a single path for Streamable HTTP (e.g. /mcp)
|
| 30 |
+
app = mcp.http_app(path="/mcp")
|
| 31 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
# No uvicorn, just internal FastMCP server
|
| 34 |
+
mcp.run(transport="http", host="0.0.0.0", port=int(os.getenv("PORT", 7860)), path="/mcp")
|