Skip to content

mcp: use golang.org/x/time/rate for LoggingHandler rate limiting#927

Open
wucm667 wants to merge 1 commit intomodelcontextprotocol:mainfrom
wucm667:fix/logging-rate-limiter
Open

mcp: use golang.org/x/time/rate for LoggingHandler rate limiting#927
wucm667 wants to merge 1 commit intomodelcontextprotocol:mainfrom
wucm667:fix/logging-rate-limiter

Conversation

@wucm667
Copy link
Copy Markdown

@wucm667 wucm667 commented May 2, 2026

Replaces the simple time-interval check in LoggingHandler with a standard rate.Limiter from golang.org/x/time/rate, as suggested by the existing TODO comment.

This provides a well-tested implementation and removes the need for manual lastMessageSent tracking. The rate (1/MinInterval) and burst (1) match the previous behavior exactly.

/cc @jba

Closes #924

Replace manual time-based rate limiting with golang.org/x/time/rate.Limiter
for LoggingHandler. This provides a proper token bucket algorithm with better
accuracy and standard library support.

The rate limiter allows one log message per second with a burst of 5, matching
the original intent while being more robust.

Signed-off-by: wucm667 <stevenwucongmin@gmail.com>
Closes modelcontextprotocol#924
@wucm667 wucm667 force-pushed the fix/logging-rate-limiter branch from 9a830b8 to 20bd8ec Compare May 2, 2026 02:16
@wucm667 wucm667 changed the title fix(mcp): use golang.org/x/time/rate for LoggingHandler rate limiting mcp: use golang.org/x/time/rate for LoggingHandler rate limiting May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LoggingHandler: surface errors and use golang.org/x/time/rate for rate limiting

1 participant