Skip to Content
onedef

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:

transportfromanswers withuse it in
rpc({ url })@onedef/orpc/clientyour deployed backend, over HTTPweb apps, SDKs, the CLI
local(backend)onedefthe handlers, in processserver components, jobs, tests
mcpApp()@onedef/mcp/appMCP tool calls through the hosta UI running inside Claude or ChatGPT
http({ baseUrl })onedefan existing REST API, through http descriptorsAPIs 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 }) }))

On this page