Run @sonnylabs/mcp inside Claude Desktop, Cursor, or Claude Code. Lets your agent scan prompts, manage API keys, and scaffold SonnyLabs into a customer codebase — all without leaving the chat.
@sonnylabs/mcp is a Model Context Protocol
server that lets agentic AI hosts drive the Sonny Labs firewall directly.
Run it locally next to your agent host — Claude Desktop, Cursor, Claude
Code, any MCP-compatible client — and the host gains a set of sonny_*
tools the agent can call as it works:
Scan prompts and model outputs for prompt-injection, PII, toxicity,
and policy violations via sonny_scan — the hot path.
Manage API keys and inspect past scans without leaving the chat.
Integrate SonnyLabs into a customer codebase via guided MCP
prompts that emit canonical FastAPI / Express / Next.js / LangChain.js
middleware.
The server is a thin layer over @sonnylabs/sdk
and works identically against the SaaS endpoint and a self-hosted
deployment — only SONNYLABS_BASE_URL changes.
Coming soon to npm. Until the first release lands, build from the
source tree:
The MCP server runs as a stdio process spawned by your host. Most hosts
can npx it directly — no global install needed. Configuration lives
in the host's MCP config file; the package itself is launched on
demand and torn down when the host exits.
~/.claude.json under the mcpServers key, identical shape. Claude
Code also accepts a workspace-scoped .claude.json if you want the
server enabled for one project only.
Host config files sit in plaintext on disk. For shared workstations,
set SONNYLABS_API_KEY_FILE instead — the server reads the file at
startup, never re-reads, and the host only needs to know the path:
MCP hosts log every tool call argument and every tool response.
That means a naive scan tool would echo PII spans straight into the
host's audit log — defeating the whole point of the firewall.
sonny_scan defaults to redact: true. The redacted shape contains
the verdict and a finding summary but never the raw findings
array (PII spans, exact rule excerpts) or the echoed content. If
the agent needs the full finding spans for triage, pass
redact: false explicitly. To later replay the original input via
sonny_get_scan, also pass capture: true on the original call so
the backend retains the content for the configured retention window.
This is the privacy boundary that makes the MCP server safe to run
on a shared workstation. Don't disable it casually.
Discovery: list endpoints declared in the spec but not yet implemented.
The full request / response shapes for the underlying API calls live
in the REST API reference. The
sonny_list_planned_endpoints tool is intentionally a single
discovery surface — see SDK reference for the
implemented client surface.
MCP prompts are server-defined templates a user can invoke from their
host UI. This package ships:
integrate-fastapi, integrate-express, integrate-nextjs,
integrate-langchain — guided walkthroughs that wire SonnyLabs into
the user's codebase. Each emits the canonical middleware snippet for
that stack.
pre-pr-scan — a pre-PR review pass that scans pending changes for
hard-coded prompt injection, leaked PII, and risky tool descriptions
before you push.
The integration prompts share their snippets with the
sonny_integration_snippet tool — invoke either, get the same code.
The MCP server inherits all the SDK behaviour
that runs underneath it: auto-generated Idempotency-Key per scan,
exponential backoff on 429 / 503, RFC 9457 application/problem+json
error envelopes surfaced as MCP tool errors. You don't usually need
to think about it — but if a scan tool errors, the agent sees the
stable dot-namespaced code (auth.api_key.invalid,
validation.field_invalid, etc.) and can act on it.
The server logs diagnostics to stderr (stdout is reserved for the
MCP JSON-RPC stream — console.log would corrupt the transport). On
macOS Claude Desktop, the host log lives at
~/Library/Logs/Claude/mcp*.log.
The startup line is the most useful single diagnostic:
The API key didn't authenticate. Check that it isn't revoked and
matches the deployment — a sk_test_* key won't work against a
production SONNYLABS_BASE_URL.
The mcp:invoke scope is reserved-but-not-enforced today. The warning
is a heads-up: when backend enforcement lands, you'll need a key
minted with that scope. Mint one now via the dashboard, or via
sonny_create_api_key from inside the chat.
Check stderr in the host log. If the startup line stops at "starting",
the host's config didn't pass SONNYLABS_API_KEY (or
SONNYLABS_API_KEY_FILE). If it stops at "connected", the transport
handshake failed — re-check the host's config syntax for typos in the
JSON.