feat(mcp): 新增 Excel 批量清单匹配工具并调整分页与采纳锚策略

This commit is contained in:
lianjianwei2024
2026-11-02 15:23:27 +08:00
parent d82b5e8676
commit 8701eaf739
13 changed files with 784 additions and 219 deletions

View File

@@ -12,7 +12,8 @@ from api_harness import post, server # noqa: F401
NEW_TOOLS = {"bills_query", "lme_prices", "market_info_prices",
"recent_review_query", "attachment_download",
"match_hist", "project_import", "bill_adopt", "lme_adopt"}
"match_hist", "project_import", "bill_adopt", "lme_adopt",
"excel_bill_match"} # 2026-11-02 主人定:Excel 批量清单匹配(只读)
def _mcp(server, body, token=None):
@@ -68,14 +69,14 @@ def test_mcp_switch_lifecycle(server):
assert r.status_code == 403
# 状态接口
st = server["client"].get("/api/mcp/status").json()
assert st["enabled"] is False and st["endpoint"] == "/mcp" and st["tools"] == 9
assert st["enabled"] is False and st["endpoint"] == "/mcp" and st["tools"] == 10
def test_mcp_readonly_toolset(server):
t = post(server, "/api/admin/mcp", {"enabled": True})
tok = t["token"]
try:
# 工具集 = 9 件套,一个不多一个不少(决策 238/239:只读 5+匹配+写入 3;旧写工具除 bill_adopt 外仍不在)
# 工具集 = 10 件套,一个不多一个不少(决策 238/239:只读 5+匹配+写入 3,+excel_bill_match;旧写工具除 bill_adopt 外仍不在)
r = _mcp(server, _rpc(2, "tools/list"), tok)
names = {x["name"] for x in r.json()["result"]["tools"]}
assert names == NEW_TOOLS, names
@@ -116,9 +117,12 @@ def test_mcp_query_matches_db(server):
if row:
bid = row[0]
want = con.execute("SELECT COUNT(*) FROM prices WHERE batch_id=?", (bid,)).fetchone()[0]
out = _call(server, tok, 1, "market_info_prices", {"batch_id": bid, "limit": 200})
out = _call(server, tok, 1, "market_info_prices", {"batch_id": bid, "limit": 250})
got = len(out["rows"])
assert out["ok"] and got == min(want, 200), (want, got)
assert out["ok"] and got == min(want, 100), (want, got) # 2026-11-02 主人定:上限收紧 100
# 默认口径:不传 limit = 只给匹配前 10 条
out2 = _call(server, tok, 2, "market_info_prices", {"batch_id": bid})
assert out2["ok"] and len(out2["rows"]) == min(want, 10), (want, len(out2["rows"]))
if out["rows"]:
for k in ("Code", "Name", "Unit", "NoTaxPrice", "TaxPrice"):
assert k in out["rows"][0], out["rows"][0].keys()