TypeScript · Next.js · MCP

Define your API once.
Serve people and agents.

Write one contract and its handlers. onedef gives you REST with OpenAPI, a typed client, an MCP server, an MCP App, a CLI with login and TanStack Query helpers, all from that one definition, and all kept in sync.

1 · Describe it

contract.ts
export const notes = collection(config, {
  name: 'notes',
  description: 'Your notes.',
  id: 'id',
  fields: Note,
  create: { input: z.object({ title: z.string() }) },
  actions: {
    complete: action({
      summary: 'Mark a note as done',
      output: Note,
      needs: 'object',
    }),
  },
})

2 · Implement it

backend.ts
export const backend = implement(contract, {
  notes: {
    list: () => db.notes.list(),
    get: ({ id }) => db.notes.get(id) ?? fail('NOT_FOUND'),
    create: ({ input }) => db.notes.create(input),
    complete: ({ object }) =>
      db.notes.save({ ...object, done: true }),
  },
})

3 · Get every surface

  • REST + OpenAPItoNextHandlers(backend)

    GET /api/notes, POST /api/notes/{id}/complete, /api/openapi.json

  • MCP servercreateMcpHandler(backend)

    notes_list, notes_create, notes_complete for Claude, ChatGPT, Cursor

  • Typed clientcreateClient(contract, rpc({ url: '/api' }))

    api.notes.complete({ id }) in your web app and SDK

  • MCP AppdefineMcpApp(contract, { routes })

    Your React screens, rendered inside Claude and ChatGPT

  • CLI with loginrunCli(contract, { transport })

    acme notes complete <id>, acme login with OAuth or an API key

  • TanStack QuerycreateQueryUtils(contract, client)

    Query keys and cache invalidation from the contract

Your API has more users than your web app

The same product needs a web app, an API, an SDK, a CLI and an MCP server. Written by hand, they drift apart. With onedef they are one thing.

One source of truth

Add a field or an endpoint once. The REST route, the MCP tool, the CLI command, the client type and the OpenAPI document all follow.

Type-safe end to end

A missing handler, a misspelled operation or a wrong return shape is a compile error, not a bug report.

Built for agents

MCP tools carry your descriptions. Your real UI renders inside Claude. Long tasks pause to ask the user or the agent, and continue.

Fits what you have

Plain fetch handlers for Next.js, Hono, Bun and workers. Your database stays yours. Already have an API? Describe it, and get an MCP server and a CLI.

Works without onedef

MCP tools that ask, then continue

With MCP elicitation, the client calls your tool again after the user answers, so everything before the question runs twice. @onedef/elicitation-workflow turns the tool into a durable workflow: it asks the user for approval or a form, or asks the agent to do a step, and continues exactly where it stopped. Add it to any MCP SDK server.

Plain MCP elicitation

BUILD ran (total 1)

user approves build-1

BUILD ran (total 2)

SHIPPED build-2 ✗

Elicitation workflow

BUILD ran (total 1)

user approves build-1

SHIPPED build-1 ✓

Read about elicitation workflows