From f2a38d275c79c230e29ffcf28778cdb08679148f Mon Sep 17 00:00:00 2001 From: Jason Cheng Date: Sun, 22 Jun 2025 14:03:50 +0800 Subject: [PATCH] custom auth configuration for remote mcp server with mcp config class --- src/fastmcp/utilities/mcp_config.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fastmcp/utilities/mcp_config.py b/src/fastmcp/utilities/mcp_config.py index e50c97be2..40300d7eb 100644 --- a/src/fastmcp/utilities/mcp_config.py +++ b/src/fastmcp/utilities/mcp_config.py @@ -4,7 +4,8 @@ import re from typing import TYPE_CHECKING, Annotated, Any, Literal from urllib.parse import urlparse -from pydantic import AnyUrl, Field +import httpx +from pydantic import AnyUrl, ConfigDict, Field from fastmcp.utilities.types import FastMCPBaseModel @@ -59,12 +60,14 @@ class RemoteMCPServer(FastMCPBaseModel): headers: dict[str, str] = Field(default_factory=dict) transport: Literal["streamable-http", "sse"] | None = None auth: Annotated[ - str | Literal["oauth"] | None, + str | Literal["oauth"] | httpx.Auth | None, Field( - description='Either a string representing a Bearer token or the literal "oauth" to use OAuth authentication.' + description='Either a string representing a Bearer token, the literal "oauth" to use OAuth authentication, or an httpx.Auth instance for custom authentication.', ), ] = None + model_config = ConfigDict(arbitrary_types_allowed=True) + def to_transport(self) -> StreamableHttpTransport | SSETransport: from fastmcp.client.transports import SSETransport, StreamableHttpTransport