-
Notifications
You must be signed in to change notification settings - Fork 151
feat: env-driven HTTP host/port and /healthz for self-hosting #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Maziak2520
wants to merge
5
commits into
makeplane:main
Choose a base branch
from
Maziak2520:feat/self-hosted-http-transport
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+237
−7
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3d2fcd8
feat: env-driven HTTP host/port and /healthz endpoint
manana2520 88c269e
chore(docker): env-driven port and self-hosting examples
manana2520 d742884
docs: self-hosting the HTTP server guide
manana2520 5cb32be
test: HTTP bind resolution, base-url propagation, header auth, /healthz
manana2520 604edb6
chore: address CodeRabbit review
manana2520 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Example environment for self-hosting the Plane MCP Server over HTTP. | ||
| # Copy to .env and fill in real values. DO NOT commit your filled-in .env. | ||
|
|
||
| # --- Plane connection ------------------------------------------------------- | ||
| # Base URL of your self-hosted Plane API (verify the path against your deployment). | ||
| PLANE_BASE_URL=https://your-plane-instance.example.com | ||
|
|
||
| # Optional: internal/server-to-server URL, takes precedence over PLANE_BASE_URL. | ||
| # PLANE_INTERNAL_BASE_URL=http://plane-api:8000 | ||
|
|
||
| # --- Bind address/port ------------------------------------------------------ | ||
| # PORT (injected by Cloud Run and similar) takes precedence over MCP_PORT. | ||
| MCP_HOST=0.0.0.0 | ||
| MCP_PORT=8211 | ||
|
|
||
| # Optional URL path prefix for all mounts (e.g. /plane -> /plane/mcp). | ||
| # MCP_PATH_PREFIX= | ||
|
|
||
| # --- OAuth provider (for the per-user OAuth mount /http/mcp) ----------------- | ||
| # Required only when running OAuth against a Plane instance that exposes OAuth apps. | ||
| # PLANE_OAUTH_PROVIDER_CLIENT_ID= | ||
| # PLANE_OAUTH_PROVIDER_CLIENT_SECRET= | ||
| # PLANE_OAUTH_PROVIDER_BASE_URL=https://your-mcp-host.example.com | ||
|
|
||
| # --- Optional: persistent OAuth token storage ------------------------------- | ||
| # REDIS_HOST=redis | ||
| # REDIS_PORT=6379 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Example: self-host the Plane MCP Server over HTTP against a self-hosted Plane. | ||
| # Usage: | ||
| # cp .env.example .env # then fill in PLANE_BASE_URL (+ PLANE_OAUTH_PROVIDER_* for OAuth) | ||
| # docker compose -f docker-compose.example.yml up --build | ||
| # | ||
| # The MCP endpoints are served on http://localhost:8211 (e.g. /http/mcp for OAuth, | ||
| # /http/api-key/mcp for per-user PAT headers). /healthz is the readiness probe. | ||
|
|
||
| services: | ||
| plane-mcp: | ||
| build: . | ||
| # Or use a published image instead of building: | ||
| # image: ghcr.io/makeplane/plane-mcp-server:latest | ||
| command: ["http"] | ||
| restart: unless-stopped | ||
| ports: | ||
| - "${MCP_PORT:-8211}:${MCP_PORT:-8211}" | ||
| env_file: | ||
| - .env | ||
| environment: | ||
| MCP_HOST: ${MCP_HOST:-0.0.0.0} | ||
| MCP_PORT: ${MCP_PORT:-8211} | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "curl -fsS http://localhost:${MCP_PORT:-8211}/healthz"] | ||
| interval: 30s | ||
| timeout: 5s | ||
| retries: 3 | ||
| start_period: 10s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| """Tests for the self-hosted HTTP deployment path. | ||
|
|
||
| Covers env-driven host/port binding (incl. ``$PORT`` precedence), transport parsing, | ||
| ``PLANE_BASE_URL`` propagation to the API client, the preserved per-user header-auth app, | ||
| and the ``/healthz`` probe. All network is avoided: the API client is only constructed | ||
| (never called) and MCP apps are exercised with Starlette's TestClient. | ||
| """ | ||
|
|
||
| from starlette.applications import Starlette | ||
| from starlette.routing import Route | ||
| from starlette.testclient import TestClient | ||
|
|
||
| from plane_mcp.__main__ import ServerMode, healthz, resolve_bind | ||
| from plane_mcp.client import get_plane_client_context | ||
| from plane_mcp.server import get_header_mcp | ||
|
|
||
| BIND_VARS = ("PORT", "MCP_HOST", "MCP_PORT") | ||
|
|
||
|
|
||
| class TestResolveBind: | ||
| """resolve_bind() reads MCP_HOST/MCP_PORT, with PORT taking precedence.""" | ||
|
|
||
| def _clean(self, monkeypatch): | ||
| for var in BIND_VARS: | ||
| monkeypatch.delenv(var, raising=False) | ||
|
|
||
| def test_defaults(self, monkeypatch): | ||
| self._clean(monkeypatch) | ||
| assert resolve_bind() == ("0.0.0.0", 8211) | ||
|
|
||
| def test_env_overrides(self, monkeypatch): | ||
| self._clean(monkeypatch) | ||
| monkeypatch.setenv("MCP_HOST", "127.0.0.1") | ||
| monkeypatch.setenv("MCP_PORT", "9000") | ||
| assert resolve_bind() == ("127.0.0.1", 9000) | ||
|
|
||
| def test_platform_port_takes_precedence_over_mcp_port(self, monkeypatch): | ||
| # Cloud Run and similar inject $PORT; it must win over MCP_PORT. | ||
| self._clean(monkeypatch) | ||
| monkeypatch.setenv("MCP_PORT", "9000") | ||
| monkeypatch.setenv("PORT", "8080") | ||
| assert resolve_bind() == ("0.0.0.0", 8080) | ||
|
|
||
|
|
||
| class TestTransportParsing: | ||
| def test_http_transport_resolves(self): | ||
| assert ServerMode("http") == ServerMode.HTTP | ||
| assert ServerMode("stdio") == ServerMode.STDIO | ||
|
|
||
|
|
||
| class TestPlaneBaseUrl: | ||
| """PLANE_BASE_URL / PLANE_INTERNAL_BASE_URL flow into the constructed client.""" | ||
|
|
||
| def test_plane_base_url_is_used(self, monkeypatch): | ||
| monkeypatch.delenv("PLANE_INTERNAL_BASE_URL", raising=False) | ||
| monkeypatch.setenv("PLANE_BASE_URL", "https://plane.example.com/api") | ||
| monkeypatch.setenv("PLANE_API_KEY", "dummy-key") | ||
| monkeypatch.setenv("PLANE_WORKSPACE_SLUG", "acme") | ||
|
|
||
| ctx = get_plane_client_context() | ||
|
|
||
| assert ctx.workspace_slug == "acme" | ||
| assert ctx.client.config.base_path.startswith("https://plane.example.com/api") | ||
|
|
||
| def test_internal_base_url_takes_precedence(self, monkeypatch): | ||
| monkeypatch.setenv("PLANE_BASE_URL", "https://public.example.com") | ||
| monkeypatch.setenv("PLANE_INTERNAL_BASE_URL", "http://plane-api:8000") | ||
| monkeypatch.setenv("PLANE_API_KEY", "dummy-key") | ||
| monkeypatch.setenv("PLANE_WORKSPACE_SLUG", "acme") | ||
|
|
||
| ctx = get_plane_client_context() | ||
|
|
||
| assert ctx.client.config.base_path.startswith("http://plane-api:8000") | ||
|
|
||
|
|
||
| class TestHeaderAuthPreserved: | ||
| """The per-user header-auth (PAT passthrough) app stays gated.""" | ||
|
|
||
| def test_header_app_rejects_request_without_workspace_slug(self): | ||
| app = get_header_mcp().http_app(stateless_http=True) | ||
| client = TestClient(app, raise_server_exceptions=False) | ||
| # Send a bearer token but omit X-Workspace-slug so the PAT-specific | ||
| # workspace-slug gate is exercised (not just generic unauthenticated handling). | ||
| response = client.post( | ||
| "/mcp", | ||
| headers={"Authorization": "Bearer dummy-pat"}, | ||
| json={"jsonrpc": "2.0", "method": "initialize", "id": 1}, | ||
| ) | ||
| assert response.status_code in (401, 403) | ||
|
|
||
|
|
||
| class TestHealthz: | ||
| """The /healthz probe returns 200 with a JSON status body.""" | ||
|
|
||
| def test_healthz_returns_ok(self): | ||
| app = Starlette(routes=[Route("/healthz", healthz)]) | ||
| client = TestClient(app) | ||
| response = client.get("/healthz") | ||
| assert response.status_code == 200 | ||
| assert response.json() == {"status": "ok"} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.