Expected Behavior

I should be able to listen to the events on both MCP Server and Client side that track the MCP protocol life-cycle.

Here is a use case.

We implement a MCP server using Stream-able HTTP protocol. The client sends a token which can only be decoded on MCP server side. We want the LLM to learn about the authorization information inside the token right at the start of the conversation. For that we will like to do this:

On MCP Server side we would like to receive the token and validate the access when the client connects. Assuming the token is good, right away we want to use MCP Sampling feature and instigate the LLM tomake a tool call back to our MCP Server to get the authorization details for that user. We will implement such a tool on our MCP server that can decode the token and prepare LLM digestible formatted user authorization info. This way we will be sure that the LLM when it plans to call tools in our server can know ahead of time how to complete the user requests for which they have permissions but instead of calling a tool for which they do not have permission and failing, even better, alert the user ahead of time and even suggest how to get the necessary permission. We want to do this right after the client connection happens and is initialized.

Current Behavior I am not able to figure out a clean way to do this.

Context

As such this needs a ability to listen to the initialization completion. However I would think it will be good to have a event mechanism for server side which tracks the client/server interaction life-cycle.

Comment From: sandipchitale

Suggest any existing Spring based mechanism if possible to implement our use case.