surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | import { TOOL_REGISTER_REFUSAL } from '../tool-register-refusal' |
| 2 | import type Types from './types' |
| 3 | |
| 4 | /** |
| 5 | * What the `tool.register` hook decides, by the caller's tier and the |
| 6 | * organization's MCP allowlist. |
| 7 | * |
| 8 | * An organization's registration continues past the user tier; a person's |
| 9 | * plugin is refused by name under an allowlist; every other passes. |
| 10 | * |
| 11 | * @param e the tool being added |
| 12 | * @param next the hook's own continuation, with the caller's origin |
| 13 | * @param isAllowlisted whether managed settings hold an MCP allowlist, |
| 14 | * asked only for a caller in the user tier; it fails closed |
| 15 | * @returns the registration's answer |
| 16 | */ |
| 17 | export async function toolRegistered<E, R>( |
| 18 | e: E, |
| 19 | next: Types.RegisterNext<E, R>, |
| 20 | isAllowlisted: () => Promise<boolean>, |
| 21 | ) { |
| 22 | const isOrgs = next.origin.tier === 'prepend' || next.origin.tier === 'append' |
| 23 | |
| 24 | if (isOrgs) { |
| 25 | return next.to(e, 'append') |
| 26 | } |
| 27 | |
| 28 | const isRefused = next.origin.tier === 'user' && (await isAllowlisted()) |
| 29 | |
| 30 | return isRefused ? { deny: TOOL_REGISTER_REFUSAL } : next(e) |
| 31 | } |