e9afd5473a
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.8 KiB
1.8 KiB
Simple Auth Client Example
A demonstration of how to use the MCP Python SDK with OAuth authentication over streamable HTTP or SSE transport.
Features
- OAuth 2.0 authentication with PKCE
- Support for both StreamableHTTP and SSE transports
- Interactive command-line interface
Installation
cd examples/clients/simple-auth-client
uv sync --reinstall
Usage
1. Start an MCP server with OAuth support
# Example with mcp-simple-auth
cd path/to/mcp-simple-auth
uv run mcp-simple-auth --transport streamable-http --port 3001
2. Run the client
# Connect to default server (http://localhost:8000/mcp)
uv run mcp-simple-auth-client
# Connect to a custom server URL
uv run mcp-simple-auth-client --url http://localhost:3001/mcp
# Use SSE transport
uv run mcp-simple-auth-client --url http://localhost:3001/sse --transport sse
# View all options
uv run mcp-simple-auth-client --help
3. Complete OAuth flow
The client will open your browser for authentication. After completing OAuth, you can use commands:
list- List available toolscall <tool_name> [args]- Call a tool with optional JSON argumentsquit- Exit
Example
🚀 Simple MCP Auth Client
Connecting to: http://localhost:8001/mcp
Transport type: streamable-http
🔗 Attempting to connect to http://localhost:8001/mcp...
Opening browser for authorization: http://localhost:9000/authorize?...
✅ Connected to MCP server at http://localhost:8001/mcp
mcp> list
📋 Available tools:
1. echo - Echo back the input text
mcp> call echo {"text": "Hello, world!"}
🔧 Tool 'echo' result:
Hello, world!
mcp> quit
👋 Goodbye!
Command Line Options
--url- Full URL of the MCP server (default:http://localhost:8000/mcp)--transport- Transport type:streamable-http(default) orsse