Skip to content

verify_key to secure the FastMCP server #25

Description

@jhgoebbert

Hello everyone,

Thank you for this great extension enabling ai-agents in JupyterLab!
Hundreds of users at our supercomputing site are using JupyterLab everday.
We are looking into Jupyter-AI to see if/how we can provide this to our users, too.

I see one critical issue with jupyter-server-mcp at the moment.
Currently the FastMCP server can be accessed/used without the need of any token/key.
In a multi-user environment this would introduce a security problem.

If multiple JupyterLabs of different users run their comprehensive jupyter-ai setup including jupyter-server-mcp each setup would start a FastMCP server on a dedicated port. Knowing that port would make it possible to run code in the name of that user.

Would it be an idea to add a verify_key call in _run_http_async_without_signals

from fastapi import Depends, Header, HTTPException
    
    async def verify_key(x_mcp_key: str = Header(...)):
        if x_mcp_key != "your-secret-key":
            raise HTTPException(status_code=403, detail="Unauthorized")
        return x_mcp_key

    app.dependencies.append(Depends(verify_key))

This key would be set randomly on startup and passed to the ai-agents so that they could include them in their configuration when accessing the MCP.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions