[Python] MCP Python SDK. How to authorise a client with Bearer header with SSE?

Discussão em 'Python' iniciado por Stack, Abril 15, 2025.

  1. Stack

    Stack Membro Participativo

    I am building the MCP server application to connect some services to LLM . I use the MCP Python SDK https://github.com/modelcontextprotocol/python-sdk One of things i want to implement is authorisation of a user with the token.

    [​IMG]

    I see it must be possible somehow.

    Most of tutorials about MCP are related to STDIO kind of a server run. My will be SSE.

    There is my code:

    from mcp.server.fastmcp import FastMCP
    from fastapi import FastAPI, Request, Depends, HTTPException

    app = FastAPI()
    mcp = FastMCP("SMB Share Server")

    @mcp.tool()
    def create_folder(parent_path: str, name: str) -> str:
    """Create new subfolder in the specified path"""
    return f"Folder {name} created in {parent_path}"

    app.mount("/", mcp.sse_app())


    How can i read Authorization header in case if it is sent by the client?

    I tried to use approaches of FastAPI - setting dependency, adding request:Request to arguments but this doesn't work.

    Is there a way?

    Continue reading...

Compartilhe esta Página