spacehub

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

claude-code / mods / sec-default / hooks / policy / managed-tools-restored / is-org-tool / is-org-tool.ts
GitHub Actions (publish-mods)chore: Update mods/ 3deb873 · 14 days ago History
33 lines · 1.5 KBRaw
1import type { Settings } from 'claude-code'
2
3import { isServerFileUnreadable } from './is-server-file-unreadable'
4import { orgPluginNames } from './org-plugin-names'
5import { orgServerNames } from './org-server-names'
6import { spellingsOf } from './spellings-of'
7import { toolPrefixOf } from './tool-prefix-of'
8import { foldedName } from './tool-prefix-of/folded-name'
9
10/**
11 * Whether a tool is the organization's: `mcp__<name>__...` for a server its
12 * policy names or delivers, and a tool under a seated plugin's name or
13 * scope (`plugin_<name>`, which holds its own manifest's servers).
14 *
15 * A server is told by its name whole, as the engine spells it (spellingsOf),
16 * never by a fold: another server whose name only begins like it is not it.
17 * A seated plugin is told fold to fold, as the registration check tells it
18 * (foldedName), since policy may list its id in another letter case. Where
19 * the server file cannot be read, every `mcp__` tool counts.
20 *
21 * @param policy the managed settings, as `$.settings.read` answers them
22 * @param tool the tool's name, as the model sees it
23 * @returns true when the tool is the organization's
24 */
25export const isOrgTool = (policy: Settings, tool: string): boolean =>
26 (isServerFileUnreadable(policy) && tool.startsWith('mcp__')) ||
27 orgServerNames(policy)
28 .flatMap(spellingsOf)
29 .some(spelt => tool.startsWith(`mcp__${spelt}__`)) ||
30 orgPluginNames(policy)
31 .filter(name => foldedName(name) !== '')
32 .flatMap(name => [name, `plugin_${name}`])
33 .some(owner => `${foldedName(tool)}_`.startsWith(toolPrefixOf(owner)))