From e49895fafa728bdbae7f0f31e5580b948ec086fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gemma=20Torell=C3=B3?= Date: Thu, 12 Nov 2026 13:35:41 +0100 Subject: [PATCH 1/2] feat(mcp): the ads tree defaults to depth=campaign and tells agents how to drill down Co-Authored-By: Claude Opus 5.5 --- scripts/generate_mcp_tools.py | 16 +++++++++++----- tests/test_mcp_agent_views.py | 11 ++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/scripts/generate_mcp_tools.py b/scripts/generate_mcp_tools.py index dc88900a..0a8b889e 100644 --- a/scripts/generate_mcp_tools.py +++ b/scripts/generate_mcp_tools.py @@ -74,7 +74,7 @@ } AGENT_DEPTHS = { - "getAdTree": "adset", + "getAdTree": "campaign", } SAME_ARGUMENTS_IDEMPOTENT_OPERATIONS = { @@ -452,7 +452,7 @@ def _with_agent_default( *, name: str, value: str | None, - widest: str, + hint: str, ) -> list[dict[str, Any]]: if value is None: return params @@ -462,7 +462,7 @@ def _with_agent_default( { **p, "default": f'"{value}"', - "description": f"{p['description'].strip()} Defaults to {value} here; pass {widest} for everything.".strip(), + "description": f"{p['description'].strip()} Defaults to {value} here; {hint}".strip(), } if p["name"] == name else p @@ -471,8 +471,14 @@ def _with_agent_default( def _with_agent_view(operation_id: str, params: list[dict[str, Any]]) -> list[dict[str, Any]]: - params = _with_agent_default(operation_id, params, name="view", value=AGENT_VIEWS.get(operation_id), widest="full") - return _with_agent_default(operation_id, params, name="depth", value=AGENT_DEPTHS.get(operation_id), widest="ad") + params = _with_agent_default(operation_id, params, name="view", value=AGENT_VIEWS.get(operation_id), hint="pass full for everything.") + return _with_agent_default( + operation_id, + params, + name="depth", + value=AGENT_DEPTHS.get(operation_id), + hint="pass adset with campaignId for one campaign's ad sets, or ad for everything.", + ) def extract_parameters( diff --git a/tests/test_mcp_agent_views.py b/tests/test_mcp_agent_views.py index 6ab38276..c246496e 100644 --- a/tests/test_mcp_agent_views.py +++ b/tests/test_mcp_agent_views.py @@ -87,7 +87,9 @@ def test_listings_default_to_the_summary_view_for_agents( ) -def test_the_ads_tree_defaults_to_ad_set_depth_for_agents(mcp_generator) -> None: +def test_the_ads_tree_defaults_to_campaign_depth_and_says_how_to_drill_down( + mcp_generator, +) -> None: operation = _operation("getAdTree", "depth", ["campaign", "adset", "ad"], "ad") params = mcp_generator._with_agent_view( "getAdTree", mcp_generator.extract_parameters(operation, {}) @@ -102,8 +104,11 @@ def test_the_ads_tree_defaults_to_ad_set_depth_for_agents(mcp_generator) -> None "Get ad tree", ) - assert "depth: Literal['campaign', 'adset', 'ad'] = \"adset\"" in handler - assert "Defaults to adset here; pass ad for everything." in handler + assert "depth: Literal['campaign', 'adset', 'ad'] = \"campaign\"" in handler + assert ( + "Defaults to campaign here; pass adset with campaignId for one campaign's ad sets, or ad for everything." + in handler + ) def test_a_tree_spec_without_the_depth_parameter_warns_and_keeps_its_parameters( From 06fcbbe90a38939d06d4de72fcc4e6f2b1e61f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gemma=20Torell=C3=B3?= Date: Thu, 12 Nov 2026 13:48:02 +0100 Subject: [PATCH 2/2] fix(mcp): the tree depth hint names the tool's campaign_id argument Co-Authored-By: Claude Opus 5.5 --- scripts/generate_mcp_tools.py | 2 +- tests/test_mcp_agent_views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/generate_mcp_tools.py b/scripts/generate_mcp_tools.py index 0a8b889e..f238f759 100644 --- a/scripts/generate_mcp_tools.py +++ b/scripts/generate_mcp_tools.py @@ -477,7 +477,7 @@ def _with_agent_view(operation_id: str, params: list[dict[str, Any]]) -> list[di params, name="depth", value=AGENT_DEPTHS.get(operation_id), - hint="pass adset with campaignId for one campaign's ad sets, or ad for everything.", + hint="pass adset with campaign_id for one campaign's ad sets, or ad for everything.", ) diff --git a/tests/test_mcp_agent_views.py b/tests/test_mcp_agent_views.py index c246496e..c1b34753 100644 --- a/tests/test_mcp_agent_views.py +++ b/tests/test_mcp_agent_views.py @@ -106,7 +106,7 @@ def test_the_ads_tree_defaults_to_campaign_depth_and_says_how_to_drill_down( assert "depth: Literal['campaign', 'adset', 'ad'] = \"campaign\"" in handler assert ( - "Defaults to campaign here; pass adset with campaignId for one campaign's ad sets, or ad for everything." + "Defaults to campaign here; pass adset with campaign_id for one campaign's ad sets, or ad for everything." in handler )