Skip to content

MCP Client -> Server authentication just using a provided access token #1083

Closed
@HarrisonUnifyAI

Description

@HarrisonUnifyAI

Question

I am trying to authenticate with an MCP server that is expecting the standard {"Authorization": f"Bearer {access_token}"} header. I have written a simple httpx.Auth implementation for this purpose, but am still failing to authenticate. Is something like this not intended to work? I verified that "auth_flow" is being called.

class AuthWithToken(httpx.Auth):
    def __init__(self, token: str):
        self.token = token

    def auth_flow(self, request):
        request.headers['Authorization'] = f'Bearer {self.token}'
        yield request

auth = AuthWithToken(auth_token) if auth_token else None
        # Connect to a streamable HTTP server
        async with streamablehttp_client(self.address, auth=auth) as (
            read_stream,
            write_stream,
            _,
        )...

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions