Menu

Your MCP tool middleware can't return a 429
πŸ“°

Your MCP tool middleware can't return a 429

DEV Community: goΒ·AlwyAbdullahΒ·7 days ago
#rrOsButY
#devtogo#devto#dev#tool#error
Long article (1520 words) β€” no AI summary yet.
Reading 0:00
15s threshold

A reader of my book on MCP servers asked a fair question: why isn't the companion code built on mcp-go ? So I ported it. The protocol part was easy. The interesting part was finding out which checks can't live where an SDK invites you to put them.

The short version: anything whose answer is an HTTP status code has to run before the SDK sees the request. That includes the 401 that starts OAuth discovery, the 403 that names the missing scope, and the 429 with Retry-After . Tool middleware is too late for all three.

The experiment

mcp-go (v1.6.0, MCP revision 2026-07-28 ) gives you server.WithToolHandlerMiddleware . It wraps every tool call, and it's the obvious place for a rate limiter:

type ToolHandlerFunc func ( ctx context . Context , request mcp . CallToolRequest ) ( * mcp . CallToolResult , error ) type ToolHandlerMiddleware func ( ToolHandlerFunc ) ToolHandlerFunc

Enter fullscreen mode

Exit fullscreen mode

Look at what a middleware can return: a result or an error. There's no http.ResponseWriter .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.