capable-kit 0.0.1-alpha.6 → 0.0.1-alpha.8
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/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 +12 -9
- 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 +2 -2
- package/dist/core.mjs +1 -1
- package/dist/eve.d.mts +1 -1
- package/dist/eve.mjs +1 -1
- package/dist/http.d.mts +2 -2
- package/dist/http.mjs +2 -2
- package/dist/{index-DwXlaTXI.d.mts → index-Dl4NK9G0.d.mts} +20 -4
- package/dist/{index-Dbc4g9WM.d.mts → index-F4ba_olD.d.mts} +3 -3
- package/dist/{index-Be8-UVBC.d.mts → index-_qKFfWV4.d.mts} +4 -2
- package/dist/{index-D2CRRUzH.d.mts → index-hdH_K5Zc.d.mts} +6 -5
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/mcp.d.mts +35 -5
- package/dist/mcp.mjs +1 -1
- package/dist/mount-CEFAplR5.mjs +227 -0
- package/dist/mount-CEFAplR5.mjs.map +1 -0
- package/dist/next.d.mts +14 -0
- package/dist/next.mjs +16 -0
- package/dist/next.mjs.map +1 -0
- package/dist/react-query.d.mts +34 -0
- package/dist/react-query.mjs +47 -0
- package/dist/react-query.mjs.map +1 -0
- package/dist/runtime-support.d.mts +1 -1
- package/dist/runtime-support.mjs +8 -8
- package/dist/runtime-support.mjs.map +1 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.mjs +1 -1
- package/dist/{src-CDxL6w3d.mjs → src-BWxDO2Ua.mjs} +9 -6
- package/dist/src-BWxDO2Ua.mjs.map +1 -0
- package/dist/{src-DdV82An-.mjs → src-D-cm2gQ6.mjs} +6 -3
- package/dist/src-D-cm2gQ6.mjs.map +1 -0
- package/dist/{src-Db6-XSnU.mjs → src-D_0PIhqq.mjs} +3 -3
- package/dist/{src-Db6-XSnU.mjs.map → src-D_0PIhqq.mjs.map} +1 -1
- package/dist/{src-C2MGIlT0.mjs → src-betOfnDL.mjs} +25 -8
- package/dist/src-betOfnDL.mjs.map +1 -0
- package/dist/{src-BF70JLxI.mjs → src-rkr5j_NH.mjs} +162 -33
- package/dist/src-rkr5j_NH.mjs.map +1 -0
- package/dist/{subscription-Bq792Ad2.d.mts → subscription-B-auXJbm.d.mts} +2 -2
- package/dist/swr.d.mts +36 -0
- package/dist/swr.mjs +48 -0
- package/dist/swr.mjs.map +1 -0
- package/docs/CONTEXT.md +3 -1
- package/docs/internal/adr/0002-version-the-capable-value-codec.md +24 -0
- package/docs/internal/architecture.md +34 -3
- package/docs/internal/capability-first-model.md +1 -1
- package/docs/internal/implementation-friction.md +110 -0
- package/docs/site/capable-orpc-and-trpc.mdx +3 -3
- package/docs/site/concepts/apps.mdx +10 -7
- package/docs/site/concepts/architecture.mdx +1 -1
- package/docs/site/hosting/any-fetch-host.mdx +2 -2
- package/docs/site/hosting/next-js.mdx +38 -4
- package/docs/site/hosting/standalone-server.mdx +2 -2
- package/docs/site/introduction.mdx +9 -6
- package/docs/site/patterns/composition.mdx +7 -3
- package/docs/site/patterns/remote-apps.mdx +62 -8
- package/docs/site/patterns/subscriptions.mdx +2 -2
- package/docs/site/quickstart.mdx +18 -13
- package/docs/site/reference/packages-and-entry-points.mdx +2 -2
- package/docs/site/reference/surface-metadata.mdx +7 -2
- package/docs/site/reference/the-cap-cli.mdx +2 -2
- package/docs/site/surfaces/ai-sdk.mdx +3 -3
- package/docs/site/surfaces/cli.mdx +3 -3
- package/docs/site/surfaces/eve.mdx +5 -5
- package/docs/site/surfaces/mcp.mdx +73 -5
- package/docs/site/surfaces/react-query.mdx +3 -3
- package/docs/site/surfaces/swr.mdx +3 -3
- package/docs/site/surfaces/typescript.mdx +5 -5
- package/docs/site/surfaces.mdx +1 -1
- package/package-docs.mjs +137 -0
- package/package.json +7 -3
- package/prepare-package.mjs +21 -0
- package/src/mcp.ts +4 -0
- package/src/package.test.ts +44 -8
- package/verify-package-exports.mjs +37 -0
- package/dist/mount-xvMsjz1B.mjs +0 -178
- package/dist/mount-xvMsjz1B.mjs.map +0 -1
- package/dist/src-BF70JLxI.mjs.map +0 -1
- package/dist/src-C2MGIlT0.mjs.map +0 -1
- package/dist/src-CDxL6w3d.mjs.map +0 -1
- package/dist/src-DdV82An-.mjs.map +0 -1
package/docs/site/quickstart.mdx
CHANGED
|
@@ -44,13 +44,16 @@ Capable works two ways: as its own service, or embedded in an app you already ha
|
|
|
44
44
|
handler: ({ input }) => ({ id: "1", title: input.title }),
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const definition = defineApp({
|
|
48
48
|
name: "Todos",
|
|
49
49
|
version: "1.0.0",
|
|
50
50
|
capabilities: {
|
|
51
51
|
todos: { list: listTodos, create: createTodo },
|
|
52
52
|
},
|
|
53
53
|
});
|
|
54
|
+
|
|
55
|
+
export type AppDefinition = typeof definition;
|
|
56
|
+
export default definition;
|
|
54
57
|
```
|
|
55
58
|
|
|
56
59
|
> This starts with the minimum useful contract. The list Capability declares `effect: "read"` only because HTTP and tool projections need its read-only intent. Add an `output` schema when you need runtime output validation or a portable output contract.
|
|
@@ -65,7 +68,7 @@ Capable works two ways: as its own service, or embedded in an app you already ha
|
|
|
65
68
|
◆ Todos 1.0.0
|
|
66
69
|
|
|
67
70
|
Local http://localhost:3000
|
|
68
|
-
Capable
|
|
71
|
+
Capable /~capable
|
|
69
72
|
HTTP /api
|
|
70
73
|
OpenAPI /openapi.json
|
|
71
74
|
MCP /mcp
|
|
@@ -167,18 +170,17 @@ Capable works two ways: as its own service, or embedded in an app you already ha
|
|
|
167
170
|
|
|
168
171
|
7. ### Call it from another process
|
|
169
172
|
|
|
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
|
|
173
|
+
Swap `createApp()` for `createRemoteApp()` and the calls are identical—only placement changed. The manifest is discovered lazily on first use, and types come from the named definition type.
|
|
171
174
|
|
|
172
175
|
```ts title="remote.ts"
|
|
173
176
|
import { createRemoteApp } from "capable-kit";
|
|
174
177
|
import { createHttpTransport } from "capable-kit/http";
|
|
175
|
-
import type
|
|
178
|
+
import type { AppDefinition } from "./capable.app";
|
|
176
179
|
|
|
177
180
|
// Same tree, same types, same errors — executed on the server.
|
|
178
|
-
|
|
179
|
-
const app = createRemoteApp<typeof definition>(
|
|
181
|
+
const app = createRemoteApp<AppDefinition>(
|
|
180
182
|
createHttpTransport({
|
|
181
|
-
url: process.env.CAPABLE_URL ?? "http://localhost:3000/
|
|
183
|
+
url: process.env.CAPABLE_URL ?? "http://localhost:3000/~capable/",
|
|
182
184
|
headers: () => ({ authorization: `Bearer ${process.env.TOKEN}` }),
|
|
183
185
|
}),
|
|
184
186
|
);
|
|
@@ -254,12 +256,15 @@ Capable works two ways: as its own service, or embedded in an app you already ha
|
|
|
254
256
|
handler: ({ input }) => ({ id: "1", title: input.title }),
|
|
255
257
|
});
|
|
256
258
|
|
|
257
|
-
|
|
259
|
+
const definition = defineApp({
|
|
258
260
|
name: "Todos",
|
|
259
261
|
capabilities: {
|
|
260
262
|
todos: { list: listTodos, create: createTodo },
|
|
261
263
|
},
|
|
262
264
|
});
|
|
265
|
+
|
|
266
|
+
export type AppDefinition = typeof definition;
|
|
267
|
+
export default definition;
|
|
263
268
|
```
|
|
264
269
|
|
|
265
270
|
> Output types are inferred from handlers. Portable output schemas, effects, descriptions, errors, middleware, and surface metadata are opt-in.
|
|
@@ -308,7 +313,7 @@ Capable works two ways: as its own service, or embedded in an app you already ha
|
|
|
308
313
|
// app/api/[[...path]]/route.ts
|
|
309
314
|
export { DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT } from "@/capable/server";
|
|
310
315
|
|
|
311
|
-
// app
|
|
316
|
+
// app/~capable/[[...path]]/route.ts
|
|
312
317
|
export { GET, POST } from "@/capable/server";
|
|
313
318
|
```
|
|
314
319
|
|
|
@@ -347,16 +352,16 @@ Capable works two ways: as its own service, or embedded in an app you already ha
|
|
|
347
352
|
|
|
348
353
|
6. ### Call from React Query
|
|
349
354
|
|
|
350
|
-
`capable-kit/react-query` mirrors the app tree into query keys and options. The browser talks to the Capable transport at
|
|
355
|
+
`capable-kit/react-query` mirrors the app tree into query keys and options. The browser talks to the Capable transport at `/~capable`.
|
|
351
356
|
|
|
352
357
|
```ts title="app/query.ts"
|
|
353
358
|
import { createRemoteApp } from "capable-kit";
|
|
354
359
|
import { createHttpTransport } from "capable-kit/http";
|
|
355
360
|
import { createReactQuery } from "capable-kit/react-query";
|
|
356
|
-
import type
|
|
361
|
+
import type { AppDefinition } from "../capable/app";
|
|
357
362
|
|
|
358
|
-
const app = createRemoteApp<
|
|
359
|
-
createHttpTransport({ url: "/
|
|
363
|
+
const app = createRemoteApp<AppDefinition>(
|
|
364
|
+
createHttpTransport({ url: "/~capable/" }),
|
|
360
365
|
);
|
|
361
366
|
|
|
362
367
|
export const query = createReactQuery(app);
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
| --- | --- |
|
|
40
40
|
| `capable-kit` | Capability authoring, app definitions, executable and remote apps, composition, and the capable command |
|
|
41
41
|
| `capable-kit/server` | `createServer()` plus the `protocol()` and `http()` mounts |
|
|
42
|
-
| `capable-kit/http` | Capable transport
|
|
42
|
+
| `capable-kit/http` | Capable transport and HTTP projection: `createHttpTransport()`, `createHttpHandler()`, `defineProtocolCodec()` |
|
|
43
43
|
| `capable-kit/cli` | `createCli()` |
|
|
44
44
|
| `capable-kit/mcp` | `createMcp()` and the `mcp()` server mount |
|
|
45
45
|
| `capable-kit/eve` | `createEveTools()` |
|
|
@@ -63,7 +63,7 @@ import {
|
|
|
63
63
|
| `defineApp()` | `defineApp({ name, version, capabilities })` | Immutable definition, no context |
|
|
64
64
|
| `group()` | `group({ middleware, errors, meta, capabilities })` | Anonymous decorated subtree |
|
|
65
65
|
| `createApp()` | `createApp(definition)` | Callable tree; context options exist only when declared |
|
|
66
|
-
| `createRemoteApp()` | `createRemoteApp<
|
|
66
|
+
| `createRemoteApp()` | `createRemoteApp<AppDefinition>(transport)` | Lazy, transport-backed remote placement |
|
|
67
67
|
| `mergeApps()` | `mergeApps(a, b, ...)` | Root-tree merge, dispatch by id |
|
|
68
68
|
| `selectApp()` | `selectApp(app, { include, exclude })` | Exclude wins over include |
|
|
69
69
|
| `subscribe()` | `subscribe(app.todos.list, input, { signal })` | Async iterator of replacements |
|
|
@@ -21,7 +21,12 @@ const deleteTodo = todo({
|
|
|
21
21
|
meta: {
|
|
22
22
|
http: { method: "DELETE", route: "/:todoId", status: 200 },
|
|
23
23
|
cli: { positional: ["todoId"] },
|
|
24
|
-
mcp: {
|
|
24
|
+
mcp: {
|
|
25
|
+
name: "todos_delete",
|
|
26
|
+
idempotentHint: true,
|
|
27
|
+
openWorldHint: false,
|
|
28
|
+
icons: [{ src: "https://example.com/delete.svg" }],
|
|
29
|
+
},
|
|
25
30
|
aiSdk: { name: "todos_delete", strict: true },
|
|
26
31
|
eve: false,
|
|
27
32
|
},
|
|
@@ -43,7 +48,7 @@ const todos = group({
|
|
|
43
48
|
| --- | --- | --- |
|
|
44
49
|
| `http` | `false \| { method, route, status }` | Overrides the derived route. `false` removes the capability from HTTP. `route` may contain `:params` that must exist in the input schema. |
|
|
45
50
|
| `cli` | `false \| { name, command, positional }` | `positional` promotes input fields to arguments, `name` renames the command, `command` replaces the whole path. |
|
|
46
|
-
| `mcp` | `false \| { name }` | Renames the tool. Default is the app path joined with `__`. |
|
|
51
|
+
| `mcp` | `false \| { name, icons, idempotentHint, openWorldHint }` | Renames, decorates, or hides the MCP tool. Default name is the app path joined with `__`; the canonical Capability ID remains available in tool `_meta`. |
|
|
47
52
|
| `eve` | `false \| { name }` | Same, for native in-process Eve tools. |
|
|
48
53
|
| `aiSdk` | `false \| { name, strict }` | Renames, constrains, or hides an AI SDK tool. |
|
|
49
54
|
|
|
@@ -31,7 +31,7 @@ pnpm dev
|
|
|
31
31
|
| Command | Description |
|
|
32
32
|
| --- | --- |
|
|
33
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
|
|
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
35
|
| `build` | Builds the project into `.output`. Presets are Nitro deployment presets, for example `node-server` or `vercel`. |
|
|
36
36
|
| `preview` | Runs a previously built `node-server` output. Other presets do not produce a locally runnable command. |
|
|
37
37
|
| `cli` | Runs the app's derived command tree without writing a CLI entry point. |
|
|
@@ -65,7 +65,7 @@ cap cli --app ./ todos list
|
|
|
65
65
|
cap cli --app https://todos.example.com todos list
|
|
66
66
|
```
|
|
67
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
|
|
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
69
|
|
|
70
70
|
| Option | Applies to | Meaning |
|
|
71
71
|
| --- | --- | --- |
|
|
@@ -74,10 +74,10 @@ Conversion reads the App manifest rather than the original live schema objects,
|
|
|
74
74
|
import { createRemoteApp } from "capable-kit";
|
|
75
75
|
import { createAiSdkTools } from "capable-kit/ai-sdk";
|
|
76
76
|
import { createHttpTransport } from "capable-kit/http";
|
|
77
|
-
import type
|
|
77
|
+
import type { AppDefinition } from "./capable.app";
|
|
78
78
|
|
|
79
|
-
const app = createRemoteApp<
|
|
80
|
-
createHttpTransport({ url: "https://todos.example.com/
|
|
79
|
+
const app = createRemoteApp<AppDefinition>(
|
|
80
|
+
createHttpTransport({ url: "https://todos.example.com/~capable/" }),
|
|
81
81
|
);
|
|
82
82
|
|
|
83
83
|
export const tools = await createAiSdkTools(app);
|
|
@@ -107,11 +107,11 @@ A remote app produces an identical command tree, because help and arguments are
|
|
|
107
107
|
import { createRemoteApp } from "capable-kit";
|
|
108
108
|
import { createCli } from "capable-kit/cli";
|
|
109
109
|
import { createHttpTransport } from "capable-kit/http";
|
|
110
|
-
import type
|
|
110
|
+
import type { AppDefinition } from "./capable.app";
|
|
111
111
|
|
|
112
|
-
const remote = createRemoteApp<
|
|
112
|
+
const remote = createRemoteApp<AppDefinition>(
|
|
113
113
|
createHttpTransport({
|
|
114
|
-
url: process.env.CAPABLE_URL ?? "http://localhost:3000/
|
|
114
|
+
url: process.env.CAPABLE_URL ?? "http://localhost:3000/~capable/",
|
|
115
115
|
headers: () => ({ authorization: `Bearer ${readToken()}` }),
|
|
116
116
|
}),
|
|
117
117
|
);
|
|
@@ -57,7 +57,7 @@ cap preview # run that production build locally
|
|
|
57
57
|
cap build --preset vercel
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
The standalone server exposes the Capable transport at
|
|
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
61
|
|
|
62
62
|
## Point Eve at the remote app [#remote]
|
|
63
63
|
|
|
@@ -68,11 +68,11 @@ import { createRemoteApp } from "capable-kit";
|
|
|
68
68
|
import { createEveTools } from "capable-kit/eve";
|
|
69
69
|
import { createHttpTransport } from "capable-kit/http";
|
|
70
70
|
import { always } from "eve/tools/approval";
|
|
71
|
-
import type
|
|
71
|
+
import type { AppDefinition } from "../../capable.app";
|
|
72
72
|
|
|
73
|
-
const app = createRemoteApp<
|
|
73
|
+
const app = createRemoteApp<AppDefinition>(
|
|
74
74
|
createHttpTransport({
|
|
75
|
-
url: "https://todos.example.com/
|
|
75
|
+
url: "https://todos.example.com/~capable/",
|
|
76
76
|
}),
|
|
77
77
|
);
|
|
78
78
|
|
|
@@ -91,7 +91,7 @@ export default createEveTools(app, {
|
|
|
91
91
|
|
|
92
92
|
> **The definition import is type-only**
|
|
93
93
|
>
|
|
94
|
-
> Eve imports
|
|
94
|
+
> Eve imports the named `AppDefinition` type, but it does not execute the local handlers. Discovery and calls go through the remote transport.
|
|
95
95
|
|
|
96
96
|
## Approvals from effect [#approvals]
|
|
97
97
|
|
|
@@ -22,7 +22,23 @@ import definition from "./capable.app";
|
|
|
22
22
|
|
|
23
23
|
export default createServer(definition, {
|
|
24
24
|
context: ({ request }) => contextFromRequest(request),
|
|
25
|
-
mounts: [
|
|
25
|
+
mounts: [
|
|
26
|
+
protocol(),
|
|
27
|
+
mcp({
|
|
28
|
+
path: "/mcp",
|
|
29
|
+
name: "todos",
|
|
30
|
+
title: "Todo tools",
|
|
31
|
+
description: "Read and manage the current user's todos.",
|
|
32
|
+
websiteUrl: "https://example.com/todos",
|
|
33
|
+
icons: [{ src: "https://example.com/todos.svg" }],
|
|
34
|
+
instructions: "Use these tools to manage the current user's todos.",
|
|
35
|
+
selection: { exclude: { admin: true } },
|
|
36
|
+
cache: {
|
|
37
|
+
discovery: { ttlMs: 60_000, cacheScope: "private" },
|
|
38
|
+
tools: { ttlMs: 300_000, cacheScope: "private" },
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
26
42
|
});
|
|
27
43
|
```
|
|
28
44
|
|
|
@@ -31,6 +47,14 @@ export default createServer(definition, {
|
|
|
31
47
|
| `path` | `/mcp` | Endpoint path |
|
|
32
48
|
| `name` | App name | Server name reported during connection setup |
|
|
33
49
|
| `version` | App version | Server version reported during connection setup |
|
|
50
|
+
| `title` | None | Human-readable server name |
|
|
51
|
+
| `description` | App description | Server description shown by supporting clients |
|
|
52
|
+
| `websiteUrl` | None | Server website shown by supporting clients |
|
|
53
|
+
| `icons` | None | Server icons shown by supporting clients |
|
|
54
|
+
| `instructions` | None | Guidance every MCP client receives during connection setup |
|
|
55
|
+
| `selection` | Everything | Capability tree exposed as tools; exclude wins over include |
|
|
56
|
+
| `cache.discovery` | `0 ms`, private | Modern-client cache hint for server discovery |
|
|
57
|
+
| `cache.tools` | `0 ms`, private | Modern-client cache hint for the tool list |
|
|
34
58
|
|
|
35
59
|
## What an agent sees [#derivation]
|
|
36
60
|
|
|
@@ -41,8 +65,15 @@ export default createServer(definition, {
|
|
|
41
65
|
| `description` | Tool description |
|
|
42
66
|
| `input` | JSON Schema for arguments |
|
|
43
67
|
| `output` | Structured output schema |
|
|
44
|
-
| `effect: "read"` | `readOnlyHint` |
|
|
45
|
-
| `effect: "
|
|
68
|
+
| `effect: "read"` | `readOnlyHint: true`, `destructiveHint: false` |
|
|
69
|
+
| `effect: "write"` | `readOnlyHint: false`, `destructiveHint: false` |
|
|
70
|
+
| `effect: "destructive"` | `readOnlyHint: false`, `destructiveHint: true` |
|
|
71
|
+
| `meta.mcp.icons` | Tool icons |
|
|
72
|
+
| `meta.mcp.idempotentHint` | Idempotence hint |
|
|
73
|
+
| `meta.mcp.openWorldHint` | Whether the tool may interact beyond a closed domain |
|
|
74
|
+
|
|
75
|
+
`idempotentHint` is meaningful only for tools that are not read-only. Omitted
|
|
76
|
+
`openWorldHint` uses MCP's default of `true`.
|
|
46
77
|
|
|
47
78
|
```ts title="capabilities.ts"
|
|
48
79
|
const getTodo = todo({
|
|
@@ -53,13 +84,34 @@ const getTodo = todo({
|
|
|
53
84
|
input: z.object({ todoId: z.string() }),
|
|
54
85
|
output: Todo,
|
|
55
86
|
meta: {
|
|
56
|
-
mcp: {
|
|
87
|
+
mcp: {
|
|
88
|
+
name: "todos_get", // default is the app path: todos__get
|
|
89
|
+
icons: [{ src: "https://example.com/todo.svg" }],
|
|
90
|
+
openWorldHint: false,
|
|
91
|
+
},
|
|
57
92
|
// mcp: false, // never expose this capability as a tool
|
|
58
93
|
},
|
|
59
94
|
handler: ({ input, context }) => context.todos.get(input.todoId),
|
|
60
95
|
});
|
|
61
96
|
```
|
|
62
97
|
|
|
98
|
+
The tool name is a portable wire name derived from the Application path; it is
|
|
99
|
+
not the Capability's canonical identity. Every derived tool also exposes that
|
|
100
|
+
identity as `_meta["dev.capable/capabilityId"]`:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"name": "todos__get",
|
|
105
|
+
"_meta": {
|
|
106
|
+
"dev.capable/capabilityId": "todos.get"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Clients call the tool by `name`. The metadata makes logs, inspectors, and
|
|
112
|
+
cross-surface tooling able to associate that name with the Capability without
|
|
113
|
+
guessing from delimiters.
|
|
114
|
+
|
|
63
115
|
> **Descriptions are part of the API now**
|
|
64
116
|
>
|
|
65
117
|
> 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.
|
|
@@ -77,9 +129,25 @@ MCP requests a capability's optional `toPresentation` result and lowers the port
|
|
|
77
129
|
|
|
78
130
|
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
131
|
|
|
132
|
+
Modern MCP 2026-07-28 clients receive the canonical JSON value directly, so an
|
|
133
|
+
array output remains an array. For a legacy client, the MCP SDK wraps a
|
|
134
|
+
non-object value under `result` and projects the advertised output schema the
|
|
135
|
+
same way. Clients should follow the tool's `outputSchema` rather than assume
|
|
136
|
+
that every MCP protocol revision has the same envelope.
|
|
137
|
+
|
|
80
138
|
## Expose less than everything [#scope]
|
|
81
139
|
|
|
82
|
-
Most apps should not offer their whole tree to an agent. Set `meta.mcp: false` on
|
|
140
|
+
Most apps should not offer their whole tree to an agent. Set `meta.mcp: false` on capabilities that are never tools. Use mount selection when one MCP endpoint should expose only part of the tree:
|
|
141
|
+
|
|
142
|
+
```ts title="capable.server.ts"
|
|
143
|
+
mcp({ selection: { exclude: { admin: true } } });
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Selection paths are checked against the resolved App manifest. A misspelled or
|
|
147
|
+
stale path in either `include` or `exclude` fails discovery instead of silently
|
|
148
|
+
exposing a different tool set.
|
|
149
|
+
|
|
150
|
+
Use `selectApp()` when creating standalone tool descriptors without the mount:
|
|
83
151
|
|
|
84
152
|
```ts title="tools.ts"
|
|
85
153
|
import { selectApp } from "capable-kit";
|
|
@@ -23,10 +23,10 @@ pnpm add capable-kit @tanstack/react-query
|
|
|
23
23
|
import { createRemoteApp } from "capable-kit";
|
|
24
24
|
import { createHttpTransport } from "capable-kit/http";
|
|
25
25
|
import { createReactQuery } from "capable-kit/react-query";
|
|
26
|
-
import type
|
|
26
|
+
import type { AppDefinition } from "../capable.app";
|
|
27
27
|
|
|
28
|
-
const app = createRemoteApp<
|
|
29
|
-
createHttpTransport({ url: "/
|
|
28
|
+
const app = createRemoteApp<AppDefinition>(
|
|
29
|
+
createHttpTransport({ url: "/~capable/" }),
|
|
30
30
|
);
|
|
31
31
|
|
|
32
32
|
export const query = createReactQuery(app);
|
|
@@ -26,10 +26,10 @@ pnpm add capable-kit swr
|
|
|
26
26
|
import { createRemoteApp } from "capable-kit";
|
|
27
27
|
import { createHttpTransport } from "capable-kit/http";
|
|
28
28
|
import { createSWR } from "capable-kit/swr";
|
|
29
|
-
import type
|
|
29
|
+
import type { AppDefinition } from "../capable.app";
|
|
30
30
|
|
|
31
|
-
const app = createRemoteApp<
|
|
32
|
-
createHttpTransport({ url: "/
|
|
31
|
+
const app = createRemoteApp<AppDefinition>(
|
|
32
|
+
createHttpTransport({ url: "/~capable/" }),
|
|
33
33
|
);
|
|
34
34
|
|
|
35
35
|
export const capableSWR = createSWR(app);
|
|
@@ -35,16 +35,16 @@ await app.todos.create({ title: "Write the docs" });
|
|
|
35
35
|
|
|
36
36
|
## Calling a remote app [#remote]
|
|
37
37
|
|
|
38
|
-
[A remote app](/patterns/remote-apps) has the identical shape.
|
|
38
|
+
[A remote app](/patterns/remote-apps) has the identical shape. Import the definition's named `AppDefinition` type, so nothing from the server bundles into the caller and no client is generated.
|
|
39
39
|
|
|
40
40
|
```ts title="client.ts"
|
|
41
41
|
import { createRemoteApp } from "capable-kit";
|
|
42
42
|
import { createHttpTransport } from "capable-kit/http";
|
|
43
|
-
import type
|
|
43
|
+
import type { AppDefinition } from "../server/capable.app";
|
|
44
44
|
|
|
45
45
|
// Same tree, same types, different placement.
|
|
46
|
-
const app = createRemoteApp<
|
|
47
|
-
createHttpTransport({ url: "https://todos.example.com/
|
|
46
|
+
const app = createRemoteApp<AppDefinition>(
|
|
47
|
+
createHttpTransport({ url: "https://todos.example.com/~capable/" }),
|
|
48
48
|
);
|
|
49
49
|
|
|
50
50
|
const todos = await app.todos.list({ status: "open" });
|
|
@@ -116,7 +116,7 @@ const todos = await executeCapability(listTodos, {
|
|
|
116
116
|
|
|
117
117
|
| Not this | Instead |
|
|
118
118
|
| --- | --- |
|
|
119
|
-
| A generated SDK | Types come from
|
|
119
|
+
| A generated SDK | Types come from the named `AppDefinition` type; the tree is a proxy built from the manifest. |
|
|
120
120
|
| A place for presentation | Titles, routes, and tool names belong to [surface metadata](/reference/metadata), not to the call. |
|
|
121
121
|
| A cache or a UI binding | Use [React Query](/surfaces/react-query) for keys, caching, and live queries in a React app. |
|
|
122
122
|
|
package/docs/site/surfaces.mdx
CHANGED
|
@@ -23,7 +23,7 @@ import definition from "./capable.app";
|
|
|
23
23
|
export default createServer(definition, {
|
|
24
24
|
context: ({ request }) => contextFromRequest(request),
|
|
25
25
|
mounts: [
|
|
26
|
-
protocol(
|
|
26
|
+
protocol(),
|
|
27
27
|
http({ path: "/api", openapiPath: "/openapi.json" }),
|
|
28
28
|
mcp({ path: "/mcp" }),
|
|
29
29
|
],
|
package/package-docs.mjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import {
|
|
3
|
+
cp,
|
|
4
|
+
mkdir,
|
|
5
|
+
readdir,
|
|
6
|
+
readFile,
|
|
7
|
+
rm,
|
|
8
|
+
writeFile,
|
|
9
|
+
} from "node:fs/promises";
|
|
10
|
+
import { dirname, join, relative } from "node:path";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
|
|
13
|
+
const repositoryDirectory = new URL("../../", import.meta.url);
|
|
14
|
+
const outputDirectory = new URL("./docs/", import.meta.url);
|
|
15
|
+
const canonicalSiteDirectory = new URL("./website/app/", repositoryDirectory);
|
|
16
|
+
const packagedSiteDirectory = new URL("./site/", outputDirectory);
|
|
17
|
+
const canonicalDocumentationAvailable = [
|
|
18
|
+
new URL("./CONTEXT.md", repositoryDirectory),
|
|
19
|
+
new URL("./docs/", repositoryDirectory),
|
|
20
|
+
canonicalSiteDirectory,
|
|
21
|
+
].every(existsSync);
|
|
22
|
+
|
|
23
|
+
async function findPages(directory) {
|
|
24
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
25
|
+
const nested = await Promise.all(
|
|
26
|
+
entries.map((entry) => {
|
|
27
|
+
const path = join(directory, entry.name);
|
|
28
|
+
if (entry.isDirectory()) return findPages(path);
|
|
29
|
+
return entry.name === "page.mdx" ? [path] : [];
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
return nested.flat();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function titleSlug(source, file) {
|
|
36
|
+
const title = source.match(/^title:\s*"([^"]+)"$/m)?.[1];
|
|
37
|
+
if (!title) throw new Error(`Missing title frontmatter in ${file}`);
|
|
38
|
+
|
|
39
|
+
return title
|
|
40
|
+
.normalize("NFKD")
|
|
41
|
+
.replace(/[\u0300-\u036f]/g, "")
|
|
42
|
+
.replace(/[^a-zA-Z0-9]+/g, "-")
|
|
43
|
+
.replace(/^-|-$/g, "")
|
|
44
|
+
.toLowerCase();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function copyPublicGuides() {
|
|
48
|
+
const sourceRoot = fileURLToPath(canonicalSiteDirectory);
|
|
49
|
+
const outputRoot = fileURLToPath(packagedSiteDirectory);
|
|
50
|
+
|
|
51
|
+
for (const page of await findPages(sourceRoot)) {
|
|
52
|
+
const source = await readFile(page, "utf8");
|
|
53
|
+
const routeDirectory = relative(sourceRoot, dirname(page));
|
|
54
|
+
const section =
|
|
55
|
+
routeDirectory === "" ? "" : dirname(routeDirectory);
|
|
56
|
+
const destinationDirectory = join(
|
|
57
|
+
outputRoot,
|
|
58
|
+
section === "." ? "" : section,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
await mkdir(destinationDirectory, { recursive: true });
|
|
62
|
+
await writeFile(
|
|
63
|
+
join(destinationDirectory, `${titleSlug(source, page)}.mdx`),
|
|
64
|
+
source,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function copyDocumentation() {
|
|
70
|
+
// A tarball can be packed again after installation. In that case the
|
|
71
|
+
// canonical repository sources are absent and the included docs are already
|
|
72
|
+
// the correct input.
|
|
73
|
+
if (!canonicalDocumentationAvailable) {
|
|
74
|
+
if (existsSync(outputDirectory)) return;
|
|
75
|
+
throw new Error("Could not find Capable's canonical documentation sources.");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
await rm(outputDirectory, { force: true, recursive: true });
|
|
79
|
+
await mkdir(outputDirectory, { recursive: true });
|
|
80
|
+
|
|
81
|
+
await Promise.all([
|
|
82
|
+
cp(
|
|
83
|
+
new URL("./docs/", repositoryDirectory),
|
|
84
|
+
new URL("./internal/", outputDirectory),
|
|
85
|
+
{ recursive: true },
|
|
86
|
+
),
|
|
87
|
+
cp(
|
|
88
|
+
new URL("./CONTEXT.md", repositoryDirectory),
|
|
89
|
+
new URL("./CONTEXT.md", outputDirectory),
|
|
90
|
+
),
|
|
91
|
+
copyPublicGuides(),
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
await writeFile(
|
|
95
|
+
new URL("./README.md", outputDirectory),
|
|
96
|
+
`# Capable documentation
|
|
97
|
+
|
|
98
|
+
This directory is assembled from Capable's canonical documentation sources when
|
|
99
|
+
the npm package is packed. It matches the installed package version.
|
|
100
|
+
|
|
101
|
+
## For coding agents
|
|
102
|
+
|
|
103
|
+
Do not rely on remembered Capable APIs. Read the relevant bundled guide and
|
|
104
|
+
inspect \`../src/\` when you need a detail the guides do not cover.
|
|
105
|
+
|
|
106
|
+
Start here:
|
|
107
|
+
|
|
108
|
+
1. [Introduction](./site/introduction.mdx)
|
|
109
|
+
2. [Quickstart](./site/quickstart.mdx)
|
|
110
|
+
3. [Capabilities](./site/concepts/capabilities.mdx)
|
|
111
|
+
4. [Apps](./site/concepts/apps.mdx)
|
|
112
|
+
5. [Surfaces](./site/surfaces.mdx)
|
|
113
|
+
6. [Packages and entry points](./site/reference/packages-and-entry-points.mdx)
|
|
114
|
+
|
|
115
|
+
Public guides are grouped by section and named from their frontmatter titles.
|
|
116
|
+
To find a topic, search the files under \`site/\` or list its \`.mdx\` files.
|
|
117
|
+
|
|
118
|
+
- \`site/\` contains the canonical, human- and agent-readable MDX guides.
|
|
119
|
+
- \`internal/\` contains design notes for contributors.
|
|
120
|
+
- \`CONTEXT.md\` defines the framework's domain language and invariants.
|
|
121
|
+
|
|
122
|
+
The canonical sources live in \`website/\`, \`docs/\`, and \`CONTEXT.md\` in the
|
|
123
|
+
Capable repository. Edit those sources rather than the generated package copy.
|
|
124
|
+
`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function cleanDocumentation() {
|
|
129
|
+
if (!canonicalDocumentationAvailable) return;
|
|
130
|
+
await rm(outputDirectory, { force: true, recursive: true });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (process.argv.includes("--clean")) {
|
|
134
|
+
await cleanDocumentation();
|
|
135
|
+
} else {
|
|
136
|
+
await copyDocumentation();
|
|
137
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "capable-kit",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"cap": "dist/bin.mjs",
|
|
@@ -61,14 +61,17 @@
|
|
|
61
61
|
"dist/*.mjs",
|
|
62
62
|
"dist/*.mjs.map",
|
|
63
63
|
"docs",
|
|
64
|
+
"package-docs.mjs",
|
|
65
|
+
"prepare-package.mjs",
|
|
64
66
|
"src",
|
|
67
|
+
"verify-package-exports.mjs",
|
|
65
68
|
"README.md"
|
|
66
69
|
],
|
|
67
70
|
"directories": {
|
|
68
71
|
"doc": "./docs"
|
|
69
72
|
},
|
|
70
73
|
"scripts": {
|
|
71
|
-
"prepack": "node package
|
|
74
|
+
"prepack": "node prepare-package.mjs",
|
|
72
75
|
"postpack": "node package-docs.mjs --clean"
|
|
73
76
|
},
|
|
74
77
|
"engines": {
|
|
@@ -82,7 +85,8 @@
|
|
|
82
85
|
"@standard-schema/spec": "^1.1.0",
|
|
83
86
|
"@modelcontextprotocol/server": "^2.0.0",
|
|
84
87
|
"markdansi": "0.3.2",
|
|
85
|
-
"nitro": "3.0.260610-beta"
|
|
88
|
+
"nitro": "3.0.260610-beta",
|
|
89
|
+
"superjson": "2.2.6"
|
|
86
90
|
},
|
|
87
91
|
"peerDependencies": {
|
|
88
92
|
"@tanstack/react-query": ">=5.80.2 <6",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const repositorySource = new URL("../../packages/capable/src/index.ts", import.meta.url);
|
|
6
|
+
if (existsSync(repositorySource)) {
|
|
7
|
+
const pnpm = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
|
|
8
|
+
const build = spawnSync(pnpm, ["--dir", "../..", "build"], {
|
|
9
|
+
cwd: fileURLToPath(new URL("./", import.meta.url)),
|
|
10
|
+
encoding: "utf8",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
if (build.status !== 0) {
|
|
14
|
+
process.stderr.write(build.stdout ?? "");
|
|
15
|
+
process.stderr.write(build.stderr ?? "");
|
|
16
|
+
process.exit(build.status ?? 1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
await import("./verify-package-exports.mjs");
|
|
21
|
+
await import("./package-docs.mjs");
|