Skip to content

Commit e9afd54

Browse files
committed
Replace environment variables with CLI arguments in simple-auth-client
The simple-auth-client example previously used environment variables (MCP_SERVER_PORT and MCP_TRANSPORT_TYPE) to configure the server URL and transport type. This approach was inflexible and couldn't handle arbitrary server URLs. This change replaces the environment variables with command-line arguments using argparse: - --url: Specifies the full URL of the MCP server - --transport: Specifies the transport type (streamable-http or sse) Benefits: - Users can now specify any server URL, not just localhost ports - More intuitive and discoverable interface with --help - Better follows CLI conventions All documentation (both client and server READMEs) has been updated to reflect the new command-line interface.
1 parent be73067 commit e9afd54

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

examples/clients/simple-auth-client/README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,38 @@ uv run mcp-simple-auth --transport streamable-http --port 3001
2828
### 2. Run the client
2929

3030
```bash
31+
# Connect to default server (http://localhost:8000/mcp)
3132
uv run mcp-simple-auth-client
3233

33-
# Or with custom server URL
34-
MCP_SERVER_PORT=3001 uv run mcp-simple-auth-client
34+
# Connect to a custom server URL
35+
uv run mcp-simple-auth-client --url http://localhost:3001/mcp
3536

3637
# Use SSE transport
37-
MCP_TRANSPORT_TYPE=sse uv run mcp-simple-auth-client
38+
uv run mcp-simple-auth-client --url http://localhost:3001/sse --transport sse
39+
40+
# View all options
41+
uv run mcp-simple-auth-client --help
3842
```
3943

4044
### 3. Complete OAuth flow
4145

4246
The client will open your browser for authentication. After completing OAuth, you can use commands:
4347

4448
- `list` - List available tools
45-
- `call <tool_name> [args]` - Call a tool with optional JSON arguments
49+
- `call <tool_name> [args]` - Call a tool with optional JSON arguments
4650
- `quit` - Exit
4751

4852
## Example
4953

5054
```markdown
51-
🔐 Simple MCP Auth Client
52-
Connecting to: http://localhost:3001
55+
🚀 Simple MCP Auth Client
56+
Connecting to: http://localhost:8001/mcp
57+
Transport type: streamable-http
5358

54-
Please visit the following URL to authorize the application:
55-
http://localhost:3001/authorize?response_type=code&client_id=...
59+
🔗 Attempting to connect to http://localhost:8001/mcp...
60+
Opening browser for authorization: http://localhost:9000/authorize?...
5661

57-
✅ Connected to MCP server at http://localhost:3001
62+
✅ Connected to MCP server at http://localhost:8001/mcp
5863

5964
mcp> list
6065
📋 Available tools:
@@ -68,7 +73,7 @@ mcp> quit
6873
👋 Goodbye!
6974
```
7075

71-
## Configuration
76+
## Command Line Options
7277

73-
- `MCP_SERVER_PORT` - Server URL (default: 8000)
74-
- `MCP_TRANSPORT_TYPE` - Transport type: `streamable-http` (default) or `sse`
78+
- `--url` - Full URL of the MCP server (default: `http://localhost:8000/mcp`)
79+
- `--transport` - Transport type: `streamable-http` (default) or `sse`

examples/clients/simple-auth-client/mcp_simple_auth_client/main.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
77
"""
88

9+
import argparse
910
import asyncio
10-
import os
1111
import threading
1212
import time
1313
import webbrowser
@@ -331,22 +331,32 @@ async def interactive_loop(self):
331331

332332
async def main():
333333
"""Main entry point."""
334-
# Default server URL - can be overridden with environment variable
335-
# Most MCP streamable HTTP servers use /mcp as the endpoint
336-
server_url = os.getenv("MCP_SERVER_PORT", 8000)
337-
transport_type = os.getenv("MCP_TRANSPORT_TYPE", "streamable-http")
338-
server_url = (
339-
f"http://localhost:{server_url}/mcp"
340-
if transport_type == "streamable-http"
341-
else f"http://localhost:{server_url}/sse"
334+
parser = argparse.ArgumentParser(
335+
description="Simple MCP client with OAuth authentication support",
336+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
342337
)
338+
parser.add_argument(
339+
"--url",
340+
type=str,
341+
default="http://localhost:8000/mcp",
342+
help="Full URL of the MCP server",
343+
)
344+
parser.add_argument(
345+
"--transport",
346+
type=str,
347+
choices=["streamable-http", "sse"],
348+
default="streamable-http",
349+
help="Transport type to use",
350+
)
351+
352+
args = parser.parse_args()
343353

344354
print("🚀 Simple MCP Auth Client")
345-
print(f"Connecting to: {server_url}")
346-
print(f"Transport type: {transport_type}")
355+
print(f"Connecting to: {args.url}")
356+
print(f"Transport type: {args.transport}")
347357

348358
# Start connection flow - OAuth will be handled automatically
349-
client = SimpleAuthClient(server_url, transport_type)
359+
client = SimpleAuthClient(args.url, args.transport)
350360
await client.connect()
351361

352362

examples/servers/simple-auth/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ uv run mcp-simple-auth-rs --port=8001 --auth-server=http://localhost:9000 --tra
4343
```bash
4444
cd examples/clients/simple-auth-client
4545
# Start client with streamable HTTP
46-
MCP_SERVER_PORT=8001 MCP_TRANSPORT_TYPE=streamable-http uv run mcp-simple-auth-client
46+
uv run mcp-simple-auth-client --url http://localhost:8001/mcp --transport streamable-http
4747
```
4848

4949
## How It Works
@@ -101,7 +101,7 @@ uv run mcp-simple-auth-legacy --port=8002
101101
```bash
102102
# Test with client (will automatically fall back to legacy discovery)
103103
cd examples/clients/simple-auth-client
104-
MCP_SERVER_PORT=8002 MCP_TRANSPORT_TYPE=streamable-http uv run mcp-simple-auth-client
104+
uv run mcp-simple-auth-client --url http://localhost:8002/mcp --transport streamable-http
105105
```
106106

107107
The client will:

0 commit comments

Comments
 (0)