go-sdk icon indicating copy to clipboard operation
go-sdk copied to clipboard

mcp: client receiving middleware doesn't see input requests on 2026-07-28

Open po-et opened this issue 2 months ago • 2 comments

On 2025-11-25, a server that needs input sends elicitation/create (or sampling/createMessage, roots/list) as a request, so it passes through the client's receiving middleware before the handler runs. On 2026-07-28 the same input arrives in a multi-round-trip result, and fulfillInputRequest calls cs.client.elicit/createMessage/listRoots directly, so receiving middleware never sees it.

With a middleware added by Client.AddReceivingMiddleware that records methods, a tool that asks for an elicitation shows [elicitation/create] on 2025-11-25 and nothing on 2026-07-28:

srv := NewServer(testImpl, nil)
AddTool(srv, &Tool{Name: "ask"}, func(ctx context.Context, req *CallToolRequest, _ struct{}) (*CallToolResult, any, error) {
	if len(req.Params.InputResponses) == 0 {
		return &CallToolResult{InputRequests: InputRequestMap{"q": &ElicitParams{Message: "OK?"}}}, nil, nil
	}
	return &CallToolResult{Content: []Content{&TextContent{Text: "done"}}}, nil, nil
})
cs := mustConnect(t, srv, &ClientOptions{ElicitationHandler: accept}) // or mustConnectOldProtocol
cs.client.AddReceivingMiddleware(record) // appends each method it sees
cs.CallTool(ctx, &CallToolParams{Name: "ask"})

So whatever a client does in receiving middleware for these requests, such as logging, metrics, or deciding whether a server may sample at all, stops applying once the server is on 2026-07-28. Would you want fulfillInputRequest to dispatch through the receiving handler, so middleware sees the same method and params on both versions? I can send a PR if that's the direction.

po-et avatar Sep 27 '26 00:09 po-et

Hi @po-et , yes this makes sense, you can open the PR

guglielmo-san avatar Sep 28 '26 15:09 guglielmo-san

I reproduced this on current main (2e00768): legacy input requests reach receiving middleware, while 2026 input requests bypass it. I have a small local fix using the existing receiving dispatcher, with offline tests for all three methods and middleware rejection. @po-et, are you already preparing a fix? I’d like to avoid duplicating your work. This patch was developed with Codex assistance.

OllieinCanada avatar Oct 26 '26 04:10 OllieinCanada