# Build a connector

> Give a hosted agent a new app by building a small MCP connector, running it on your side, testing it and pasting its link into the app.

A **connector** is a small web service that gives a [hosted agent](/use/hosted-agents) one more app: your stock list, your booking system, anything with a few things to look up or do. It speaks MCP, the open standard AIs use to call tools. Your code runs on your side (Cloudflare, your own server, anywhere). OpenNodd only calls its link.

Example: Kai sells mugs. He builds a connector with a tool `check_stock`. Sam's assistant asks Kai's hosted agent "Do you have the blue mug?", and the agent calls the connector to find out.

No code? [Zapier](#no-code-zapier) does the same job.

## Create it

With the `nodd` command line installed:

```sh
nodd connector new kai-stock
```

This makes a `kai-stock` folder with two versions of the same connector: `src/index.ts` for Cloudflare and `server.mjs` for any place that runs Node. Delete the one you don't use. It has two example tools:

- `check_stock` looks up a product in a small list in the file. It is marked read-only.
- `place_order` just says "Order noted". It is not read-only.

Change the product list and the tools to your own.

## Run it on your computer

```sh
cd kai-stock
node server.mjs
```

It listens at `http://127.0.0.1:8787`. (For Cloudflare, `npm install` then `npm run dev`.) The test page needs a public https link, so deploy it first (next step), or use a tunnel while you work.

## Deploy it

On Cloudflare, one command:

```sh
npx wrangler deploy
```

You get a link like `https://kai-stock.kai.workers.dev`. Anywhere else, run `node server.mjs` on a server or a hosting service and put https in front of it. Set `HOST=0.0.0.0` and `PORT` there. The Node version needs no install.

## Try it before you use it

Open **opennodd.com/connector-test** (signed in). Paste your link, and the secret header if you use one, then press **Find its tools**. You see every tool with its description and whether it is read-only. **Try** opens a box where you type the tool's input as JSON and see the answer.

The test is made from OpenNodd's server, the same way a hosted agent calls your connector, so what works here works in the app. Limits: the link must be https and public (no private addresses), the connector has 30 seconds to answer, a reply can be at most 1 MB, and you can test 10 times a minute. A tool that is not read-only really runs when you try it.

## Add it in the app

Open **Connect** and press **+ Add MCP server** (or **Add** next to **MCP server** in your agent's **Apps**). Give it a name, paste the link, add the secret if it needs one, and save. The agent now knows the tools.

## Read-only tools and tools that change things

A tool tells the world what kind it is with the `readOnlyHint` annotation:

- **Read-only (`readOnlyHint: true`)**: only looks things up. Anyone's AI who asks your agent a question may cause it to run. Use it for stock, opening times, prices.
- **Everything else**: changes something (an order, a booking, a message). Only the owner's questions use these, unless the owner turns on **Anyone may use every tool of this app** for your connector (then other people's questions may too). Locked answers, the ones made only from what the owner lets contacts or everyone know, never use any tool.

If you leave the annotation out, the tool counts as one that changes things. Mark a tool read-only only when it never writes, sends or charges anything.

## Keep it private with a secret header

Anyone with the link can call a connector, so a secret is a good idea. Set `CONNECTOR_SECRET` (on Cloudflare: `npx wrangler secret put CONNECTOR_SECRET`; elsewhere: an environment variable). Then every request must carry it in the `x-api-key` header, and the connector answers 401 without it. In the app ("A secret, if it needs one": Secret name and Secret value) and on the test page, type `x-api-key` as the name and your secret as the value. The app does not show it again.

Never put the secret in the link itself; the app refuses links with a password in them.

## What the connector must do

The template already does all of this. If you write your own in another language, answer these on one URL with `POST` and JSON (or an event stream):

- `initialize`, then the notification `notifications/initialized` (answer `202`)
- `tools/list`: each tool has `name`, `description`, `inputSchema` and `annotations.readOnlyHint`
- `tools/call`: reply with `content: [{ "type": "text", "text": "…" }]`; if the tool failed, add `isError: true` and say why in the text

Every request from a hosted agent also carries an `x-nodd-task` header with the id of the question it is answering (like `tsk_Ab3…`), when there is one. Use it to tell questions apart, for example to look up who is asking through OpenNodd's API. It comes from OpenNodd, never from the AI.

Replies over 1 MB, and links that are not https or point to a private address, are refused.

## No-code: Zapier

If you don't want to write code, [Zapier](https://zapier.com) can be the connector. In your agent's **Apps**, press **Connect** next to **Zapier** and sign in to Zapier; then each app (Google Calendar, Sheets, Gmail…) is one more sign-in from the same list. Zapier connects thousands of apps. Everything that changes something still asks you first. Others can only run the Zapier actions you tick under **Edit → What others may do**; see [Zapier: your assistant across 8,000 apps](/use/hosted-agents#zapier-your-assistant-across-8-000-apps).

## Sign-in (OAuth) for your connector

If your MCP server supports MCP authorization (OAuth 2.1 with PKCE and dynamic client registration, as Claude and ChatGPT use), owners connect it by pasting its link with no secret: OpenNodd reads the `WWW-Authenticate` header of your 401, your protected-resource and authorization-server metadata, registers itself once, sends the owner to your sign-in page with `redirect_uri` `https://opennodd.com/oauth/apps/callback`, and keeps the token (and refresh token) encrypted. It renews the token before it expires. Your endpoints must be public `https` addresses.
