add_key
Add a new key-value pair to dictionary-like structures in JSON, YAML, TOML, or Python files using AST-based editing.
Instructions
Add a new key-value pair inside a dict-like container. Works for JSON objects, YAML mappings, TOML tables, AND Python module-level dict literals.
For JSON/YAML/TOML: parent_target is the dotted path to the parent (use "" for root). For Python (.py): parent_target is the module-level variable name (e.g. 'CONFIG'). value should be a literal source expression in the target file's syntax (e.g. JSON '"foo"' or '42'; Python '"foo"' or '42').
Use this when: The key does not exist yet and you want to add it.
Don't use this when: The key already exists -> use replace_value. You're
adding an item to a list/array -> use append_to_array.
Example (JSON): parent_target="dependencies" key="mcp" value='"^1.2.0"' Example (Python): parent_target="CONFIG" # module-level CONFIG = {...} key='"timeout"' # include quotes if key is a string literal value="30"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| parent_target | Yes | ||
| key | Yes | ||
| value | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |