Skip to main content
Glama

snippet_save

Destructive

Create or update PHP, CSS, JS, or HTML snippets on a WordPress site, control where they run and whether they are active, and record purpose and impact.

Instructions

Create or update a code snippet that runs on the site — like WPCode/Code Snippets. Types: php (runs in WordPress; NO <?php tags; use add_action/add_filter/functions), css, js, html. Location controls where it runs: everywhere, admin_only, frontend_only, header (wp_head), footer (wp_footer), before_content, after_content, shortcode (use [keelhob_snippet id=N]), or page_template (serve raw PHP/HTML as a whole page for target_id — the pixel-perfect custom-coded page mode). ALWAYS fill name, tags, purpose and impact: the site owner reads them on the Keelhob > Snippets admin page and that is their only way to judge what you installed. Updates MERGE — send only the fields you are changing and everything else, including code, is preserved. PHP is parse-checked first; code that does not parse is still saved but forced inactive with the error attached. A PHP snippet that fatals at runtime is auto-deactivated so the site stays up. Set active=true to turn it on. WARNING — the auto-deactivate guard only catches FATAL ERRORS. A snippet that runs perfectly can still take the site down, and the two ways that happens are: (1) sending a 4xx/5xx status from the front end — hosts poll the home page for liveness and read a 503 there as "server dead", then stop routing to the site entirely, including wp-admin and this MCP endpoint, so you lose the ability to undo it; serve coming-soon and maintenance pages with status 200 plus a noindex meta tag instead. (2) gating the front end without letting wp-login.php, /wp-admin, /wp-json, wp-cron.php and xmlrpc.php through, which locks the owner out of their own site. After activating anything that changes what a logged-out visitor sees, fetch the home page with no cookies and confirm it returns 200 before reporting done. If a snippet does break the site, the owner recovers by adding define('KEELHOB_SNIPPETS_OFF', true); to wp-config.php, which disables every snippet without needing a working site or a database client.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "code": "<code>"
    },
    "name": "snippet_save"
  }
}

Input Schema

NameRequiredDescriptionDefault
idNoOmit to create; include to update.
uidNoPortable identity. Omit on new snippets — one is generated.
codeYesThe snippet code. For php, do NOT include <?php tags (except page_template, where inline HTML with <?php islands is allowed).
nameNo
tagsNoShort lowercase labels the owner filters by, e.g. ["seo","header"]. Max 10.
activeNo
impactNoWhat it changes on the site, and what breaks if it is switched off.
purposeNoWhy this snippet exists, in plain English for the site owner.
locationNocss, js and html only run from header, footer, before_content, after_content or shortcode — everywhere/admin_only/frontend_only/page_template only execute php, so a css/js/html snippet saved there is refused.everywhere
priorityNo
target_idNoFor page_template: the page/post ID this template serves.
conditionsNoOptional load rules. {enabled:true, relation:"AND"|"OR", rules:[{type,operator,value}]}. type is one of user_status, user_role, page_type, post_type, post_id, url_path, device. operator is "is"/"is_not" (or "contains"/"equals"/"starts_with" for url_path). value may be an array, meaning "any of these". Example: {"enabled":true,"relation":"AND","rules":[{"type":"user_status","operator":"is","value":"logged_out"},{"type":"page_type","operator":"is","value":"front_page"}]}. The older flat shape {logged_in, front_page, post_types, post_ids} is still accepted and is converted on read, so existing snippets keep working.
origin_uidNoWhen copying from another site: the source snippet's uid. Re-copying with the same origin_uid UPDATES the existing copy instead of duplicating it — which also overwrites any edit the owner made here.
descriptionNo
origin_siteNoWhen copying from another site: that site's label.
snippet_typeNophp

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv2.1.2

TDQS

A4.5/5.0
Behavior5/5

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

Annotations supply only destructiveHint=true; the description carries the rest and then some — merge-on-update semantics, PHP parse-check behavior (saved but forced inactive with error), runtime fatal auto-deactivation, and the precise failure modes that the guard does not catch. The 4xx/5xx liveness-polling risk and the KEELHOB_SNIPPETS_OFF recovery constant are exactly the kind of non-obvious consequences an agent needs, and they are consistent with destructiveHint=true.

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?

Long, but front-loaded with purpose before the operational rules, and nearly every sentence carries decision-relevant information. The WARNING block runs long and mixes two distinct hazards plus recovery advice, which could be tighter, but nothing is purely redundant filler.

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?

For a 16-parameter, nested-object, destructive mutation with no output schema, the description covers prerequisites, side effects, failure modes and recovery. The main omission is what a successful save returns (the resulting id/uid or activation state), which the agent must infer since no output schema exists.

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?

Beyond the 69% schema coverage, the description explains what each snippet_type means behaviorally ('php runs in WordPress; NO <?php tags'), expands the location values with runtime meaning (wp_head, wp_footer, [keelhob_snippet id=N]), and clarifies that location restricts which types are accepted. uid, origin_uid, origin_site, priority, target_id (beyond page_template) and the conditions rule grammar are left to the schema.

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?

Opens with a specific verb+resource ('Create or update a code snippet that runs on the site') and anchors it with a familiar analogue (WPCode/Code Snippets). It then enumerates the snippet types and every location mode, including the distinctive page_template 'whole page' mode, so an agent can distinguish this from snippet_toggle/snippet_delete without opening a schema.

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?

Gives clear operational context: omit id to create, include it to update; 'Set active=true to turn it on'; ALWAYS supply name/tags/purpose/impact; and post-activation verification steps. It stops short of naming sibling alternatives explicitly (e.g., that turning a snippet on/off can also be done via snippet_toggle, or that deletions belong to snippet_delete), so routing guidance is implied rather than stated.

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