Skip to content

Commit e4cdfb3

Browse files
committed
auth: client implementation
1 parent 94d326d commit e4cdfb3

File tree

9 files changed

+623
-32
lines changed

9 files changed

+623
-32
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,5 @@ cython_debug/
165165
#.idea/
166166

167167
# vscode
168-
.vscode/
168+
.vscode/
169+
.windsurfrules

examples/clients/simple-chatbot/mcp_simple_chatbot/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ async def process_llm_response(self, llm_response: str) -> str:
322322
total = result["total"]
323323
percentage = (progress / total) * 100
324324
logging.info(
325-
f"Progress: {progress}/{total} "
326-
f"({percentage:.1f}%)"
325+
f"Progress: {progress}/{total} ({percentage:.1f}%)"
327326
)
328327

329328
return f"Tool execution result: {result}"

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ mcp = "mcp.cli:app [cli]"
4343
[tool.uv]
4444
resolution = "lowest-direct"
4545
dev-dependencies = [
46-
"pyright>=1.1.391",
46+
"pyright>=1.1.396",
4747
"pytest>=8.3.4",
4848
"ruff>=0.8.5",
4949
"trio>=0.26.2",
50-
"pytest-flakefinder>=1.1.0",
5150
"pytest-xdist>=3.6.1",
5251
]
5352

src/mcp/client/__main__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
from urllib.parse import urlparse
66

77
import anyio
8+
import httpx
9+
from pydantic import AnyHttpUrl
810

11+
from mcp.client.auth.httpx import McpOAuth
12+
from mcp.client.auth.oauth import InMemoryOAuthStore, OAuthClient
913
from mcp.client.session import ClientSession
1014
from mcp.client.sse import sse_client
1115
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]])
4650

4751
if urlparse(command_or_url).scheme in ("http", "https"):
4852
# 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)
5162
else:
5263
# Use stdio client for commands
5364
server_parameters = StdioServerParameters(

src/mcp/client/auth/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)