Skip to content

feat(server): add TimeoutMiddleware for tool handlers#204

Merged
jesse-engineer merged 2 commits into
ThinkInAIXYZ:mainfrom
knightxiaoxi:feat/tool-timeout-middleware
Jun 29, 2026
Merged

feat(server): add TimeoutMiddleware for tool handlers#204
jesse-engineer merged 2 commits into
ThinkInAIXYZ:mainfrom
knightxiaoxi:feat/tool-timeout-middleware

Conversation

@knightxiaoxi

Copy link
Copy Markdown
Contributor

Summary

Add TimeoutMiddleware that enforces a per-tool execution timeout.

Changes

  • TimeoutMiddleware(timeout) wraps handler context with WithTimeout
  • Placed alongside existing RateLimitMiddleware for consistency

Motivation

Slow/hanging tool implementations can block the MCP server. This middleware + RateLimitMiddleware form a basic resilience pair.

Usage

server.RegisterTool(&protocol.Tool{Name: "search"},
    server.TimeoutMiddleware(30*time.Second)(myHandler),
)

## Summary
Add `TimeoutMiddleware` that enforces a per-tool execution timeout.

## Changes
- `TimeoutMiddleware(timeout)` wraps handler context with `WithTimeout`
- Placed alongside existing `RateLimitMiddleware` for consistency

## Motivation
Slow/hanging tool implementations can block the MCP server. This middleware + RateLimitMiddleware form a basic resilience pair.

## Usage
```go
server.RegisterTool(&protocol.Tool{Name: "search"},
    server.TimeoutMiddleware(30*time.Second)(myHandler),
)
```
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/server.go 0.00% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@jesse-engineer

jesse-engineer commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

@knightxiaoxi pls,fix lint.

@jesse-engineer jesse-engineer merged commit 0767a50 into ThinkInAIXYZ:main Jun 29, 2026
6 checks passed
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.

3 participants