Connect your agent
Give your agent a world's MCP address and token, from Claude Code, Cursor, Codex, a stdio-only client, Scalekit or Python.
Give your agent a world's MCP address and token. Nothing in your agent needs to know it is a twin.
Twins
Google Calendar · Gmail
You need
a world, from twin start, twin world create or twin world run
Clients
Claude Code, Cursor, Codex, stdio-only agents such as goose, Scalekit, your own code or Python
Watch out
the token lets anyone act in the world. Keep it secret
Prerequisites
An agent that speaks MCP.
A sign-in, to make a world: run
twin login, or setTWINS_API_KEY. See Keys and limits.
Copy this
Make a world, then add it to Claude Code as an HTTP MCP server with the address and token twin start prints:
twin start calendar
claude mcp add --transport http calendar-twin <mcp address> --header "Authorization: Bearer <token>"Then ask Claude Code "what's on my calendar?" It is reading the twin.
How it works
A world is two things: an MCP address and a token. Your agent connects to that address and sends the token, exactly as it would connect to the real Google Calendar or Gmail MCP server.
Get the address and token
There are three ways, depending on how you made the world.
twin start makes a fresh world and prints everything you need to connect:
Use twin start gmail for a mailbox.
twin world create makes a world from your seed file. It prints the MCP address of each app, and keeps the tokens in the folder:
To see the tokens, print the world's handle. Its env holds TWIN_MCP, TWIN_TOKEN, and the Gmail pair when the world has a mailbox:
twin world run starts your agent with the address and token already in its environment. Nothing to copy:
See Run your agent.
What your agent gets in its environment
When you run your agent with twin world run, it gets these variables:
TWIN_MCP
the calendar's MCP address in this world
TWIN_TOKEN
the token to send it: Authorization: Bearer $TWIN_TOKEN
TWIN_GMAIL_MCP, TWIN_GMAIL_TOKEN
the mailbox's address and token, when the world has one
TWIN_NOW
the world's "now" (from now:), so your agent's "today" matches the world's
Your agent never gets your sign-in key. That stays with twin.
Connect a client
Add the world as an HTTP MCP server:
Then ask Claude Code "what's on my calendar?" It is reading the twin.
To hand Claude Code a world for one run only, without saving anything in your Claude settings, write a short script and start it with twin world run. It builds an MCP config from TWIN_MCP and TWIN_TOKEN and passes it with --mcp-config and --strict-mcp-config:
The token goes into a file only you can read, which is removed when the script ends. It never appears on a command line.
add-mcp detects the MCP clients on your machine (Claude Code, Cursor, Codex and others) and adds the world to them:
twin start prints this line for you, filled in.
Read the address and token from the environment instead of hard-coding them. Then the same code reaches the twin under twin world run, and the real service in production:
For a mailbox, connect a second MCP server with TWIN_GMAIL_MCP and TWIN_GMAIL_TOKEN.
Agents that need stdio
Some agents only start MCP servers as a command (goose, some desktop apps). Others take a URL but cannot add a header. For these, use the bridge that ships with twin-harness. It reads the world's address and token from the environment, relays each message to the twin with the token attached, and sends the answer back on stdout:
Run your agent under twin world run, so the bridge finds TWIN_MCP and TWIN_TOKEN. For example, goose:
--app gmailserves the mailbox instead of the calendar (TWIN_GMAIL_MCPandTWIN_GMAIL_TOKEN). Add one bridge per app.The bridge never takes the token on the command line, where other users of the machine could see it.
The bridge is a Python module in twin-harness. Run it with a Python that can import
twin_harness.
Scalekit agents
If your agent reaches Google Calendar through Scalekit, point it at a twin by adding the twin as a custom connector. The swap is configuration, not code.
The calendar twin answers on two MCP endpoints. Same calendar, same data, different tool names. Pick the one that matches the code you have:
Scalekit shape
<twin>/scalekit/mcp
googlecalendar_create_event, start_datetime, event_duration_hour
Google API shape
<twin>/mcp
events.create, start, end
If your agent calls Scalekit's built-in Google Calendar connector today, use the Scalekit shape. The argument shapes are the same, so the call your code already makes is the call the twin takes:
Map the tool names
Scalekit renames the tools it imports from a custom connector:
every name gains a
c-<connector>_prefix. A connector called "Calendar Twin Scalekit" servesc-calendartwinscalekit_googlecalendar_create_event;every name is lowercased (
events.quickAddarrives asevents.quickadd).
Ask Scalekit for the exact spellings rather than guessing:
Keep the mapping in one place, keyed by connection. Make a missing entry raise an error, never fall back to the production name.
Python
If you run your agent from your own Python code, use Twin from the twin-harness package. It makes the world, gives you its MCP servers, and deletes the world when the with block ends:
world.mcp
each app's MCP address and token
world.agent_env()
the TWIN_* variables twin world run gives an agent (for the stdio bridge). Never your sign-in key
world.calls()
the twin's record of every call made in the world
world.api("events.list", maxResults=5)
one tool call, as your agent would make it
Twin.from_test("seed.md", lease=7200, label="ci-1234")
a world that lives 2 hours if nobody deletes it, listed under a label
Twin.from_snapshot("snap.json")
a world made again from a snapshot
From asyncio, AsyncTwin is the same world with every call awaited:
A case that is cancelled (a timeout, Ctrl-C) still deletes its world on the way out. A twin that is busy (429 or 503) is asked again after its Retry-After.
Common mistakes
The twin's tool names (events.list) passed straight to an OpenAI or Anthropic model
The model refuses a tool name with a dot, and your agent fails on its first request. Use the stdio bridge
A new world or token, with the old Scalekit connector
Every call fails with 401, the credential presented is not one this twin issued. Update the connector and reconnect
A flag such as IS_TEST to switch between twin and production
A missing flag reaches production. Read a connection name with no default instead
An imported Scalekit schema with a dangling $ref, handed to OpenAI or Groq
The whole tool list is refused with "json-pointer not found". Replace the $ref with {}
Next
Run your agent in the world.
Troubleshooting, if a call fails.
Last updated: 27 October 2026
Was this helpful?