mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-22 13:34:17 +02:00
Fix version badges for icons and website_url; add Discord example (#2509)
* Fix version badges and remove redundant badges from Discord doc * Add Discord OAuth example
This commit is contained in:
parent
aa53bdf53e
commit
83085c3cd3
8 changed files with 105 additions and 9 deletions
|
|
@ -149,8 +149,6 @@ auth_provider = DiscordProvider(
|
|||
|
||||
## Production Configuration
|
||||
|
||||
<VersionBadge version="2.13.2" />
|
||||
|
||||
For production deployments with persistent token management across server restarts, configure `jwt_signing_key` and `client_storage`:
|
||||
|
||||
```python server.py
|
||||
|
|
@ -187,8 +185,6 @@ For complete details on these parameters, see the [OAuth Proxy documentation](/s
|
|||
|
||||
## Environment Variables
|
||||
|
||||
<VersionBadge version="2.13.2" />
|
||||
|
||||
For production deployments, use environment variables instead of hardcoding credentials.
|
||||
|
||||
### Provider Selection
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ def data_analysis_prompt(
|
|||
</ParamField>
|
||||
|
||||
<ParamField body="icons" type="list[Icon] | None">
|
||||
<VersionBadge version="2.14.0" />
|
||||
<VersionBadge version="2.13.0" />
|
||||
|
||||
Optional list of icon representations for this prompt. See [Icons](/servers/icons) for detailed examples
|
||||
</ParamField>
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ def get_application_status() -> dict:
|
|||
</ParamField>
|
||||
|
||||
<ParamField body="icons" type="list[Icon] | None">
|
||||
<VersionBadge version="2.14.0" />
|
||||
<VersionBadge version="2.13.0" />
|
||||
|
||||
Optional list of icon representations for this resource or template. See [Icons](/servers/icons) for detailed examples
|
||||
</ParamField>
|
||||
|
|
|
|||
|
|
@ -45,13 +45,13 @@ The `FastMCP` constructor accepts several arguments:
|
|||
</ParamField>
|
||||
|
||||
<ParamField body="website_url" type="str | None">
|
||||
<VersionBadge version="2.14.0" />
|
||||
<VersionBadge version="2.13.0" />
|
||||
|
||||
URL to a website with more information about your server. Displayed in client applications
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="icons" type="list[Icon] | None">
|
||||
<VersionBadge version="2.14.0" />
|
||||
<VersionBadge version="2.13.0" />
|
||||
|
||||
List of icon representations for your server. Icons help users visually identify your server in client applications. See [Icons](/servers/icons) for detailed examples
|
||||
</ParamField>
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ def search_products_implementation(query: str, category: str | None = None) -> l
|
|||
</ParamField>
|
||||
|
||||
<ParamField body="icons" type="list[Icon] | None">
|
||||
<VersionBadge version="2.14.0" />
|
||||
<VersionBadge version="2.13.0" />
|
||||
|
||||
Optional list of icon representations for this tool. See [Icons](/servers/icons) for detailed examples
|
||||
</ParamField>
|
||||
|
|
|
|||
33
examples/auth/discord_oauth/README.md
Normal file
33
examples/auth/discord_oauth/README.md
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Discord OAuth Example
|
||||
|
||||
Demonstrates FastMCP server protection with Discord OAuth.
|
||||
|
||||
## Setup
|
||||
|
||||
1. Create a Discord OAuth App:
|
||||
- Go to https://discord.com/developers/applications
|
||||
- Click "New Application" and give it a name
|
||||
- Go to OAuth2 in the left sidebar
|
||||
- Add a Redirect URL: `http://localhost:8000/auth/callback`
|
||||
- Copy the Client ID and Client Secret
|
||||
|
||||
2. Set environment variables:
|
||||
|
||||
```bash
|
||||
export FASTMCP_SERVER_AUTH_DISCORD_CLIENT_ID="your-client-id"
|
||||
export FASTMCP_SERVER_AUTH_DISCORD_CLIENT_SECRET="your-client-secret"
|
||||
```
|
||||
|
||||
3. Run the server:
|
||||
|
||||
```bash
|
||||
python server.py
|
||||
```
|
||||
|
||||
4. In another terminal, run the client:
|
||||
|
||||
```bash
|
||||
python client.py
|
||||
```
|
||||
|
||||
The client will open your browser for Discord authentication.
|
||||
32
examples/auth/discord_oauth/client.py
Normal file
32
examples/auth/discord_oauth/client.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
"""Discord OAuth client example for connecting to FastMCP servers.
|
||||
|
||||
This example demonstrates how to connect to a Discord OAuth-protected FastMCP server.
|
||||
|
||||
To run:
|
||||
python client.py
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
|
||||
from fastmcp.client import Client
|
||||
|
||||
SERVER_URL = "http://127.0.0.1:8000/mcp"
|
||||
|
||||
|
||||
async def main():
|
||||
try:
|
||||
async with Client(SERVER_URL, auth="oauth") as client:
|
||||
assert await client.ping()
|
||||
print("✅ Successfully authenticated!")
|
||||
|
||||
tools = await client.list_tools()
|
||||
print(f"🔧 Available tools ({len(tools)}):")
|
||||
for tool in tools:
|
||||
print(f" - {tool.name}: {tool.description}")
|
||||
except Exception as e:
|
||||
print(f"❌ Authentication failed: {e}")
|
||||
raise
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
35
examples/auth/discord_oauth/server.py
Normal file
35
examples/auth/discord_oauth/server.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
"""Discord OAuth server example for FastMCP.
|
||||
|
||||
This example demonstrates how to protect a FastMCP server with Discord OAuth.
|
||||
|
||||
Required environment variables:
|
||||
- FASTMCP_SERVER_AUTH_DISCORD_CLIENT_ID: Your Discord OAuth app client ID
|
||||
- FASTMCP_SERVER_AUTH_DISCORD_CLIENT_SECRET: Your Discord OAuth app client secret
|
||||
|
||||
To run:
|
||||
python server.py
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from fastmcp import FastMCP
|
||||
from fastmcp.server.auth.providers.discord import DiscordProvider
|
||||
|
||||
auth = DiscordProvider(
|
||||
client_id=os.getenv("FASTMCP_SERVER_AUTH_DISCORD_CLIENT_ID") or "",
|
||||
client_secret=os.getenv("FASTMCP_SERVER_AUTH_DISCORD_CLIENT_SECRET") or "",
|
||||
base_url="http://localhost:8000",
|
||||
# redirect_path="/auth/callback", # Default path - change if using a different callback URL
|
||||
)
|
||||
|
||||
mcp = FastMCP("Discord OAuth Example Server", auth=auth)
|
||||
|
||||
|
||||
@mcp.tool
|
||||
def echo(message: str) -> str:
|
||||
"""Echo the provided message."""
|
||||
return message
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
mcp.run(transport="http", port=8000)
|
||||
Loading…
Add table
Add a link
Reference in a new issue