Skip to main content

Query Events API Reference

The Query Events API enables logging and querying tool retrieval events for dashboard visibility and observability.

Overview

Purpose

  • Log tool retrieval queries with metadata (selected tools, scores, source)
  • Retrieve historical queries for analytics and debugging
  • Track request origin (CLI, API, Dashboard)
  • Monitor tool selection patterns and performance

Base URL


Endpoints

/v2/retrieve_tools — Tool Retrieval (with Logging)

Automatically logs to query_events when user is authenticated. Endpoint: GET /v2/retrieve_tools Description: Retrieve tools matching a query. Logs the request and results to query_events table automatically.

Request

Query Parameters: Headers:

Response

Status: 200 OK
Response Fields:

Side Effects

When authenticated, automatically logs to query_events table:

Examples

CLI Request (with MCP header):
Result logged with source: "mcp". API Request (no special header):
Result logged with source: "api" (default). Dashboard Request:
Result logged with source: "dashboard".

QueryEventService (Backend)

The QueryEventService is the modular service responsible for logging queries.

Import

Methods

__init__(supabase_url: Optional[str] = None, service_key: Optional[str] = None)

Initialize the service with Supabase credentials. Parameters:
If not provided, credentials are read from environment:
  • SUPABASE_URL
  • SUPABASE_SERVICE_KEY
Returns: QueryEventService instance

async log_retrieval(user_id, query, source, tools, scores, timeout)

Log a tool retrieval to the query_events table. Parameters: Returns: str | None — Inserted event ID (UUID) or None if failed Side Effects:
  • Writes to Supabase query_events table
  • Logs warnings if HTTP/network fails (non-blocking)
  • Returns gracefully if Supabase unavailable
Examples:

is_ready() -> bool

Check if service is properly configured (has Supabase credentials). Returns: True if ready, False otherwise Example:

Query Events Table Schema


Querying Query Events

Via Supabase REST API

Get user’s recent queries:
Response:
Filter by date range:
Filter by source:

Via Python


Errors

401 Unauthorized

Cause: Missing or invalid API key Response:
Solution: Provide valid Authorization: Bearer {api_key} header

400 Bad Request

Cause: Missing required parameters Response:
Solution: Check all required parameters are provided

500 Internal Server Error

Cause: Backend error (e.g., Supabase unavailable) Response:
Note: Query events failing does NOT block tool retrieval — the endpoint still returns tools but logs a warning.

Rate Limiting

Query event logging does NOT count against rate limits (fire-and-forget background logging).

Authentication

All endpoints require authentication:
Get your API key in the dashboard under SettingsAPI Keys.

Best Practices

1. Always Include Source Header

Help analytics by identifying request origin:

2. Handle Gracefully

Query event logging is non-blocking and fire-and-forget:

3. Monitor Query Volume

Track queries per minute and patterns:

4. Archive Old Events

Keep dashboard responsive by archiving:


Key Takeaway: Query events provide complete visibility into tool retrieval patterns. They’re logged automatically and never block requests. Use them for analytics, debugging, and monitoring. 📊