Skip to content

Migrate MCP Server to Newer Mounted Implementation - #78

Merged
maxjb-xyz merged 9 commits into
mainfrom
fix/mcp-server
May 20, 2026
Merged

maxjb-xyz merged 9 commits into
mainfrom
fix/mcp-server

Conversation

@maxjb-xyz

@maxjb-xyz maxjb-xyz commented May 20, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • MCP is now mounted at /mcp on the main server; Admin UI shows the endpoint URL, lets you copy/regenerate the server-wide MCP bearer token, and lets you dismiss a migration warning. Legacy port input removed.
  • Bug Fixes

    • Komodo data source marked nonfunctional pending upstream fix.
  • Documentation

    • Deployment, integration, and setup docs updated with /mcp mounting, reverse-proxy guidance, token handling, and breaking-change/migration notes for older clients.

Review Change Stack

@maxjb-xyz maxjb-xyz self-assigned this May 20, 2026
@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 730d28d8-6a8e-47c6-9c34-afeecfa22dfc

📥 Commits

Reviewing files that changed from the base of the PR and between 32e7f32 and bbc60af.

📒 Files selected for processing (2)
  • server/internal/mcp/origin.go
  • server/internal/mcp/origin_test.go

📝 Walkthrough

Walkthrough

Blackbox MCP moves from a separate-port SSE server to a mounted /mcp streamable HTTP endpoint; settings and admin UI now surface a derived endpoint and server-wide bearer token, origin validation is enforced for browser requests, and legacy mcp_port is removed across code, tests, seed data, and docs.

Changes

MCP Mounted Endpoint Migration

Layer / File(s) Summary
Design specification and user documentation
docs/superpowers/specs/2026-05-19-mcp-mounted-streamable-http-design.md, README.md, docs/site/docs/deployment/reverse-proxy-and-tls.md, docs/site/docs/getting-started/first-login-and-setup.md, docs/site/docs/integrations/mcp-server.md, docs/site/docs/data-sources/komodo.md
Design spec and docs updated to document mounting MCP at /mcp, bearer-token auth, origin validation, admin UI changes, and migration notes.
Demo types and seed data
demo/worker/src/types.ts, demo/worker/src/seed-data.ts
Removed legacy mcp_port; added mcp_endpoint_url: string and mcp_migration_warning: boolean in demo types and seed seed data.
MCPManager refactor: port-based → handler-gating
server/internal/mcp/server.go, server/go.mod
MCPManager now stores a pre-built streamable HTTP handler and gates requests by enabled/token; removed port/listener lifecycle and updated manager tests; upgraded github.com/mark3labs/mcp-go.
Auth error helpers & origin validation
server/internal/mcp/auth.go, server/internal/mcp/origin.go, server/internal/mcp/origin_test.go
Centralized JSON error helpers for 401/403/503 and added origin validation (normalization, forwarded headers trust, default-port stripping, IPv6 formatting) with unit tests.
Admin config handler & helpers
server/internal/handlers/admin_config.go
AdminConfig exposes mcp_endpoint_url and mcp_migration_warning; UpdateMCPSettings supports acknowledge-only updates, conditional token generation/persistence, base_url normalization, and calls the new ApplySettings(enabled, token) signature.
Admin handler tests
server/internal/handlers/admin_config_test.go
Added/updated tests for AdminConfig exposure (no mcp_port), endpoint derivation/normalization, migration-warning visibility, base_url validation, ignoring legacy port input, token generation/preservation, and acknowledge-only flows.
Server wiring & tools
server/main.go, server/internal/mcp/tools.go
Registered /mcp route to mcpMgr.Handler(); startup restores only mcp_enabled/mcp_auth_token and calls ApplySettings(enabled, token); MCP tool handlers now use req.GetArguments().
Frontend contract & endpoint resolver
web/src/api/client.ts, web/src/pages/adminMcp.ts
AdminConfig removes mcp_port and adds mcp_endpoint_url/mcp_migration_warning; MCPSettingsInput makes mcp_enabled optional and supports acknowledge_mcp_migration_warning?: true; added resolveMcpEndpointUrl.
Admin page UI & frontend tests
web/src/pages/AdminPage.tsx, web/tests/admin-mcp.test.ts
AdminPage computes/displays MCP endpoint, removes port input, adds migration-warning banner with DISMISS action, adjusts save logic, and tests validate resolver, contract shape, wiring, and demo seed behavior.

Sequence Diagram(s)

sequenceDiagram
  participant AdminPage
  participant MainServer
  participant MCPManager
  participant DB
  AdminPage->>MainServer: updateMCPSettings(acknowledge or mcp_enabled)
  MainServer->>DB: persist mcp_enabled / mcp_auth_token / ack flag
  MainServer->>MCPManager: ApplySettings(enabled, token)
  MCPManager->>MCPManager: update internal enabled/token state
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • maxjb-xyz/blackbox#57: Overlaps on base_url handling and UpdateBaseURLSetting changes in admin_config.go.

"I charted the stream, the endpoint found,
/mcp now mounted, tokens stand their ground.
Origins checked, the banner can be dismissed,
Legacy ports retired—let new clients exist."

🚥 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 directly and clearly summarizes the primary change: migrating the MCP Server to a newer mounted implementation on the main server at /mcp instead of a separate port.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mcp-server

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
server/main.go (1)

11-11: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Remove the unused strconv import at line 11 to unblock the build.

The compiler has flagged this one: strconv is imported but never referenced anywhere in the file. That's a compile error waiting to happen. Go doesn't tolerate unused imports, so this needs to come out.

Fix
 import (
 	"context"
 	"embed"
 	"errors"
 	"log"
 	"net/http"
 	"os"
 	"os/signal"
-	"strconv"
 	"strings"
 	"syscall"
 	"time"
🤖 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 `@server/main.go` at line 11, Remove the unused strconv import from main.go:
delete the "strconv" entry in the import block (the unused symbol is strconv) so
the file compiles; ensure no other code in functions like main or any helpers
references strconv before removing.
🤖 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 `@server/internal/mcp/origin.go`:
- Around line 37-53: The inferRequestOrigin function currently trusts
X-Forwarded-Proto and X-Forwarded-Host unconditionally; change it to prefer
r.URL.Scheme and r.Host and only accept X-Forwarded-Proto / X-Forwarded-Host
when the request comes from a trusted proxy. Implement or call a trusted-proxy
check (e.g., isTrustedProxy(r.RemoteAddr) or a trustedProxies list) inside
inferRequestOrigin and gate the r.Header.Get("X-Forwarded-Proto") and
r.Header.Get("X-Forwarded-Host") usage behind that check so forwarded headers
are ignored for non-trusted clients; keep trimming logic and fallback to
r.TLS/"https" and "http" as currently done.

In `@web/tests/admin-mcp.test.ts`:
- Around line 13-16: The test swallows module loader errors by doing
import('../src/pages/adminMcp.ts').catch(() => null); remove the .catch(...) so
the dynamic import can throw and surface resolver diagnostics; update usages of
helperModule (the const helperModule and the subsequent assert.ok that
references adminMcpHelperPath.pathname) to assume import either succeeds or
fails by exception (i.e., drop the null-check/assert that expects a nullable
helperModule).

---

Outside diff comments:
In `@server/main.go`:
- Line 11: Remove the unused strconv import from main.go: delete the "strconv"
entry in the import block (the unused symbol is strconv) so the file compiles;
ensure no other code in functions like main or any helpers references strconv
before removing.
🪄 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 UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e5427a23-c7a7-43b4-96f8-72760f09c210

📥 Commits

Reviewing files that changed from the base of the PR and between 11cb447 and 5a4b031.

⛔ Files ignored due to path filters (2)
  • go.work.sum is excluded by !**/*.sum
  • server/go.sum is excluded by !**/*.sum
📒 Files selected for processing (22)
  • README.md
  • demo/worker/src/seed-data.ts
  • demo/worker/src/types.ts
  • docs/site/docs/data-sources/komodo.md
  • docs/site/docs/deployment/reverse-proxy-and-tls.md
  • docs/site/docs/getting-started/first-login-and-setup.md
  • docs/site/docs/integrations/mcp-server.md
  • docs/superpowers/specs/2026-05-19-mcp-mounted-streamable-http-design.md
  • server/go.mod
  • server/internal/handlers/admin_config.go
  • server/internal/handlers/admin_config_test.go
  • server/internal/mcp/auth.go
  • server/internal/mcp/origin.go
  • server/internal/mcp/origin_test.go
  • server/internal/mcp/server.go
  • server/internal/mcp/server_test.go
  • server/internal/mcp/tools.go
  • server/main.go
  • web/src/api/client.ts
  • web/src/pages/AdminPage.tsx
  • web/src/pages/adminMcp.ts
  • web/tests/admin-mcp.test.ts

Comment thread server/internal/mcp/origin.go Resolved
Comment thread web/tests/admin-mcp.test.ts Resolved

@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 `@server/internal/mcp/origin.go`:
- Around line 59-65: When reading X-Forwarded-Proto and X-Forwarded-Host in
origin.go (the block using isTrustedProxy(r.RemoteAddr) and r.Header.Get), guard
against comma-appended values from multiple proxies by splitting the header
value on ',', trimming each token, and using the first non-empty token as the
effective scheme/host (instead of using the whole header string). Update the
forwardedProto and forwardedHost handling to parse and select that first token
before assigning scheme and host so composed origin is valid behind multi-proxy
chains.
🪄 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 UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 533f2d3a-a702-4bcf-902e-eea6397c2f08

📥 Commits

Reviewing files that changed from the base of the PR and between 5a4b031 and 32e7f32.

📒 Files selected for processing (4)
  • server/internal/mcp/origin.go
  • server/internal/mcp/origin_test.go
  • server/main.go
  • web/tests/admin-mcp.test.ts
💤 Files with no reviewable changes (1)
  • server/main.go

Comment thread server/internal/mcp/origin.go Resolved
@maxjb-xyz
maxjb-xyz merged commit b27bd7f into main May 20, 2026
4 checks passed
@maxjb-xyz
maxjb-xyz deleted the fix/mcp-server branch May 20, 2026 06:38
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.

1 participant