mcp: improve documentation of Add*Middleware#688
mcp: improve documentation of Add*Middleware#688jboolean wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
…ddleware Updated comment to clarify how middleware is ordered
| // executed first. | ||
| // AddSendingMiddleware wraps the current sending method handler using | ||
| // the provided middleware. | ||
| // Middleware supplied via arguments is applied from right to left at the time it is added, |
There was a problem hiding this comment.
When I first read this, I wondered "how else can middleware be applied other than as arguments" -- to me at least, it's a bit hard to parse.
How about "Arguments to AddSendingMiddleware are applied from right to left, so that the first middleware is executed first."
There was a problem hiding this comment.
I see your point. I'd like to keep the phrase "among these" though because the key is that not all middleware is applied right to left, it's each set that was added together.
"Middleware in each call is applied from right to left, so that the first middleware among these is executed first." Or something like that.
There was a problem hiding this comment.
Sorry for not replying: that sounds like a good middle ground.
|
Hi @jboolean, would you like to finalize the PR with the latest feedback from from Rob? |
This updates the documentation comments for
AddReceivingMiddlewareandAddSendingMiddlewareto clarify how middlewares are ordered. The existing documentation is confusing and could lead one to believe middleware is applied from right to left at the time of execution (e.g. themcp-gosdk does it this way).In fact, because the wrapping is done at the time of adding and not at the time of execution, middleware is only applied in reverse order (and therefore run in order) within the set of middlewares being added together, while middleware added successively is applied on top of existing middleware and thus run in reverse order.