Skip to content

SANDBOX-1813: Implement bash MCP tool handler - #18

Merged
fbm3307 merged 3 commits into
codeready-toolchain:masterfrom
fbm3307:feat/SANDBOX-1813-bash-mcp-tool-handler
Jul 16, 2026
Merged

SANDBOX-1813: Implement bash MCP tool handler#18
fbm3307 merged 3 commits into
codeready-toolchain:masterfrom
fbm3307:feat/SANDBOX-1813-bash-mcp-tool-handler

Conversation

@fbm3307

@fbm3307 fbm3307 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator
  • Add pkg/tools/bash.gobash MCP tool handler with BashInput/BashOutput types, CommandExecutor interface, session ID extraction from X-Session-ID header, and timeout clamping (default 60s, max 300s)
  • Non-zero exit codes set IsError: true with structured output retained (stdout/stderr/exit_code/duration_ms available to the LLM)
  • Infrastructure/validation failures return tool-level IsError without BashOutput (option A per design doc)

Assisted By: Cursor

Summary by CodeRabbit

  • New Features
    • Added a new “bash” tool to execute shell commands via the MCP interface.
    • Includes session handling, command validation, timeout limits, and structured outputs (stdout, stderr, exit code, duration, and error status for non-zero exits).
  • Tests
    • Added unit tests for tool registration, request/header handling, timeout clamping, correct executor invocation, and error mapping behavior.
  • Chores
    • Updated Go module requirements to include an additional MCP-related dependency and expanded indirect module lists.

- Add pkg/tools with BashTool handler, BashInput/BashOutput types, and
  CommandExecutor interface (satisfied by *session.SessionManager)
- Extract X-Session-ID from request headers; reject if missing
- Clamp timeout: default 60s, max 300s
- Non-zero exit codes return IsError with structured output retained
- Infrastructure failures return tool-level errors (option A)
- Unit tests with mock executor covering all AC scenarios
- Add github.com/modelcontextprotocol/go-sdk v1.4.0 dependency

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Feny Mehta <fbm3307@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: ef860cc0-69f0-4903-8810-90460929f969

📥 Commits

Reviewing files that changed from the base of the PR and between 84a192d and 847d853.

📒 Files selected for processing (1)
  • pkg/tools/bash_test.go
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • codeready-toolchain/mcp-common (manual)
  • codeready-toolchain/mcp-server-devsandbox (manual)
  • codeready-toolchain/api (manual)
  • codeready-toolchain/toolchain-common (manual)
  • codeready-toolchain/host-operator (manual)
  • codeready-toolchain/toolchain-e2e (manual)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/tools/bash_test.go
📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: govulncheck

Walkthrough

Adds an MCP bash tool with structured input/output, session validation, bounded timeouts, injectable command execution, non-zero exit handling, MCP registration, and unit tests. Updates Go module requirements for the MCP SDK and related indirect dependencies.

Changes

Bash MCP tool

Layer / File(s) Summary
Tool contract and MCP wiring
go.mod, pkg/tools/bash.go
Adds MCP SDK requirements, bash input/output schemas, executor abstraction, timeout bounds, tool metadata, and server registration.
Validation and command execution
pkg/tools/bash.go
Validates session headers and commands, clamps timeouts, executes commands, maps responses, and marks non-zero exits as errors.
Execution and registration tests
pkg/tools/bash_test.go
Covers validation, executor forwarding, output mapping, exit handling, timeout clamping, and MCP tool discovery.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MCPClient
  participant BashTool
  participant CommandExecutor
  MCPClient->>BashTool: Call bash with command and X-Session-ID
  BashTool->>BashTool: Validate request and clamp timeout
  BashTool->>CommandExecutor: ExecuteCommand
  CommandExecutor-->>BashTool: Return execution response
  BashTool-->>MCPClient: Return BashOutput and call result
Loading

Possibly related PRs

Suggested labels: feature, test, dependencies

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: implementing the bash MCP tool handler.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/tools/bash_test.go (1)

207-220: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert that the server actually exposes the registered tool.

This test passes even if RegisterWith is a no-op because Line 219 only inspects tool.Tool(). Use the SDK’s tool-listing or invocation path to verify that server exposes bash, as required by the PR objective.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/tools/bash_test.go` around lines 207 - 220, Update TestRegisterWith to
verify the server exposes the registered bash tool through the MCP server’s SDK
tool-listing or invocation API, rather than only asserting tool.Tool().Name.
Keep the existing registration setup and assert that the exposed tool is named
“bash,” ensuring the test fails when RegisterWith is a no-op.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@go.mod`:
- Line 9: Update the github.com/modelcontextprotocol/go-sdk dependency in go.mod
to version v1.4.1 or newer, then regenerate or update go.sum so it contains the
matching checksum entries.

---

Nitpick comments:
In `@pkg/tools/bash_test.go`:
- Around line 207-220: Update TestRegisterWith to verify the server exposes the
registered bash tool through the MCP server’s SDK tool-listing or invocation
API, rather than only asserting tool.Tool().Name. Keep the existing registration
setup and assert that the exposed tool is named “bash,” ensuring the test fails
when RegisterWith is a no-op.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 6513cfa4-d698-4d3b-b697-e3d556175237

📥 Commits

Reviewing files that changed from the base of the PR and between 22e0202 and 3d6cbed.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • go.mod
  • pkg/tools/bash.go
  • pkg/tools/bash_test.go
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • codeready-toolchain/mcp-common (manual)
  • codeready-toolchain/mcp-server-devsandbox (manual)
  • codeready-toolchain/api (manual)
  • codeready-toolchain/toolchain-common (manual)
  • codeready-toolchain/host-operator (manual)
  • codeready-toolchain/toolchain-e2e (manual)
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • pkg/tools/bash.go
  • pkg/tools/bash_test.go
  • go.mod
🪛 OSV Scanner (2.4.0)
go.mod

[HIGH] 9-9: github.com/modelcontextprotocol/go-sdk 1.4.0: Improper handling of null Unicode character when parsing JSON in github.com/modelcontextprotocol/go-sdk

(GO-2026-4770)


[HIGH] 9-9: github.com/modelcontextprotocol/go-sdk 1.4.0: Cross-Site Tool Execution for HTTP Servers without Authorizatrion in github.com/modelcontextprotocol/go-sdk

(GO-2026-4773)


[HIGH] 9-9: github.com/modelcontextprotocol/go-sdk 1.4.0: Cross-Site Tool Execution for HTTP Servers without Authorizatrion in github.com/modelcontextprotocol/go-sdk

(GHSA-89xv-2j6f-qhc8)


[HIGH] 9-9: github.com/modelcontextprotocol/go-sdk 1.4.0: Improper handling of null Unicode character when parsing JSON in github.com/modelcontextprotocol/go-sdk

(GHSA-q382-vc8q-7jhj)

🔇 Additional comments (3)
go.mod (1)

27-38: LGTM!

pkg/tools/bash.go (1)

1-112: LGTM!

pkg/tools/bash_test.go (1)

1-205: LGTM!

Comment thread go.mod
- Address CodeRabbit review: TestRegisterWith now connects a client
  via in-memory transport and asserts the server exposes "bash" tool
- Test fails if RegisterWith is a no-op

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Feny Mehta <fbm3307@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/tools/bash_test.go`:
- Line 226: Update the test setup around server.Connect to retain the returned
*mcp.ServerSession, then close that session during t.Cleanup alongside
cs.Close(). Handle and report any session-close error so teardown failures are
not silently ignored.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: ea719c62-8d9f-43d7-8046-9e3b38f4d402

📥 Commits

Reviewing files that changed from the base of the PR and between 3d6cbed and 84a192d.

📒 Files selected for processing (1)
  • pkg/tools/bash_test.go
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • codeready-toolchain/mcp-common (manual)
  • codeready-toolchain/mcp-server-devsandbox (manual)
  • codeready-toolchain/api (manual)
  • codeready-toolchain/toolchain-common (manual)
  • codeready-toolchain/host-operator (manual)
  • codeready-toolchain/toolchain-e2e (manual)
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: govulncheck
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • pkg/tools/bash_test.go
🪛 golangci-lint (2.12.2)
pkg/tools/bash_test.go

[error] 226-226: Error return value of cs.Close is not checked

(errcheck)

🔇 Additional comments (1)
pkg/tools/bash_test.go (1)

207-225: LGTM!

Also applies to: 227-232

Comment thread pkg/tools/bash_test.go Outdated
- Capture *ServerSession from server.Connect and close in t.Cleanup
- Check and report Close() errors for both server and client sessions
- Addresses CodeRabbit review: errcheck lint and resource leak

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Feny Mehta <fbm3307@gmail.com>
@fbm3307
fbm3307 merged commit 6aacce8 into codeready-toolchain:master Jul 16, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant