Skip to content

MCP server

@kinglet/mcp is a local Model Context Protocol server for Kinglet. It lets AI clients search logs, inspect monitors and alerts, and — when the key allows it — create, update, or delete monitors in one project.

The server runs on your machine over stdio and calls the normal Kinglet HTTP API with a project-scoped MCP key. It never opens the database, never ingests logs, and never inherits a human role. It requires Node.js 24 or newer and works with any stdio-capable MCP client.

MCP keys are separate from API keys. A km_... key is bound to one project, has its own scopes, and never grants a human role or admin access.

  1. Open Settings → Projects, then open the project the client should use.
  2. In MCP keys, choose new MCP key, name it for the client, and select scopes.
  3. Copy the secret when it is shown. It is displayed once; only a hash is stored.
Scope Grants
logs.read Search and read events, histograms, counts, and services
monitors.read List and get monitors, recent alerts, and channel summaries (no URLs)
monitors.write Create, update, and delete monitors; requires monitors.read

New keys default to read-only: logs.read and monitors.read on, monitors.write off. At least one scope is required, and write implies read. Monitor writes also need KINGLET_MCP_ALLOW_MONITOR_WRITES=1 on the server; the scope alone is not enough, so AI-driven monitor changes stay off until the deployer enables them.

Revoke or reroll the key in the same card. The change applies on the next request; the old secret then gets 401.

Variable Required Description
KINGLET_URL yes Base URL, for example https://logs.example.com; must be http:// or https://
KINGLET_MCP_KEY yes MCP key starting with km_...; a kl_... API key is rejected
KINGLET_MCP_TIMEOUT_MS no Per-request timeout in milliseconds; default 15000 (1000–300000)

The URL may include a path prefix, such as https://example.com/kinglet, but not credentials, a query string, or a fragment. Use HTTPS outside local development.

These clients use the same mcpServers shape:

Client Config file
Claude Desktop claude_desktop_config.json (Settings → Developer → Edit Config)
Cursor ~/.cursor/mcp.json (global) or .cursor/mcp.json (project)
Windsurf ~/.codeium/windsurf/mcp_config.json
Claude Code .mcp.json in the project (or use the CLI tab)
{
"mcpServers": {
"kinglet": {
"command": "npx",
"args": ["-y", "@kinglet/mcp@0.5.0"],
"env": {
"KINGLET_URL": "https://logs.example.com",
"KINGLET_MCP_KEY": "km_..."
}
}
}
}

In a committed file, prefer ${KINGLET_MCP_KEY} environment expansion where the client supports it over a literal secret.

To try unreleased changes, build the package from a Kinglet checkout and point the client at the compiled entry point:

Terminal window
pnpm --filter @kinglet/mcp build
{
"mcpServers": {
"kinglet": {
"command": "node",
"args": ["/absolute/path/to/kinglet/packages/mcp/dist/cli.js"],
"env": {
"KINGLET_URL": "http://localhost:3000",
"KINGLET_MCP_KEY": "km_..."
}
}
}
}

All tools are limited to the key’s project and need their matching scope; get_context works with any valid key. The exception is list_channels: notification channels are shared across projects, so it lists every channel’s id, name, type, enabled status, and health. The three monitor write tools are advertised only when the key has monitors.write and the server sets KINGLET_MCP_ALLOW_MONITOR_WRITES=1; otherwise the client sees the 12 read tools. Hiding tools is UX only: the API authorizes every write.

The search_events description teaches the client the Trill filter syntax, with examples; get_histogram and count_events take the same q filter.

Tool Scope What it does
get_context any valid key Project, key metadata, capabilities, monitor write gate, version, retention
search_events logs.read Events for a filter and time range, newest first, with a cursor and optional fields
get_event logs.read One event by uid
get_event_context logs.read One event plus before/after neighbours in (ts, id) order
get_histogram logs.read Bucket counts for a filter and time range (buckets 1–240, default 60)
list_services logs.read Services with event counts (top 200 by count)
count_events logs.read Effective from/to, total, and optional service/level/env groups
list_monitors monitors.read Monitors, state, last evaluation, and channel summaries
get_monitor monitors.read One monitor by id
list_alerts monitors.read Recent alerts; optional monitor/state/time filters
get_alert monitors.read One alert by id, with the same masking rules
list_channels monitors.read Channel id, name, type, enabled, and health only
create_monitor monitors.write Create a monitor; channels are attached with channelIds
update_monitor monitors.write Partial update by id
delete_monitor monitors.write Delete a monitor and its alert history (destructive)

Monitor writes accept channel ids, never webhook URLs, and reads never return URLs or raw delivery errors. There is no tool for ingest, clearing logs, projects, users, keys, backups, restore, archive, channel administration, settings, SQL, or shell: an MCP client cannot delete logs or change access.

  • Log and monitor results from MCP tools leave your server and go to the AI provider configured in your client. Logs can contain personal data, tokens, or regulated data; point the key at a project whose contents are appropriate for that provider.
  • Event messages and fields are untrusted input. A log line can contain text that looks like an instruction; the server never acts on it, but prompt injection defense ultimately depends on the client and model. Be cautious with agents that can take follow-up actions.
  • Never paste secrets into logs you plan to search, and grant only the scopes the client needs. Omit monitors.write unless the client should change monitors.
  • The server logs one line per tool call to stderr with the tool name, duration, status, and row count — never arguments, filters, event contents, or the key.
  • Requests: 60 per minute per key, burst 10. Back off on 429; there are no automatic retries. Each API process enforces its own bucket, so with several instances add a shared limit at the proxy or edge.
  • Rows: 50 by default, 200 maximum. search_events returns a nextCursor when more rows are available. Its optional fields list (id, uid, ts, level, service, env, message, fields; max 8, unique) projects each event without changing the cursor (when fields is set, level returns the numeric level 0–5 and levelName is omitted).
  • Context: get_event_context returns the event plus chronological before/after lists; both default to 5 and cap at 20. If the result exceeds the 256 KiB cap, retry with smaller before/after.
  • Groups: count_events returns 50 groups by default, 200 maximum, ordered by count, with truncated: true when more exist. total is always the full match count, and the response echoes the clamped from/to window.
  • Alerts: list_alerts filters by monitorId, state, and from/to on firedAt; when from/to are supplied, the alert window is clamped to 31 days. With no bounds, history remains all-time and is capped by limit. get_alert returns one alert or a clean alert not found.
  • Response size: 256 KiB per result. Large list responses are trimmed and marked truncated: true; a single result that still exceeds the cap returns an error asking for a narrower query.
  • Event content: messages are truncated at 4 KiB (…), and any event whose fields object exceeds 8 KiB has fields replaced with null and fieldsTruncated: true set. Filters are limited to 500 characters and 32 terms, and the API clamps search windows to 31 days.

The key was revoked or rerolled, its owner was disabled, or KINGLET_URL points at a different Kinglet instance. Create a new MCP key and update the client configuration.

The key does not have the scope the tool needs. The error names the missing scope, such as logs.read or monitors.write. Add the scope to the key (or create a new key with it) and retry.

Desktop clients often start with a different PATH than your terminal. Use an absolute node path, or the Windows cmd /c npx wrapper above. Run the same command and environment directly in a terminal to see stderr; stdout is reserved for MCP protocol frames.

The Inspector passes only the variables you give it with -e:

Terminal window
npx -y @modelcontextprotocol/inspector -e KINGLET_URL=https://logs.example.com -e KINGLET_MCP_KEY=km_... npx -y @kinglet/mcp@0.5.0

To test a local build instead, replace npx -y @kinglet/mcp@0.5.0 with node /absolute/path/to/kinglet/packages/mcp/dist/cli.js.

v1 is local stdio only. There is no remote HTTP /mcp endpoint yet, so clients that only accept a URL — Claude web, ChatGPT connectors, and similar hosted clients — cannot use the server in this release.