Skip to content

Conversation

@yugannkt
Copy link

Standardize timeout values to floats in seconds

Summary

Standardizes all timeout parameters across the SDK to use float values representing seconds, following Python ecosystem conventions (httpx, starlette, stdlib).

Motivation and Context

  • Timeout values were inconsistent, mixing timedelta and float types
  • Python ecosystem standards use floats representing seconds for timeouts
  • Eliminates unnecessary complexity and improves API consistency
  • Aligns with community expectations and reduces cognitive load

Changes Made

  • Converted all timeout parameters from timedelta | None to float | None
  • Updated StreamableHttpParameters and SseServerParameters to use float values
  • Removed timedelta imports and conversion logic
  • Updated all examples and tests to use float values
  • Added "(in seconds)" clarification to all timeout parameter docstrings

Files Modified: 9 files across core SDK, examples, and tests

How Has This Been Tested?

  • All modified Python files compile successfully
  • Type consistency verified across all timeout parameters
  • Default values aligned across all transport types
  • Documentation consistency verified
  • Examples validated with new float-based API

Breaking Changes

YES - This is a breaking change for v2

Migration:

# Before
from datetime import timedelta
params = StreamableHttpParameters(timeout=timedelta(seconds=30))

# After
params = StreamableHttpParameters(timeout=30.0)

Replace timedelta(seconds=X) with X.0 and remove unused timedelta imports.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added or updated documentation as needed

Additional context

Default Timeout Values:

  • SSE timeout: 5.0 seconds
  • SSE read timeout: 300.0 seconds (5 minutes)
  • StreamableHTTP timeout: 30.0 seconds
  • StreamableHTTP read timeout: 300.0 seconds (5 minutes)

Design: Aligns with Python ecosystem standards, maintains equivalent behavior, uses explicit .0 notation for clarity.

Fixes #1747

- Convert all timeout parameters from timedelta to float type
- Update StreamableHttpParameters, SseServerParameters timeouts to float
- Change read_timeout_seconds from timedelta | None to float | None
- Remove timedelta imports from modified files
- Update examples and tests to use float values (e.g., 30.0 instead of timedelta(seconds=30))
- Add '(in seconds)' clarification to all timeout parameter docstrings
- Align with Python ecosystem conventions (httpx, starlette, stdlib)

BREAKING CHANGE: All timeout parameters now accept float (seconds) instead of timedelta objects

Fixes modelcontextprotocol#1747
- Fix test_response_id_non_numeric_string_no_match to use float (0.5) instead of timedelta(seconds=0.5)
- Resolves TypeError: unsupported operand type(s) for +: 'float' and 'datetime.timedelta'
@yugannkt yugannkt force-pushed the feat/standardize-timeout-to-float branch from 36b964b to faff0bb Compare December 10, 2025 16:38
@felixweinberger felixweinberger added v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes breaking change Will break existing deployments when updated without changes labels Dec 10, 2025
@felixweinberger
Copy link
Contributor

felixweinberger commented Dec 10, 2025

Thanks - as you mentioned this is a breaking change but we're starting work on that now, so marking this as draft for now and have added it to our internal tracking, we'll come back to this.

@felixweinberger felixweinberger marked this pull request as draft December 10, 2025 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Will break existing deployments when updated without changes v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardize timeout values to floats in seconds

2 participants