feat(auth): track unique tools in access metrics
Some checks failed
CI / build-and-test (push) Failing after -31m49s

* Add tool tracking to AccessTracker and metrics
* Update tests to validate tool tracking functionality
* Modify middleware to record tool usage
* Enhance observability with tool context
* Update UI to display unique tools in metrics
This commit is contained in:
2026-04-26 23:25:51 +02:00
parent 63f8dcacb6
commit b17241b928
10 changed files with 112 additions and 15 deletions

View File

@@ -128,8 +128,10 @@
unique_principals: raw?.metrics?.unique_principals ?? 0,
unique_ips: raw?.metrics?.unique_ips ?? 0,
unique_agents: raw?.metrics?.unique_agents ?? 0,
unique_tools: raw?.metrics?.unique_tools ?? 0,
top_ips: Array.isArray(raw?.metrics?.top_ips) ? raw.metrics.top_ips : [],
top_agents: Array.isArray(raw?.metrics?.top_agents) ? raw.metrics.top_agents : []
top_agents: Array.isArray(raw?.metrics?.top_agents) ? raw.metrics.top_agents : [],
top_tools: Array.isArray(raw?.metrics?.top_tools) ? raw.metrics.top_tools : []
}
};
} catch (err) {

View File

@@ -50,7 +50,7 @@
{/if}
{#if data}
<div class="mt-6 grid gap-6 xl:grid-cols-2">
<div class="mt-6 grid gap-6 xl:grid-cols-3">
<ConnectionBreakdown
title="Requests By IP Address"
entries={data.metrics.top_ips}
@@ -61,5 +61,10 @@
entries={data.metrics.top_agents}
emptyLabel="No user agents recorded yet."
/>
<ConnectionBreakdown
title="Requests By MCP Tool"
entries={data.metrics.top_tools}
emptyLabel="No MCP tool calls recorded yet."
/>
</div>
{/if}

View File

@@ -4,7 +4,7 @@
const { data }: { data: StatusResponse } = $props();
</script>
<div class="mt-6 grid gap-4 sm:grid-cols-2 xl:grid-cols-3">
<div class="mt-6 grid gap-4 sm:grid-cols-2 xl:grid-cols-4">
<div class="rounded-2xl border border-white/10 bg-white/5 p-5">
<p class="text-sm uppercase tracking-[0.2em] text-slate-400">Connected users</p>
<p class="mt-2 text-3xl font-semibold text-white">{data.connected_count}</p>
@@ -25,6 +25,10 @@
<p class="text-sm uppercase tracking-[0.2em] text-slate-400">Unique agents</p>
<p class="mt-2 text-3xl font-semibold text-white">{data.metrics.unique_agents}</p>
</div>
<div class="rounded-2xl border border-white/10 bg-white/5 p-5">
<p class="text-sm uppercase tracking-[0.2em] text-slate-400">Unique MCP tools</p>
<p class="mt-2 text-3xl font-semibold text-white">{data.metrics.unique_tools}</p>
</div>
<div class="rounded-2xl border border-white/10 bg-white/5 p-5">
<p class="text-sm uppercase tracking-[0.2em] text-slate-400">Version</p>
<p class="mt-2 break-all text-2xl font-semibold text-white">{data.version}</p>

View File

@@ -17,8 +17,10 @@ export type AccessMetrics = {
unique_principals: number;
unique_ips: number;
unique_agents: number;
unique_tools: number;
top_ips: RequestAggregate[];
top_agents: RequestAggregate[];
top_tools: RequestAggregate[];
};
export type StatusResponse = {