diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7cec36..90c30e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,6 +65,38 @@ jobs: stdio: dotnet samples/WeatherServer/bin/Release/net10.0/WeatherServer.dll baseline: samples/WeatherServer.Tests/mcp-tools.json + - name: Check MCP tool surface with report + if: matrix.os == 'ubuntu-latest' || matrix.os == 'windows-latest' + uses: ./ + with: + source: artifacts + from-file: samples/WeatherServer.Tests/mcp-tools.json + baseline: samples/WeatherServer.Tests/mcp-tools.json + strict: true + report: mcpprobe-reports + + - name: Assert HTML reports were written + if: matrix.os == 'ubuntu-latest' || matrix.os == 'windows-latest' + shell: bash + run: | + set -euo pipefail + for pair in "lint.html:McpProbe lint report" "diff.html:McpProbe diff report"; do + file="mcpprobe-reports/${pair%%:*}" + needle="${pair##*:}" + if [[ ! -f "$file" ]]; then + echo "error: expected $file" + exit 1 + fi + if ! grep -F -q "$needle" "$file"; then + echo "error: $file does not look like a $needle" + exit 1 + fi + if grep -F -q '` and `mcpprobe diff --report ` also write that page. Stdout and exit codes are unchanged. The file is written on exit 0 and 1, not on a usage or connection error (exit 2). +- GitHub Action and Azure Pipelines template inputs `strict`, `transport`, and `report`. All three are off by default, so existing workflows keep the same CLI invocation. `report` is a directory (`lint.html` and `diff.html`); the job summary is unchanged, and artifact upload is left to the workflow (`actions/upload-artifact` / `PublishPipelineArtifact@1`). `report` requires a CLI that has `--report`; the wrapper fails fast if the installed tool does not. ## [0.3.0-preview] - 2026-11-28 diff --git a/README.md b/README.md index 70c02d3..b6682ba 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,29 @@ jobs: baseline: mcp-tools.json ``` -Inputs follow the CLI: `stdio`, `http`, or `from-file` (exactly one), plus `baseline` (default `mcp-tools.json`), `header`, `env`, `cwd`, `timeout`, `diff`, `lint`, `fail-on-non-breaking`, `fail-on`, `nested`, `rule`, `min-description-length`, `version`, and `source`. Both `diff` and `lint` are on by default. The Action fails the step on a breaking change or a lint finding at or above `--fail-on` (default `warning`). +Inputs follow the CLI: `stdio`, `http`, or `from-file` (exactly one), plus `baseline` (default `mcp-tools.json`), `header`, `env`, `cwd`, `timeout`, `diff`, `lint`, `fail-on-non-breaking`, `fail-on`, `nested`, `rule`, `min-description-length`, `strict`, `transport`, `report`, `version`, and `source`. Both `diff` and `lint` are on by default. The Action fails the step on a breaking change or a lint finding at or above `--fail-on` (default `warning`). + +`strict`, `transport`, and `report` are off by default, so an unchanged workflow runs the same commands as before. `strict` is lint-only. `transport` is only used with `http`. `report` is a directory, not a file: the Action writes `lint.html` and/or `diff.html` there (both checks run by default, so a single file path would overwrite one report with the other). The job summary stays the plain-text report. Upload is left to your workflow. + +`strict` and `transport` already work against the 0.3.0-preview CLI. `report` needs a CLI that has `--report`, which 0.3.0-preview does not. If you set `report` and the installed tool lacks the flag, the Action fails fast with a message instead of a generic "unrecognized option". Until 0.4 is published, use `uses: ./` with `source:` pointing at a just-packed folder, or pin a later tag that includes these inputs. Do not add these inputs to a workflow that pins `ShmueLior/mcpprobe@v0.3.0-preview`; that tag's wrapper does not have them. + +```yaml + - name: Check MCP tool surface + id: mcpprobe + uses: ShmueLior/mcpprobe@ + with: + stdio: dotnet run --no-build --project src/MyServer -c Release + baseline: mcp-tools.json + strict: true + report: mcpprobe-reports + - uses: actions/upload-artifact@v7 + if: always() + with: + name: mcpprobe-reports + path: mcpprobe-reports/ +``` + +The `lint-report` and `diff-report` outputs are the paths of the files that were written (empty if that check did not write one). ### Azure Pipelines @@ -221,7 +243,17 @@ steps: baseline: mcp-tools.json ``` -The template needs bash (Git Bash on Windows). If you cannot reference the GitHub repo, install the tool and run the same commands yourself: +The template needs bash (Git Bash on Windows). It also accepts `strict`, `transport`, and `report` (`report` is a directory, as in the Action). Do not add those parameters to a pipeline that pins `refs/tags/v0.3.0-preview`; that tag's template does not have them. Upload is a separate step; the template does not publish an artifact: + +```yaml + - task: PublishPipelineArtifact@1 + condition: always() + inputs: + targetPath: mcpprobe-reports + artifact: mcpprobe-reports +``` + +If you cannot reference the GitHub repo, install the tool and run the same commands yourself: ```yaml - task: UseDotNet@2 diff --git a/action.yml b/action.yml index 15be847..a505f86 100644 --- a/action.yml +++ b/action.yml @@ -76,6 +76,23 @@ inputs: description: Minimum tool description length for MCPP002. Leave empty to use the CLI default (20). required: false default: '' + strict: + description: Also run schema-portability lint rules MCPP009-MCPP012 (lint only). Off by default. + required: false + default: 'false' + transport: + description: >- + Pin the HTTP transport: auto, streamable-http, or sse. Only used with http. + Leave empty to use the CLI default (auto). + required: false + default: '' + report: + description: >- + Directory where HTML reports are written (lint.html and/or diff.html). This + input is a directory, not a file; the CLI --report flag takes a file. Leave + empty to skip writing HTML files. Requires a CLI that has --report. + required: false + default: '' version: description: >- Exact McpProbe.Cli version to install. Defaults to the same version as this @@ -99,6 +116,12 @@ outputs: lint-exit: description: Exit code of mcpprobe lint. Empty if lint was skipped. value: ${{ steps.mcpprobe.outputs.lint-exit }} + lint-report: + description: Path to lint.html if that file was written. Empty otherwise. + value: ${{ steps.mcpprobe.outputs.lint-report }} + diff-report: + description: Path to diff.html if that file was written. Empty otherwise. + value: ${{ steps.mcpprobe.outputs.diff-report }} runs: using: composite @@ -122,6 +145,9 @@ runs: MCPPROBE_NESTED: ${{ inputs.nested }} MCPPROBE_RULE: ${{ inputs.rule }} MCPPROBE_MIN_DESCRIPTION_LENGTH: ${{ inputs.min-description-length }} + MCPPROBE_STRICT: ${{ inputs.strict }} + MCPPROBE_TRANSPORT: ${{ inputs.transport }} + MCPPROBE_REPORT: ${{ inputs.report }} MCPPROBE_VERSION: ${{ inputs.version }} MCPPROBE_SOURCE: ${{ inputs.source }} run: bash "$GITHUB_ACTION_PATH/action/run.sh" diff --git a/action/run.sh b/action/run.sh index e0e8901..4cc9723 100755 --- a/action/run.sh +++ b/action/run.sh @@ -10,6 +10,8 @@ SUMMARY_REPORT_LIMIT=204800 conclusion=error diff_exit= lint_exit= +lint_report= +diff_report= ado_summary_file= # shellcheck disable=SC2317 # invoked from the EXIT trap @@ -21,6 +23,8 @@ write_github_outputs() { printf 'conclusion=%s\n' "$conclusion" printf 'diff-exit=%s\n' "$diff_exit" printf 'lint-exit=%s\n' "$lint_exit" + printf 'lint-report=%s\n' "$lint_report" + printf 'diff-report=%s\n' "$diff_report" } >> "$GITHUB_OUTPUT" || true } @@ -57,6 +61,14 @@ is_true() { esac } +# Trim leading and trailing whitespace. bash 3.2-safe (no ${var,,}). +trim_ws() { + local s=${1-} + s="${s#"${s%%[![:space:]]*}"}" + s="${s%"${s##*[![:space:]]}"}" + printf '%s' "$s" +} + # Convert paths for Git Bash on Windows. No-op when cygpath is not available. to_unix_path() { if command -v cygpath >/dev/null 2>&1; then @@ -150,6 +162,31 @@ if [[ "$run_diff" != true && "$run_lint" != true ]]; then die "Enable at least one of diff or lint." fi +transport=$(trim_ws "${MCPPROBE_TRANSPORT:-}") +if [[ -n "$transport" && -z "${MCPPROBE_HTTP:-}" ]]; then + die "transport can only be used with http." +fi + +report_dir=$(trim_ws "${MCPPROBE_REPORT:-}") +if [[ -n "$report_dir" ]]; then + # Strip trailing slashes before the .html / existing-file checks so + # mcp-lint.html/ is rejected the same way as mcp-lint.html. + if [[ "$report_dir" != / ]]; then + while [[ "$report_dir" == */ ]]; do + report_dir="${report_dir%/}" + done + fi + report_lower=$(printf '%s' "$report_dir" | tr '[:upper:]' '[:lower:]') + case "$report_lower" in + *.html|*.htm) + die "The report input is a directory (the CLI --report flag takes a file; both checks run by default). Use a directory such as mcpprobe-reports, not a .html path." + ;; + esac + if [[ -e "$report_dir" && ! -d "$report_dir" ]]; then + die "The report input is a directory (the CLI --report flag takes a file; both checks run by default). '$report_dir' exists and is not a directory." + fi +fi + version="${MCPPROBE_VERSION:-}" if [[ -z "$version" ]]; then script_dir=$(cd "$(dirname "$0")" && pwd) @@ -206,6 +243,39 @@ if ! command -v mcpprobe >/dev/null 2>&1; then die "mcpprobe was not found on PATH after installing McpProbe.Cli $version." fi +cli_help= +ensure_cli_help() { + if [[ -z "$cli_help" ]]; then + if ! cli_help=$(mcpprobe lint --help 2>&1); then + die "mcpprobe lint --help failed after installing McpProbe.Cli $version." + fi + fi +} + +require_cli_flag() { + local input_name=$1 + local flag=$2 + ensure_cli_help + case "$cli_help" in + *"$flag"*) return 0 ;; + esac + die "The $input_name input needs a McpProbe.Cli that supports $flag. The installed version is $version, and it does not have that flag. Leave $input_name empty, or set version / source to a build that includes $flag (this repository's packed artifacts, or a later release)." +} + +if [[ -n "$report_dir" ]]; then + require_cli_flag report --report +fi +if is_true "${MCPPROBE_STRICT:-}" && [[ "$run_lint" == true ]]; then + require_cli_flag strict --strict +fi +if [[ -n "$transport" ]]; then + require_cli_flag transport --transport +fi + +if [[ -n "$report_dir" ]]; then + mkdir -p "$report_dir" || die "Could not create the report directory '$report_dir'." +fi + common_args=() if [[ -n "${MCPPROBE_STDIO:-}" ]]; then common_args+=(--stdio "$MCPPROBE_STDIO") @@ -222,6 +292,7 @@ done < <(each_nonempty_line "${MCPPROBE_HEADER:-}") while IFS= read -r line; do common_args+=(--env "$line") done < <(each_nonempty_line "${MCPPROBE_ENV:-}") +[[ -n "$transport" ]] && common_args+=(--transport "$transport") run_mcpprobe() { local title=$1 @@ -251,8 +322,12 @@ run_mcpprobe() { if [[ "$run_diff" == true ]]; then diff_args=(diff --baseline "${MCPPROBE_BASELINE:-mcp-tools.json}" "${common_args[@]}") is_true "${MCPPROBE_FAIL_ON_NON_BREAKING:-}" && diff_args+=(--fail-on-non-breaking) + [[ -n "$report_dir" ]] && diff_args+=(--report "$report_dir/diff.html") diff_exit=0 run_mcpprobe "McpProbe diff" "${diff_args[@]}" || diff_exit=$? + if [[ -n "$report_dir" && -f "$report_dir/diff.html" && "$diff_exit" -ne 2 ]]; then + diff_report="$report_dir/diff.html" + fi fi if [[ "$run_lint" == true ]]; then @@ -263,8 +338,13 @@ if [[ "$run_lint" == true ]]; then while IFS= read -r line; do lint_args+=(--rule "$line") done < <(each_nonempty_line "${MCPPROBE_RULE:-}") + is_true "${MCPPROBE_STRICT:-}" && lint_args+=(--strict) + [[ -n "$report_dir" ]] && lint_args+=(--report "$report_dir/lint.html") lint_exit=0 run_mcpprobe "McpProbe lint" "${lint_args[@]}" || lint_exit=$? + if [[ -n "$report_dir" && -f "$report_dir/lint.html" && "$lint_exit" -ne 2 ]]; then + lint_report="$report_dir/lint.html" + fi fi set -e diff --git a/templates/azure-pipelines/mcpprobe.yml b/templates/azure-pipelines/mcpprobe.yml index 4a3526b..4c6675f 100644 --- a/templates/azure-pipelines/mcpprobe.yml +++ b/templates/azure-pipelines/mcpprobe.yml @@ -66,6 +66,15 @@ parameters: - name: minDescriptionLength type: string default: '' +- name: strict + type: boolean + default: false +- name: transport + type: string + default: '' +- name: report + type: string + default: '' - name: version type: string default: '' @@ -119,5 +128,8 @@ steps: MCPPROBE_NESTED: ${{ parameters.nested }} MCPPROBE_RULE: ${{ parameters.rule }} MCPPROBE_MIN_DESCRIPTION_LENGTH: ${{ parameters.minDescriptionLength }} + MCPPROBE_STRICT: ${{ parameters.strict }} + MCPPROBE_TRANSPORT: ${{ parameters.transport }} + MCPPROBE_REPORT: ${{ parameters.report }} MCPPROBE_VERSION: ${{ parameters.version }} MCPPROBE_SOURCE: ${{ parameters.source }}