scripts/mcp/DiscoveryAgent/Rich/README.md
This prototype is a single-file Python CLI that runs an LLM-driven database discovery agent against an existing MCP Query endpoint.
It is designed to be:
asyncio + async HTTP clients)--trace trace.jsonl records every LLM request/response and every MCP tool call/result--debug shows stack tracesThe UI is rendered in the terminal using Rich (live dashboard + status).
The CLI (discover_cli.py) implements a minimal but real “multi-expert” agent:
Experts do not talk to the database directly. They only request MCP tools. Discoveries can be stored in the MCP catalog (if your MCP provides catalog tools).
Bootstrap
list_schemas--schema or first returned)list_tables(schema)Iterate (up to --max-iterations)
--tasks-per-iter tasks:
catalog_upsert (if present)Stop
Create a venv and install dependencies:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
The script needs two endpoints:
/v1/chat/completions)You can configure via environment variables or CLI flags.
export MCP_ENDPOINT="https://127.0.0.1:6071/mcp/query"
export MCP_AUTH_TOKEN="YOUR_TOKEN"
export MCP_INSECURE_TLS="1"
# export MCP_AUTH_TOKEN="..." # if your MCP needs auth
CLI flags override env vars:
--mcp-endpoint--mcp-auth-token--mcp-insecure-tlsThe LLM client expects an OpenAI‑compatible /chat/completions endpoint.
For OpenAI:
export LLM_BASE_URL="https://api.openai.com/v1" # must include `v1`
export LLM_API_KEY="YOUR_KEY"
export LLM_MODEL="gpt-4o-mini"
For Z.ai:
export LLM_BASE_URL="https://api.z.ai/api/coding/paas/v4"
export LLM_API_KEY="YOUR_KEY"
export LLM_MODEL="GLM-4.7"
For a local OpenAI‑compatible server (vLLM / llama.cpp / etc.):
export LLM_BASE_URL="http://localhost:8001" # example
export LLM_API_KEY="" # often unused locally
export LLM_MODEL="your-model-name"
CLI flags override env vars:
--llm-base-url--llm-api-key--llm-modelpython discover_cli.py run --max-iterations 6 --tasks-per-iter 3
python discover_cli.py run --schema public
python discover_cli.py run --debug
python discover_cli.py run --trace trace.jsonl
The trace is JSONL and includes:
llm.request, llm.raw, and optional llm.repair.*mcp.call and mcp.resulterror and error.traceback (when --debug)Store intent in the MCP catalog so it influences planning:
python discover_cli.py intent --run-id <RUN_ID> --audience support --goals qna documentation
python discover_cli.py intent --run-id <RUN_ID> --constraint max_db_load=low --constraint max_seconds=120
The agent reads intent from:
kind=intentkey=intent/<run_id>If it errors and you don’t know where:
--trace trace.jsonl --debugllm.request / mcp.callCommon issues:
llm.raw)mcp.call)The Query expert can call run_sql_readonly if the planner chooses it.
To disable SQL execution, remove run_sql_readonly from the Query expert allow-list.
Prototype / internal use.