Repository navigation
[feat][MCP] Make public routing mode explicit #391
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
arnold-retool
wants to merge
4
commits into
arnold/mcp-helm-public-url-test
from
arnold/mcp-routing-mode
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
497b1e0
[feat][MCP] Make public routing mode explicit
arnold-retool 5e62ba5
[fix][MCP] Explain upgrade values migration
arnold-retool d2ab40d
[fix][MCP] Validate legacy flags and keep routing docs in values
arnold-retool 3aed673
[fix][MCP] Keep direct routing as compatible default
arnold-retool 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,166 @@ | ||
| """Check MCP public routes and migration errors in rendered Helm manifests.""" | ||
|
|
||
| import re | ||
| import subprocess | ||
| import unittest | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| ROOT = Path(__file__).resolve().parents[1] | ||
| BASE = [ | ||
| "helm", "template", "routing", "charts/retool", | ||
| "--values", "charts/retool/ci/test-install-values.yaml", | ||
| "--values", "charts/retool/ci/test-mcp-enabled-option.yaml", | ||
| "--set", "ingress.hosts[0].host=retool.example.com", | ||
| "--set", "ingress.hosts[0].paths[0].path=/", | ||
| ] | ||
| MAIN = "routing-retool" | ||
| MCP = "routing-retool-mcp" | ||
| BACKEND_API = "routing-retool-backend-internal" | ||
|
|
||
|
|
||
| def render(*settings): | ||
| command = BASE.copy() | ||
| for setting in settings: | ||
| command.extend(("--set", setting)) | ||
| return subprocess.run(command, cwd=ROOT, text=True, capture_output=True) | ||
|
|
||
|
|
||
| def manifest(output, filename): | ||
| marker = f"# Source: retool/templates/{filename}\n" | ||
| return output.split(marker, 1)[1].split("\n---\n", 1)[0] | ||
|
|
||
|
|
||
| def ingress_routes(output): | ||
| document = manifest(output, "ingress.yaml") | ||
| return re.findall( | ||
| r"(?m)^\s+- path: (\S+)\n\s+pathType: (\S+)\n\s+backend:\n\s+service:\n\s+name: (\S+)\n\s+port:\n\s+number: (\d+)", | ||
| document, | ||
| ) | ||
|
|
||
|
|
||
| def http_routes(output): | ||
| document = manifest(output, "httproute.yaml") | ||
| return re.findall( | ||
| r"(?m)^\s+- matches:\n\s+- path:\n\s+type: (\S+)\n\s+value: (\S+)\n\s+backendRefs:\n\s+- name: (\S+)\n\s+port: (\d+)", | ||
| document, | ||
| ) | ||
|
|
||
|
|
||
| INGRESS_DIRECT = [ | ||
| ("/.well-known/oauth-authorization-server", "Exact", BACKEND_API, "3001"), | ||
| ("/.well-known/oauth-protected-resource", "Exact", MCP, "4010"), | ||
| ("/mcp", "Prefix", MCP, "4010"), | ||
| ("/", "ImplementationSpecific", MAIN, "3000"), | ||
| ] | ||
| HTTP_DIRECT = [ | ||
| ("Exact", "/.well-known/oauth-authorization-server", BACKEND_API, "3001"), | ||
| ("Exact", "/.well-known/oauth-protected-resource", MCP, "4010"), | ||
| ("PathPrefix", "/mcp", MCP, "4010"), | ||
| ("PathPrefix", "/", MAIN, "3000"), | ||
| ] | ||
|
|
||
|
|
||
| class RoutingTests(unittest.TestCase): | ||
| def assert_rendered(self, *settings): | ||
| result = render(*settings) | ||
| self.assertEqual(result.returncode, 0, result.stderr) | ||
| return result.stdout | ||
|
|
||
| def assert_rejected(self, message, *settings): | ||
| result = render(*settings) | ||
| self.assertNotEqual(result.returncode, 0, result.stdout) | ||
| self.assertIn(message, result.stderr) | ||
|
|
||
| def test_default_direct_preserves_legacy_routes_for_both_route_types(self): | ||
| output = self.assert_rendered() | ||
| self.assertEqual(ingress_routes(output), INGRESS_DIRECT) | ||
| self.assertEqual(http_routes(output), HTTP_DIRECT) | ||
| self.assertIn('value: "http://routing-retool-mcp:4010"', manifest(output, "deployment_backend.yaml")) | ||
| self.assertIn("- name: MCP_SERVICE_INGRESS_DOMAIN", manifest(output, "deployment_backend.yaml")) | ||
|
|
||
| def test_backend_relay_uses_main_service_for_both_route_types(self): | ||
| output = self.assert_rendered("mcp.routing.mode=backendRelay") | ||
| self.assertEqual(ingress_routes(output), [INGRESS_DIRECT[-1]]) | ||
| self.assertEqual(http_routes(output), [HTTP_DIRECT[-1]]) | ||
| self.assertIn("- name: MCP_SERVICE_INGRESS_DOMAIN", manifest(output, "deployment_backend.yaml")) | ||
|
|
||
| def test_hostname_ingress_branch_follows_mode(self): | ||
| output = self.assert_rendered("ingress.hostName=retool.example.com") | ||
| self.assertEqual(ingress_routes(output), INGRESS_DIRECT) | ||
| output = self.assert_rendered("ingress.hostName=retool.example.com", "mcp.routing.mode=backendRelay") | ||
| self.assertEqual(ingress_routes(output), [INGRESS_DIRECT[-1]]) | ||
|
|
||
| def test_explicit_true_legacy_flags_work_in_direct_mode(self): | ||
| output = self.assert_rendered("mcp.routing.mode=direct", "mcp.ingress.enabled=true", "mcp.httpRoute.enabled=true") | ||
| self.assertEqual(ingress_routes(output), INGRESS_DIRECT) | ||
| self.assertEqual(http_routes(output), HTTP_DIRECT) | ||
|
|
||
| def test_disabled_mcp_has_only_main_routes(self): | ||
| output = self.assert_rendered("mcp.enabled=false", "mcp.routing.mode=direct", "mcp.ingress.enabled=true", "mcp.httpRoute.enabled=true") | ||
| self.assertEqual(ingress_routes(output), [INGRESS_DIRECT[-1]]) | ||
| self.assertEqual(http_routes(output), [HTTP_DIRECT[-1]]) | ||
| self.assertNotIn("- name: MCP_SERVICE_INGRESS_DOMAIN", manifest(output, "deployment_backend.yaml")) | ||
|
|
||
| def test_explicit_false_skips_direct_rules_on_that_surface(self): | ||
| output = self.assert_rendered("mcp.routing.mode=direct", "mcp.ingress.enabled=false") | ||
| self.assertEqual(ingress_routes(output), [INGRESS_DIRECT[-1]]) | ||
| self.assertEqual(http_routes(output), HTTP_DIRECT) | ||
| output = self.assert_rendered("mcp.routing.mode=direct", "mcp.httpRoute.enabled=false") | ||
| self.assertEqual(ingress_routes(output), INGRESS_DIRECT) | ||
| self.assertEqual(http_routes(output), [HTTP_DIRECT[-1]]) | ||
|
|
||
| def test_custom_legacy_ports_survive_in_direct_mode(self): | ||
| output = self.assert_rendered( | ||
| "mcp.routing.mode=direct", | ||
| "mcp.ingress.paths[0].path=/.well-known/oauth-authorization-server", | ||
| "mcp.ingress.paths[0].pathType=Exact", | ||
| "mcp.ingress.paths[0].target=backendInternal", | ||
| "mcp.ingress.paths[0].port=3002", | ||
| "mcp.httpRoute.rules[0].path=/mcp", | ||
| "mcp.httpRoute.rules[0].pathType=PathPrefix", | ||
| "mcp.httpRoute.rules[0].port=4020", | ||
| ) | ||
| self.assertEqual(ingress_routes(output)[0], ("/.well-known/oauth-authorization-server", "Exact", BACKEND_API, "3002")) | ||
| self.assertEqual(http_routes(output)[0], ("PathPrefix", "/mcp", MCP, "4020")) | ||
|
|
||
| def test_explicit_false_is_accepted_in_backend_relay(self): | ||
| output = self.assert_rendered("mcp.routing.mode=backendRelay", "mcp.ingress.enabled=false", "mcp.httpRoute.enabled=false") | ||
| self.assertEqual(ingress_routes(output), [INGRESS_DIRECT[-1]]) | ||
| self.assertEqual(http_routes(output), [HTTP_DIRECT[-1]]) | ||
|
|
||
| def test_old_explicit_true_flags_fail_with_migration_guidance(self): | ||
| for surface in ("ingress", "httpRoute"): | ||
| with self.subTest(surface=surface): | ||
| self.assert_rejected( | ||
| f"mcp.{surface}.enabled=true conflicts with mcp.routing.mode=backendRelay", | ||
| "mcp.routing.mode=backendRelay", | ||
| f"mcp.{surface}.enabled=true", | ||
| ) | ||
|
|
||
| def test_legacy_flags_reject_non_boolean_values(self): | ||
| for surface in ("ingress", "httpRoute"): | ||
| for value in ("0", ""): | ||
| with self.subTest(surface=surface, value=value): | ||
| self.assert_rejected( | ||
| f"mcp.{surface}.enabled must be true, false, or null", | ||
| "mcp.routing.mode=direct", | ||
| f"mcp.{surface}.enabled={value}", | ||
| ) | ||
|
|
||
| def test_unknown_mode_fails_even_if_mcp_and_public_routes_are_disabled(self): | ||
| self.assert_rejected('mcp.routing.mode must be "backendRelay" or "direct"', "mcp.routing.mode=other") | ||
| self.assert_rejected( | ||
| 'mcp.routing.mode must be "backendRelay" or "direct"', | ||
| "mcp.routing.mode=other", "mcp.enabled=false", "ingress.enabled=false", "httpRoute.enabled=false", | ||
| ) | ||
|
|
||
| def test_missing_mode_gives_upgrade_guidance(self): | ||
| self.assert_rejected( | ||
| "mcp.routing.mode is missing: when upgrading from an older chart, use --reset-then-reuse-values", | ||
| "mcp.routing=null", | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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
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,2 @@ | ||
| {{- /* Run mode and migration validation even when neither public route is enabled. */ -}} | ||
| {{- $mode := include "retool.mcp.routingMode" . -}} | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait why do we still need to run the validation helper if neither the ingress nor httproute are enabled?