Skip to content

Limit max tokens for docs search and logs#2114

Merged
jonaro00 merged 8 commits intoshuttle-hq:mainfrom
dcodesdev:dcodes/mcp-upgrade
Sep 11, 2025
Merged

Limit max tokens for docs search and logs#2114
jonaro00 merged 8 commits intoshuttle-hq:mainfrom
dcodesdev:dcodes/mcp-upgrade

Conversation

@dcodesdev
Copy link
Collaborator

No description provided.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Docs Search Enhancement: The search_docs function now accepts a structured SearchDocsArgs parameter instead of a simple string query. This new structure includes a max_tokens field with a default value of 4000, allowing users to limit the amount of documentation content returned from the API.

  2. Logs Output Limiting: A new lines parameter was added to the logs tool with a default of 50 lines. This is implemented through a new helper function limit_to_last_n_lines that truncates log output to show only the most recent N lines.

  3. Code Modernization: The PR includes minor stylistic improvements, updating string formatting from format!("text: {}", variable) to the more modern format!("text: {variable}") syntax introduced in Rust 2021.

  4. Dependency Formatting: A cosmetic change to the workspace Cargo.toml standardizes 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

Edit Code Review Bot Settings | Greptile

@jonaro00 jonaro00 merged commit 0615adb into shuttle-hq:main Sep 11, 2025
22 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