Logo di Mercure

Mercure

Organizzazione
api-platform
mercure

Pushes real-time resource updates from API Platform to clients over the Mercure protocol (Server-Sent Events). Use whenever the user mentions real-time updates, live data, push notifications, websockets-vs-SSE, Mercure, subscribing to changes, "update the UI when data changes", broadcasting create/update/delete, private/authorized updates, or custom Mercure topics.

Panoramica

Autoreapi-platform
Repositoryskillset
Nome della skillmercure
Stelle
29
Fork
1
File inclusi
Solo istruzioni
Link
  • Istruzioni in Markdown

    Un file SKILL.md che il modello carica quando serve, consumando token solo quando una richiesta è effettivamente pertinente.

  • Funziona con qualsiasi LLM

    Le skill IA sono in semplice Markdown, non in codice specifico di un fornitore, quindi funzionano con GPT, Claude, Gemini, Grok o un modello locale.

  • Tutto nelle istruzioni

    Tutto ciò che serve al modello è nelle istruzioni: nessun file aggiuntivo da sincronizzare.

  • Open source

    Pubblicata da api-platform su GitHub. Leggi i sorgenti prima di installarla.

Installazione

Installa la skill IA Mercure in TypingMind per usarla con qualsiasi LLM, oppure copiala in un altro agente in grado di leggere SKILL.md.

1

Installa in TypingMind

TypingMind installa una skill direttamente dalla sua cartella GitHub: legge SKILL.md, raccoglie i file delle risorse e salva il risultato in locale.

  1. Apri l'app e vai su Plugin → Skill.
  2. Scegli "Installa da GitHub".
  3. Incolla l'URL della cartella della skill riportato qui sotto e conferma.
    https://github.com/api-platform/skillset/tree/main/skills/mercure
  4. Attiva la skill in ogni chat in cui vuoi averla a disposizione.
Plugin → Skill → Nuova skill → Da URL GitHub, poi incolla l'URL della cartella e premi Continua.
2

Installa in un altro agente

Qualsiasi agente che legge il formato Agent Skills può usare questa skill: copia la cartella nella cartella delle skill di quell'agente.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/api-platform/skillset.git /tmp/skillset
mkdir -p .claude/skills
cp -r /tmp/skillset/skills/mercure .claude/skills/mercure
Dopo la copia, riavvia Claude Code per caricare la nuova skill.

Usala in TypingMind

Attiva Mercure in qualsiasi chat di TypingMind e al resto pensa il modello. Il nome e la descrizione della skill sono nel prompt di sistema e, non appena arriva una richiesta pertinente, il modello carica da solo le istruzioni complete: non devi mai richiamarla manualmente e non consuma token finché non viene effettivamente usata.

Il modello carica automaticamente Mercure non appena riceve una richiesta pertinente.

Funziona con qualsiasi modello IA

Le skill IA sono semplici istruzioni in Markdown, non codice specifico di un fornitore, quindi Mercure non è vincolata al modello per cui è stata scritta. Installala una sola volta in TypingMind e usala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modello locale che esegui tu, sempre con le tue chiavi API.

  • Caricata solo quando serve

    Il prompt di sistema contiene solo il nome e la descrizione. Le istruzioni vengono recuperate alla prima richiesta pertinente, quindi una skill inutilizzata non costa nulla.

  • Cambia modello durante la chat

    Poiché la skill è composta da istruzioni e non da codice, continua a funzionare anche se cambi modello: il nuovo modello legge lo stesso file SKILL.md.

Istruzioni della skill

Questo è il contenuto di SKILL.md che il modello carica. Leggilo prima dell'installazione: una skill è un insieme di istruzioni che il tuo modello seguirà.

Mercure: Real-Time Updates

Symfony-only. The Mercure integration is built on Doctrine's lifecycle events and symfony/mercure-bundle; the API Platform Laravel package ships no Mercure support. On Laravel use Laravel's own broadcasting (Reverb/Echo/Pusher).

Mercure pushes the new version of a resource to all subscribed clients whenever it is created, updated or deleted. API Platform hooks Doctrine's lifecycle: after a write it serializes the resource and publishes it to the Mercure hub, which fans it out to connected clients over Server-Sent Events. Clients subscribe with the native EventSource API — no extra client library required.

Use this for dashboards, collaborative editing, notifications. It is push-only and one-directional (server → client); for bidirectional messaging you still need something else.

Enabling on a resource

php
use ApiPlatform\Metadata\ApiResource;

#[ApiResource(mercure: true)]
class Book {}

Now every create/update/delete on a Book publishes to the hub. On delete, only the (now-gone) IRI is sent so clients can drop it. API Platform also adds a Link header advertising the hub URL on every response for this resource, so smart clients auto-discover where to subscribe.

mercure is intentionally untyped — it accepts true, an options array, or an ExpressionLanguage string. There is no MercureOptions attribute class in core; pass a plain array. (Verified against ApiResource::$mercure, declared mixed.)

Symfony hub configuration

Mercure is preconfigured in the API Platform distribution. With a manual install, add the MercureBundle and point it at a hub:

yaml
# config/packages/mercure.yaml
mercure:
    hubs:
        default:
            url: '%env(MERCURE_URL)%'          # internal URL API Platform publishes to
            public_url: '%env(MERCURE_PUBLIC_URL)%'  # URL the browser subscribes to
            jwt:
                secret: '%env(MERCURE_JWT_SECRET)%'
                publish: ['*']                 # API Platform must be allowed to publish

The hub itself runs as a separate process/container (the mercure.rocks binary or the Caddy Mercure module).

Subscribing from a browser

Read the hub URL from the Link header, then open an EventSource on the topic (the resource IRI):

js
const url = new URL('https://example.com/.well-known/mercure');
url.searchParams.append('topic', 'https://example.com/books/1');

const es = new EventSource(url);
es.onmessage = ({ data }) => {
    const book = JSON.parse(data);   // the serialized resource, or {"@id": "..."} on delete
};

Use a topic template like https://example.com/books/{id} to receive updates for every book in one subscription.

Available options

Pass an array instead of true:

php
#[ApiResource(mercure: [
    'private' => true,                          // authorized subscribers only (see below)
    'topics' => ['https://example.com/books'],  // override the default (resource IRI)
    'normalization_context' => ['groups' => ['book:push']], // serialize differently for the push
    'type' => 'book-updated',                   // SSE event type
    'retry' => 3000,                            // SSE retry hint (ms)
])]
class Book {}

data (override the published payload) and id (SSE event id) are also accepted. A common reason to set normalization_context is to push a leaner shape than the HTTP response, or to avoid pushing fields a subscriber shouldn't compute on.

Private (authorized) updates

A public update reaches anyone subscribed to the topic. For per-user data, mark the update private so only clients whose JWT carries a matching subscribe target selector receive it:

php
#[ApiResource(mercure: ['private' => true])]
class Notification {}

The subscriber's Mercure JWT must include a mercure.subscribe claim matching the topic. This is the mechanism that prevents one user's real-time updates leaking to another — pair it with HTTP-level security (see operations) so the resource is both fetch-protected and push-protected.

Dynamic options via expression

When the options depend on the resource instance (e.g. the topic must include the owner), use an ExpressionLanguage string resolved per object. iri() builds an IRI, escape() is rawurlencode:

php
use ApiPlatform\Metadata\ApiResource;

#[ApiResource(mercure: 'object.getMercureOptions()')]
class Book
{
    public function getMercureOptions(): array
    {
        return [
            'private' => true,
            // '@=' marks each topic value as an expression
            'topics' => [
                '@=iri(object)',
                '@=iri(object.getOwner()) ~ "/?topic=" ~ escape(iri(object))',
            ],
        ];
    }
}

The alternate owner/?topic=... form is the "restrictive update" pattern: a subscriber authorized only for https://example.com/users/foo/{?topic} receives the update via the alternate topic without being able to subscribe to all books. This is how you scope a shared resource type to per-owner visibility.

GraphQL subscriptions

When GraphQL is enabled (see graphql), mercure: true also powers GraphQL subscription operations — clients subscribe to a query and receive pushes through the same hub via a generated subscription IRI.

Checklist

  • Hub configured with separate internal url and public public_url
  • API Platform's publisher JWT allows publish
  • Per-user resources use 'private' => true, not public topics
  • Private pushes paired with HTTP security on the same resource
  • normalization_context set when the push shape differs from the HTTP response
  • Clients discover the hub from the Link header, not a hardcoded URL

Domande frequenti

Cosa fa la skill IA Mercure?

Pushes real-time resource updates from API Platform to clients over the Mercure protocol (Server-Sent Events). Use whenever the user mentions real-time updates, live data, push notifications, websockets-vs-SSE, Mercure, subscribing to changes, "update the UI when data changes", broadcasting create/update/delete, private/authorized updates, or custom Mercure topics.

Perché usare Mercure su TypingMind?

Perché la installi una volta e la usi con qualsiasi modello. Mercure è scritta in semplice Markdown anziché in codice specifico di un fornitore, quindi la stessa skill funziona con GPT-5, Claude, Gemini, Grok o un modello locale, e puoi cambiare modello durante la chat senza che smetta di funzionare. TypingMind usa le tue chiavi API, quindi paghi direttamente i fornitori anziché un abbonamento per posto utente, e le tue skill e chat restano nel tuo spazio di archiviazione.

Come installo Mercure in TypingMind?

Apri Plugin → Skill → Installa da GitHub in TypingMind e incolla https://github.com/api-platform/skillset/tree/main/skills/mercure. TypingMind legge il file SKILL.md e installa la skill, che puoi abilitare per ogni singola chat.

Quali modelli IA possono usare Mercure?

Qualsiasi modello che colleghi in TypingMind. Le skill IA sono semplici istruzioni in Markdown anziché codice specifico di un fornitore, quindi GPT, Claude, Gemini, Grok e i modelli locali possono tutti caricare questa skill quando una richiesta corrisponde al suo scopo.

Quanti modelli IA posso usare con Mercure?

Quanti ne vuoi. Se un modello supporta le skill, puoi usarlo con Mercure: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e molti altri, tutti su TypingMind con le tue chiavi API.

La skill IA Mercure è gratuita?

È pubblicata su GitHub da api-platform. Consulta il repository per i termini di licenza. Paghi solo il tuo fornitore IA per i token che usi.

Cosa sono le skill IA?

Una skill IA è un pacchetto di istruzioni riutilizzabili che insegna a un modello IA come svolgere un'attività specifica. Segue il formato aperto Agent Skills: un file SKILL.md con un nome e una descrizione, più eventuali script, modelli o file di riferimento di cui il modello potrebbe aver bisogno. Il modello legge le istruzioni solo quando la tua richiesta corrisponde alla skill, quindi una skill installata non comporta costi finché non viene usata.

In cosa si differenziano le skill IA dai plugin o dai server MCP?

Un plugin o un server MCP fornisce a un modello nuovi strumenti da richiamare: codice che viene eseguito da qualche parte e restituisce un risultato. Una skill IA, invece, fornisce al modello conoscenze e procedure: come affrontare un'attività, quali passaggi seguire e quali caratteristiche deve avere un buon output. Le skill sono semplici istruzioni in Markdown, quindi non richiedono server, chiavi API né ambienti di esecuzione e funzionano con qualsiasi modello.

Vedi tutti

Crea subito la tua area di lavoro IA

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇