A Cursor hook that restricts MCP (Model Context Protocol) calls to only servers managed by ToolHive, Stacklok's MCP Platform.
MCP adoption spreads organically: MCP configurations get shared, copied from READMEs, and rarely cleaned up. Security teams lose visibility into what's connected and what data is flowing where causing security risks and compliance headaches.
ToolHive is Stacklok's open-source platform that brings enterprise-grade security to MCP deployment. It provides a curated registry of approved servers, isolated container runtimes, centralized policy enforcement, and audit logging—without blocking developers from using the tools they need.
This hook is the Cursor integration. It intercepts every MCP call before execution and verifies the target server is ToolHive-managed. Unauthorized servers are blocked with a clear error message.
When Cursor's agent attempts to make an MCP call, this hook:
- Intercepts the call before execution
- Checks if the target server is managed by ToolHive
- Optionally validates the server is from the configured ToolHive registry (registry-only mode)
- Allows approved servers, denies everything else
- Returns a helpful message to both the user and the agent
./install.shThis will:
- Copy the hook to
~/.cursor/hooks/ - Configure
~/.cursor/hooks.json - Remind you to restart Cursor
For enterprise environments that want to restrict MCP servers to only those from the configured ToolHive registry:
./install.sh --registry-onlyThis blocks custom/local servers that aren't in the registry, even if they're managed by ToolHive. Users attempting to use non-registry servers will see a message directing them to contact their administrator.
./uninstall.shRun the unit tests (mocks the thv CLI):
./tests/stacklok-hook-test.shThe hook (hooks/stacklok-hook.sh):
- Receives MCP call details as JSON via stdin
- Extracts the target URL or command
- Queries
thv listto get allowed MCP server URLs - Normalizes URLs (handles localhost/127.0.0.1/::1 equivalence)
- If
THV_REGISTRY_ONLY=true, validates the server is from the configured ToolHive registry - Returns
{"permission": "allow"}or{"permission": "deny", ...}
You can also enable registry-only mode manually by setting the THV_REGISTRY_ONLY environment variable:
THV_REGISTRY_ONLY=true ~/.cursor/hooks/stacklok-hook.sh| Mode | Behavior |
|---|---|
Default (THV_REGISTRY_ONLY unset or false) |
Allows any ToolHive-managed server |
Registry-only (THV_REGISTRY_ONLY=true) |
Only allows servers from the configured ToolHive registry |