-
Notifications
You must be signed in to change notification settings - Fork 71
feat(mcp): Add AIRBYTE_MCP_DOMAINS and AIRBYTE_MCP_DOMAINS_DISABLED env vars
#890
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
Merged
Aaron ("AJ") Steers (aaronsteers)
merged 6 commits into
main
from
devin/1764726550-mcp-domain-filtering
Dec 3, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eb36226
feat(mcp): Add AIRBYTE_MCP_DOMAINS and AIRBYTE_MCP_DOMAINS_DISABLED e…
devin-ai-integration[bot] 48a2fd1
refactor(mcp): Move domain constants to constants module and fix case…
devin-ai-integration[bot] 75e3a17
feat(mcp): Add MCPToolDomain enum and unknown domain warnings
devin-ai-integration[bot] 27b15aa
refactor(mcp): Move domain constants to global constants file with lr…
devin-ai-integration[bot] e95c4cf
refactor(mcp): Simplify domain env var parsing
devin-ai-integration[bot] c995a02
refactor(mcp): Rewrite tests to be compact and table-driven
devin-ai-integration[bot] 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
Some comments aren't visible on the classic Files Changed page.
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
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
aaronsteers marked this conversation as resolved.
Show resolved
Hide resolved
|
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,153 @@ | ||
| # Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
| """Unit tests for MCP tool utility functions.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import importlib | ||
| import warnings | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
|
|
||
| import airbyte.constants as constants | ||
| import airbyte.mcp._tool_utils as tool_utils | ||
| from airbyte.mcp._annotations import READ_ONLY_HINT | ||
|
|
||
| # (enabled, disabled, domain, readonly_mode, is_readonly, domain_enabled, should_register) | ||
| _DOMAIN_CASES = [ | ||
| (None, None, "cloud", False, False, True, True), | ||
| (None, None, "registry", False, False, True, True), | ||
| (None, None, "local", False, False, True, True), | ||
| (["cloud"], None, "cloud", False, False, True, True), | ||
| (["cloud"], None, "registry", False, False, False, False), | ||
| (None, ["registry"], "registry", False, False, False, False), | ||
| (None, ["registry"], "cloud", False, False, True, True), | ||
| (["registry", "cloud"], ["registry"], "cloud", False, False, True, True), | ||
| (["registry", "cloud"], ["registry"], "registry", False, False, False, False), | ||
| (["cloud"], ["registry"], "local", False, False, False, False), | ||
| (["CLOUD"], None, "cloud", False, False, True, True), | ||
| (["cloud"], None, "CLOUD", False, False, True, True), | ||
| (None, None, "cloud", True, False, True, False), | ||
| (None, None, "cloud", True, True, True, True), | ||
| (None, None, "registry", True, False, True, True), | ||
| (["cloud"], None, "cloud", True, True, True, True), | ||
| (["registry"], None, "cloud", True, True, False, False), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "enabled,disabled,domain,readonly_mode,is_readonly,domain_enabled,should_register", | ||
| _DOMAIN_CASES, | ||
| ) | ||
| def test_domain_logic( | ||
| enabled: list[str] | None, | ||
| disabled: list[str] | None, | ||
| domain: str, | ||
| readonly_mode: bool, | ||
| is_readonly: bool, | ||
| domain_enabled: bool, | ||
| should_register: bool, | ||
| ) -> None: | ||
| norm_enabled = [d.lower() for d in enabled] if enabled else None | ||
| norm_disabled = [d.lower() for d in disabled] if disabled else None | ||
| with ( | ||
| patch("airbyte.mcp._tool_utils.AIRBYTE_MCP_DOMAINS", norm_enabled), | ||
| patch("airbyte.mcp._tool_utils.AIRBYTE_MCP_DOMAINS_DISABLED", norm_disabled), | ||
| patch("airbyte.mcp._tool_utils.AIRBYTE_CLOUD_MCP_READONLY_MODE", readonly_mode), | ||
| ): | ||
| tool_utils._resolve_mcp_domain_filters.cache_clear() | ||
| assert tool_utils.is_domain_enabled(domain) == domain_enabled | ||
| assert ( | ||
| tool_utils.should_register_tool({ | ||
| "domain": domain, | ||
| READ_ONLY_HINT: is_readonly, | ||
| }) | ||
| == should_register | ||
| ) | ||
|
|
||
|
|
||
| # (env_var, attr, env_value, expected) | ||
| _ENV_PARSE_CASES = [ | ||
| ("AIRBYTE_MCP_DOMAINS", "AIRBYTE_MCP_DOMAINS", "", None), | ||
| ("AIRBYTE_MCP_DOMAINS", "AIRBYTE_MCP_DOMAINS", "cloud", ["cloud"]), | ||
| ( | ||
| "AIRBYTE_MCP_DOMAINS", | ||
| "AIRBYTE_MCP_DOMAINS", | ||
| "registry,cloud", | ||
| ["registry", "cloud"], | ||
| ), | ||
| ( | ||
| "AIRBYTE_MCP_DOMAINS", | ||
| "AIRBYTE_MCP_DOMAINS", | ||
| "registry, cloud", | ||
| ["registry", "cloud"], | ||
| ), | ||
| ( | ||
| "AIRBYTE_MCP_DOMAINS", | ||
| "AIRBYTE_MCP_DOMAINS", | ||
| "REGISTRY,CLOUD", | ||
| ["registry", "cloud"], | ||
| ), | ||
| ( | ||
| "AIRBYTE_MCP_DOMAINS", | ||
| "AIRBYTE_MCP_DOMAINS", | ||
| "registry,,cloud", | ||
| ["registry", "cloud"], | ||
| ), | ||
| ("AIRBYTE_MCP_DOMAINS_DISABLED", "AIRBYTE_MCP_DOMAINS_DISABLED", "", None), | ||
| ( | ||
| "AIRBYTE_MCP_DOMAINS_DISABLED", | ||
| "AIRBYTE_MCP_DOMAINS_DISABLED", | ||
| "registry", | ||
| ["registry"], | ||
| ), | ||
| ( | ||
| "AIRBYTE_MCP_DOMAINS_DISABLED", | ||
| "AIRBYTE_MCP_DOMAINS_DISABLED", | ||
| "registry,local", | ||
| ["registry", "local"], | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("env_var,attr,env_value,expected", _ENV_PARSE_CASES) | ||
| def test_env_parsing( | ||
| env_var: str, attr: str, env_value: str, expected: list[str] | None | ||
| ) -> None: | ||
| with patch.dict("os.environ", {env_var: env_value}, clear=False): | ||
| importlib.reload(constants) | ||
| assert getattr(constants, attr) == expected | ||
| importlib.reload(constants) | ||
|
|
||
|
|
||
| # (env_var, env_value, warning_fragment) | ||
| _WARNING_CASES = [ | ||
| ( | ||
| "AIRBYTE_MCP_DOMAINS", | ||
| "cloud,invalid", | ||
| "AIRBYTE_MCP_DOMAINS contains unknown domain(s)", | ||
| ), | ||
| ( | ||
| "AIRBYTE_MCP_DOMAINS_DISABLED", | ||
| "registry,fake", | ||
| "AIRBYTE_MCP_DOMAINS_DISABLED contains unknown domain(s)", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("env_var,env_value,fragment", _WARNING_CASES) | ||
| def test_unknown_domain_warning(env_var: str, env_value: str, fragment: str) -> None: | ||
| with ( | ||
| patch.dict("os.environ", {env_var: env_value}, clear=False), | ||
| warnings.catch_warnings(record=True) as caught, | ||
| ): | ||
| warnings.simplefilter("always") | ||
| importlib.reload(constants) | ||
| importlib.reload(tool_utils) | ||
| tool_utils._resolve_mcp_domain_filters.cache_clear() | ||
| tool_utils._resolve_mcp_domain_filters() | ||
| messages = [str(w.message) for w in caught] | ||
| assert any(fragment in m for m in messages) | ||
| assert any("Known MCP domains are:" in m for m in messages) | ||
| importlib.reload(constants) | ||
| importlib.reload(tool_utils) |
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.