custom auth configuration for remote mcp server with mcp config class

This commit is contained in:
Jason Cheng 2025-06-22 14:03:50 +08:00
commit f2a38d275c

View file

@ -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