capable-kit 0.0.1-alpha.4 → 0.0.1-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/ai-sdk.d.mts +2 -2
  2. package/dist/ai-sdk.mjs +1 -1
  3. package/dist/app.d.mts +1 -1
  4. package/dist/app.mjs +1 -1
  5. package/dist/bin.mjs +4 -4
  6. package/dist/cli.d.mts +1 -1
  7. package/dist/cli.mjs +1 -1
  8. package/dist/core.d.mts +3 -3
  9. package/dist/core.mjs +2 -2
  10. package/dist/eve.d.mts +1 -1
  11. package/dist/eve.mjs +1 -1
  12. package/dist/http.d.mts +1 -1
  13. package/dist/http.mjs +1 -1
  14. package/dist/{index-BB5ogMv-.d.mts → index-Be8-UVBC.d.mts} +49 -8
  15. package/dist/{index-DJ--zcWG.d.mts → index-D2CRRUzH.d.mts} +4 -4
  16. package/dist/{index-B_I9n6gN.d.mts → index-Dbc4g9WM.d.mts} +4 -3
  17. package/dist/{index-DCrxWCTv.d.mts → index-DwXlaTXI.d.mts} +3 -3
  18. package/dist/index.d.mts +4 -4
  19. package/dist/index.mjs +3 -3
  20. package/dist/mcp.d.mts +2 -2
  21. package/dist/mcp.mjs +1 -1
  22. package/dist/{mount-BEBJ2Tss.mjs → mount-xvMsjz1B.mjs} +53 -9
  23. package/dist/mount-xvMsjz1B.mjs.map +1 -0
  24. package/dist/runtime-support.d.mts +1 -1
  25. package/dist/runtime-support.mjs +4 -4
  26. package/dist/runtime-support.mjs.map +1 -1
  27. package/dist/server.d.mts +1 -1
  28. package/dist/server.mjs +1 -1
  29. package/dist/{src-D9pLpfeO.mjs → src-BF70JLxI.mjs} +23 -12
  30. package/dist/src-BF70JLxI.mjs.map +1 -0
  31. package/dist/{src-3UaBqI8H.mjs → src-C2MGIlT0.mjs} +17 -18
  32. package/dist/src-C2MGIlT0.mjs.map +1 -0
  33. package/dist/{src-ChDFqZaE.mjs → src-CDxL6w3d.mjs} +3 -3
  34. package/dist/{src-ChDFqZaE.mjs.map → src-CDxL6w3d.mjs.map} +1 -1
  35. package/dist/{src-BjBxOv7x.mjs → src-Db6-XSnU.mjs} +20 -12
  36. package/dist/src-Db6-XSnU.mjs.map +1 -0
  37. package/dist/{src-B53ZbNtC.mjs → src-DdV82An-.mjs} +137 -3
  38. package/dist/src-DdV82An-.mjs.map +1 -0
  39. package/dist/{subscription-McaLyHM2.d.mts → subscription-Bq792Ad2.d.mts} +2 -2
  40. package/docs/CONTEXT.md +8 -3
  41. package/docs/internal/architecture.md +11 -3
  42. package/docs/internal/capability-first-model.md +7 -1
  43. package/docs/internal/implementation-friction.md +31 -0
  44. package/docs/site/concepts/architecture.mdx +10 -2
  45. package/docs/site/concepts/capabilities.mdx +6 -6
  46. package/docs/site/concepts/presentations.mdx +161 -0
  47. package/docs/site/introduction.mdx +166 -49
  48. package/docs/site/quickstart.mdx +103 -10
  49. package/docs/site/reference/packages-and-entry-points.mdx +2 -0
  50. package/docs/site/reference/the-cap-cli.mdx +1 -1
  51. package/docs/site/surfaces/cli.mdx +2 -2
  52. package/docs/site/surfaces/http-and-openapi.mdx +1 -1
  53. package/docs/site/surfaces/mcp.mdx +13 -0
  54. package/package.json +1 -1
  55. package/src/index.test.ts +1 -0
  56. package/src/index.ts +5 -1
  57. package/src/package.test.ts +2 -1
  58. package/dist/mount-BEBJ2Tss.mjs.map +0 -1
  59. package/dist/src-3UaBqI8H.mjs.map +0 -1
  60. package/dist/src-B53ZbNtC.mjs.map +0 -1
  61. package/dist/src-BjBxOv7x.mjs.map +0 -1
  62. package/dist/src-D9pLpfeO.mjs.map +0 -1
@@ -57,8 +57,14 @@ A transport may perform I/O to discover its manifest, but `createRemoteApp()` do
57
57
  ```ts title="transport-and-runtime.ts"
58
58
  interface ApplicationTransport {
59
59
  manifest(): Promise<ApplicationManifest>;
60
- call(args): Promise<{ output: unknown; markdown?: string }>;
61
- subscribe(args): AsyncIterableIterator<{ output: unknown }>;
60
+ call(args: {
61
+ id: string;
62
+ input: unknown;
63
+ presentation?: boolean;
64
+ }): Promise<{
65
+ output: unknown;
66
+ presentation?: readonly PresentationPart[];
67
+ }>;
62
68
  }
63
69
 
64
70
  const app = createRemoteApp(transport);
@@ -68,6 +74,8 @@ const tools = await createAiSdkTools(app);
68
74
 
69
75
  Its HTTP encoding lives in `@capable/fetch` as server plumbing, separate from the authored HTTP API. Apps keep this runtime behind an internal symbol so capability names can never collide with `manifest` or `call`.
70
76
 
77
+ Presentation is opt-in at this low-level boundary. A typed call does not compute or transport Markdown, images, or files; a surface requests those parts only when it can use them.
78
+
71
79
  ## Open metadata, closed core [#metadata]
72
80
 
73
81
  Surface metadata is declared by the surface package through module augmentation, which is how `meta.http`, `meta.cli`, `meta.mcp`, and `meta.aiSdk` become type-safe without the core knowing what HTTP, MCP, or the AI SDK is. The core preserves group ancestry and never merges metadata generically; each surface compiler decides what inheritance means for it.
@@ -163,9 +163,9 @@ export const getTodo = todoCapability({
163
163
 
164
164
  Here the HTTP metadata describes a resource-shaped route, while the CLI metadata says that `todoId` is positional. The handler does not see these presentation details, and other surfaces ignore keys they do not own. See [Surface metadata](/reference/metadata) for every supported key.
165
165
 
166
- ## Add a Markdown rendering [#markdown]
166
+ ## Add a presentation [#presentation]
167
167
 
168
- A capability always returns one canonical structured value. `toMarkdown` optionally turns that same value into an easy-to-read representation for both people and agents.
168
+ A capability always returns one canonical structured value. `toPresentation` can derive an optional human-readable view without changing that contract. Returning a string is the smallest form and is treated as Markdown.
169
169
 
170
170
  ```ts title="capabilities.ts" highlight="1,6-9"
171
171
  import { md } from "capable-kit";
@@ -173,14 +173,14 @@ import { md } from "capable-kit";
173
173
  export const listTodos = todoCapability({
174
174
  id: "todos.list",
175
175
  handler: ({ context }) => context.todos.list(context.userId),
176
- toMarkdown: (todos) =>
176
+ toPresentation: (todos) =>
177
177
  todos.length === 0
178
178
  ? "No todos."
179
179
  : todos.map((todo) => md`- **${todo.title}**`).join("\n"),
180
180
  });
181
181
  ```
182
182
 
183
- The CLI renders this Markdown in the terminal, MCP gives it to agents as tool text, and HTTP returns it when the caller accepts `text/markdown`. Typed calls still receive the original array.
183
+ Only surfaces that need a presentation ask the runtime to produce it. The CLI renders this Markdown in the terminal, MCP gives it to agents as tool text, and HTTP requests it when the caller accepts `text/markdown`. Typed calls and `--json` still receive only the original array. For tables, images, and downloadable files, see [Presentations](/concepts/presentations).
184
184
 
185
185
  ## How execution fits together [#lifecycle]
186
186
 
@@ -215,7 +215,7 @@ A capability can grow into the full declaration below, but only as each concern
215
215
  Subscriptions are the remaining optional execution mode. A read capability can add `subscribe` beside its handler when it needs to emit replacement snapshots; see [Subscriptions](/patterns/subscriptions).
216
216
 
217
217
  ```ts title="capabilities.ts"
218
- import { defineErrors, md, capability } from "capable-kit";
218
+ import { capability, defineErrors, md } from "capable-kit";
219
219
  import { z } from "zod";
220
220
 
221
221
  const TodoErrors = defineErrors({
@@ -242,7 +242,7 @@ export const getTodo = todoCapability({
242
242
  if (!found) throw TodoErrors.NOT_FOUND();
243
243
  return found;
244
244
  },
245
- toMarkdown: (todo) => md`- **${todo.title}**`,
245
+ toPresentation: (todo) => md`- **${todo.title}**`,
246
246
  });
247
247
  ```
248
248
 
@@ -0,0 +1,161 @@
1
+ ---
2
+ title: "Presentations"
3
+ description: "Derive portable Markdown, tables, images, and files from canonical output."
4
+ ---
5
+
6
+ import { DocsPage, docMetadata } from "../../_components/docs-page";
7
+
8
+ export const metadata = docMetadata("/concepts/presentations", frontmatter);
9
+
10
+ <DocsPage href="/concepts/presentations" frontmatter={frontmatter}>
11
+
12
+ A capability returns one canonical output. `toPresentation` derives a meaningful representation of that data without turning the representation into the API contract. The same Presentation helps a person understand a result in the CLI and gives an agent a focused, often more token-efficient account of what happened.
13
+
14
+ ## Why present canonical output? [#purpose]
15
+
16
+ Canonical output is designed for programs: it is complete, stable, and structured. That does not mean its raw JSON is the best explanation of a result. It may repeat field names hundreds of times, expose internal bookkeeping, or leave important values without useful labels.
17
+
18
+ A Presentation lets the capability author select what matters, name it clearly, and put it in a useful order. Humans get readable headings, tables, images, and file links. Agents get concise text and structured visual resources instead of having to infer the meaning of an entire JSON object. The canonical output remains available whenever exact machine-readable data is needed.
19
+
20
+ ## Start with Markdown [#markdown]
21
+
22
+ Return a string when Markdown is enough. Existing string renderers stay small and need no wrapper.
23
+
24
+ ```ts title="capabilities.ts"
25
+ import { capability, md } from "capable-kit";
26
+
27
+ export const getWeather = capability({
28
+ id: "weather.get",
29
+ handler: () => ({ city: "Vienna", temperature: 24 }),
30
+ toPresentation: (weather) =>
31
+ md`**${weather.city}:** ${weather.temperature}°C`,
32
+ });
33
+ ```
34
+
35
+ Typed calls still receive `{ city, temperature }`. The string is only produced when a presentation-aware surface asks for it.
36
+
37
+ ## Compose richer output [#parts]
38
+
39
+ `toPresentation` may also return one part or an ordered array of strings and parts. Import the builders from the same root entry point:
40
+
41
+ ```ts title="capabilities.ts"
42
+ import { capability, md, present } from "capable-kit";
43
+
44
+ export const createReport = capability({
45
+ id: "reports.create",
46
+ handler: () => buildReport(),
47
+ toPresentation: (report) => [
48
+ md`## ${report.title}`,
49
+ present.table({
50
+ caption: "Daily totals",
51
+ columns: ["Date", "Requests", "Errors"],
52
+ rows: report.days.map((day) => [
53
+ day.date,
54
+ day.requests,
55
+ day.errors,
56
+ ]),
57
+ }),
58
+ present.image({
59
+ base64: report.chartBase64,
60
+ mimeType: "image/png",
61
+ alt: "Requests and errors over time",
62
+ }),
63
+ present.file({
64
+ url: report.csvUrl,
65
+ name: "daily-totals.csv",
66
+ mimeType: "text/csv",
67
+ size: report.csvSize,
68
+ description: "The underlying report data",
69
+ }),
70
+ ],
71
+ });
72
+ ```
73
+
74
+ The array order is meaningful. A surface can render a heading, then a table, then an image and a file link in that sequence.
75
+
76
+ ## What the CLI shows [#cli]
77
+
78
+ The CLI uses the general Markdown representation and adds terminal styling. The report above reads approximately like this:
79
+
80
+ ```text title="terminal"
81
+ $ cap cli reports create
82
+
83
+ API traffic
84
+
85
+ Daily totals
86
+
87
+ Date Requests Errors
88
+ 2026-07-30 18,420 31
89
+ 2026-07-31 19,105 22
90
+
91
+ [Image: Requests and errors over time]
92
+
93
+ daily-totals.csv — The underlying report data — text/csv, 42.3 kB
94
+ ```
95
+
96
+ Running the same command with `--json` skips `toPresentation` entirely and prints the canonical report object. An MCP client can instead keep the heading and table as text while receiving the chart and file as native content blocks.
97
+
98
+ ## The complete presentation API [#api]
99
+
100
+ ```ts title="types.ts"
101
+ type PresentationValue =
102
+ | string
103
+ | PresentationPart
104
+ | readonly (string | PresentationPart)[];
105
+
106
+ type PresentationPart =
107
+ | {
108
+ type: "markdown";
109
+ markdown: string;
110
+ }
111
+ | {
112
+ type: "table";
113
+ caption?: string;
114
+ columns: readonly string[];
115
+ rows: readonly (readonly (string | number | boolean | null)[])[];
116
+ }
117
+ | {
118
+ type: "image";
119
+ base64: string;
120
+ mimeType: `image/${string}`;
121
+ alt: string;
122
+ }
123
+ | {
124
+ type: "file";
125
+ url: string;
126
+ name: string;
127
+ mimeType?: string;
128
+ size?: number;
129
+ description?: string;
130
+ };
131
+ ```
132
+
133
+ Strings are normalized to Markdown parts. The builders make each part explicit; validation and defensive copying happen only when a surface materializes the presentation:
134
+
135
+ | Builder | Required fields | Purpose |
136
+ | --- | --- | --- |
137
+ | `present.table()` | `columns`, `rows` | Structured scalar data that can become a terminal or Markdown table |
138
+ | `present.image()` | `base64`, `mimeType`, `alt` | An inline image for surfaces that support image content |
139
+ | `present.file()` | `url`, `name` | A reference to a downloadable or otherwise addressable resource |
140
+
141
+ An image is inline because image-capable protocols commonly need its bytes. A file is deliberately a reference: Capable transports its URL and metadata, not the file body. If an image should stay lazy, represent it as a file with an image MIME type instead. Fetching, authentication, expiry, and storage remain the application's responsibility.
142
+
143
+ ## Surface behavior [#surfaces]
144
+
145
+ Each surface chooses whether to request a presentation and how to lower its parts.
146
+
147
+ An empty array means that no presentation is available, so the surface falls back to canonical output. Return an explicit empty Markdown string only when blank presentation output is intentional.
148
+
149
+ | Surface | Behavior |
150
+ | --- | --- |
151
+ | Typed App call | Returns canonical output and does not run `toPresentation` |
152
+ | CLI | Renders the general Markdown representation with terminal styling |
153
+ | CLI `--json` | Prints canonical output and does not run `toPresentation` |
154
+ | HTTP JSON | Returns canonical output and does not run `toPresentation` |
155
+ | HTTP `Accept: text/markdown` | Returns the general Markdown representation |
156
+ | MCP | Sends text, images, and resource links using native MCP content blocks |
157
+ | Other surfaces | May support, partially lower, or ignore presentations |
158
+
159
+ This is a portable presentation model, not an MCP authoring API and not a UI component framework. It has no JSX, layout system, callbacks, or protocol-specific fields. New part types should be added only when several surfaces can give them a useful meaning.
160
+
161
+ </DocsPage>
@@ -1,30 +1,40 @@
1
1
  ---
2
2
  title: "Introduction"
3
- description: "Capable turns one typed capability into a typed client, an HTTP API, a CLI, and agent tools."
3
+ description: "Define typed application capabilities and use them across runtime surfaces."
4
4
  ---
5
5
 
6
6
  import { DocsPage, docMetadata } from "./_components/docs-page";
7
7
  import { Card, Cards } from "./_components/cards";
8
+ import { Tab, Tabs } from "./_components/tabs";
8
9
 
9
10
  export const metadata = docMetadata("/", frontmatter);
10
11
 
11
12
  <DocsPage href="/" frontmatter={frontmatter}>
12
13
 
13
- Most applications end up implementing the same capability several times: once for the product UI, once as a public HTTP route, once as a CLI command, and once as a tool for an agent. Capable gives that capability a single definition — a **capability** — and lets you use it across every surface.
14
+ Capable is a framework for defining the operations an application provides—its capabilities—using types and schemas. Add them to an app, then run or call that app in-process, over HTTP, through a CLI, or with AI tools.
14
15
 
15
- ## Define one capability [#capability]
16
+ ## 1. Define a capability [#capability]
16
17
 
17
- Start with an id, an optional input schema, and a handler. TypeScript infers the handler's output type. Schemas use the Standard Schema interface, so Capable is not tied to the Zod authoring API shown here. A capability has no HTTP method, no command name, and no framework attached.
18
+ Start with an id, input schema, and handler. A capability has no HTTP method, command name, or framework attached.
18
19
 
19
- ```ts title="capable.app.ts"
20
- import { defineApp, capability } from "capable-kit";
20
+ ```ts title="capabilities/create-todo.ts"
21
+ import { capability } from "capable-kit";
21
22
  import { z } from "zod";
22
23
 
23
- const createTodo = capability({
24
+ export const createTodo = capability({
24
25
  id: "todos.create",
25
26
  input: z.object({ title: z.string().min(1) }),
26
27
  handler: ({ input }) => ({ id: "1", title: input.title }),
27
28
  });
29
+ ```
30
+
31
+ ## 2. Put it in an app [#app]
32
+
33
+ An app gives capabilities a path: `todos.create`.
34
+
35
+ ```ts title="capable.app.ts"
36
+ import { defineApp } from "capable-kit";
37
+ import { createTodo } from "./capabilities/create-todo";
28
38
 
29
39
  export default defineApp({
30
40
  name: "Todos",
@@ -35,13 +45,28 @@ export default defineApp({
35
45
  });
36
46
  ```
37
47
 
38
- Add a portable `output` schema, effect metadata, declared errors, middleware, descriptions, or presentation metadata only when the capability needs the behavior they enable.
48
+ Add output schemas, errors, middleware, or surface metadata only when the app needs them.
49
+
50
+ ## 3. Initialize the app [#choose]
51
+
52
+ Choose where the app runs. The in-process option has no network boundary; the other options accept requests from outside the process.
39
53
 
40
- Capabilities are composed into an _app_: an ordinary named object tree. The path `todos.create` is how callers navigate to the capability. The id `todos.create` is its permanent execution identity, which is what remote calls and conflict detection use. Add context, errors, middleware, and `group()` only when a subtree needs them.
54
+ <Tabs id="introduction-hosting" label="Choose a host">
55
+ <Tab label="In-Process">
41
56
 
42
- ## Run it [#run]
57
+ Use the executable app directly in a script, test, server action, or agent. No HTTP server is started.
43
58
 
44
- `cap dev` discovers `capable.app.ts` and serves the derived surfaces.
59
+ ```ts title="app.ts"
60
+ import { createApp } from "capable-kit";
61
+ import definition from "./capable.app";
62
+
63
+ export const app = createApp(definition);
64
+ ```
65
+
66
+ </Tab>
67
+ <Tab label="Capable CLI">
68
+
69
+ The zero-config standalone option. With only `capable.app.ts`, the toolchain mounts Capable, HTTP/OpenAPI, and MCP for you.
45
70
 
46
71
  ```sh title="terminal"
47
72
  $ cap dev
@@ -57,70 +82,162 @@ MCP /mcp
57
82
  ✓ 1 capability ready, watching for changes
58
83
  ```
59
84
 
60
- The same `title` input reaches the capability through a flag or a JSON body — no extra code to write.
85
+ </Tab>
86
+ <Tab label="Next.js">
87
+
88
+ Keep your existing Next.js application, authentication, and deployment. Mount a Capable server in App Router handlers.
89
+
90
+ ```ts title="capable/server.ts"
91
+ import { createNextRouteHandlers } from "@capable/next";
92
+ import { mcp } from "capable-kit/mcp";
93
+ import { createServer, http, protocol } from "capable-kit/server";
94
+ import definition from "../capable.app";
95
+
96
+ const server = createServer(definition, {
97
+ mounts: [protocol(), http(), mcp()],
98
+ });
99
+
100
+ export const { DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT } =
101
+ createNextRouteHandlers(server.fetch);
102
+ ```
103
+
104
+ Re-export those handlers at the `/api`, `/_capable`, `/openapi.json`, and `/mcp` URLs. The [Next.js guide](/hosting/next) shows the complete route layout.
105
+
106
+ </Tab>
107
+ <Tab label="Any Fetch host">
108
+
109
+ Use the server directly in Bun, Hono, H3, or another Fetch-compatible runtime.
110
+
111
+ ```ts title="server.ts"
112
+ import { mcp } from "capable-kit/mcp";
113
+ import { createServer, http, protocol } from "capable-kit/server";
114
+ import definition from "./capable.app";
115
+
116
+ const server = createServer(definition, {
117
+ mounts: [protocol(), http(), mcp()],
118
+ });
119
+
120
+ Bun.serve({ port: 3000, fetch: server.fetch });
121
+ ```
122
+
123
+ </Tab>
124
+ </Tabs>
125
+
126
+ ## 4. Use the app [#consuming]
127
+
128
+ Call the same capability in-process or through an endpoint exposed by the app above.
129
+
130
+ <Tabs id="introduction-consuming" label="Choose a consumer">
131
+ <Tab label="TypeScript">
132
+
133
+ ```ts title="app.ts"
134
+ import { app } from "./app";
135
+
136
+ const todo = await app.todos.create({ title: "Read the docs" });
137
+ ```
138
+
139
+ </Tab>
140
+ <Tab label="Capable CLI">
141
+
142
+ Run the app in this directory. The CLI imports it and calls it in-process.
143
+
144
+ ```sh title="terminal"
145
+ $ cap cli todos create --title "Read the docs"
146
+
147
+ {
148
+ "id": "1",
149
+ "title": "Read the docs"
150
+ }
151
+ ```
152
+
153
+ Point the CLI at an app that is already running or deployed.
61
154
 
62
155
  ```sh title="terminal"
63
- # The capability as a command
64
- cap cli todos create --title "Read the docs"
156
+ $ cap cli --app http://localhost:3000 todos create --title "Read the docs"
157
+ ```
158
+
159
+ </Tab>
160
+ <Tab label="HTTP">
65
161
 
66
- # The same capability as a derived HTTP route
67
- curl -X POST localhost:3000/api/todos/create \
162
+ ```sh title="terminal"
163
+ # Against a host that mounts http():
164
+ $ curl -X POST http://localhost:3000/api/todos/create \
68
165
  -H 'content-type: application/json' \
69
166
  -d '{"title":"Read the docs"}'
70
167
  ```
71
168
 
72
- That one file is also an MCP endpoint at `/mcp`, so an agent can connect and call `todos__create` with the same input schema. Every surface reads the same tree and contracts, so one capability shows up consistently everywhere:
169
+ </Tab>
170
+ <Tab label="MCP">
73
171
 
74
- | Surface | What todos.create becomes |
75
- | --- | --- |
76
- | TypeScript | `await app.todos.create({ title })` |
77
- | HTTP | `POST /api/todos/create` |
78
- | OpenAPI | `/openapi.json` |
79
- | CLI | `todos create --title "..."` |
80
- | MCP | `todos__create` |
81
- | React Query | `query.todos.create.mutationOptions()` |
172
+ Connect any Streamable HTTP MCP client to `http://localhost:3000/mcp`. It discovers `todos__create` with the same input schema.
82
173
 
83
- Nothing is exposed implicitly. A surface exists because you mounted it, and you can narrow the tree per boundary with `selectApp()`.
174
+ ```json title="tools/call params"
175
+ {
176
+ "name": "todos__create",
177
+ "arguments": { "title": "Read the docs" }
178
+ }
179
+ ```
84
180
 
85
- ## Use it programmatically [#programmatic]
181
+ </Tab>
182
+ <Tab label="AI SDK">
86
183
 
87
- No toolchain required. The app is an ordinary typed object — call it from a script, a server action, or a test, and the same validation, middleware, and errors apply.
184
+ ```ts title="agent.ts"
185
+ import { generateText } from "ai";
186
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
187
+ import { app } from "./app";
88
188
 
89
- ```ts title="app.ts"
90
- import { createApp } from "capable-kit";
91
- import definition from "./capable.app";
189
+ await generateText({
190
+ model: "anthropic/claude-sonnet-4.5",
191
+ tools: await createAiSdkTools(app),
192
+ prompt: "Create a todo to read the docs.",
193
+ });
194
+ ```
92
195
 
93
- const app = createApp(definition);
196
+ </Tab>
197
+ <Tab label="Eve">
94
198
 
95
- const todo = await app.todos.create({ title: "Read the docs" });
199
+ ```ts title="agent/tools/todos.ts"
200
+ import { createEveTools } from "capable-kit/eve";
201
+ import { app } from "../../app";
202
+
203
+ export default createEveTools(app);
204
+ // Eve resolves todos__create as a native tool at each step.
96
205
  ```
97
206
 
98
- To get a surface instead of a call, hand the same `app` to `createCli`, `createMcp`, or `createReactQuery`. A surface is just a function that takes an app.
207
+ </Tab>
208
+ <Tab label="React Query">
99
209
 
100
- To call a deployed app instead, swap `createApp` for `createRemoteApp`. Types come from a type-only import of the definition, so there is still no generated client, and every surface works the same over a transport.
210
+ ```tsx title="add-todo.tsx"
211
+ "use client";
101
212
 
102
- ```ts title="remote.ts"
213
+ import { createReactQuery } from "@capable/react-query";
214
+ import { useMutation } from "@tanstack/react-query";
103
215
  import { createRemoteApp } from "capable-kit";
104
216
  import { createHttpTransport } from "capable-kit/http";
105
217
  import type definition from "./capable.app";
106
218
 
107
- const app = createRemoteApp<typeof definition>(
108
- createHttpTransport({ url: "https://todos.example.com/_capable/" }),
219
+ const query = createReactQuery(
220
+ createRemoteApp<typeof definition>(
221
+ createHttpTransport({
222
+ url: () => new URL("/_capable/", window.location.origin),
223
+ }),
224
+ ),
109
225
  );
110
226
 
111
- // Identical call, executed on the server.
112
- const todo = await app.todos.create({ title: "Read the docs" });
113
- ```
114
-
115
- ## What Capable is not [#scope]
227
+ // Render this component beneath a QueryClientProvider.
228
+ export function AddTodo() {
229
+ const createTodo = useMutation(query.todos.create.mutationOptions());
116
230
 
117
- - **Not a replacement for your web framework.** Mount Capable in Next.js, Hono, H3, or any Fetch-compatible server — or run it as a standalone service.
118
- - **No generated client required.** Typed calls, commands, and tools are derived from the same capability definitions and schemas.
119
- - **Not tied to one protocol.** HTTP, the Capable transport, MCP, CLI, and in-process tools are projections of the same protocol-neutral capabilities.
231
+ return (
232
+ <button onClick={() => createTodo.mutate({ title: "Read the docs" })}>
233
+ Add todo
234
+ </button>
235
+ );
236
+ }
237
+ ```
120
238
 
121
- > **Early development**
122
- >
123
- > The documented APIs are implemented and tested, but breaking changes are expected.
239
+ </Tab>
240
+ </Tabs>
124
241
 
125
242
  ## Where to go next [#next]
126
243
 
@@ -12,7 +12,7 @@ export const metadata = docMetadata("/quickstart", frontmatter);
12
12
 
13
13
  Capable works two ways: as its own service, or embedded in an app you already have. Both start from the same capability. Pick the path that matches your project.
14
14
 
15
- <Tabs id="quickstart-path">
15
+ <Tabs id="quickstart-path" label="Choose a setup path">
16
16
  <Tab label="Standalone service">
17
17
 
18
18
  1. ### Install Capable
@@ -104,7 +104,68 @@ Capable works two ways: as its own service, or embedded in an app you already ha
104
104
  const todos = await app.todos.list({});
105
105
  ```
106
106
 
107
- 6. ### Call it from another process
107
+ 6. ### Hand the same app to a surface
108
+
109
+ A surface is just a function that takes an app. Nothing about the capability changes — `createAiSdkTools()` reads the same tree, the same schemas, and the same `effect` metadata that HTTP and the CLI read, and returns an AI SDK v7 tool set.
110
+
111
+ ```ts title="agent.ts"
112
+ import { generateText, stepCountIs } from "ai";
113
+ import { createApp } from "capable-kit";
114
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
115
+ import definition from "./capable.app";
116
+
117
+ export const app = createApp(definition);
118
+
119
+ // todos.list -> tool "todos__list", todos.create -> tool "todos__create".
120
+ // Input schemas, output schemas, and execution come from the capabilities.
121
+ const tools = await createAiSdkTools(app);
122
+
123
+ const result = await generateText({
124
+ model: "anthropic/claude-sonnet-4.5",
125
+ tools,
126
+ stopWhen: stepCountIs(5),
127
+ prompt: "Add a todo to read the Capable quickstart, then list the todos.",
128
+ });
129
+ ```
130
+
131
+ The model's tool call goes through the same runtime as `app.todos.create(...)`: input validation, middleware, declared errors, output validation. There is no second definition of the capability, and no hand-written tool wrapper to keep in sync.
132
+
133
+ Swapping the surface swaps the projection, not the app. The same `app` value drives an agent running in your process, a terminal command tree, or a React data layer:
134
+
135
+ ```ts title="surfaces.ts"
136
+ import { createCli } from "capable-kit/cli";
137
+ import { createEveTools } from "capable-kit/eve";
138
+ import { createMcp } from "capable-kit/mcp";
139
+ import { always } from "eve/tools/approval";
140
+ import { app } from "./agent";
141
+
142
+ // Durable in-process agent tools, with approvals derived from effect.
143
+ export const eveTools = createEveTools(app, {
144
+ approval: (capability) =>
145
+ capability.effect === "destructive" ? always() : undefined,
146
+ });
147
+
148
+ // The same app as a command tree, or as MCP tools for an external agent.
149
+ await createCli(app).run(process.argv.slice(2));
150
+ const mcpTools = await createMcp(app);
151
+ ```
152
+
153
+ A surface should often see less than the whole app. `selectApp()` narrows the tree before projection, so an agent can be given reads without ever seeing the destructive capabilities.
154
+
155
+ ```ts title="agent-tools.ts"
156
+ import { selectApp } from "capable-kit";
157
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
158
+ import { app } from "./agent";
159
+
160
+ // The model gets todos__list only. todos__create is not projected at all.
161
+ const readOnly = selectApp(app, { include: { todos: { list: true } } });
162
+
163
+ export const tools = await createAiSdkTools(readOnly);
164
+ ```
165
+
166
+ Per-capability metadata renames or hides a capability on one surface without touching the others — `meta.aiSdk.name` sets the tool name, and `meta.aiSdk: false` keeps a capability out of the tool set entirely. See [AI SDK](/surfaces/ai-sdk), [Eve](/surfaces/eve), and the [metadata reference](/reference/metadata).
167
+
168
+ 7. ### Call it from another process
108
169
 
109
170
  Swap `createApp()` for `createRemoteApp()` and the calls are identical—only placement changed. The manifest is discovered lazily on first use, and types come from a type-only import of the definition.
110
171
 
@@ -126,26 +187,25 @@ Capable works two ways: as its own service, or embedded in an app you already ha
126
187
  const todos = await app.todos.list({});
127
188
  ```
128
189
 
129
- Because a surface is just a function that takes an app, the remote app also drives a CLI, MCP, or React Query — pointed at the deployed service instead of this process.
190
+ Every surface from the previous step still applies, because they take an app rather than a server. Point them at the remote app and they run against the deployed service instead of this process.
130
191
 
131
192
  ```ts title="cli.ts"
132
193
  import { createCli } from "capable-kit/cli";
133
- import { createMcp } from "capable-kit/mcp";
194
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
134
195
  import { app } from "./remote";
135
196
 
136
- // Surfaces take an app, not a server. A remote app works everywhere
137
- // a local one does — this CLI runs against the deployed service.
197
+ // Same projection code as the local app — only placement changed.
138
198
  process.exit(await createCli(app).run(process.argv.slice(2)));
139
199
 
140
- // ...or turn the deployed service into agent tools from here.
141
- const tools = await createMcp(app);
200
+ // ...or give a model tools backed by the deployed service.
201
+ const tools = await createAiSdkTools(app);
142
202
  ```
143
203
 
144
204
  > **Remote apps are apps**
145
205
  >
146
206
  > A remote app can be merged with a local one using `mergeApps()`, so one command tree can mix capabilities that run on the server with capabilities that must run here. See [Composition](/patterns/composition).
147
207
 
148
- 7. ### Build for production
208
+ 8. ### Build for production
149
209
 
150
210
  `cap build` emits a standalone server. A preset changes the output target without touching the app definition.
151
211
 
@@ -252,7 +312,40 @@ Capable works two ways: as its own service, or embedded in an app you already ha
252
312
  export { GET, POST } from "@/capable/server";
253
313
  ```
254
314
 
255
- 5. ### Call from React Query
315
+ 5. ### Turn the same capabilities into agent tools
316
+
317
+ The capabilities you already call from a server component are also a tool set. In a chat route, project the app with `createAiSdkTools()` and pass it to `streamText()` — the model calls the same handlers your UI does.
318
+
319
+ ```ts title="app/api/chat/route.ts"
320
+ import { convertToModelMessages, streamText, type UIMessage } from "ai";
321
+ import { createApp, selectApp } from "capable-kit";
322
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
323
+ import definition from "../../../capable/app";
324
+
325
+ const app = createApp(definition);
326
+
327
+ // The agent sees a narrowed tree: reads and creates, nothing destructive.
328
+ const agentApp = selectApp(app, {
329
+ include: { todos: { list: true, create: true } },
330
+ });
331
+ const tools = await createAiSdkTools(agentApp);
332
+
333
+ export async function POST(request: Request) {
334
+ const { messages }: { messages: UIMessage[] } = await request.json();
335
+
336
+ const result = streamText({
337
+ model: "anthropic/claude-sonnet-4.5",
338
+ messages: convertToModelMessages(messages),
339
+ tools,
340
+ });
341
+
342
+ return result.toUIMessageStreamResponse();
343
+ }
344
+ ```
345
+
346
+ Nothing was added to the capability to make this work. `todos.create` became the tool `todos__create` because a surface projected it, with the same input schema, middleware, and errors the server component gets.
347
+
348
+ 6. ### Call from React Query
256
349
 
257
350
  `@capable/react-query` mirrors the app tree into query keys and options. The browser talks to the Capable transport at `/_capable`.
258
351