albertvillanova HF Staff commited on
Commit
795d29b
·
verified ·
1 Parent(s): 48ef557

Create MCP app

Browse files
Files changed (3) hide show
  1. Dockerfile +1 -1
  2. app.py +17 -5
  3. requirements.txt +1 -2
Dockerfile CHANGED
@@ -1,7 +1,7 @@
1
  # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
  # you will also find guides on how best to write your Dockerfile
3
 
4
- FROM python:3.9
5
 
6
  RUN useradd -m -u 1000 user
7
  USER user
 
1
  # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
  # you will also find guides on how best to write your Dockerfile
3
 
4
+ FROM python:3.10
5
 
6
  RUN useradd -m -u 1000 user
7
  USER user
app.py CHANGED
@@ -1,8 +1,20 @@
1
- from fastapi import FastAPI
2
 
3
- app = FastAPI()
4
 
5
- @app.get("/")
6
- def greet_json():
7
- return {"Hello": "World!"}
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
 
 
3
 
4
+ # Stateful server (maintains session state)
5
+ mcp = FastMCP("StatefulServer")
 
6
 
7
+
8
+ @mcp.tool()
9
+ def greet(name: str = "World") -> str:
10
+ """Greet someone by name."""
11
+ return f"Hello, {name}!"
12
+
13
+
14
+ # Return an instance of the StreamableHTTP server app
15
+ app = mcp.streamable_http_app()
16
+
17
+
18
+ # Run server with streamable_http transport
19
+ if __name__ == "__main__":
20
+ mcp.run(transport="streamable-http")
requirements.txt CHANGED
@@ -1,3 +1,2 @@
1
- fastapi
2
  uvicorn[standard]
3
-
 
1
+ mcp[cli]
2
  uvicorn[standard]