@brickkit/core 0.1.3 → 0.2.1

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 CHANGED
@@ -26,3 +26,73 @@ export const db = defineDatabase({
26
26
 
27
27
  Bun-only APIs are lazy-loaded, so the package imports cleanly under
28
28
  strict Node ESM too. Source: <https://github.com/Chandraprakash-Darji/brick>.
29
+
30
+ ## Typed client
31
+
32
+ `@brickkit/core/client` (also re-exported from the package root) offers an
33
+ Eden-style HTTP client inferred from your contract type — no OpenAPI codegen:
34
+
35
+ With the Brick Vite plugin configured for your default-exported app, Vite
36
+ creates `_brick/contract.ts` automatically:
37
+
38
+ ```ts
39
+ import { createBrickClient } from "@brickkit/core/client";
40
+ import { contract } from "../_brick/contract";
41
+
42
+ const api = createBrickClient({ baseUrl: "http://localhost:4000", contract });
43
+ const pages = await api.page.list({ limit: 10 });
44
+ ```
45
+
46
+ The generated contract contains browser-safe route metadata and inferred
47
+ input/output/error types. It honors custom action paths and methods, encodes
48
+ path parameters, and removes them from the remaining payload. No backend
49
+ handlers are bundled. See the CLI README and
50
+ `www/content/docs/(brick)/typed-client.mdx` for Vite setup and error handling.
51
+
52
+ ## MCP tools
53
+
54
+ Define tools like actions, with typed input/output schemas and inline metadata:
55
+
56
+ ```ts
57
+ import {
58
+ defineService,
59
+ createMcpRegistry,
60
+ createMcpHandler,
61
+ t,
62
+ } from "@brickkit/core";
63
+
64
+ const crm = defineService("crm");
65
+ const whoami = crm.tool({
66
+ name: "crm_whoami",
67
+ title: "View Connected CRM Account",
68
+ annotations: { readOnlyHint: true },
69
+ input: t.Object({}),
70
+ output: t.String(),
71
+ authorize: ({ user }) => !!user?.id,
72
+ execute: ({ ctx }) => ctx.user.id,
73
+ });
74
+
75
+ const registry = createMcpRegistry({ services: [crm] });
76
+ registry.listTools();
77
+ await registry.callTool("crm_whoami", {}, { user: { id: "user_1" } });
78
+
79
+ const handleMcp = createMcpHandler({
80
+ registry,
81
+ serverInfo: { name: "crm", version: "1.0.0" },
82
+ });
83
+ // After your app authenticates a request:
84
+ // return handleMcp(request, { user: { id: verifiedSubject } });
85
+ ```
86
+
87
+ Tools use action validation, authorization, and service context. They are stored
88
+ separately from HTTP actions and stay out of routes and OpenAPI by default,
89
+ including when their service is passed to `brick()`. Add
90
+ `http: true` to a tool definition, or register it with `crm.action(whoami)`, to
91
+ expose it over HTTP as well.
92
+
93
+ The registry accepts `services` and/or an explicit `tools` array, rejects duplicate
94
+ names, and reads annotations directly from definitions. The handler is a
95
+ stateless POST JSON-RPC helper for initialize, ping, tools/list, and tools/call;
96
+ notifications receive an empty 202 response. Authentication and mounting remain
97
+ in your app. Its default protocol version is `2025-06-18`, following the
98
+ [MCP tools specification](https://modelcontextprotocol.io/specification/2025-06-18/server/tools).