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.
Create an MCP key
Section titled “Create an MCP key”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.
- Open Settings → Projects, then open the project the client should use.
- In MCP keys, choose new MCP key, name it for the client, and select scopes.
- 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.
Configuration
Section titled “Configuration”| 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.
Client setup
Section titled “Client setup”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.
Add the server from a terminal:
claude mcp add kinglet \ --env KINGLET_URL=https://logs.example.com \ --env KINGLET_MCP_KEY=km_... \ -- npx -y @kinglet/mcp@0.5.0Edit .vscode/mcp.json:
{ "servers": { "kinglet": { "type": "stdio", "command": "npx", "args": ["-y", "@kinglet/mcp@0.5.0"], "env": { "KINGLET_URL": "https://logs.example.com", "KINGLET_MCP_KEY": "km_..." } } }}VS Code supports inputs for secrets; use an input instead of a literal key when
the configuration is shared.
Edit ~/.codex/config.toml:
[mcp_servers.kinglet]command = "npx"args = ["-y", "@kinglet/mcp@0.5.0"]env = { KINGLET_URL = "https://logs.example.com", KINGLET_MCP_KEY = "km_..." }Add the server to settings.json; Settings → AI → MCP Servers → Add Server
writes the same entry:
{ "context_servers": { "kinglet": { "command": "npx", "args": ["-y", "@kinglet/mcp@0.5.0"], "env": { "KINGLET_URL": "https://logs.example.com", "KINGLET_MCP_KEY": "km_..." } } }}Add a local server to opencode.json or opencode.jsonc:
{ "$schema": "https://opencode.ai/config.json", "mcp": { "servers": { "kinglet": { "type": "local", "command": ["npx", "-y", "@kinglet/mcp@0.5.0"], "environment": { "KINGLET_URL": "https://logs.example.com", "KINGLET_MCP_KEY": "km_...", }, }, }, },}OpenCode releases before V2 put server names directly under mcp instead of
mcp.servers.
Any MCP client that can launch a command with environment variables works:
command: npxargs: -y @kinglet/mcp@0.5.0env: KINGLET_URL=https://logs.example.com KINGLET_MCP_KEY=km_...Run from a checkout
Section titled “Run from a checkout”To try unreleased changes, build the package from a Kinglet checkout and point the client at the compiled entry point:
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.
Security
Section titled “Security”- 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.writeunless 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.
Limits
Section titled “Limits”- 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_eventsreturns anextCursorwhen more rows are available. Its optionalfieldslist (id,uid,ts,level,service,env,message,fields; max 8, unique) projects each event without changing the cursor (whenfieldsis set,levelreturns the numeric level0–5andlevelNameis omitted). - Context:
get_event_contextreturns the event plus chronologicalbefore/afterlists; both default to 5 and cap at 20. If the result exceeds the 256 KiB cap, retry with smallerbefore/after. - Groups:
count_eventsreturns 50 groups by default, 200 maximum, ordered by count, withtruncated: truewhen more exist.totalis always the full match count, and the response echoes the clampedfrom/towindow. - Alerts:
list_alertsfilters bymonitorId,state, andfrom/toonfiredAt; whenfrom/toare supplied, the alert window is clamped to 31 days. With no bounds, history remains all-time and is capped bylimit.get_alertreturns one alert or a cleanalert 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 whosefieldsobject exceeds 8 KiB hasfieldsreplaced withnullandfieldsTruncated: trueset. Filters are limited to 500 characters and 32 terms, and the API clamps search windows to 31 days.
Troubleshooting
Section titled “Troubleshooting”401 / “Kinglet rejected the MCP key”
Section titled “401 / “Kinglet rejected the MCP key””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.
403 / missing scope
Section titled “403 / missing scope”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.
Nothing starts, or npx is not found
Section titled “Nothing starts, or npx is not found”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.
Check the server with MCP Inspector
Section titled “Check the server with MCP Inspector”The Inspector passes only the variables you give it with -e:
npx -y @modelcontextprotocol/inspector -e KINGLET_URL=https://logs.example.com -e KINGLET_MCP_KEY=km_... npx -y @kinglet/mcp@0.5.0pnpm dlx @modelcontextprotocol/inspector -e KINGLET_URL=https://logs.example.com -e KINGLET_MCP_KEY=km_... npx -y @kinglet/mcp@0.5.0yarn dlx @modelcontextprotocol/inspector -e KINGLET_URL=https://logs.example.com -e KINGLET_MCP_KEY=km_... npx -y @kinglet/mcp@0.5.0bunx @modelcontextprotocol/inspector -e KINGLET_URL=https://logs.example.com -e KINGLET_MCP_KEY=km_... npx -y @kinglet/mcp@0.5.0nub dlx @modelcontextprotocol/inspector -e KINGLET_URL=https://logs.example.com -e KINGLET_MCP_KEY=km_... npx -y @kinglet/mcp@0.5.0To test a local build instead, replace npx -y @kinglet/mcp@0.5.0 with
node /absolute/path/to/kinglet/packages/mcp/dist/cli.js.
Remote-only clients cannot connect
Section titled “Remote-only clients cannot connect”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.