Limit max tokens for docs search and logs#2114
Conversation
Co-authored-by: johan <[email protected]>
Co-authored-by: johan <[email protected]>
There was a problem hiding this comment.
Greptile Summary
This PR introduces token and line limiting functionality to the MCP (Model Context Protocol) server's docs search and logs tools. The main changes include:
-
Docs Search Enhancement: The
search_docsfunction now accepts a structuredSearchDocsArgsparameter instead of a simple string query. This new structure includes amax_tokensfield with a default value of 4000, allowing users to limit the amount of documentation content returned from the API. -
Logs Output Limiting: A new
linesparameter was added to the logs tool with a default of 50 lines. This is implemented through a new helper functionlimit_to_last_n_linesthat truncates log output to show only the most recent N lines. -
Code Modernization: The PR includes minor stylistic improvements, updating string formatting from
format!("text: {}", variable)to the more modernformat!("text: {variable}")syntax introduced in Rust 2021. -
Dependency Formatting: A cosmetic change to the workspace
Cargo.tomlstandardizes the tokio-tungstenite dependency declaration to use single-line feature arrays, consistent with other dependencies.
These changes fit into the broader MCP server architecture by providing better resource management and preventing oversized responses that could overwhelm AI clients or hit API limits. The structured parameter approach also makes the tools more extensible for future enhancements.
Important Files Changed
Changed Files
| Filename | Score | Overview |
|---|---|---|
| Cargo.toml | 5/5 | Minor formatting change to standardize tokio-tungstenite dependency declaration |
| mcp/src/mcp.rs | 5/5 | Refactored search_docs method to pass structured parameters instead of query string |
| mcp/src/utils.rs | 5/5 | Updated error message formatting to use modern string interpolation syntax |
| mcp/src/tools/logs.rs | 4/5 | Added log output limiting with new lines parameter and helper function |
| mcp/src/tools/docs.rs | 5/5 | Added SearchDocsArgs struct with max_tokens parameter for documentation search limiting |
Confidence score: 4/5
- This PR is safe to merge with minimal risk as it primarily adds optional limiting parameters with sensible defaults
- Score reflects well-structured code changes that improve resource management without breaking existing functionality
- Pay close attention to mcp/src/tools/logs.rs for the new line limiting logic implementation
Context used:
Context - Include comments explaining the purpose of functions, especially for new or complex functionality. (link)
5 files reviewed, no comments
No description provided.