Skip to content

SANDBOX-1814: Implement MCP server setup and entry point - #21

Merged
fbm3307 merged 3 commits into
codeready-toolchain:masterfrom
fbm3307:feat/SANDBOX-1814-mcp-server-setup
Jul 17, 2026
Merged

SANDBOX-1814: Implement MCP server setup and entry point#21
fbm3307 merged 3 commits into
codeready-toolchain:masterfrom
fbm3307:feat/SANDBOX-1814-mcp-server-setup

Conversation

@fbm3307

@fbm3307 fbm3307 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator
  • Add pkg/server with MCP server construction, HTTP mux, session delete, health/live endpoints, loopback validation, and transport flag validation
  • Replace cmd/server stub with Cobra CLI, runServer bootstrap, signal handling (SIGTERM/SIGINT for both HTTP and stdio), and graceful shutdown
  • Add mcp-common, cobra, prometheus/client_golang dependencies
  • Validate session ID format on DELETE for defense-in-depth
  • Generic 500 on cleanup failure (no internal error leakage)
  • Add /server and /agent to .gitignore

Assisted by: Cursor

Summary by CodeRabbit

  • New Features
    • Added a configurable server CLI (build info, transport selection, sandbox/session settings, Kubernetes config, HMAC auth).
    • Introduced an MCP server with HTTP endpoints for MCP, metrics, liveness, health, and session termination, plus warm pooling and background stale-session cleanup.
  • Bug Fixes
    • Strengthened transport/stateless and loopback validation, and standardized health/session error responses.
  • Tests
    • Added coverage for endpoints, health/liveness behavior, session cleanup, loopback checks, and transport-flag validation.
  • Chores
    • Updated ignore rules and refreshed Go dependencies.

- Add pkg/server with MCP server construction, HTTP mux, session delete,
  health/live endpoints, loopback validation, and transport flag validation
- Replace cmd/server stub with Cobra CLI, runServer bootstrap, signal
  handling (SIGTERM/SIGINT for both HTTP and stdio), and graceful shutdown
- Add mcp-common, cobra, prometheus/client_golang dependencies
- Validate session ID format on DELETE for defense-in-depth
- Generic 500 on cleanup failure (no internal error leakage)
- Add /server and /agent to .gitignore

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

coderabbitai Bot commented Jul 17, 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: cb802dd9-41ac-48eb-a804-1db7bcd631c9

📥 Commits

Reviewing files that changed from the base of the PR and between 79ae028 and 3ce74ad.

📒 Files selected for processing (3)
  • pkg/server/server.go
  • pkg/session/manager.go
  • pkg/session/manager_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/server/server.go
📜 Recent 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/session/manager_test.go
  • pkg/session/manager.go
🧬 Code graph analysis (1)
pkg/session/manager.go (1)
pkg/session/manager_test.go (1)
  • GetOrCreatePod (192-192)
🔀 Multi-repo context codeready-toolchain/mcp-server-devsandbox, codeready-toolchain/mcp-common

Linked repositories findings

codeready-toolchain/mcp-server-devsandbox

  • Deployment config runs HTTP on 0.0.0.0:8080 with --stateless; the new loopback-only HTTP validation would reject this configuration at startup. [::codeready-toolchain/mcp-server-devsandbox::] deploy/base/deployment.yaml:60-67
  • Existing deployment contracts rely on port 8080 and /mcp, /metrics, and /live endpoints. [::codeready-toolchain/mcp-server-devsandbox::] deploy/base/deployment.yaml:57-64, deploy/base/service.yaml:12-18
  • Documentation and development configuration expose externally reachable /mcp URLs, which conflicts with requiring HTTP addresses to be loopback-only. [::codeready-toolchain/mcp-server-devsandbox::] deploy/README.md:117-139, make/dev.mk:42-81
  • The existing server uses mcp.NewStreamableHTTPHandler with Stateless: stateless, consistent with the new streamable HTTP route. [::codeready-toolchain/mcp-server-devsandbox::] pkg/mcpinit/init.go:187-194

codeready-toolchain/mcp-common

  • Existing middleware APIs accept MCP request sessions and record server/method/tool/success metrics; the new middleware wiring should preserve those request/session assumptions. [::codeready-toolchain/mcp-common::] pkg/middleware/metrics.go:14-34, pkg/middleware/logging.go:11-49
  • No consumers of the new SessionCleaner, HealthChecker, or ValidateSessionID APIs were found in linked repositories.
🔇 Additional comments (3)
pkg/session/manager.go (2)

105-106: LGTM!


116-116: LGTM!

pkg/session/manager_test.go (1)

104-104: LGTM!


Walkthrough

Adds a Cobra-based MCP server CLI with HTTP and stdio transports, Kubernetes-backed session management, health and lifecycle handling, server routes, validation helpers, tests, and dependency updates.

Changes

MCP server runtime

Layer / File(s) Summary
Server contracts and HTTP routes
pkg/server/server.go, pkg/server/server_test.go
Defines MCP construction, health and session-cleanup interfaces, HTTP endpoints, loopback detection, transport validation, and tests for routes and validation.
CLI configuration and runtime bootstrap
cmd/server/main.go
Adds Cobra flags, runtime configuration, HMAC loading, Kubernetes client creation, session-manager setup, and Bash tool registration.
Transport serving and session lifecycle
cmd/server/main.go
Adds HTTP and stdio serving, signal-driven shutdown, stale-session cleanup, warm-pool startup, and Kubernetes namespace health checks.
Session validation and module support
pkg/session/manager.go, pkg/session/manager_test.go, go.mod
Exports session ID validation, updates its test call site, and updates module requirements.
Repository integration
.gitignore
Ignores the top-level server and agent directories.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant runServer
  participant Kubernetes
  participant SessionManager
  participant MCPServer
  participant HTTPServer
  CLI->>runServer: Parse runtime configuration
  runServer->>Kubernetes: Build clientset
  runServer->>SessionManager: Create and configure manager
  runServer->>MCPServer: Register Bash tool
  runServer->>HTTPServer: Start MCP routes
  HTTPServer->>Kubernetes: Check namespace health
  Kubernetes-->>HTTPServer: Health result
  HTTPServer-->>CLI: Serve until shutdown
  runServer->>SessionManager: CleanupStale periodically
Loading

Possibly related PRs

Suggested labels: feature, test, dependencies, security

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 summarizes the main change: implementing the MCP server setup and CLI entry point.
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: 3

🤖 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 `@cmd/server/main.go`:
- Around line 88-115: Validate cfg.idleTimeout in runServer before constructing
or starting the session cleanup configuration, rejecting zero and negative
durations with a clear error. Preserve the existing configuration flow for
positive idle timeouts so CleanupStale cannot run with a non-positive interval.
- Around line 148-155: Set a narrow read-header timeout on the http.Server
constructed in the srv initialization, using the server’s ReadHeaderTimeout
field while leaving ReadTimeout unset to preserve MCP streamable HTTP behavior.

In `@pkg/server/server_test.go`:
- Line 50: Replace all seven httptest.NewRequest calls in the server tests with
httptest.NewRequestWithContext, passing context.Background() for each request
while preserving their existing methods, URLs, and bodies.
🪄 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: 88ca783a-dbb8-41e6-999e-953ac40e3bc0

📥 Commits

Reviewing files that changed from the base of the PR and between 935a019 and 6e3faa2.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • .gitignore
  • cmd/server/main.go
  • go.mod
  • pkg/server/server.go
  • pkg/server/server_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: build-test-coverage
🧰 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/server/server_test.go
  • pkg/server/server.go
  • cmd/server/main.go
  • go.mod
🧬 Code graph analysis (1)
cmd/server/main.go (4)
pkg/session/manager.go (3)
  • NewSessionManager (60-81)
  • CleanupStale (521-564)
  • StartPool (85-89)
pkg/session/config.go (1)
  • DefaultConfig (25-39)
pkg/version/version.go (2)
  • Commit (11-11)
  • BuildTime (14-14)
pkg/tools/bash.go (2)
  • NewBashTool (44-52)
  • RegisterWith (55-57)
🪛 ast-grep (0.44.1)
cmd/server/main.go

[warning] 147-147: This http.Server is constructed without a ReadTimeout. Without a read timeout, a slow or malicious client can hold connections open indefinitely (e.g. a Slowloris attack), exhausting server resources and causing a denial of service. Set ReadTimeout (and ideally ReadHeaderTimeout, WriteTimeout, and IdleTimeout) on the http.Server to bound how long the server waits while reading a request.
Context: http.Server{Addr: address, Handler: mux}
Note: [CWE-400] Uncontrolled Resource Consumption.

(http-server-missing-read-timeout-go)

🪛 golangci-lint (2.12.2)
pkg/server/server_test.go

[error] 50-50: net/http/httptest.NewRequest must not be called. use net/http/httptest.NewRequestWithContext

(noctx)


[error] 68-68: net/http/httptest.NewRequest must not be called. use net/http/httptest.NewRequestWithContext

(noctx)


[error] 86-86: net/http/httptest.NewRequest must not be called. use net/http/httptest.NewRequestWithContext

(noctx)

pkg/server/server.go

[error] 18-18: const serverName is unused

(unused)

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

6-19: LGTM!

Also applies to: 31-44

.gitignore (1)

44-45: LGTM!

cmd/server/main.go (1)

237-239: 🔒 Security & Privacy

Keep the namespace GET for /health. This check is meant to verify K8s API reachability; probing pods would change the endpoint’s contract.

			> Likely an incorrect or invalid review comment.
pkg/server/server.go (1)

51-56: 🔒 Security & Privacy

Keep DisableLocalhostProtection as-is
pkg/server/server.go:51-56 is required by the HTTP transport spec, and ValidateTransportFlags already rejects non-loopback addresses for this mode.

			> Likely an incorrect or invalid review comment.

Comment thread cmd/server/main.go
Comment thread cmd/server/main.go Outdated
Comment thread pkg/server/server_test.go Outdated
- Bump golang.org/x/net to v0.55.0 for GO-2026-5026/4918 (called via session HTTP)
- Reject non-positive --idle-timeout and negative --warm-pool-size
- Set ReadHeaderTimeout on HTTP server; leave ReadTimeout unset for MCP streams
- Use httptest.NewRequestWithContext in server tests for noctx lint

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Feny Mehta <fbm3307@gmail.com>
Export ValidateSessionID for the DELETE handler instead of duplicating
the regex, and report version.Commit on the MCP server implementation.

Co-authored-by: Cursor <cursoragent@cursor.com>
@fbm3307
fbm3307 merged commit 559548e into codeready-toolchain:master Jul 17, 2026
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