60e0ffc959
Upgrade checks / Notify on failure (push) Has been cancelled
Upgrade checks / Close issue on success (push) Has been cancelled
Schema Crash Test / Real-world schema crash test (232K schemas) (push) Has been cancelled
Run static analysis / static_analysis (push) Has been cancelled
Tests / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Tests / Tests with lowest-direct dependencies (push) Has been cancelled
Tests / MCP conformance tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Package install smoke (push) Has been cancelled
Upgrade checks / Static analysis (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Upgrade checks / Integration tests (push) Has been cancelled
Update MCPServerConfig Schema / update-config-schema (push) Has been cancelled
Update SDK Documentation / update-sdk-docs (push) Has been cancelled
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import os
|
|
|
|
from fastmcp import FastMCP
|
|
from fastmcp.server.auth.providers.huggingface import HuggingFaceProvider
|
|
|
|
auth_provider = HuggingFaceProvider(
|
|
# Your Hugging Face OAuth app client ID
|
|
client_id=os.getenv("FASTMCP_SERVER_AUTH_HF_CLIENT_ID") or "",
|
|
# Your Hugging Face OAuth app client secret
|
|
client_secret=os.getenv("FASTMCP_SERVER_AUTH_HF_CLIENT_SECRET") or "",
|
|
# Must match your OAuth configuration
|
|
base_url="http://localhost:8000",
|
|
# Supply jwt_signing_key instead of client_secret for public applications
|
|
# jwt_signing_key="replace-with-a-secure-secret"
|
|
)
|
|
|
|
mcp = FastMCP(name="Hugging Face Secured App", auth=auth_provider)
|
|
|
|
|
|
# Add a tool to test authentication
|
|
@mcp.tool
|
|
async def get_user_info() -> dict:
|
|
"""Returns information about the authenticated Hugging Face user."""
|
|
from fastmcp.server.dependencies import get_access_token
|
|
|
|
token = get_access_token()
|
|
return {
|
|
"subject": token.claims.get("sub"),
|
|
"username": token.claims.get("preferred_username"),
|
|
"profile": token.claims.get("profile"),
|
|
}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
mcp.run(transport="http", port=8000)
|