modelcontextprotocol/java-sdk

Add an ability to trace requests

Opened this issue · 5 comments

Expected Behavior

User can specify a file to dump information about all requests being sent between MCP server and the client

Current Behavior

I don't think there is a way to do it currently.

Context

We created a LoggingServletTransportProvider which does that, but with the new changes that no longer compiles since there is no public constructor. Using the builder and then composing is also not possible because the methods are protected.

We could upstream the LoggingServletTransportProvider or something along these lines if it makes sense.

This is very useful for debugging potential issues with MCP servers especially when users turn on automatic accept.

@tgodzik
Sampling function is now available. You can customize log tracking points to collect the required information according to your needs. https://modelcontextprotocol.io/specification/2025-06-18/client/sampling,
Or use @McpLogging
https://docs.spring.io/spring-ai/reference/1.1/api/mcp/mcp-annotations-client.html

If my understanding is wrong, please feel free to correct me.

It seems like sampling is for getting LLM responses from server from clients, which is for sure useful, but it's a bit different from what we need.

We just want a simple way of logging the MCP requests and the responses. If someone sets auto approve on the tools from MCP server we can then investigate those requests if something went wrong

I modified my reply and hope it can help you.

That one seems something we can use for MCP clients, but not in the server really.

The server can use McpSyncServerExchange in the tool to customize the server's log information and send it to the client's @McpLogging for collection.