Skip to main content
Glama

add_rule

Create and install a new Karabiner-Elements keyboard remapping rule with immediate effect, supporting simple key remaps, modifiers, tap/hold actions, and app-specific conditions.

Instructions

Create and install a new Karabiner-Elements rule.

Writes the rule to an asset file AND installs it in karabiner.json for immediate effect. Karabiner-Elements auto-reloads on file change.

For simple remaps, use to_key_code. For tap-vs-hold, combine to_key_code (held behavior) with to_if_alone_key_code (tap behavior).

Examples:

  • Simple remap (caps->esc): from_key_code="caps_lock", to_key_code="escape"

  • With modifier (ctrl+h->backspace): from_key_code="h", from_mandatory_modifiers=["control"], to_key_code="delete_or_backspace"

  • Tap/hold (caps: tap=esc, hold=ctrl): from_key_code="caps_lock", to_key_code="left_control", to_if_alone_key_code="escape"

  • App-specific: add app_if=['^com.apple.Terminal$']

  • Shell command: from_key_code="f5", to_shell_command="open -a Safari"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
app_ifNoBundle ID regexes — rule only fires in these apps (e.g. ['^com\\.apple\\.Terminal$']). Use app_unless for the inverse.
to_keysNoFull output key list. Each entry: {key_code, modifiers[], pointing_button}. Use instead of to_key_code for multi-key or complex outputs.
device_ifNoDevice identifiers — rule only fires on these devices. Each dict may contain: vendor_id (int), product_id (int), location_id (int), is_keyboard (bool), is_pointing_device (bool).
app_unlessNoBundle ID regexes — rule fires everywhere EXCEPT these apps.
asset_titleNoAsset file group title. Rules with the same title go in the same file. Default: 'MCP Rules'.
descriptionYesHuman-readable rule description. Must be unique across all rules.
to_key_codeNoOutput key code (shorthand for a single to-key). For multiple outputs or modifiers on output, use to_keys instead.
to_modifiersNoModifiers to apply to the output key (used with to_key_code).
device_unlessNoDevice identifiers — rule fires on all devices EXCEPT these. Same fields as device_if.
from_key_codeNoTrigger key code (e.g. 'caps_lock', 'a', 'left_command'). Mutually exclusive with from_pointing_button.
profile_indexNoProfile to install the rule in. Omit for the selected profile.
to_shell_commandNoShell command to execute when the rule fires (e.g. 'open -a Terminal').
from_pointing_buttonNoTrigger mouse button (e.g. 'button1'). Mutually exclusive with from_key_code.
to_if_alone_key_codeNoKey to send if the trigger is tapped briefly (not held). Common for dual-purpose keys like 'caps_lock as escape when tapped, control when held'.
from_optional_modifiersNoModifiers allowed but not required. Use ['any'] to ignore all extra modifiers (recommended for most remaps).
from_mandatory_modifiersNoModifiers that must be held for the rule to fire (e.g. ['command', 'shift']). Use search_key_codes to find valid names.
to_if_held_down_key_codeNoKey to send if the trigger is held down past the threshold.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses side effects: writes to an asset file and installs in karabiner.json, and notes auto-reload behavior. This goes beyond the schema. However, it doesn't mention potential pitfalls like rule conflicts or whether the operation is reversible, but the core behavioral traits are sufficiently transparent for a creation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core action, followed by behavioral notes and then examples. It is somewhat long, but every sentence earns its place—the examples specifically illustrate parameter combinations that would otherwise be unclear. No fluff or repetition.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's high complexity (17 parameters) and no annotations, the description covers the essential mechanics (file writes, installation, auto-reload), provides usage guidance, and gives practical examples. An output schema exists, so return values are handled elsewhere. The only minor gap is not discussing how this interacts with existing rules on the same keys, but overall it is sufficiently complete for a creation tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema already provides descriptions for all 17 parameters (100% coverage), so the baseline is 3. The description adds value by giving real usage examples that tie parameters together, such as from_key_code='caps_lock', to_key_code='escape', and combining to_key_code with to_if_alone_key_code for tap-vs-hold behavior. This contextualizes parameters beyond their individual schema definitions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: 'Create and install a new Karabiner-Elements rule.' It clearly differentiates from sibling tools by stating it writes to an asset file AND installs in karabiner.json for immediate effect, which is distinct from listing, toggling, removing, or editing rules.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives explicit usage guidance for parameter selection: 'For simple remaps, use to_key_code. For tap-vs-hold, combine to_key_code (held behavior) with to_if_alone_key_code (tap behavior).' It also provides concrete examples for various scenarios, which helps the agent choose appropriate parameters. It doesn't explicitly contrast with sibling tools like edit_rule, but the intent to create is clear from the first sentence.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jason-weddington/karabiner-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server