Skip to content

HarborMCPMixin#1146

Merged
willccbb merged 16 commits intomainfrom
cooper/harbormcpsupport
Apr 20, 2026
Merged

HarborMCPMixin#1146
willccbb merged 16 commits intomainfrom
cooper/harbormcpsupport

Conversation

@kcoopermiller
Copy link
Copy Markdown
Member

@kcoopermiller kcoopermiller commented Apr 16, 2026

Description

HarborMCPMixin gives HarborEnv support for the [[environment.mcp_servers]] section of Harbor's task.toml. On post_sandbox_setup, the mixin parses each entry, decides whether the server is framework-managed or externally-managed (a real remote MCP endpoint), and handles each accordingly. Framework-managed servers have their hostname aliased to 127.0.0.1 in the sandbox's /etc/hosts, and get a HARBOR_MCP_<NAME>_URL env var published with the URL rewritten to loopback. For each network-transport server, the mixin starts the launch command via start_background_job then polls a configurable healthcheck until the port is listening. Externally-managed servers have their task.toml URL published to the agent unchanged and get no /etc/hosts patch so remote managed endpoints stay reachable. A @vf.cleanup(priority=1) handler kills each recorded process group before the sandbox is destroyed. Subclasses can override pre_mcp_setup to stage code or install dependencies between task-asset upload and server launch, or override mcp_launch_command for per-rollout launches.

Any task.toml that's valid Harbor should work. Network transports (streamable-http, sse, http) are fully supported and stdio entries are parsed and validated but intentionally left for the agent tooling to spawn (same as in the Harbor SDK). The one unavoidable departure from Harbor's native flow is that launch commands come from a Python-side mcp_launch_commands dict instead of environment/docker-compose.yaml, since prime-sandboxes uses a single sandbox container rather than compose sidecars.

There is one example (hello_mcp_harbor) which demonstrates the full end-to-end flow with a FastMCP get_secret server.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Test improvement

Testing

  • All existing tests pass when running uv run pytest locally.
  • New tests have been added to cover the changes

Checklist

  • My code follows the style guidelines of this project as outlined in AGENTS.md
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Additional Notes


Note

Medium Risk
Changes Harbor sandbox startup/cleanup to launch and health-check MCP daemons and to rewrite/publish MCP URLs, which can affect rollout reliability and process cleanup semantics.

Overview
Adds first-class MCP server lifecycle support to HarborEnv. HarborEnv now parses [[environment.mcp_servers]], publishes HARBOR_MCP_<NAME>_URL env vars (rewriting managed servers to loopback), patches /etc/hosts for managed hostnames, starts declared network MCP servers via background jobs with configurable healthchecks, and SIGKILLs their process groups during cleanup.

Introduces a new hello_mcp_harbor example environment that stages a minimal FastMCP get_secret server into the sandbox and runs an OpenCode agent against it, plus extensive unit tests (test_harbor_env_mcp.py) covering parsing/URL rewriting, parallel startup and failure cancellation, /etc/hosts behavior, and healthcheck semantics.

Reviewed by Cursor Bugbot for commit 2a32b3b. Bugbot is set up for automated code reviews on this repo. Configure here.

@kcoopermiller kcoopermiller marked this pull request as ready for review April 16, 2026 18:00
@kcoopermiller kcoopermiller changed the title mcp in harborenv HarborMCPMixin Apr 16, 2026
Comment thread verifiers/envs/experimental/harbor_env/mcp.py Outdated
Comment thread environments/hello_mcp_harbor/README.md
Comment thread tests/test_harbor_env_mcp.py Outdated
Comment thread environments/README.md
Comment thread environments/dspy_rlm_oolong/dspy_rlm_oolong.py Outdated
Comment thread verifiers/envs/experimental/harbor_env/env.py
Comment thread verifiers/envs/experimental/harbor_env/mcp.py
Comment thread environments/hello_mcp_harbor/hello_mcp_harbor.py Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b9f27de. Configure here.

Comment thread environments/hello_mcp_harbor/hello_mcp_harbor.py
@kcoopermiller
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff423e47d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread verifiers/envs/experimental/harbor_env/mcp.py Outdated
Comment thread verifiers/envs/experimental/harbor_env/mcp.py
@kcoopermiller
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c5edf3b57b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread verifiers/envs/experimental/harbor_env/mcp.py Outdated
Comment thread verifiers/envs/experimental/harbor_env/mcp.py Outdated
@kcoopermiller
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 540c8bc8fb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread verifiers/envs/experimental/harbor_env/mcp.py Outdated
Comment thread verifiers/envs/experimental/harbor_env/mcp.py
@willccbb willccbb merged commit 848e331 into main Apr 20, 2026
6 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.

2 participants