Skip to content

Parsing context from axum to tools #644

@d00z3l

Description

@d00z3l

Hi,

I have been struggling to work out how to pass information from my http server (axum) for use it tools. After a few hours of digging I found how to get the HTTP headers in the tool (#365), specifically, I can get the mcp-session-id. For those wanting a example you can use this code:

#[tool(description = "Example tool")]
async fn example_tool(&self, ctx: RequestContext<RoleServer>) -> Result<CallToolResult, rmcp::ErrorData> {
    let parts = ctx.extensions.get::<axum::http::request::Parts>().unwrap();
    let mcp_session_id = parts.headers.get("mcp-session-id").unwrap().to_str().unwrap();
    todo!("do something with the mcp-session_id")
}

Is there a way to pass something that is in Axum extensions to the extensions in the RequestContext of the tool? They appear to separate. I might be missing something obvious but any help is appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions