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
2 changes: 1 addition & 1 deletion docs/MCP_TOOLS.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Benchmark, evaluate, and peer-grade candidate AI models across engineering tasks

| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| `models` | `string` | No | - | Comma-separated candidate models (e.g. 'qwen2.5:0.5b,llama3.1:8b@http://gpu2:11434'). A model@url runs on that server, which gets the AI key only when it is the configured api_base_url, gateway_url or provider API. The output and the reports name it model@host[:port]. The MCP tool refuses a model@url. |
| `models` | `string` | No | - | Comma-separated candidate model names (e.g. 'qwen2.5:0.5b,llama3.1:8b'). Each model runs on the servers that the configuration names. |
| `provider` | `string` | No | - | AI or cloud provider. |
| `benchmark_type` | `string` | No | `auto` | Benchmark mode: 'auto', 'chat', 'embedding'. |
| `tasks_filter` | `string` | No | - | Filter specific task categories or IDs (e.g. 'security,kubernetes'). |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

Kind: behavior. Reads: `src/devops_cli/ai/mcp/generator.py` lines 29 to 90 (`_PATH_PARAM_RESTRICTIONS`), 166 to 210 (`_build_parameter_field`, `_introspect_command_parameters`) and 289 to 303 (`_check_model_endpoints`), `src/devops_cli/lang/en/help.py` lines 899 to 909 (`MCPCommandHelp`) and 1850 to 1855 (`BenchmarkCommandHelp.models`). Changes: `tests/ai/mcp/test_ai_benchmark_mcp_tool.py`, `src/devops_cli/ai/mcp/generator.py`, `src/devops_cli/lang/en/help.py`.

- [ ] 1.1 In `tests/ai/mcp/test_ai_benchmark_mcp_tool.py`, add a class `TestBenchmarkToolPublishesPlainModelNames` with `@pytest.mark.usefixtures("keyring_store")`, as the class above it has. One async test lists the tools with `Client(mcp)` and reads `input_schema["properties"]["models"]["description"]` of `ai_benchmark`. It asserts that the text holds none of `@`, `model@url`, `api_base_url`, `gateway_url` and `key`. It takes the first quoted example of the text (`re.search(r"'([^']+)'", text)`), asserts that it exists, and gives it to `_check_model_endpoints(("ai", "benchmark"), {"models": example})` from `devops_cli.ai.mcp.generator`, which must not raise. One sync test asserts that `HELP.benchmark.models` holds `llama3.1:8b@http://gpu2:11434` and `The MCP tool refuses a model@url.` (the guard of the second requirement; it passes on the base). Verify that `uv run devops ci test tests/ai/mcp/test_ai_benchmark_mcp_tool.py` fails on the base
- [ ] 1.2 In `src/devops_cli/lang/en/help.py`, add `benchmark_models: str` to `MCPCommandHelp` with the value `Comma-separated candidate model names (e.g. 'qwen2.5:0.5b,llama3.1:8b'). Each model runs on the servers that the configuration names.`, written as two implicitly joined strings. In `src/devops_cli/ai/mcp/generator.py`, import `HELP` from `devops_cli.lang`, and add `_PARAM_DESCRIPTIONS: dict[tuple[tuple[str, ...], str], str]` with the entry `(("ai", "benchmark"), "models"): HELP.mcp.benchmark_models`, and a comment that says why the table exists. Give `_build_parameter_field` the parameter `description: str | None = None`, and set `"description": description or _clean_text(getattr(param, "help", None) or "")`. In `_introspect_command_parameters`, pass `_PARAM_DESCRIPTIONS.get((path, p.name))` to it. Leave `HELP.benchmark.models` and `_PATH_PARAM_RESTRICTIONS` as they are. Verify that `uv run devops ci test tests/ai/mcp/test_ai_benchmark_mcp_tool.py` passes
- [ ] 1.3 Check the tests that must keep passing: `test_mcp_tool_schema_and_argv_parsing` of `tests/ai/mcp/test_mcp.py`, `test_no_tool_text_names_a_flag_that_the_tool_does_not_publish` of `tests/ai/mcp/test_fastmcp_contracts.py`, and `tests/lang/test_language_catalogs.py`. Verify that `uv run devops ci test tests/ai/mcp/test_mcp.py tests/ai/mcp/test_fastmcp_contracts.py tests/lang/test_language_catalogs.py` passes
- [x] 1.1 In `tests/ai/mcp/test_ai_benchmark_mcp_tool.py`, add a class `TestBenchmarkToolPublishesPlainModelNames` with `@pytest.mark.usefixtures("keyring_store")`, as the class above it has. One async test lists the tools with `Client(mcp)` and reads `input_schema["properties"]["models"]["description"]` of `ai_benchmark`. It asserts that the text holds none of `@`, `model@url`, `api_base_url`, `gateway_url` and `key`. It takes the first quoted example of the text (`re.search(r"'([^']+)'", text)`), asserts that it exists, and gives it to `_check_model_endpoints(("ai", "benchmark"), {"models": example})` from `devops_cli.ai.mcp.generator`, which must not raise. One sync test asserts that `HELP.benchmark.models` holds `llama3.1:8b@http://gpu2:11434` and `The MCP tool refuses a model@url.` (the guard of the second requirement; it passes on the base). Verify that `uv run devops ci test tests/ai/mcp/test_ai_benchmark_mcp_tool.py` fails on the base
- [x] 1.2 In `src/devops_cli/lang/en/help.py`, add `benchmark_models: str` to `MCPCommandHelp` with the value `Comma-separated candidate model names (e.g. 'qwen2.5:0.5b,llama3.1:8b'). Each model runs on the servers that the configuration names.`, written as two implicitly joined strings. In `src/devops_cli/ai/mcp/generator.py`, import `HELP` from `devops_cli.lang`, and add `_PARAM_DESCRIPTIONS: dict[tuple[tuple[str, ...], str], str]` with the entry `(("ai", "benchmark"), "models"): HELP.mcp.benchmark_models`, and a comment that says why the table exists. Give `_build_parameter_field` the parameter `description: str | None = None`, and set `"description": description or _clean_text(getattr(param, "help", None) or "")`. In `_introspect_command_parameters`, pass `_PARAM_DESCRIPTIONS.get((path, p.name))` to it. Leave `HELP.benchmark.models` and `_PATH_PARAM_RESTRICTIONS` as they are. Verify that `uv run devops ci test tests/ai/mcp/test_ai_benchmark_mcp_tool.py` passes
- [x] 1.3 Check the tests that must keep passing: `test_mcp_tool_schema_and_argv_parsing` of `tests/ai/mcp/test_mcp.py`, `test_no_tool_text_names_a_flag_that_the_tool_does_not_publish` of `tests/ai/mcp/test_fastmcp_contracts.py`, and `tests/lang/test_language_catalogs.py`. Verify that `uv run devops ci test tests/ai/mcp/test_mcp.py tests/ai/mcp/test_fastmcp_contracts.py tests/lang/test_language_catalogs.py` passes

## 2. Regenerate the MCP tool reference

Kind: documentation. Reads: `docs/MCP_TOOLS.md` lines 187 to 205 (`ai_benchmark`). Changes: `docs/MCP_TOOLS.md` (generated).

- [ ] 2.1 Run `uv run devops docs generate --sync-readme`. Only the `models` row of `ai_benchmark` in `docs/MCP_TOOLS.md` changes: `docs/CLI_REFERENCE.md`, `docs/commands/ai.md` and `README.md` keep the text of the command help. Verify that `uv run devops docs check` passes
- [x] 2.1 Run `uv run devops docs generate --sync-readme`. Only the `models` row of `ai_benchmark` in `docs/MCP_TOOLS.md` changes: `docs/CLI_REFERENCE.md`, `docs/commands/ai.md` and `README.md` keep the text of the command help. Verify that `uv run devops docs check` passes

## Workflow follow-up

Expand Down
18 changes: 18 additions & 0 deletions openspec/specs/ai-benchmark/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,21 @@ The MCP tool `ai_benchmark` SHALL publish no `output`, `document` or `code` para
#### Scenario: A call that gives a path
- **WHEN** a client calls `ai_benchmark` with `output`, `document` or `code` set to a path in an existing directory
- **THEN** the call fails with an error that names that parameter, the directory holds the same files as before, and the socket gets no dial and no written byte

### Requirement: The MCP benchmark tool describes models by plain name
The MCP tool `ai_benchmark` SHALL publish a `models` description that gives plain model names only. The description SHALL hold no `model@url` form and no rule for the key or the server of such a form. The example in it SHALL be one that the tool accepts.

#### Scenario: Published description holds no model@url
- **WHEN** a client reads the published schema of `ai_benchmark` and inspects the description of `models`
- **THEN** the description holds no `@`, no `api_base_url`, no `gateway_url` and no word `key`

#### Scenario: The published example is accepted
- **WHEN** the `models` value of a call to `ai_benchmark` is the example that the published description quotes
- **THEN** the refusal check of the tool for a model endpoint passes the value

### Requirement: The benchmark command help keeps model@url
The help text of the option `--models` of `devops ai benchmark` SHALL keep the `model@url` form and the sentence that the MCP tool refuses it, for a person at the command line.

#### Scenario: Command help still shows model@url
- **WHEN** a person reads the help text of `--models` of `devops ai benchmark`
- **THEN** the text holds the example `llama3.1:8b@http://gpu2:11434` and the sentence `The MCP tool refuses a model@url.`
18 changes: 15 additions & 3 deletions src/devops_cli/ai/mcp/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@
from devops_cli.config.constants import CONST_MCP_EXPOSURE_TABLE
from devops_cli.core.command_resolver import module_click_command
from devops_cli.docs.generator import _clean_text
from devops_cli.lang import HELP
from devops_cli.main import _COMMAND_SPECS

_IGNORED_PARAM_NAMES: frozenset[str] = frozenset({"help", "install_completion", "show_completion"})
_JSON_PARAM_NAMES: frozenset[str] = frozenset({"format", "output_format", "json"})
_INTEGER_ID_PARAM_NAMES: frozenset[str] = frozenset(
{"number", "pr_number", "issue_number", "run_id"}
)
# The description of an option in the schema of a tool, where the help text of the command does not
# fit a model that calls the tool. The command keeps its own help text for a person. The key is the
# command path and the option name.
_PARAM_DESCRIPTIONS: dict[tuple[tuple[str, ...], str], str] = {
(("ai", "benchmark"), "models"): HELP.mcp.benchmark_models,
}

# The options of a command that its MCP tool publishes. A command lists an option here when the
# other options are for a person at the command line. A URL option is input from the model that
# calls the tool, so the tool does not publish it. The tool queries the service that the
Expand Down Expand Up @@ -247,10 +255,12 @@ def _normalize_default(default_val: Any) -> Any:
return default_val


def _build_parameter_field(param: Any, default_val: Any, is_required: bool = False) -> Any:
def _build_parameter_field(
param: Any, default_val: Any, is_required: bool = False, description: str | None = None
) -> Any:
"""Construct Pydantic Field instance for Click parameter."""
field_kwargs: dict[str, Any] = {
"description": _clean_text(getattr(param, "help", None) or ""),
"description": description or _clean_text(getattr(param, "help", None) or ""),
}
type_name = type(param.type).__name__
is_seq = _is_sequence_param(param)
Expand Down Expand Up @@ -285,7 +295,9 @@ def _introspect_command_parameters(
py_type = _deduce_parameter_type(p)
default_val = _normalize_default(getattr(p, "default", None))
is_required = bool(p.required or (restrictions and p.name in restrictions["required"]))
field = _build_parameter_field(p, default_val, is_required)
field = _build_parameter_field(
p, default_val, is_required, _PARAM_DESCRIPTIONS.get((path, p.name))
)
ann: Any
if is_required:
param_default = inspect.Parameter.empty
Expand Down
4 changes: 4 additions & 0 deletions src/devops_cli/lang/en/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,10 @@ class MCPCommandHelp:
allow_remote: str = "Permit binding a network transport to non-loopback network interfaces."
export_schemas: str = "Export FastMCP tool JSON schemas and instructions for MCP clients."
output_dir: str = "Destination directory for tool schema JSON files."
benchmark_models: str = (
"Comma-separated candidate model names (e.g. 'qwen2.5:0.5b,llama3.1:8b'). "
"Each model runs on the servers that the configuration names."
)


@dataclass(frozen=True)
Expand Down
36 changes: 35 additions & 1 deletion tests/ai/mcp/test_ai_benchmark_mcp_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
from __future__ import annotations

import json
import re
from collections.abc import Callable
from pathlib import Path
from typing import Any

import httpx2
import pytest

from devops_cli.lang import ERRORS
from devops_cli.lang import ERRORS, HELP
from tests.support.fakes.http import WebFake

BENCHMARK_TOOL_PARAMETERS = [
Expand Down Expand Up @@ -239,3 +240,36 @@ def test_the_command_runs_on_the_server_that_a_person_types(
result.exit_code,
{f"{request.url.host}:{request.url.port}" for request in web.sent},
) == (0, {"example.com:11435"})


@pytest.mark.usefixtures("keyring_store")
class TestBenchmarkToolPublishesPlainModelNames:
"""The `models` description in the schema of `ai_benchmark` names plain models, because the
tool refuses a `model@url` (#2743)."""

async def test_the_published_description_gives_an_example_that_the_tool_accepts(self) -> None:
"""The description holds no `model@url` and no key rule, and its example passes the check
of the tool for a model endpoint.

On `origin/main` the description quoted `llama3.1:8b@http://gpu2:11434`.
"""
from fastmcp import Client

from devops_cli.ai.mcp.generator import _check_model_endpoints
from devops_cli.ai.mcp.server import mcp

async with Client(mcp) as client:
tools = await client.list_tools()
text = next(t for t in tools if t.name == "ai_benchmark").input_schema["properties"][
"models"
]["description"]
quoted = re.search(r"'([^']+)'", text)

assert quoted is not None
assert [word for word in ("@", "api_base_url", "gateway_url", "key") if word in text] == []
_check_model_endpoints(("ai", "benchmark"), {"models": quoted.group(1)})

def test_the_command_help_keeps_the_model_url_form(self) -> None:
"""A person at the command line still reads the `model@url` form."""
assert "llama3.1:8b@http://gpu2:11434" in HELP.benchmark.models
assert "The MCP tool refuses a model@url." in HELP.benchmark.models
Loading