Skip to content

Request Metadata Context #61

@EItanya

Description

@EItanya

First off I just want to say that this library is awesome, and I'm really glad you created it!

Is your feature request related to a problem? Please describe.

I am developing a server using this library in which I want to perform certain logic based on the identity of the client. For example, the client is using sse or the new streamable HTTP protocol, and there is a Bearer token present in the request which I need when performing the logic in the server.

The function call_tool for example currently has the following signature:

	async fn call_tool(
		&self,
		request: CallToolRequestParam,
		context: RequestContext<RoleServer>,
	) -> std::result::Result<CallToolResult, McpError> {

The context has information about the client, but it's limited to exactly what's in the spec. It would be very useful if a consumer of this library could also include some generic metadata struct to pass information from the source of the request into the handlers.

Describe the solution you'd like

The metadata source could take many forms:

  1. It could be a trait which the consumer must implement
  2. It could be some sort of generic HashMap<String, serde_json::Value> to allow for generic json values.

I haven't dug too deep into the exact solution, but I think this would have to live on the sink/stream layer, for example instead of a tokio::sync::mpsc::Sender<ClientJsonRpcMessage> it might need to be tokio::sync::mpsc::Sender<Option<Metadata>, ClientJsonRpcMessage> or something like that. Thereby allowing the user to control it.

Describe alternatives you've considered

Another alternative I considered is attempting to add a generic metadata mechanism to the upstream protocol. However I don't think that's actually necessary. All of the protocols already have ways of passing metadata back and forth, so all that's needed is a way within the library itself to access it.

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-enhancementNew features and enhancements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions