|
5 | 5 | from urllib.parse import urlparse |
6 | 6 |
|
7 | 7 | import anyio |
| 8 | +import httpx |
| 9 | +from pydantic import AnyHttpUrl |
8 | 10 |
|
| 11 | +from mcp.client.auth.httpx import McpOAuth |
| 12 | +from mcp.client.auth.oauth import InMemoryOAuthStore, OAuthClient |
9 | 13 | from mcp.client.session import ClientSession |
10 | 14 | from mcp.client.sse import sse_client |
11 | 15 | from mcp.client.stdio import StdioServerParameters, stdio_client |
@@ -46,8 +50,15 @@ async def main(command_or_url: str, args: list[str], env: list[tuple[str, str]]) |
46 | 50 |
|
47 | 51 | if urlparse(command_or_url).scheme in ("http", "https"): |
48 | 52 | # Use SSE client for HTTP(S) URLs |
49 | | - async with sse_client(command_or_url) as streams: |
50 | | - await run_session(*streams) |
| 53 | + oauth_client = OAuthClient( |
| 54 | + client_name="mcp-client", |
| 55 | + server_url=AnyHttpUrl(command_or_url), |
| 56 | + redirect_url=AnyHttpUrl("http://localhost:5999/auth"), |
| 57 | + provider=InMemoryOAuthStore(), |
| 58 | + ) |
| 59 | + async with httpx.AsyncClient(auth=McpOAuth(oauth_client)) as http: |
| 60 | + async with sse_client(http, command_or_url) as streams: |
| 61 | + await run_session(*streams) |
51 | 62 | else: |
52 | 63 | # Use stdio client for commands |
53 | 64 | server_parameters = StdioServerParameters( |
|
0 commit comments