Files
Yuri Yaryshev 2b285b5a3d
All checks were successful
ci / test (push) Successful in 39s
ci / deploy (push) Successful in 2m44s
Миграция 040: RLS для acc_mcp_log (тест миграций в CI)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-18 18:59:17 +03:00

33 lines
1.8 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Журнал вызовов MCP accounting_automation: разбор ошибок и доли неудачных запросов, когда чата сотрудника не видно.
create table if not exists acc_mcp_log (
id bigserial primary key,
at timestamptz not null default now(),
person_id text,
method text not null, -- tools/call, tools/list, initialize, resources/read ...
tool text, -- имя инструмента для tools/call
args jsonb, -- аргументы (усечённые)
ok boolean not null,
error_kind text, -- invalid_args | not_found | forbidden | internal | unknown_tool | rpc | partial
error text,
items_total int, -- для acc_review_batch: действий в пакете
items_failed int, -- для acc_review_batch: неудачных действий
duration_ms int,
result_bytes int
);
alter table acc_mcp_log enable row level security;
create index if not exists acc_mcp_log_at_idx on acc_mcp_log (at desc);
create index if not exists acc_mcp_log_tool_idx on acc_mcp_log (tool, at desc);
-- Доля ошибок по инструментам и дням: >3-5% = баг инструмента или мало инструкций.
create or replace view acc_mcp_error_rate as
select date_trunc('day', at)::date as day, tool,
count(*) as calls,
count(*) filter (where not ok or coalesce(items_failed, 0) > 0) as bad_calls,
round(100.0 * count(*) filter (where not ok or coalesce(items_failed, 0) > 0) / count(*), 1) as bad_pct,
coalesce(sum(items_total), 0) as batch_items,
coalesce(sum(items_failed), 0) as batch_items_failed
from acc_mcp_log
where method = 'tools/call'
group by 1, 2
order by 1 desc, 2;