Skip to content

Commit b05778f

Browse files
committed
fix delegated_access example project and support Zone URL
1 parent a8d50b9 commit b05778f

4 files changed

Lines changed: 609 additions & 869 deletions

File tree

packages/mcp-fastmcp/examples/delegated_access/README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,30 @@ Use the public URL from your tunnel as `MCP_SERVER_URL`.
9696
### 2. Set Environment Variables
9797

9898
```bash
99-
export KEYCARD_ZONE_ID="your-zone-id"
99+
export KEYCARD_ZONE_ID="your-zone-id" # or use KEYCARD_ZONE_URL
100100
export KEYCARD_CLIENT_ID="your-client-id"
101101
export KEYCARD_CLIENT_SECRET="your-client-secret"
102102
export MCP_SERVER_URL="https://your-tunnel-url.ngrok.io/" # Must be publicly reachable
103103
```
104104

105-
### 3. Install Dependencies
105+
### 3. Install Dependencies and Run the Server
106106

107107
```bash
108108
cd packages/mcp-fastmcp/examples/delegated_access
109109
uv sync
110-
```
111-
112-
### 4. Run the Server
113-
114-
```bash
115110
uv run python main.py
116111
```
117112

118113
The server will start on `http://localhost:8000`.
119114

115+
> **Local SDK development:** If you're working on the Keycard SDK packages locally and want to run this example against your local changes, run from the repository root instead:
116+
>
117+
> ```bash
118+
> uv run --package delegated-access-example python packages/mcp-fastmcp/examples/delegated_access/main.py
119+
> ```
120+
>
121+
> This uses the root workspace to resolve all SDK packages from source.
122+
120123
### 5. Verify the Server
121124
122125
Check that OAuth metadata is being served:
@@ -176,11 +179,14 @@ The example demonstrates comprehensive error handling patterns:
176179

177180
| Variable | Required | Description |
178181
|----------|----------|-------------|
179-
| `KEYCARD_ZONE_ID` | Yes | Your Keycard zone ID |
182+
| `KEYCARD_ZONE_ID` | Yes* | Your Keycard zone ID |
183+
| `KEYCARD_ZONE_URL` | Yes* | Your full Keycard zone URL (alternative to `KEYCARD_ZONE_ID`) |
180184
| `KEYCARD_CLIENT_ID` | Yes | Client ID from application credentials |
181185
| `KEYCARD_CLIENT_SECRET` | Yes | Client secret from application credentials |
182186
| `MCP_SERVER_URL` | Yes | Server URL (must be publicly reachable for delegated access) |
183187

188+
\* Provide either `KEYCARD_ZONE_ID` or `KEYCARD_ZONE_URL`, not both.
189+
184190
## Learn More
185191

186192
- [Keycard Documentation](https://docs.keycard.ai)

packages/mcp-fastmcp/examples/delegated_access/main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@
1919
from keycardai.mcp.integrations.fastmcp import AccessContext, AuthProvider, ClientSecret
2020

2121
# Configure Keycard authentication with client credentials for delegated access
22-
# Get your zone_id and client credentials from console.keycard.ai
22+
# Set KEYCARD_ZONE_ID (or KEYCARD_ZONE_URL) and client credentials from console.keycard.ai
2323
auth_provider = AuthProvider(
24-
zone_id=os.getenv("KEYCARD_ZONE_ID", "your-zone-id"),
2524
mcp_server_name="GitHub API Server",
2625
mcp_base_url=os.getenv("MCP_SERVER_URL", "http://localhost:8000/"),
2726
# ClientSecret enables token exchange for delegated access
2827
application_credential=ClientSecret(
2928
(
30-
os.getenv("KEYCARD_CLIENT_ID", "your-client-id"),
31-
os.getenv("KEYCARD_CLIENT_SECRET", "your-client-secret"),
29+
os.getenv("KEYCARD_CLIENT_ID"),
30+
os.getenv("KEYCARD_CLIENT_SECRET"),
3231
)
3332
),
3433
)

packages/mcp-fastmcp/examples/delegated_access/pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,5 @@ dependencies = [
1010
"httpx>=0.27.0,<1.0.0",
1111
]
1212

13-
[tool.uv.sources]
14-
keycardai-mcp-fastmcp = { path = "../../", editable = true }
15-
1613
[project.scripts]
1714
delegated-access-server = "main:main"

0 commit comments

Comments
 (0)