Fancellu commited on
Commit
756d101
·
verified ·
1 Parent(s): ff72ec6

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +38 -34
server.py CHANGED
@@ -1,34 +1,38 @@
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")
 
 
 
 
 
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
+ @mcp.custom_route("/", methods=["GET"])
29
+ async def index(request: Request) -> PlainTextResponse:
30
+ return PlainTextResponse("MCP is on https://fancellu-fastmcp-space.hf.space/mcp")
31
+
32
+
33
+ # Export an ASGI app for uvicorn; choose a single path for Streamable HTTP (e.g. /mcp)
34
+ app = mcp.http_app(path="/mcp")
35
+
36
+ if __name__ == "__main__":
37
+ # No uvicorn, just internal FastMCP server
38
+ mcp.run(transport="http", host="0.0.0.0", port=int(os.getenv("PORT", 7860)), path="/mcp")