Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions scripts/generate_mcp_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
}

AGENT_DEPTHS = {
"getAdTree": "adset",
"getAdTree": "campaign",
}

SAME_ARGUMENTS_IDEMPOTENT_OPERATIONS = {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 campaign_id for one campaign's ad sets, or ad for everything.",
)


def extract_parameters(
Expand Down
11 changes: 8 additions & 3 deletions tests/test_mcp_agent_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, {})
Expand All @@ -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 campaign_id 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(
Expand Down
Loading