https://agent.embededitor.com, with your license’s public key. Run your own relay when:
- the link and How to Connect must show your own address, not ours (a white-label Full);
- only your signed-in users may make a link;
- the agent’s calls must pass only through your own servers.
@embededitor/relay, under the MIT license, and it runs on Node or on Cloudflare Workers, with the same settings. Embed Editor’s own relay is this package on Cloudflare.
The steps below run it on Node. To start from a ready project instead, see Deploy a Template.
Set It Up
The examples use a shop, Acme, whose editor runs athttps://shop.example.com and whose relay will run at https://agent.shop.example.com.
1
Install
In the project of your server, on Node 20 or later:
2
Create the Relay
Create the relay with its three settings, and start it. They’re plain values: write them in the code, or read them from wherever you keep your configuration.
relay.js
With no page in
allowedOrigins and no agentSessionSecret, the relay makes no link.To serve it from a server of your own instead, see In Your Own Server.3
Put It Online
https://agent.shop.example.com, the way you serve your other apps: a reverse proxy, a load balancer or your hosting platform. It needs WebSockets, which most do.Claude, ChatGPT, Grok and Perplexity reach the relay from their own servers, so it must be public, at an https:// address. Keep it on the standard port, 443: Claude can’t reach an address with another port. A relay on localhost works only for agents on the same computer, like Claude Code, Codex and Cursor.4
Point the Editor at It
Give the editor your relay’s address in
agentRelay, with enableAgent. Your own relay needs no public key:5
Try It
-
Connect your agent to your relay’s MCP address,
https://agent.shop.example.com/mcp. In Claude Code:How to Connect, in the editor’s card, shows your users this address and the steps for each agent (Connecting Their Agent). - Tap Agent in the editor, copy the link, and paste it into your agent with a request.
Which Pages Make a Link
allowedOrigins lists the pages whose editor makes its own link, straight from the browser. Each entry is one of:
An origin is the scheme, the host and the port, as the address bar shows them, with no path:
https://shop.example.com, http://localhost:5173.
This stops other sites’ pages, since the browser says which page is asking. A script outside a browser can claim any page, so where only your own users may make links, use your backend.
For a check of your own in front of POST /sessions, @embededitor/relay exports relay.access(request) (whether the relay makes a link for it, with the CORS headers its answer carries), originAllowed({ entries, origin }) (whether one of entries, read as allowedOrigins reads its own, names origin) and readJson({ max, req }): a request’s body as JSON, read up to max bytes, null past them, for no body, for a body whose stream fails midway (an upload cut), and for one that isn’t JSON. Read the body from request.clone(), so the relay gets the request whole.
Only Signed-In Users
To let only signed-in users make a link, your backend makes it, with a secret only it and the relay know:-
Make a secret, and keep it in your backend’s secret store:
-
Give it to the relay, as
agentSessionSecret, read from the same store:Withrelay.jsallowedOriginsempty, no page makes a link on its own: only your backend does. -
Add a route to your backend that checks the user’s sign-in and asks the relay for a link. In Hono:
Your route
-
Give the editor
onAgentLink, which calls your route when the user taps Agent:
In Your Own Server
createRelay also gives the relay’s Hono app and the editor’s socket server, to serve them from a Node server of yours:
On Cloudflare Workers
The same relay runs as a Cloudflare Worker, from@embededitor/relay/cloudflare. Each link is a Durable Object, so the relay runs on any number of Cloudflare’s machines, with nothing else to set up.
1
Install
In your Worker’s project:
2
Create the Relay
The Worker is the relay’s
fetch and the Durable Object class it exports, EditorSession. Its settings are the same three as on Node:src/index.ts
3
Bind Its Durable Object
The relay reads its Durable Object under the binding Keep the class name and the migration once deployed: the Worker’s Durable Objects are found by them.
EDITOR_SESSION:wrangler.jsonc
4
Put It Online
agent.shop.example.com, in its settings. The links name the address each request came in on, so publicOrigin stays null.Point the editor at it and try it as on Node: Point the Editor at It.Deploy a Template
Two ready projects come in the package, each a folder to copy whole, set and deploy (node_modules/@embededitor/relay/templates/ once it’s installed):
In each, set
allowedOrigins to your editor’s pages before you deploy. Its README says the rest.
To deploy without copying the folder, the buttons below start from the templates in the public repository, embededitor/relay, a copy of the package’s source:
wrangler.jsonc, then asks for the settings in src/index.ts. Render’s button reads render.yaml at the repository’s root, which points at templates/node. On Railway, make a new project from the GitHub repository embededitor/relay and set its root directory to templates/node: Railway has no button for it, since that needs a template published on Railway’s dashboard.
Troubleshooting
The card says “Couldn’t Create the Link”
The relay made no link. The browser’s console says why, afterembed-editor: the agent link wasn't made.
- Without
onAgentLink: your page’s origin isn’t inallowedOrigins, and the browser’s console shows a CORS error on/sessions. Add the origin as the address bar shows it, likehttps://shop.example.comorhttp://localhost:5173, and restart the relay. - With
onAgentLink: your route didn’t answer with a link. See the next one.
Your route gets 403 from the relay
The secret your route sends isn’t the relay’sagentSessionSecret, or the relay has none. Give both the same value, from the same store.
The link shows the wrong address
The relay names the address it was asked on. SetpublicOrigin to its public address, or call it there.
Claude or ChatGPT can’t reach the relay
They call it from their own servers, so it needs a public HTTPS address.localhost works only for agents on the same computer.
Limits
To build a relay in another language or stack, see Protocol.
MCP
Add MCP to your editor, and what your users see.
Protocol
Every route, message and timing, to build a relay in any stack.