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 type { Settings } from 'claude-code' |
| 2 | |
| 3 | import { isServerFileUnreadable } from './managed-tools-restored/is-org-tool/is-server-file-unreadable' |
| 4 | import { orgNames } from './managed-tools-restored/is-org-tool/org-names' |
| 5 | import { toolPrefixOf } from './managed-tools-restored/is-org-tool/tool-prefix-of' |
| 6 | import { foldedName } from './managed-tools-restored/is-org-tool/tool-prefix-of/folded-name' |
| 7 | |
| 8 | /** |
| 9 | * Whether the tool a plugin registers would read as the organization's: it |
| 10 | * is called `mcp__<plugin>__<tool>`, compared fold to fold with the prefix |
| 11 | * of each server the policy names, each plugin it seats, and each seated |
| 12 | * plugin's scope, which holds the servers its own manifest declares. |
| 13 | * |
| 14 | * So a plugin named as one of them in any case or with other separators, one |
| 15 | * whose name and tool together spell a prefix, and one whose tool's own name |
| 16 | * folds to nothing all count. A name of the organization's that folds to |
| 17 | * nothing cannot be told from any name, and a server file that cannot be |
| 18 | * read names nobody: every registration then reads as the organization's. |
| 19 | * The plugin whose engine-recorded id managed enabledPlugins turn on keeps |
| 20 | * its own name; an unreadable server file holds it all the same. |
| 21 | * |
| 22 | * @param policy the managed settings, as `$.settings.read` answers them |
| 23 | * @param plugin the registering plugin's name |
| 24 | * @param tool the tool's own name, as the plugin registers it |
| 25 | * @param id the id the engine recorded for the registering plugin |
| 26 | * (`<name>@<source>`), where the mod heard its admission |
| 27 | * @returns true when the tool would read as the organization's |
| 28 | */ |
| 29 | export function namesOrgTool( |
| 30 | policy: Settings, |
| 31 | plugin: string, |
| 32 | tool: string, |
| 33 | id?: string, |
| 34 | ): boolean { |
| 35 | const registered = `${foldedName(`mcp__${plugin}__${tool}`)}_` |
| 36 | |
| 37 | return ( |
| 38 | isServerFileUnreadable(policy) || |
| 39 | orgNames(policy, id).some( |
| 40 | owner => |
| 41 | foldedName(owner) === '' || registered.startsWith(toolPrefixOf(owner)), |
| 42 | ) |
| 43 | ) |
| 44 | } |