freddyaboulton HF Staff commited on
Commit
76d3296
·
verified ·
1 Parent(s): e03f714

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Run from the repository root:
3
+ uv run examples/snippets/servers/oauth_server.py
4
+ """
5
+
6
+ from pydantic import AnyHttpUrl
7
+
8
+ from mcp.server.auth.provider import AccessToken, TokenVerifier
9
+ from mcp.server.auth.settings import AuthSettings
10
+ from mcp.server.fastmcp import FastMCP
11
+
12
+
13
+ class SimpleTokenVerifier(TokenVerifier):
14
+ """Simple token verifier for demonstration."""
15
+
16
+ async def verify_token(self, token: str) -> AccessToken | None:
17
+ pass # This is where you would implement actual token validation
18
+
19
+
20
+ # Create FastMCP instance as a Resource Server
21
+ mcp = FastMCP(
22
+ "Weather Service",
23
+ # Token verifier for authentication
24
+ token_verifier=SimpleTokenVerifier(),
25
+ # Auth settings for RFC 9728 Protected Resource Metadata
26
+ auth=AuthSettings(
27
+ issuer_url=AnyHttpUrl("https://huggingface.co/.well-known/oauth-authorization-server"), # Authorization Server URL
28
+ resource_server_url=AnyHttpUrl("https://freddyaboulton-fastmcp-oauth.hf.space"), # This server's URL
29
+ required_scopes=["user"],
30
+ ),
31
+ port=7860
32
+ )
33
+
34
+
35
+ @mcp.tool()
36
+ async def get_weather(city: str = "London") -> dict[str, str]:
37
+ """Get weather data for a city"""
38
+ return {
39
+ "city": city,
40
+ "temperature": "22",
41
+ "condition": "Partly cloudy",
42
+ "humidity": "65%",
43
+ }
44
+
45
+
46
+ if __name__ == "__main__":
47
+ mcp.run(transport="streamable-http")