idx-cli/web/scripts/gen-mcp-tools.sh
0xrsydn 7830de3636 docs(mcp): the generated tools page names warnings
The tools reference page described results as {data, source, fetched_at,
stale} and failures as {error, code, message}, without the `warnings` this
PR adds (Pullfrog on #81). The generator's intro says so; page regenerated.

Claude-Session: https://claude.ai/code/session_01RqPPVeVDrnLoP7NUZmLRxY
2026-11-04 20:46:27 +07:00

51 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
# Writes the MCP tools page from idx-mcp's tools golden
# (crates/idx-mcp/tests/golden/tools.json). `nix flake check` fails when the
# committed page is out of date.
#
# web/scripts/gen-mcp-tools.sh crates/idx-mcp/tests/golden/tools.json > web/src/content/docs/mcp/tools.md
set -euo pipefail
tools=${1:?usage: gen-mcp-tools.sh <tools.json>}
cat <<'EOF'
---
title: Tools
description: Every idx-mcp tool and its inputs, generated from the server's tool list.
---
<!-- Generated by web/scripts/gen-mcp-tools.sh; do not edit by hand. -->
idx-mcp serves these tools. `ownership_sync` is listed only when the server
starts with `--allow-sync`. Results that come from a live provider are wrapped
as `{data, source, fetched_at, stale}`; failures return `{error, code,
message}` with `isError` set. Either may carry `warnings`, what idx worked
around (such as a history fallback or a stale cache entry), when there was
any.
EOF
jq -r '
def typ($defs):
if .["$ref"] then ($defs[.["$ref"] | sub("^#/\\$defs/"; "")] | .enum | map("`" + . + "`") | join(" / "))
elif .enum then (.enum | map("`" + tostring + "`") | join(" / "))
elif (.type | type) == "array" then
(.type | map(select(. != "null")) | join(" | "))
+ (if .items then " of " + (.items | typ($defs)) else "" end)
elif .type == "array" and .items then "array of " + (.items | typ($defs))
else (.type // "any") end;
[.[]
| .inputSchema as $s
| ($s["$defs"] // {}) as $defs
| ($s.required // []) as $req
| "## `\(.name)`\n\n\(.description)\n\n"
+ (if ($s.properties // {}) == {} then "No inputs.\n"
else
"| Input | Type | Required | Description |\n| --- | --- | --- | --- |\n"
+ ([$s.properties | to_entries[]
| .key as $k
| "| `\($k)` | \(.value | typ($defs)) | \(if ($req | index($k)) then "yes" else "no" end) | \((.value.description // "") | gsub("\\|"; "\\|") | gsub("\n"; " ")) |"]
| join("\n")) + "\n"
end)]
| join("\n")
' "$tools" | sed '${/^$/d}'