Add your description here
Project description
belgie-mcp
[!WARNING] This package follows the current MCP Python SDK auth APIs. Expect small compatibility updates as the SDK evolves.
belgie-mcp connects Belgie's OAuth server to the MCP Python SDK. It builds MCP AuthSettings, provides a token
verifier that understands both local OAuth provider state and HTTP introspection, and includes a helper for resolving
the current user from the active access token.
Installation
uv add belgie[mcp] belgie[oauth]
[!NOTE] The
belgie.mcpre-exports are only available when themcpextra is installed. The quick-start also importsbelgie.oauth.server, which requires theoauthextra.
Quick Start
Here is a complete setup for a single FastAPI app that hosts both Belgie OAuth and an MCP server:
Project Structure:
my-app/
├── main.py
└── ...
main.py:
from fastapi import FastAPI
from mcp.server.mcpserver import MCPServer
from belgie import Belgie
from belgie.mcp import Mcp, get_user_from_access_token
from belgie.oauth.server import OAuthResource, OAuthServer
app = FastAPI()
belgie = Belgie(
settings=..., # your BelgieSettings
adapter=..., # your database adapter
database=..., # async DB dependency
)
oauth_settings = OAuthServer(
base_url="https://auth.local",
prefix="/oauth",
client_id="demo-client",
client_secret="demo-secret", # noqa: S106
redirect_uris=["http://localhost:3030/callback"],
default_scope="user",
login_url="/login",
resources=[OAuthResource(prefix="/mcp", scopes=["user"])],
)
_ = belgie.add_plugin(oauth_settings)
mcp_plugin = belgie.add_plugin(
Mcp(
oauth=oauth_settings,
base_url="https://app.local",
),
)
mcp_server = MCPServer(
name="Belgie MCP",
instructions="MCP server protected by Belgie OAuth",
token_verifier=mcp_plugin.token_verifier,
auth=mcp_plugin.auth,
)
app.include_router(belgie.router)
app.mount(
mcp_plugin.server_path,
mcp_server.streamable_http_app(
streamable_http_path="/",
),
)
@mcp_server.tool()
async def get_user_email() -> dict[str, str | None]:
user = await get_user_from_access_token(belgie)
return {
"user_id": str(user.id) if user else None,
"user_email": user.email if user else None,
}
McpPlugin gives you the MCP auth settings, token verifier, and derived server_path. Your app owns the transport
mounting and any streamable_http_app(...) options.
Notes
- If the MCP server shares a host with Belgie, set
base_urland letMcpderive the resource URL fromserver_path. - If you pass a
server_urldirectly, it takes precedence overbase_urlandserver_path. oauth_strict=Trueenables strict resource validation against the issued token audience.get_user_from_access_tokenresolves the current user from a co-located OAuth provider first, then falls back to decoding a JWTsubclaim.- The package is designed to work with the example in
examples/mcp.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file belgie_mcp-0.12.3.tar.gz.
File metadata
- Download URL: belgie_mcp-0.12.3.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b4f95e530b9c4631ef605ef2904e6214a875d5c1fb26876336c80e068a9b1a9
|
|
| MD5 |
c9aef19480fd64f73197b1fe3a3b6e48
|
|
| BLAKE2b-256 |
e4fcc39c8a4af7e2fd9d754ab90ea6ca3a13e4a2bb6cdd61b17399c68cfa90c5
|
File details
Details for the file belgie_mcp-0.12.3-py3-none-any.whl.
File metadata
- Download URL: belgie_mcp-0.12.3-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a0a6ede8e2d76053aa21612f736044e3e995861c0af84d6397796e34c2b3526
|
|
| MD5 |
07d5a7e79930e228d00461cc9ae9d6c1
|
|
| BLAKE2b-256 |
7180c29eb08cb1e31675f0cace59d3175de19f519bf437bf826991f7f4bd9a80
|