capable-kit 0.0.1-alpha.3 → 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.
- package/README.md +21 -3
- package/dist/ai-sdk.d.mts +2 -2
- package/dist/ai-sdk.mjs +1 -1
- package/dist/app.d.mts +1 -1
- package/dist/app.mjs +1 -1
- package/dist/bin.mjs +17 -16
- package/dist/bin.mjs.map +1 -1
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/core.d.mts +3 -3
- package/dist/core.mjs +2 -2
- package/dist/eve.d.mts +1 -1
- package/dist/eve.mjs +1 -1
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +1 -1
- package/dist/{index-BB5ogMv-.d.mts → index-Be8-UVBC.d.mts} +49 -8
- package/dist/{index-B2ru1zGQ.d.mts → index-D2CRRUzH.d.mts} +6 -6
- package/dist/{index-B_I9n6gN.d.mts → index-Dbc4g9WM.d.mts} +4 -3
- package/dist/{index-AqKbVZ8Z.d.mts → index-DwXlaTXI.d.mts} +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/mcp.d.mts +2 -2
- package/dist/mcp.mjs +1 -1
- package/dist/{mount--YHrgRHJ.mjs → mount-xvMsjz1B.mjs} +65 -27
- package/dist/mount-xvMsjz1B.mjs.map +1 -0
- package/dist/runtime-support.d.mts +1 -1
- package/dist/runtime-support.mjs +6 -6
- package/dist/runtime-support.mjs.map +1 -1
- package/dist/server.d.mts +2 -2
- package/dist/server.mjs +2 -2
- package/dist/{src-DX2xrplP.mjs → src-BF70JLxI.mjs} +24 -13
- package/dist/src-BF70JLxI.mjs.map +1 -0
- package/dist/{src-3UaBqI8H.mjs → src-C2MGIlT0.mjs} +17 -18
- package/dist/src-C2MGIlT0.mjs.map +1 -0
- package/dist/{src-DtSY5fzY.mjs → src-CDxL6w3d.mjs} +7 -7
- package/dist/{src-DtSY5fzY.mjs.map → src-CDxL6w3d.mjs.map} +1 -1
- package/dist/{src-BjBxOv7x.mjs → src-Db6-XSnU.mjs} +20 -12
- package/dist/src-Db6-XSnU.mjs.map +1 -0
- package/dist/{src-B53ZbNtC.mjs → src-DdV82An-.mjs} +137 -3
- package/dist/src-DdV82An-.mjs.map +1 -0
- package/dist/{subscription-McaLyHM2.d.mts → subscription-Bq792Ad2.d.mts} +2 -2
- package/docs/CONTEXT.md +113 -0
- package/docs/README.md +28 -0
- package/docs/internal/README.md +16 -0
- package/docs/internal/adr/0001-capability-is-the-semantic-boundary.md +24 -0
- package/docs/internal/architecture.md +134 -0
- package/docs/internal/capability-first-model.md +160 -0
- package/docs/internal/implementation-friction.md +705 -0
- package/docs/internal/why-capable.md +94 -0
- package/docs/site/capable-orpc-and-trpc.mdx +133 -0
- package/docs/site/concepts/apps.mdx +217 -0
- package/docs/site/concepts/architecture.mdx +83 -0
- package/docs/site/concepts/capabilities.mdx +249 -0
- package/docs/site/concepts/errors.mdx +93 -0
- package/docs/site/concepts/presentations.mdx +161 -0
- package/docs/site/hosting/any-fetch-host.mdx +74 -0
- package/docs/site/hosting/next-js.mdx +77 -0
- package/docs/site/hosting/standalone-server.mdx +94 -0
- package/docs/site/introduction.mdx +259 -0
- package/docs/site/patterns/composition.mdx +142 -0
- package/docs/site/patterns/remote-apps.mdx +117 -0
- package/docs/site/patterns/subscriptions.mdx +87 -0
- package/docs/site/quickstart.mdx +386 -0
- package/docs/site/reference/packages-and-entry-points.mdx +72 -0
- package/docs/site/reference/surface-metadata.mdx +84 -0
- package/docs/site/reference/the-cap-cli.mdx +81 -0
- package/docs/site/surfaces/ai-sdk.mdx +94 -0
- package/docs/site/surfaces/cli.mdx +138 -0
- package/docs/site/surfaces/eve.mdx +121 -0
- package/docs/site/surfaces/http-and-openapi.mdx +111 -0
- package/docs/site/surfaces/mcp.mdx +110 -0
- package/docs/site/surfaces/react-query.mdx +80 -0
- package/docs/site/surfaces/typescript.mdx +123 -0
- package/docs/site/surfaces.mdx +78 -0
- package/docs/site/why-capable.mdx +99 -0
- package/package.json +13 -3
- package/src/index.test.ts +1 -0
- package/src/index.ts +5 -1
- package/src/package.test.ts +102 -0
- package/dist/mount--YHrgRHJ.mjs.map +0 -1
- package/dist/src-3UaBqI8H.mjs.map +0 -1
- package/dist/src-B53ZbNtC.mjs.map +0 -1
- package/dist/src-BjBxOv7x.mjs.map +0 -1
- package/dist/src-DX2xrplP.mjs.map +0 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "The cap CLI"
|
|
3
|
+
description: "Commands, options, and project discovery for the toolchain."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { DocsPage, docMetadata } from "../../_components/docs-page";
|
|
7
|
+
|
|
8
|
+
export const metadata = docMetadata("/reference/cli", frontmatter);
|
|
9
|
+
|
|
10
|
+
<DocsPage href="/reference/cli" frontmatter={frontmatter}>
|
|
11
|
+
|
|
12
|
+
The `cap` command ships with the `capable-kit` package. There is no separate CLI package to install. Apps hosted inside another framework can simply ignore the command.
|
|
13
|
+
|
|
14
|
+
## Usage [#usage]
|
|
15
|
+
|
|
16
|
+
```sh title="terminal"
|
|
17
|
+
cap init [directory]
|
|
18
|
+
cap dev [project] [--host localhost] [--port 3000]
|
|
19
|
+
cap build [project] [--output .output] [--preset node-server]
|
|
20
|
+
cap preview [project] [--output .output] [--host localhost] [--port 3000]
|
|
21
|
+
cap cli [--app <project-or-url>] <command...>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```ts title="new standalone App"
|
|
25
|
+
cap init apps/todos
|
|
26
|
+
cd apps/todos
|
|
27
|
+
pnpm install
|
|
28
|
+
pnpm dev
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
| Command | Description |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| `init` | Creates capable.app.ts and a runnable package.json in the current directory or a supplied directory. Existing fields and Capable App entries are never overwritten. |
|
|
34
|
+
| `dev` | Starts a watching development server. Without a capable.server.ts it serves /\_capable, /api, /openapi.json, and /mcp, plus a read-only capability index at /. With one, it wraps the authored server and adds only the index. |
|
|
35
|
+
| `build` | Builds the project into `.output`. Presets are Nitro deployment presets, for example `node-server` or `vercel`. |
|
|
36
|
+
| `preview` | Runs a previously built `node-server` output. Other presets do not produce a locally runnable command. |
|
|
37
|
+
| `cli` | Runs the app's derived command tree without writing a CLI entry point. |
|
|
38
|
+
|
|
39
|
+
## Project discovery [#discovery]
|
|
40
|
+
|
|
41
|
+
The first match wins:
|
|
42
|
+
|
|
43
|
+
```sh title="terminal"
|
|
44
|
+
# 1. Positional argument or --app
|
|
45
|
+
cap dev ./services/todos
|
|
46
|
+
|
|
47
|
+
# 2. CAPABLE_APP environment variable
|
|
48
|
+
CAPABLE_APP=./services/todos cap dev
|
|
49
|
+
|
|
50
|
+
# 3. The "capable" field in package.json
|
|
51
|
+
{ "capable": "./services/todos" }
|
|
52
|
+
|
|
53
|
+
# 4. capable.app.* in the current directory
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Recognized entry files are `capable.app.ts`, `.tsx`, `.js`, `.mjs`, and `.cjs`. If a `capable.server.*` file sits in the same package root, it is used as the server.
|
|
57
|
+
|
|
58
|
+
## Invoking capabilities [#invoke]
|
|
59
|
+
|
|
60
|
+
```sh title="terminal"
|
|
61
|
+
# In-process, using capable.server.ts when present
|
|
62
|
+
cap cli --app ./ todos list
|
|
63
|
+
|
|
64
|
+
# Against a deployed server, over the Capable transport
|
|
65
|
+
cap cli --app https://todos.example.com todos list
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
A local project runs in-process, so no development server is needed. A URL is treated as the root of a Capable server and reached through `/_capable/`. Both produce the same commands and help, because both read the same manifest.
|
|
69
|
+
|
|
70
|
+
| Option | Applies to | Meaning |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| `--app` | `cli` | Project path or server URL |
|
|
73
|
+
| `--json` | Any capability | Print canonical JSON without computing the presentation |
|
|
74
|
+
| `--watch` | Subscribable read capabilities | Follow replacements, redrawing in place in a TTY |
|
|
75
|
+
| `--help` | Any command | Help for the root, a group, or one capability |
|
|
76
|
+
|
|
77
|
+
> **Exit codes**
|
|
78
|
+
>
|
|
79
|
+
> `0` success, `1` capability failure, `2` usage error. Suitable for scripts and CI.
|
|
80
|
+
|
|
81
|
+
</DocsPage>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "AI SDK"
|
|
3
|
+
description: "Turn an executable app into typed AI SDK tools for generateText, streamText, and agents."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { DocsPage, docMetadata } from "../../_components/docs-page";
|
|
7
|
+
|
|
8
|
+
export const metadata = docMetadata("/surfaces/ai-sdk", frontmatter);
|
|
9
|
+
|
|
10
|
+
<DocsPage href="/surfaces/ai-sdk" frontmatter={frontmatter}>
|
|
11
|
+
|
|
12
|
+
`createAiSdkTools()` turns an executable app into a typed AI SDK v7 tool set. Names, schemas, execution, and cancellation come from the same capabilities used by every other surface.
|
|
13
|
+
|
|
14
|
+
## Create a tool set [#create]
|
|
15
|
+
|
|
16
|
+
```ts title="agent.ts"
|
|
17
|
+
import { generateText, stepCountIs } from "ai";
|
|
18
|
+
import { createApp } from "capable-kit";
|
|
19
|
+
import { createAiSdkTools } from "capable-kit/ai-sdk";
|
|
20
|
+
import definition from "./capable.app";
|
|
21
|
+
|
|
22
|
+
const app = createApp(definition);
|
|
23
|
+
const tools = await createAiSdkTools(app);
|
|
24
|
+
|
|
25
|
+
const result = await generateText({
|
|
26
|
+
model: "anthropic/claude-sonnet-4.5",
|
|
27
|
+
tools,
|
|
28
|
+
stopWhen: stepCountIs(5),
|
|
29
|
+
prompt: "Create a todo to read the Capable documentation.",
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The returned object can go directly into `generateText()`,`streamText()`, or an AI SDK agent. Tool calls run through the app runtime, so middleware, declared errors, validation, and output validation stay in one place. If a capability declares context, bind its provider when creating the app; context-free apps need no options.
|
|
34
|
+
|
|
35
|
+
## What gets projected [#mapping]
|
|
36
|
+
|
|
37
|
+
| AI SDK field | Capable source |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| Object key | Application path joined with \_\_ |
|
|
40
|
+
| `description` | Description, then title |
|
|
41
|
+
| `inputSchema` | Capability input JSON Schema |
|
|
42
|
+
| `outputSchema` | Declared output JSON Schema |
|
|
43
|
+
| `execute` | App runtime call by Capability ID |
|
|
44
|
+
| `metadata.capable` | Capability ID, path, effect, title, and deprecation |
|
|
45
|
+
|
|
46
|
+
A typed local or remote app preserves literal tool names and Capability input/output types in AI SDK tool calls and results. Projection is asynchronous because it discovers the manifest needed to enumerate the tools.
|
|
47
|
+
|
|
48
|
+
## Rename, constrain, or hide tools [#metadata]
|
|
49
|
+
|
|
50
|
+
```ts title="capabilities.ts"
|
|
51
|
+
const createTodo = capability({
|
|
52
|
+
id: "todos.create",
|
|
53
|
+
input: z.object({ title: z.string() }),
|
|
54
|
+
output: TodoSchema,
|
|
55
|
+
meta: {
|
|
56
|
+
aiSdk: {
|
|
57
|
+
name: "create_todo", // default: todos__create
|
|
58
|
+
strict: true,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
handler: ({ input, context }) => context.todos.create(input),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// meta: { aiSdk: false } keeps a capability out of this tool set.
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Duplicate names and names outside the portable 1–64 character tool subset fail while the tool set is created. Use [selectApp()](/patterns/composition) when an entire exposure boundary should see only part of an app.
|
|
68
|
+
|
|
69
|
+
## Local and remote execution [#remote]
|
|
70
|
+
|
|
71
|
+
Conversion reads the App manifest rather than the original live schema objects, so local, remote, merged, and selected Apps use the same path.
|
|
72
|
+
|
|
73
|
+
```ts title="tools.ts"
|
|
74
|
+
import { createRemoteApp } from "capable-kit";
|
|
75
|
+
import { createAiSdkTools } from "capable-kit/ai-sdk";
|
|
76
|
+
import { createHttpTransport } from "capable-kit/http";
|
|
77
|
+
import type definition from "./capable.app";
|
|
78
|
+
|
|
79
|
+
const app = createRemoteApp<typeof definition>(
|
|
80
|
+
createHttpTransport({ url: "https://todos.example.com/_capable/" }),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
export const tools = await createAiSdkTools(app);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
> **Unary execution only**
|
|
87
|
+
>
|
|
88
|
+
> A subscribable Capability becomes a normal unary tool that returns its current snapshot. AI SDK streamed tool outputs are preliminary execution results, not Capable replacement subscriptions.
|
|
89
|
+
|
|
90
|
+
## Approval stays with the AI SDK call [#approval]
|
|
91
|
+
|
|
92
|
+
Capable exposes `effect` under `toolMetadata.capable.effect`, but does not automatically approve or block a call. Configure AI SDK v7's top-level `toolApproval` policy at `generateText()`, `streamText()`, or agent construction.
|
|
93
|
+
|
|
94
|
+
</DocsPage>
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "CLI"
|
|
3
|
+
description: "Turn an app into a command tree that runs in-process or against a remote server."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { DocsPage, docMetadata } from "../../_components/docs-page";
|
|
7
|
+
|
|
8
|
+
export const metadata = docMetadata("/surfaces/cli", frontmatter);
|
|
9
|
+
|
|
10
|
+
<DocsPage href="/surfaces/cli" frontmatter={frontmatter}>
|
|
11
|
+
|
|
12
|
+
`createCli()` derives a command tree from the app: paths become commands, input fields become arguments and flags, and titles and descriptions become help text. It works with any app, so the same file can drive a local tool or a remote one.
|
|
13
|
+
|
|
14
|
+
## Build a CLI [#build]
|
|
15
|
+
|
|
16
|
+
```ts title="cli.ts"
|
|
17
|
+
#!/usr/bin/env bun
|
|
18
|
+
import { createApp } from "capable-kit";
|
|
19
|
+
import { createCli } from "capable-kit/cli";
|
|
20
|
+
import definition from "./capable.app";
|
|
21
|
+
import { createContext } from "./context";
|
|
22
|
+
|
|
23
|
+
const app = createApp(definition, { context: createContext });
|
|
24
|
+
const cli = createCli(app, { invocationName: "todo" });
|
|
25
|
+
|
|
26
|
+
process.exit(await cli.run(process.argv.slice(2)));
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The app tree is available as a discoverable root command immediately:
|
|
30
|
+
|
|
31
|
+
```sh title="terminal"
|
|
32
|
+
todo --help
|
|
33
|
+
|
|
34
|
+
Todo App
|
|
35
|
+
Manage your todo list
|
|
36
|
+
|
|
37
|
+
todo <command> [options]
|
|
38
|
+
|
|
39
|
+
Commands
|
|
40
|
+
|
|
41
|
+
todos list List todos
|
|
42
|
+
todos create <title> Create a todo
|
|
43
|
+
todos delete <todoId> Delete a todo
|
|
44
|
+
|
|
45
|
+
Options
|
|
46
|
+
|
|
47
|
+
--json Print canonical JSON
|
|
48
|
+
-h, --help Show help
|
|
49
|
+
|
|
50
|
+
Run `todo <command> --help` for details on a command.
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`run()` resolves to an exit code: `0` on success, `1` for a failed capability, and `2` for a usage error.
|
|
54
|
+
|
|
55
|
+
## How commands are derived [#mapping]
|
|
56
|
+
|
|
57
|
+
| Authored | Becomes |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| App path `todos.create` | `todos create` |
|
|
60
|
+
| Input field `dueDate` | `--due-date` |
|
|
61
|
+
| Field listed in `cli.positional` | `<title>` |
|
|
62
|
+
| Boolean field `notify` | `--notify` |
|
|
63
|
+
| `title` and `description` | Help text for the command |
|
|
64
|
+
| `toPresentation` | Default terminal output |
|
|
65
|
+
|
|
66
|
+
```sh title="terminal"
|
|
67
|
+
todo --help
|
|
68
|
+
todo todos --help
|
|
69
|
+
todo todos create --help
|
|
70
|
+
|
|
71
|
+
# Positional argument plus flags
|
|
72
|
+
todo todos create "Read the docs" --due 2025-01-31
|
|
73
|
+
|
|
74
|
+
# Canonical JSON instead of the presentation
|
|
75
|
+
todo todos list --json
|
|
76
|
+
|
|
77
|
+
# Follow a subscribable read capability
|
|
78
|
+
todo todos list --watch
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Values are coerced with the input schema, required fields are checked before the call, and unknown commands or options suggest the nearest match and point at the right `--help`.
|
|
82
|
+
|
|
83
|
+
## CLI metadata [#metadata]
|
|
84
|
+
|
|
85
|
+
Metadata only changes presentation. Everything else — validation, middleware, errors — is the capability's.
|
|
86
|
+
|
|
87
|
+
```ts title="capabilities.ts"
|
|
88
|
+
const createTodo = todo({
|
|
89
|
+
id: "todos.create",
|
|
90
|
+
title: "Create a todo",
|
|
91
|
+
input: z.object({ title: z.string(), dueDate: z.string().optional() }),
|
|
92
|
+
meta: {
|
|
93
|
+
cli: { positional: ["title"] }, // <title> instead of --title
|
|
94
|
+
// cli: { name: "add" }, // rename this command
|
|
95
|
+
// cli: { command: ["todo", "add"] } // place it anywhere
|
|
96
|
+
// cli: false, // keep it out of the CLI
|
|
97
|
+
},
|
|
98
|
+
handler: ({ input, context }) => context.todos.create(input),
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Point it at a server [#remote]
|
|
103
|
+
|
|
104
|
+
A remote app produces an identical command tree, because help and arguments are derived from the manifest rather than from local code.
|
|
105
|
+
|
|
106
|
+
```ts title="cli.ts"
|
|
107
|
+
import { createRemoteApp } from "capable-kit";
|
|
108
|
+
import { createCli } from "capable-kit/cli";
|
|
109
|
+
import { createHttpTransport } from "capable-kit/http";
|
|
110
|
+
import type definition from "./capable.app";
|
|
111
|
+
|
|
112
|
+
const remote = createRemoteApp<typeof definition>(
|
|
113
|
+
createHttpTransport({
|
|
114
|
+
url: process.env.CAPABLE_URL ?? "http://localhost:3000/_capable/",
|
|
115
|
+
headers: () => ({ authorization: `Bearer ${readToken()}` }),
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
process.exit(await createCli(remote).run(process.argv.slice(2)));
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
> **Local and remote in one tree**
|
|
123
|
+
>
|
|
124
|
+
> Merge a local app with a remote one to add commands such as `login` or `status` that must run on the user's machine. See [Composition](/patterns/composition).
|
|
125
|
+
|
|
126
|
+
## Without writing a CLI file [#toolchain]
|
|
127
|
+
|
|
128
|
+
The toolchain ships a generic runner. It imports `capable.server.ts` for a local project, or connects to a URL.
|
|
129
|
+
|
|
130
|
+
```sh title="terminal"
|
|
131
|
+
# Run the local project in-process
|
|
132
|
+
cap cli --app ./ todos list
|
|
133
|
+
|
|
134
|
+
# Run the same commands against a deployed server
|
|
135
|
+
cap cli --app https://todos.example.com todos list
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
</DocsPage>
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Eve"
|
|
3
|
+
description: "Give an Eve agent native in-process tools without a second server."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { DocsPage, docMetadata } from "../../_components/docs-page";
|
|
7
|
+
|
|
8
|
+
export const metadata = docMetadata("/surfaces/eve", frontmatter);
|
|
9
|
+
|
|
10
|
+
<DocsPage href="/surfaces/eve" frontmatter={frontmatter}>
|
|
11
|
+
|
|
12
|
+
`createEveTools()` projects an executable app into native Eve tools. Start with the app inside the agent process. If it later needs to become its own service, host the same definition and replace the local app with a remote one. The Eve tools do not change.
|
|
13
|
+
|
|
14
|
+
## Start in-process [#local]
|
|
15
|
+
|
|
16
|
+
Put an executable app directly in Eve's `agent/tools/` directory. There is no second server and no HTTP hop.
|
|
17
|
+
|
|
18
|
+
```ts title="agent/tools/todos.ts"
|
|
19
|
+
import { createApp } from "capable-kit";
|
|
20
|
+
import { createEveTools } from "capable-kit/eve";
|
|
21
|
+
import { always } from "eve/tools/approval";
|
|
22
|
+
import definition from "../../capable.app";
|
|
23
|
+
import { todos } from "../../todos";
|
|
24
|
+
|
|
25
|
+
const app = createApp(definition, {
|
|
26
|
+
context: () => ({ todos }),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export default createEveTools(app, {
|
|
30
|
+
approval: (capability) =>
|
|
31
|
+
capability.effect === "destructive" ? always() : undefined,
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The agent now sees `todos__list`, `todos__add`, and `todos__delete` with names, descriptions, input schemas, and output schemas derived from the app. Calls run through the local app runtime, so context creation, middleware, declared errors, and validation all happen in the agent process.
|
|
36
|
+
|
|
37
|
+
## Move it into a standalone service [#host]
|
|
38
|
+
|
|
39
|
+
When the capability needs independent deployment, shared access, or its own scaling boundary, keep `capable.app.ts` unchanged and add a server file. Context moves with execution to the service.
|
|
40
|
+
|
|
41
|
+
```ts title="capable.server.ts"
|
|
42
|
+
import { createServer } from "capable-kit/server";
|
|
43
|
+
import definition from "./capable.app";
|
|
44
|
+
import { todos } from "./todos";
|
|
45
|
+
|
|
46
|
+
export default createServer(definition, {
|
|
47
|
+
context: () => ({ todos }),
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```sh title="terminal"
|
|
52
|
+
cap dev # run the service with file watching
|
|
53
|
+
cap build # build a standalone Node service
|
|
54
|
+
cap preview # run that production build locally
|
|
55
|
+
|
|
56
|
+
# Or build for another deployment target
|
|
57
|
+
cap build --preset vercel
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The standalone server exposes the Capable transport at `/_capable/`. Its manifest describes the same capability tree, effects, schemas, and metadata the local app exposed.
|
|
61
|
+
|
|
62
|
+
## Point Eve at the remote app [#remote]
|
|
63
|
+
|
|
64
|
+
Replace `createApp()` with `createRemoteApp()`. The tool projection and approval policy stay the same; only the placement of execution changes.
|
|
65
|
+
|
|
66
|
+
```ts title="agent/tools/todos.ts"
|
|
67
|
+
import { createRemoteApp } from "capable-kit";
|
|
68
|
+
import { createEveTools } from "capable-kit/eve";
|
|
69
|
+
import { createHttpTransport } from "capable-kit/http";
|
|
70
|
+
import { always } from "eve/tools/approval";
|
|
71
|
+
import type definition from "../../capable.app";
|
|
72
|
+
|
|
73
|
+
const app = createRemoteApp<typeof definition>(
|
|
74
|
+
createHttpTransport({
|
|
75
|
+
url: "https://todos.example.com/_capable/",
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export default createEveTools(app, {
|
|
80
|
+
approval: (capability) =>
|
|
81
|
+
capability.effect === "destructive" ? always() : undefined,
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
| | Local app | Remote app |
|
|
86
|
+
| --- | --- | --- |
|
|
87
|
+
| Handler runs | Inside the Eve process | Inside the service |
|
|
88
|
+
| Context lives | With the agent | With the service |
|
|
89
|
+
| Tool discovery | In-memory manifest | Remote manifest |
|
|
90
|
+
| Eve tool names and schemas | Derived by createEveTools() | The same projection |
|
|
91
|
+
|
|
92
|
+
> **The definition import is type-only**
|
|
93
|
+
>
|
|
94
|
+
> Eve imports `typeof definition` for static typing, but it does not execute the local handlers. Discovery and calls go through the remote transport.
|
|
95
|
+
|
|
96
|
+
## Approvals from effect [#approvals]
|
|
97
|
+
|
|
98
|
+
The `approval` option receives each capability from the manifest and returns an Eve approval policy, which is a direct use of `effect` as a safety signal.
|
|
99
|
+
|
|
100
|
+
| Effect | Typical policy |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| `read` | No approval |
|
|
103
|
+
| `write` | No approval, or ask once |
|
|
104
|
+
| `destructive` | `always()` — a human confirms every call |
|
|
105
|
+
|
|
106
|
+
```ts title="capabilities.ts"
|
|
107
|
+
meta: {
|
|
108
|
+
eve: { name: "todos_add" }, // default is the app path: todos__add
|
|
109
|
+
// eve: false, // keep this capability away from the agent
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Durability [#durability]
|
|
114
|
+
|
|
115
|
+
The tool definition resolves at Eve's `step.started` boundary. With a local app, Eve keeps the app and its context provider in memory. With a remote app, it keeps the transport-backed runtime live instead. In both cases Eve checkpoints the tool call and its result.
|
|
116
|
+
|
|
117
|
+
> **Interrupted steps can re-run**
|
|
118
|
+
>
|
|
119
|
+
> As with any Eve tool, a side effect must be idempotent: an interrupted step may execute again. This is a property of durable agent execution, not of Capable.
|
|
120
|
+
|
|
121
|
+
</DocsPage>
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "HTTP and OpenAPI"
|
|
3
|
+
description: "Derive routes from the app tree, or author them when the contract is public."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { DocsPage, docMetadata } from "../../_components/docs-page";
|
|
7
|
+
|
|
8
|
+
export const metadata = docMetadata("/surfaces/http", frontmatter);
|
|
9
|
+
|
|
10
|
+
<DocsPage href="/surfaces/http" frontmatter={frontmatter}>
|
|
11
|
+
|
|
12
|
+
The HTTP mount compiles the app tree into routes and owns the generated OpenAPI document. It is one projection of the app — the Capable transport used by remote Capable clients is a separate mount.
|
|
13
|
+
|
|
14
|
+
## Mount it [#mount]
|
|
15
|
+
|
|
16
|
+
```ts title="capable.server.ts"
|
|
17
|
+
import { createServer, http } from "capable-kit/server";
|
|
18
|
+
import definition from "./capable.app";
|
|
19
|
+
|
|
20
|
+
export default createServer(definition, {
|
|
21
|
+
context: ({ request }) => contextFromRequest(request),
|
|
22
|
+
mounts: [
|
|
23
|
+
http({
|
|
24
|
+
path: "/api",
|
|
25
|
+
openapiPath: "/openapi.json",
|
|
26
|
+
requireExplicitRoutes: false,
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
| Option | Default | Effect |
|
|
33
|
+
| --- | --- | --- |
|
|
34
|
+
| `path` | `/api` | Base path for every route |
|
|
35
|
+
| `openapiPath` | `/openapi.json` | Where the document is served. `false` disables it. |
|
|
36
|
+
| `requireExplicitRoutes` | `false` | Fail at startup if any exposed capability has no authored method and route |
|
|
37
|
+
| `selection` | all | Include or exclude a subtree from this surface |
|
|
38
|
+
|
|
39
|
+
## Derived routes [#derived]
|
|
40
|
+
|
|
41
|
+
Without metadata, the route is the app path under the base path and the method comes from `effect`.
|
|
42
|
+
|
|
43
|
+
| Capability | Effect | Route |
|
|
44
|
+
| --- | --- | --- |
|
|
45
|
+
| `todos.list` | `read` | `GET /api/todos/list` |
|
|
46
|
+
| `todos.create` | `write` | `POST /api/todos/create` |
|
|
47
|
+
| `todos.delete` | `destructive` | `POST /api/todos/delete` |
|
|
48
|
+
|
|
49
|
+
Input is read from path parameters first, then from the query string for `GET` or the JSON body for everything else. Query and path values are coerced using the input schema, so `?limit=10` reaches the handler as a number.
|
|
50
|
+
|
|
51
|
+
## Authored routes [#authored]
|
|
52
|
+
|
|
53
|
+
Derived routes are convenient internally, but a public API usually deserves deliberate methods and paths. Authoring one is metadata, not a second implementation.
|
|
54
|
+
|
|
55
|
+
```ts title="capabilities.ts"
|
|
56
|
+
const getTodo = todo({
|
|
57
|
+
id: "todos.get",
|
|
58
|
+
effect: "read",
|
|
59
|
+
input: z.object({ todoId: z.string() }),
|
|
60
|
+
output: Todo,
|
|
61
|
+
errors: TodoErrors,
|
|
62
|
+
meta: {
|
|
63
|
+
http: { method: "GET", route: "/todos/:todoId" },
|
|
64
|
+
},
|
|
65
|
+
handler: ({ input, context }) => context.todos.get(input.todoId),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Group prefixes apply to derived routes and to authored ones.
|
|
69
|
+
const todos = group({
|
|
70
|
+
meta: { http: { prefix: "/todos" } },
|
|
71
|
+
capabilities: { get: getTodo, archive: archiveTodo },
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Keep a capability off HTTP entirely.
|
|
75
|
+
const rotateKeys = todo({ id: "admin.rotate-keys", meta: { http: false } });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
> **requireExplicitRoutes**
|
|
79
|
+
>
|
|
80
|
+
> Set it to `true` on a public mount. The server then refuses to start if any exposed capability is relying on a derived route, which turns "we forgot to design that URL" into a startup error instead of a shipped one.
|
|
81
|
+
|
|
82
|
+
## OpenAPI [#openapi]
|
|
83
|
+
|
|
84
|
+
The document is generated from the same schemas: path parameters, query parameters for `GET`, request bodies, the success response with its status, and one response per declared error status. Descriptions come from `title` and `description`.
|
|
85
|
+
|
|
86
|
+
Because it is derived, it cannot drift from the implementation. There is no separate spec to update.
|
|
87
|
+
|
|
88
|
+
## Errors and representations [#responses]
|
|
89
|
+
|
|
90
|
+
Declared errors are serialized with their code, message, status, and validated data. Undeclared failures become a 500 with `INTERNAL_SERVER_ERROR` and no details.
|
|
91
|
+
|
|
92
|
+
```ts title="404 response"
|
|
93
|
+
{
|
|
94
|
+
"ok": false,
|
|
95
|
+
"error": {
|
|
96
|
+
"code": "NOT_FOUND",
|
|
97
|
+
"message": "Todo not found",
|
|
98
|
+
"status": 404,
|
|
99
|
+
"data": { "todoId": "t_123" }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
If a capability defines `toPresentation`, requesting `text/markdown` returns a Markdown lowering of the same canonical output. Markdown and tables are rendered directly, images become labeled placeholders, and files become links.
|
|
105
|
+
|
|
106
|
+
```sh title="terminal"
|
|
107
|
+
curl http://localhost:3000/api/todos/list \
|
|
108
|
+
-H 'accept: text/markdown'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
</DocsPage>
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "MCP"
|
|
3
|
+
description: "Expose capabilities to any MCP client as tools with schemas and safety hints."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { DocsPage, docMetadata } from "../../_components/docs-page";
|
|
7
|
+
|
|
8
|
+
export const metadata = docMetadata("/surfaces/mcp", frontmatter);
|
|
9
|
+
|
|
10
|
+
<DocsPage href="/surfaces/mcp" frontmatter={frontmatter}>
|
|
11
|
+
|
|
12
|
+
The MCP mount serves your capabilities as stateless MCP tools over Streamable HTTP. Modern clients use the sessionless MCP 2026-07-28 lifecycle, while older clients use the legacy handshake without requiring server-side session storage. Tool names, input and output schemas, descriptions, and safety hints are all derived from the app, so an agent sees the same contract your code does.
|
|
13
|
+
|
|
14
|
+
## Mount it [#mount]
|
|
15
|
+
|
|
16
|
+
`cap dev` and the toolchain's default production build already mount MCP at `/mcp`, so a contextless app needs no server file to expose tools. Mount it explicitly when you add a `capable.server.ts`, or when you want a different path or name.
|
|
17
|
+
|
|
18
|
+
```ts title="capable.server.ts"
|
|
19
|
+
import { mcp } from "capable-kit/mcp";
|
|
20
|
+
import { protocol, createServer } from "capable-kit/server";
|
|
21
|
+
import definition from "./capable.app";
|
|
22
|
+
|
|
23
|
+
export default createServer(definition, {
|
|
24
|
+
context: ({ request }) => contextFromRequest(request),
|
|
25
|
+
mounts: [protocol(), mcp({ path: "/mcp", name: "todos" })],
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
| Option | Default | Effect |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| `path` | `/mcp` | Endpoint path |
|
|
32
|
+
| `name` | App name | Server name reported during connection setup |
|
|
33
|
+
| `version` | App version | Server version reported during connection setup |
|
|
34
|
+
|
|
35
|
+
## What an agent sees [#derivation]
|
|
36
|
+
|
|
37
|
+
| Authored | Tool field |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| App path `todos.get` | `todos__get` |
|
|
40
|
+
| `title` | Tool title |
|
|
41
|
+
| `description` | Tool description |
|
|
42
|
+
| `input` | JSON Schema for arguments |
|
|
43
|
+
| `output` | Structured output schema |
|
|
44
|
+
| `effect: "read"` | `readOnlyHint` |
|
|
45
|
+
| `effect: "destructive"` | `destructiveHint` |
|
|
46
|
+
|
|
47
|
+
```ts title="capabilities.ts"
|
|
48
|
+
const getTodo = todo({
|
|
49
|
+
id: "todos.get",
|
|
50
|
+
title: "Get a todo",
|
|
51
|
+
description: "Returns one todo with its owner and due date.",
|
|
52
|
+
effect: "read",
|
|
53
|
+
input: z.object({ todoId: z.string() }),
|
|
54
|
+
output: Todo,
|
|
55
|
+
meta: {
|
|
56
|
+
mcp: { name: "todos_get" }, // default is the app path: todos__get
|
|
57
|
+
// mcp: false, // never expose this capability as a tool
|
|
58
|
+
},
|
|
59
|
+
handler: ({ input, context }) => context.todos.get(input.todoId),
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
> **Descriptions are part of the API now**
|
|
64
|
+
>
|
|
65
|
+
> An agent chooses tools by reading them. A precise `description` is as load-bearing as the input schema, and it is written once for every surface instead of separately for each one.
|
|
66
|
+
|
|
67
|
+
## Rich tool results [#presentation]
|
|
68
|
+
|
|
69
|
+
MCP requests a capability's optional `toPresentation` result and lowers the portable parts into native content. The capability does not author MCP content blocks directly.
|
|
70
|
+
|
|
71
|
+
| Presentation part | MCP result |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| Markdown | Text content |
|
|
74
|
+
| Table | Markdown table as text content |
|
|
75
|
+
| Image | Alt text followed by image content |
|
|
76
|
+
| File | Resource link with its name and metadata |
|
|
77
|
+
|
|
78
|
+
The canonical output remains available as the tool's structured content. This lets an agent inspect exact data while a client displays the richer view. See [Presentations](/concepts/presentations) for the surface-neutral API.
|
|
79
|
+
|
|
80
|
+
## Expose less than everything [#scope]
|
|
81
|
+
|
|
82
|
+
Most apps should not offer their whole tree to an agent. Set `meta.mcp: false` on the capabilities that are never tools, and narrow a projected app with `selectApp()`.
|
|
83
|
+
|
|
84
|
+
```ts title="tools.ts"
|
|
85
|
+
import { selectApp } from "capable-kit";
|
|
86
|
+
import { createMcp } from "capable-kit/mcp";
|
|
87
|
+
|
|
88
|
+
const agentApp = selectApp(app, { exclude: { admin: true } });
|
|
89
|
+
const tools = await createMcp(agentApp);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Tools without a server [#tools]
|
|
93
|
+
|
|
94
|
+
`createMcp()` returns plain tool descriptors you can host yourself — over stdio, inside a test, or in another MCP server.
|
|
95
|
+
|
|
96
|
+
```ts title="tools.ts"
|
|
97
|
+
import { createMcp } from "capable-kit/mcp";
|
|
98
|
+
|
|
99
|
+
const tools = await createMcp(app);
|
|
100
|
+
|
|
101
|
+
for (const tool of tools) {
|
|
102
|
+
console.log(tool.name, tool.annotations);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
await tools[0].call({ todoId: "t_123" });
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
For an agent running in the same process, skip MCP entirely and use [native Eve tools](/surfaces/eve).
|
|
109
|
+
|
|
110
|
+
</DocsPage>
|