Clients and transports
One typed client. A transport decides who answers each call.
createClient(contract, transport) gives you a client typed from the contract. The
transport decides who actually answers the call:
| transport | from | answers with | use it in |
|---|---|---|---|
rpc({ url }) | @onedef/orpc/client | your deployed backend, over HTTP | web apps, SDKs, the CLI |
local(backend) | onedef | the handlers, in process | server components, jobs, tests |
mcpApp() | @onedef/mcp/app | MCP tool calls through the host | a UI running inside Claude or ChatGPT |
http({ baseUrl }) | onedef | an existing REST API, through http descriptors | APIs onedef didn't build |
import { createClient } from 'onedef'
import { rpc } from '@onedef/orpc/client'
import { contract } from './contract'
export const api = createClient(contract, rpc({ url: '/api' }))
const song = await api.songs.get({ slug: 'la-vie-en-rose' }) // typed from `fields`
await api.songs.rename({ slug: song.slug, title: 'La Vie en rose' })One UI, two places
mcpApp() returns a transport when the page runs inside an MCP App, and undefined
otherwise. So one expression picks the right transport, and the same components work on
your website and inside Claude:
import { mcpApp } from '@onedef/mcp/app'
export const api = createClient(contract, mcpApp() ?? rpc({ url: '/api' }))See MCP Apps.
Credentials
Every transport accepts the caller's credentials and sends them the way the contract's
auth config says:
rpc({ url: '/api', auth: () => ({ bearer: session.token }) })See Auth.
A published SDK
An SDK is the contract plus rpc(), bundled. There is no handler code in it to leak:
export const createAcme = (options: { apiKey: string }) =>
createClient(contract, rpc({ url: 'https://api.acme.dev', auth: () => ({ apiKey: options.apiKey }) }))