feat: add local tools and read-only remote MCP servers
Increment 6 of .scratch/solution-architect-agent/spec.md, test-first. - app/tools/mcp.py: MCP client and catalog exposing only allowlisted, readOnlyHint tools as framework-neutral ToolSpecs; unreachable servers and failed calls become discovery gaps; ADC auth with quota project. - app/tools/local.py: Mermaid structure check and Terraform fmt, validate and plan in a scratch copy; apply is never constructed. - Tool factory gives roles their named local tools and bundle MCP servers; pillar advisors get general-tier documentation tools. - providers/gcp.yaml: 42 allowlisted tools reviewed against live tools/list of 12 Google Cloud MCP servers (snapshot in providers/reviews/), excluding data-reading and secret-capable tools. - scripts/list-mcp-tools.py, docs/operations/mcp-access.md (IAM deny policy, service account roles), cloud-discovery and iac-validation Skills, MCP and Terraform settings, pytest asyncio auto mode. - 31 new tests; full suite 189 passed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
79
scripts/list-mcp-tools.py
Normal file
79
scripts/list-mcp-tools.py
Normal file
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
"""List every tool a provider bundle's remote MCP servers offer, with read-only hints.
|
||||
|
||||
Use it to review allowlists: only list tools; this never calls one.
|
||||
|
||||
Usage: .venv/bin/python scripts/list-mcp-tools.py [provider] [--json] [--no-auth]
|
||||
|
||||
--no-auth lists without credentials; Google Cloud MCP servers allow tools/list anonymously.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from app.config import get_settings
|
||||
from app.providers import load_provider
|
||||
from app.tools.mcp import McpClient, NoAuth, auth_from_config
|
||||
|
||||
|
||||
async def main(provider: str, as_json: bool, no_auth: bool) -> int:
|
||||
bundle = load_provider(provider)
|
||||
auth = (
|
||||
NoAuth()
|
||||
if no_auth
|
||||
else auth_from_config(bundle.mcp_auth, get_settings().MCP_QUOTA_PROJECT)
|
||||
)
|
||||
report = {}
|
||||
for server in bundle.mcp_servers.values():
|
||||
try:
|
||||
tools = await McpClient(server, auth, timeout=30).list_tools()
|
||||
except Exception as exc: # noqa: BLE001 - report every server
|
||||
report[server.id] = {
|
||||
"url": server.url,
|
||||
"error": f"{type(exc).__name__}: {exc}",
|
||||
}
|
||||
continue
|
||||
report[server.id] = {
|
||||
"url": server.url,
|
||||
"tools": [
|
||||
{
|
||||
"name": tool.name,
|
||||
"read_only": tool.read_only,
|
||||
"allowed": tool.name in server.allow,
|
||||
"description": tool.description.split("\n")[0][:200],
|
||||
}
|
||||
for tool in tools
|
||||
],
|
||||
}
|
||||
if as_json:
|
||||
print(json.dumps(report, indent=2))
|
||||
return 0
|
||||
for server_id, entry in report.items():
|
||||
print(f"\n== {server_id} ({entry['url']})")
|
||||
if "error" in entry:
|
||||
print(f" ERROR {entry['error'][:200]}")
|
||||
continue
|
||||
for tool in entry["tools"]:
|
||||
flag = "RO" if tool["read_only"] else "RW"
|
||||
allowed = "allowed" if tool["allowed"] else ""
|
||||
print(f" [{flag}] {tool['name']:<40} {allowed:<8} {tool['description']}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = [a for a in sys.argv[1:] if not a.startswith("--")]
|
||||
sys.exit(
|
||||
asyncio.run(
|
||||
main(
|
||||
args[0] if args else "gcp",
|
||||
"--json" in sys.argv,
|
||||
"--no-auth" in sys.argv,
|
||||
)
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user