feat: add qmt_list_apis MCP tool (OpenAPI endpoint discovery for coding agents)
This commit is contained in:
+27
-5
@@ -96,16 +96,38 @@ check("initialize", st == 200 and r["result"]["protocolVersion"] == "2025-06-18"
|
||||
and r["result"]["capabilities"].get("tools") is not None,
|
||||
str(r))
|
||||
|
||||
# 2. tools/list -> 9 tools
|
||||
# 2. tools/list -> 10 tools (9 query + qmt_list_apis)
|
||||
st, r = post({"jsonrpc": "2.0", "id": 2, "method": "tools/list"})
|
||||
tools = r["result"]["tools"]
|
||||
names = [t["name"] for t in tools]
|
||||
check("tools/list count", len(tools) == 9, str(names))
|
||||
for need in ["qmt_kline", "qmt_quote", "qmt_tick", "qmt_instrument",
|
||||
"qmt_trading_dates", "qmt_positions", "qmt_asset",
|
||||
"qmt_orders", "qmt_trades"]:
|
||||
check("tools/list count", len(tools) == 10, str(names))
|
||||
for need in ["qmt_list_apis", "qmt_kline", "qmt_quote", "qmt_tick",
|
||||
"qmt_instrument", "qmt_trading_dates", "qmt_positions",
|
||||
"qmt_asset", "qmt_orders", "qmt_trades"]:
|
||||
check("tool %s" % need, need in names)
|
||||
|
||||
# 2b. tools/call qmt_list_apis (needs openapi.json next to src module)
|
||||
import shutil, os as _os
|
||||
SRC = _os.path.join(_os.path.dirname(_os.path.abspath(__file__)), "..", "src")
|
||||
SPEC_SRC = _os.path.join(_os.path.dirname(_os.path.abspath(__file__)), "..",
|
||||
"docs", "api_spec", "openapi.json")
|
||||
SPEC_DST = _os.path.join(SRC, "openapi.json")
|
||||
if _os.path.exists(SPEC_SRC):
|
||||
shutil.copy(SPEC_SRC, SPEC_DST)
|
||||
st, r = post({"jsonrpc": "2.0", "id": 2, "method": "tools/call",
|
||||
"params": {"name": "qmt_list_apis", "arguments": {}}})
|
||||
text = json.loads(r["result"]["content"][0]["text"])
|
||||
check("qmt_list_apis compact", text["ok"] is True
|
||||
and len(text["endpoints"]) == 13, str(text)[:150])
|
||||
st, r = post({"jsonrpc": "2.0", "id": 2, "method": "tools/call",
|
||||
"params": {"name": "qmt_list_apis", "arguments": {"detail": True}}})
|
||||
text = json.loads(r["result"]["content"][0]["text"])
|
||||
check("qmt_list_apis detail", text["ok"] is True
|
||||
and "paths" in text["spec"] and "/mcp" in text["spec"]["paths"],
|
||||
str(text)[:150])
|
||||
if _os.path.exists(SPEC_DST):
|
||||
_os.remove(SPEC_DST)
|
||||
|
||||
# 3. tools/call qmt_kline
|
||||
st, r = post({"jsonrpc": "2.0", "id": 3, "method": "tools/call",
|
||||
"params": {"name": "qmt_kline",
|
||||
|
||||
Reference in New Issue
Block a user