A Claude Code plugin that restricts MCP (Model Context Protocol) tool calls to only servers managed by ToolHive.
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 an 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 Claude Code 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 Claude Code attempts to use an MCP tool, this hook:
- Intercepts the call before execution (PreToolUse hook)
- Parses the tool name (
mcp__<server>__<tool>) to extract the server name - Queries ToolHive (
thv list --format json) to get managed servers - Fail-closed: If ToolHive is unavailable, denies the call
- Allows or denies based on plugin mode (see Available Plugins below)
- Returns structured JSON to Claude Code indicating allow/deny and reason
This marketplace provides two plugin variants:
| Plugin | Description |
|---|---|
stacklok-hook |
Allows any MCP server managed by ToolHive |
stacklok-hook-registry-restricted |
Only allows servers from the ToolHive registry |
-
stacklok-hook: Use this if you trust all servers your team adds to ToolHive. Any server in
thv listis allowed. -
stacklok-hook-registry-restricted: Use this for stricter enterprise environments. Servers must be in ToolHive AND match the ToolHive registry:
- Container workloads: The server's package must match an image in the registry
- Remote workloads: The server's remote URL must match a URL in the registry
- Linux - Fully supported
- macOS - Supported (requires GNU coreutils)
- Windows - Not currently supported (requires bash shell)
- Claude Code CLI installed
- jq - JSON processor (
brew install jqon macOS) - GNU coreutils - Required for
timeoutcommand (brew install coreutilson macOS). Linux systems typically have this pre-installed. - ToolHive (
thvCLI)
-
Launch Claude Code in any directory:
claude
-
Add the marketplace:
/plugin marketplace add StacklokLabs/stacklok-claude-hooksIf you see an error about marketplace not being found or authentication failed try
/plugin marketplace add [email protected]:StacklokLabs/stacklok-claude-hooks.gitor
/plugin marketplace add https://github.com/StacklokLabs/stacklok-claude-hooks -
Install your preferred plugin:
/plugin install stacklok-hookOr for registry-restricted mode:
/plugin install stacklok-hook-registry-restricted -
Select "Install for you (user scope)" when prompted.
-
Exit and restart Claude Code.
-
Clone this repository:
git clone https://github.com/StacklokLabs/stacklok-claude-hooks.git cd stacklok-claude-hooks -
Start Claude Code with the plugin directory (use absolute path):
claude --plugin-dir /path/to/stacklok-claude-hooks/plugins/stacklok-hook
Or for registry-restricted mode:
claude --plugin-dir /path/to/stacklok-claude-hooks/plugins/stacklok-hook-registry-restricted
-
Restart Claude Code.
/plugin uninstall stacklok-hook
Or for registry-restricted:
/plugin uninstall stacklok-hook-registry-restricted
Run the unit tests (mocks the thv CLI):
# Test default mode plugin
./plugins/stacklok-hook/tests/stacklok-hook-test.sh
# Test registry-restricted mode plugin
./plugins/stacklok-hook-registry-restricted/tests/stacklok-hook-test.shThe hook (scripts/stacklok-hook.sh):
- Receives MCP call details as JSON via stdin
- Extracts
tool_name(format:mcp__<server>__<tool>) - Parses out the server name
- Queries
thv list --format jsonto get managed servers - For registry-restricted mode: Also checks
thv registry list --format json - Returns structured JSON:
- Allow:
{"hookSpecificOutput": {"permissionDecision": "allow", ...}} - Deny:
{"hookSpecificOutput": {"permissionDecision": "deny", ...}, "systemMessage": "..."}
- Allow:
Note that shared functions are in scripts/stacklok-hook-common.sh and sourced by both plugins via symlinks.
Enable debug logs by setting the environment variable:
export THV_HOOK_DEBUG=trueLogs are written to ~/temp_logs/toolhive-hook-bash.log.
- Verify the plugin is installed:
/plugin list - Check that the tool name matches the pattern
mcp__.* - Restart Claude Code after installation
Install jq:
brew install jq # macOS
apt install jq # Ubuntu/DebianInstall ToolHive from: https://github.com/stacklok/toolhive
Make sure the script is executable:
chmod +x ~/.claude/plugins/stacklok-hook/scripts/stacklok-hook.shApache 2.0