Integrations

MCP

Hyper integrates with Craft’s Model Context Protocol (MCP) server, so an AI client can read and edit the links in your Hyper fields. For example, you can ask a connected client to list the buttons on your Pricing page, change a button’s text, or add a link to your Contact page.

This integration requires Craft 5.12.1 or later. Hyper still works on earlier supported Craft versions, without this integration.

Connecting a Client

Follow Craft’s MCP setup instructions (opens new window) to connect a client through the authenticated HTTP server or the local mcp/serve command. Hyper fields work through Craft’s own element tools, such as elements_get and elements_update, so there’s nothing extra to install or enable.

The client acts as the signed-in user. It can read the Hyper fields on elements that user can view, and change them on elements the user can save. An HTTP connection authorised for read-only access can read links but can’t change them. Linked entries, assets and other elements keep their own permissions, so a link to an element the user can’t view is left out of what the client sees.

elements_get returns a Hyper field as a list of links, even when the field holds a single link. Suppose your Pricing entry has a ctaLinks field with a URL link and a link to your Contact entry. Asking for that field by handle returns something like this:

{
  "ctaLinks": [
    {
      "linkTypeHandle": "url",
      "uid": "6f1c2a8e-4b0d-4a5e-9d7b-2f6a1c3e8b90",
      "linkValue": "https://verbb.io/docs",
      "linkText": "Read the docs",
      "classes": "button",
      "url": "https://verbb.io/docs",
      "text": "Read the docs"
    },
    {
      "linkTypeHandle": "entry",
      "uid": "0b9e4d7c-1a2f-4c3b-8e5d-7f6a9b2c1d0e",
      "linkValue": 42,
      "linkText": "Talk to us",
      "url": "https://example.com/contact",
      "text": "Talk to us",
      "element": {
        "type": "craft\\elements\\Entry",
        "id": 42,
        "title": "Contact"
      }
    }
  ]
}

linkTypeHandle is the handle of the link’s type on this field, and linkValue is its destination. For an element link, that’s the linked element’s ID. The link’s text, title, classes, custom attributes and URL suffix appear when its type’s layout includes them, using the same names as the link’s properties. Values for any custom fields in the layout are under fields, keyed by field handle.

url, text and target show the link the way your templates would render it, and are read-only. A link to a disabled entry has no url, but the client still sees its linkValue and the entry’s status. When you name the field in fields, element links also include the linked element. Reading all fields leaves the element out, following Craft’s rules for related elements.

Before writing, call elements_field_schema for the element. The schema lists the link types this field accepts and what linkValue holds for each, along with any custom fields in their layouts. Then pass the field’s new value in the fields argument of elements_update or elements_create.

Writing replaces all of the field’s links, the same as saving the field in the control panel. Include the links you want to keep, with their uid, so Hyper treats them as the same links. The simplest approach is to read the field, change what you need, and write the whole list back. The read-only values can stay in place, as Hyper ignores them when saving.

For example, these arguments to elements_update keep the docs link and add a Contact button below it:

{
  "type": "entries",
  "id": 15,
  "fields": {
    "ctaLinks": [
      {
        "linkTypeHandle": "url",
        "uid": "6f1c2a8e-4b0d-4a5e-9d7b-2f6a1c3e8b90",
        "linkValue": "https://verbb.io/docs",
        "linkText": "Read the docs",
        "classes": "button"
      },
      {
        "linkTypeHandle": "entry",
        "linkValue": 42,
        "linkText": "Talk to us"
      }
    ]
  }
}

Each link type stores its destination differently:

Link TypelinkValue
Entry, Category, Asset, User and other element linksThe element’s ID, such as 42. Add linkSiteId to link to the element in a particular site.
URLA URL or relative address, such as https://verbb.io or /contact.
EmailAn email address. Hyper adds mailto: when rendering it.
PhoneA phone number. Hyper adds tel: when rendering it.
CustomA complete URI, such as mailto:[email protected]?subject=Hello.
SiteThe UID of the site. The schema lists the sites the link type allows.
EmbedThe URL to embed.
PassiveNone. A Passive link only has text.

An Embed link written with a URL renders as a plain link until Hyper fetches its embed code. That happens when an editor refreshes the link in the control panel, or when you run hyper/content/refresh-embeds. To keep an existing embed’s fetched data, write its linkValue back unchanged.

Craft checks a write against the schema before saving anything. A link of a type the field doesn’t allow, a linkValue in the wrong format, or an attribute that the link type’s layout doesn’t include is rejected with an explanation. The entry then saves as it would from the control panel, so the field’s other validation, such as minimum and maximum links or allowed URL schemes, still applies.

Only enabled link types can be written. Disabling a type on the field keeps its existing links working, but a client can’t write them back, so it can’t save the field until an editor changes those links in the control panel. The same applies to links whose type no longer exists.

When a link type’s layout includes custom fields, such as a Caption field on URL links, pass their values in the link’s fields object, keyed by field handle. The schema describes each one as Craft describes the same field on an entry.

Matrix and other fields holding nested entries can’t be written inside a link. When a link type’s layout includes one, the schema leaves that link type out and names it in the field’s description, so editors keep managing those links in the control panel. A client can still read them.