-
Notifications
You must be signed in to change notification settings - Fork 0
Implement Output Size Limits for MCP Server Responses #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Add SizeLimiter class with fast token estimation (~4 chars per token) - Support configurable limits via MCP_TOKEN_LIMIT environment variable - Include MCP_SIZE_CHECK_ENABLED flag for testing environments - Provide overflow summary generation for oversized content - Follow project coding conventions and pass all quality checks
- Add SizeLimiter class with fast token estimation (~4 chars per token) - Extend ResponseFormatter with tool-specific overflow messages - Integrate centralized size checking in all MCP tool handlers - Support configurable limits via MCP_TOKEN_LIMIT environment variable - Add comprehensive unit tests (66 tests, all passing) - Preserve existing functionality for content within limits
All files have been formatted according to project standards using ruff format. This resolves the CI formatting check failures.
Reduced test data sizes to prevent CI timeouts: - Changed 1M character test string to 10k characters - Reduced very_long test from 100k to 10k characters - Reduced over_limit test from 200k to 50k characters - Updated test expectations to match new sizes This fixes the 17+ minute CI hang that was caused by large string creation in the test suite, especially when running with coverage.
- Removed redundant and excessive test cases - Kept essential functionality coverage intact - Improved unit test performance from 51s to 24s (53% reduction) - Maintained core testing for token estimation, size limits, env vars, and edge cases
- Replace == True/False comparisons with direct/negated assertions - Maintains same test logic while following ruff style guidelines
- Apply ruff formatting to test_size_limiter.py - Ensures consistent code style across the project
chris-sanders
added a commit
that referenced
this pull request
Aug 11, 2025
* Implement core SizeLimiter module for MCP response optimization - Add SizeLimiter class with fast token estimation (~4 chars per token) - Support configurable limits via MCP_TOKEN_LIMIT environment variable - Include MCP_SIZE_CHECK_ENABLED flag for testing environments - Provide overflow summary generation for oversized content - Follow project coding conventions and pass all quality checks * Implement output size limits for MCP server responses - Add SizeLimiter class with fast token estimation (~4 chars per token) - Extend ResponseFormatter with tool-specific overflow messages - Integrate centralized size checking in all MCP tool handlers - Support configurable limits via MCP_TOKEN_LIMIT environment variable - Add comprehensive unit tests (66 tests, all passing) - Preserve existing functionality for content within limits
chris-sanders
added a commit
that referenced
this pull request
Aug 11, 2025
* Implement core SizeLimiter module for MCP response optimization - Add SizeLimiter class with fast token estimation (~4 chars per token) - Support configurable limits via MCP_TOKEN_LIMIT environment variable - Include MCP_SIZE_CHECK_ENABLED flag for testing environments - Provide overflow summary generation for oversized content - Follow project coding conventions and pass all quality checks * Implement output size limits for MCP server responses - Add SizeLimiter class with fast token estimation (~4 chars per token) - Extend ResponseFormatter with tool-specific overflow messages - Integrate centralized size checking in all MCP tool handlers - Support configurable limits via MCP_TOKEN_LIMIT environment variable - Add comprehensive unit tests (66 tests, all passing) - Preserve existing functionality for content within limits
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements configurable size limits (~25k tokens) on all MCP server responses with helpful overflow messages directing users to filtering and formatting commands to reduce output size.
Key Features
check_response_size()
function applied to all MCP tool responsesMCP_TOKEN_LIMIT
(default 25k),MCP_SIZE_CHECK_ENABLED
Changes Made
src/mcp_server_troubleshoot/size_limiter.py
- Core size limiting functionalitysrc/mcp_server_troubleshoot/formatters.py
- Overflow message formatting with tool-specific guidancesrc/mcp_server_troubleshoot/server.py
- Applied size limiting to all 6 MCP tool handlerstests/unit/test_size_limiter.py
- Comprehensive unit test suiteTest Results
Test plan