Skip to main content
You don’t need this page to use MCP: every editor links through ours, at 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.
The relay is a small server between the editor’s tab and the user’s AI agent. The editor connects to it, the agent calls it over MCP, and it passes each call to the editor and the answer back. It keeps no photo and no call. It’s a public package on npm, @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 at https://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

The relay listens on port 8788. Put it at a public HTTPS address of its own, 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

  1. 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).
  2. Tap Agent in the editor, copy the link, and paste it into your agent with a request.
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:
  1. Make a secret, and keep it in your backend’s secret store:
  2. Give it to the relay, as agentSessionSecret, read from the same store:
    relay.js
    With allowedOrigins empty, no page makes a link on its own: only your backend does.
  3. Add a route to your backend that checks the user’s sign-in and asks the relay for a link. In Hono:
    Your route
  4. Give the editor onAgentLink, which calls your route when the user taps Agent:
The secret never reaches a page. Call the relay on its public address from your route, since the link names the address it was asked on. Make the link when the user taps, never ahead of time: a link whose editor doesn’t connect within 2 minutes ends.

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:
The relay answers at the root of its address, so give it a host of its own. Every link lives in the process’s memory: run one process per relay.

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 EDITOR_SESSION:
wrangler.jsonc
Keep the class name and the migration once deployed: the Worker’s Durable Objects are found by them.
4

Put It Online

Then give the Worker a Custom Domain of its own, 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: Deploy to Cloudflare Deploy to Render Cloudflare’s button provisions the Worker and its Durable Object from 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, after embed-editor: the agent link wasn't made.
  • Without onAgentLink: your page’s origin isn’t in allowedOrigins, and the browser’s console shows a CORS error on /sessions. Add the origin as the address bar shows it, like https://shop.example.com or http://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’s agentSessionSecret, or the relay has none. Give both the same value, from the same store. The relay names the address it was asked on. Set publicOrigin 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.