@buildaureon/mcp 0.1.8 → 0.1.10

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.
@@ -1,377 +1,384 @@
1
- # Architecture
2
-
3
- How `@buildaureon/mcp` sits on top of `@buildaureon/sdk` and the hosted AUREON API.
4
-
5
- This document is for humans integrating the package and for AI agents that need a stable mental model of layers, ownership, and request flow. It describes the published adapter only: a thin stdio MCP server that forwards tool calls to the SDK. Default API is local mainnet `http://127.0.0.1:8788` (chain 4663). `AUREON_NETWORK=testnet` selects `https://api.aureonlabs.network` (still 46630).
6
-
7
- ---
8
-
9
- ## 1. Overview
10
-
11
- **AUREON** exposes Financial Compass control-plane APIs (objectives, portfolio book, health, restore plans, vault prepare helpers, developer keys). Agents do not need to invent HTTP paths or auth headers when they can call named MCP tools instead.
12
-
13
- **`@buildaureon/mcp`** is that named surface. It:
14
-
15
- - Speaks Model Context Protocol over **stdio** to a host (Cursor, Claude Desktop, or any MCP-compatible runner).
16
- - Validates tool arguments with **Zod** schemas at the handler boundary.
17
- - Delegates every successful call to **`@buildaureon/sdk`** (`AureonClient`).
18
- - Formats JSON results and maps SDK errors into short, agent-readable text.
19
-
20
- It does **not** embed policy math, vault encoding, keeper logic, or chain broadcasting. Those live in the API, the chain contracts, and the operator’s own signing path.
21
-
22
- ### Layer stack
23
-
24
- ```
25
- Host (Cursor / Claude / other MCP host)
26
- → MCP JSON-RPC over stdio
27
- → mcp handlers + Zod
28
- → @buildaureon/sdk HTTP client
29
- http://127.0.0.1:8788 (4663) or public testnet host (46630)
30
- → vault / Robinhood Chain settlement path
31
- ```
32
-
33
- ### System context (mermaid)
34
-
35
- ```mermaid
36
- flowchart TB
37
- subgraph hosts [MCP_hosts]
38
- Cursor[Cursor]
39
- Claude[Claude_Desktop]
40
- Other[Other_MCP_hosts]
41
- end
42
-
43
- subgraph mcpPkg ["@buildaureon/mcp"]
44
- Stdio[StdioServerTransport]
45
- Registry[McpServer_tool_registry]
46
- Handlers[Zod_handlers]
47
- Format[format_and_errors]
48
- Session[SessionTokenProvider]
49
- Client[AureonClient_bundle]
50
- end
51
-
52
- subgraph sdkPkg ["@buildaureon/sdk"]
53
- HTTP[HTTP_transport]
54
- Types[Types_and_validation]
55
- ErrModel[Error_codes]
56
- end
57
-
58
- API[8788_mainnet_or_public_testnet]
59
- Vault[Smart_Vault]
60
- Chain[Robinhood_Chain]
61
-
62
- Cursor --> Stdio
63
- Claude --> Stdio
64
- Other --> Stdio
65
- Stdio --> Registry
66
- Registry --> Handlers
67
- Handlers --> Format
68
- Handlers --> Client
69
- Client --> Session
70
- Client --> HTTP
71
- HTTP --> Types
72
- HTTP --> ErrModel
73
- HTTP --> API
74
- API --> Vault
75
- Vault --> Chain
76
- ```
77
-
78
- The MCP binary is a **local adapter**. Hosts spawn it as a child process; it is not intended as a public HTTP gateway.
79
-
80
- ---
81
-
82
- ## 2. Responsibility table
83
-
84
- | Concern | Owner | Notes |
85
- | --- | --- | --- |
86
- | Tool names and descriptions | MCP | One tool per public SDK method |
87
- | Zod argument schemas | MCP | Reject bad shapes before network I/O |
88
- | Pretty-print JSON for agents | MCP (`format.ts`) | Stable indentation / truncation hygiene |
89
- | Map SDK errors → text | MCP (`errors.ts`) | Prefer `[CODE] message` form |
90
- | Env config (`AUREON_*`) | MCP (`config.ts`) | Startup validation |
91
- | stdio / MCP JSON-RPC | `@modelcontextprotocol/sdk` | Transport + server primitives |
92
- | HTTPS client, retries, timeouts | SDK | Shared with non-MCP apps |
93
- | Request/response types | SDK | Canonical TypeScript contracts |
94
- | Input normalization | SDK | Amounts, ids, enums |
95
- | Error codes (`UNAUTHORIZED`, …) | SDK | Cross-client consistency |
96
- | Session token holder | SDK provider + MCP auth tools | Mutable Bearer in-process |
97
- | Policy engine / restore planning | Hosted API | Not reimplemented in MCP |
98
- | Vault calldata encoding | Hosted API | Prepare endpoints return unsigned steps |
99
- | On-chain broadcast / signing | Operator / host wallet | Outside MCP process |
100
- | Key pause / revoke | API + developer tools | Control-plane lifecycle |
101
-
102
- Rule of thumb: if a change affects every AUREON client (CLI scripts, bots, MCP), put it in the **SDK or API**. If it only helps agents discover or call the surface, put it in **MCP**.
103
-
104
- ---
105
-
106
- ## 3. Request lifecycle
107
-
108
- ### Process start
109
-
110
- 1. Host launches `aureon-mcp` (or `npx -y @buildaureon/mcp`) with environment variables.
111
- 2. `src/index.ts` calls `startServer()` from `server.ts`.
112
- 3. `loadConfig()` uses `resolveAureonNetworkFromEnv()` (default 8788 / 4663; `AUREON_NETWORK=testnet` for the public host, still 46630), plus `AUREON_API_KEY` and optional `AUREON_AUTH_TOKEN`.
113
- 4. Startup requires at least one credential: issued API key and/or initial Bearer.
114
- 5. `createClient()` builds a `SessionTokenProvider` and an `AureonClient` bound to that provider.
115
- 6. `registerTools()` attaches the full tool catalog to an `McpServer` instance.
116
- 7. `StdioServerTransport` connects; the process blocks on stdin/stdout until the host exits.
117
-
118
- ### Per tool call
119
-
120
- ```mermaid
121
- sequenceDiagram
122
- participant Host as MCP_host
123
- participant MCP as aureon_mcp
124
- participant Zod as Zod_schema
125
- participant SDK as AureonClient
126
- participant API as AUREON_API
127
-
128
- Host->>MCP: tools/call name + args
129
- MCP->>Zod: parse arguments
130
- alt invalid
131
- Zod-->>MCP: ZodError
132
- MCP-->>Host: isError text
133
- else valid
134
- MCP->>SDK: matching method
135
- SDK->>API: HTTPS + auth headers
136
- alt API / transport failure
137
- API-->>SDK: error
138
- SDK-->>MCP: AureonError or Error
139
- MCP-->>Host: fail mapped text
140
- else success
141
- API-->>SDK: JSON body
142
- SDK-->>MCP: typed result
143
- MCP-->>Host: ok formatted JSON
144
- end
145
- end
146
- ```
147
-
148
- Typical agent loop (restore):
149
-
150
- 1. `aureon_get_health` — detect violation / drift.
151
- 2. `aureon_get_restore_plan` — inspect proposed steps and settlement mode.
152
- 3. `aureon_restore_objective` — execute plan; read `settlement: "vault" | "staged"`.
153
- 4. Optionally `aureon_list_executions` / timeline tools for receipts.
154
-
155
- Issued API keys travel as `X-Aureon-Api-Key`. Optional wallet Bearer uses `Authorization`. Neither is printed into tool results.
156
-
157
- ---
158
-
159
- ## 4. Tool registration
160
-
161
- Registration is centralized and domain-split:
162
-
163
- | Module | Role |
164
- | --- | --- |
165
- | `tools/catalog.ts` | Canonical ordered list of tool names / count |
166
- | `tools/index.ts` | Calls each domain `register*` helper |
167
- | `tools/handler.ts` | Shared `ok` / `fail` wrappers |
168
- | `tools/read.ts` | Overview, portfolio read, health, timeline, … |
169
- | `tools/compass.ts` | Restore plan, restore, executions |
170
- | `tools/vault.ts` | Vault status + prepare deposit/withdraw |
171
- | `tools/auth.ts` | Nonce, verify, login, logout, me |
172
- | `tools/objectives.ts` | Create / update / pause / resume |
173
- | `tools/portfolio.ts` | Set / clear / sync Capital Book |
174
- | `tools/market.ts` | Presets, shocks, watchdog |
175
- | `tools/developer.ts` | List / create / revoke / toggle API keys |
176
-
177
- Design constraints:
178
-
179
- 1. **One tool per SDK method** predictable for agents and docs.
180
- 2. **Names are stable** — `aureon_*` prefix; catalog is the source of truth for count.
181
- 3. **Handlers stay thin** parse call format; no second business layer.
182
- 4. **Write tools are explicit** — agents must choose create/restore/prepare; nothing auto-trades.
183
-
184
- When adding a new SDK method, the MCP checklist is: catalog entry, Zod schema, register helper, docs row in `tools.md`, and a short example in the agent guide if the workflow is non-obvious.
185
-
186
- ---
187
-
188
- ## 5. Session provider
189
-
190
- `client.ts` wires:
191
-
192
- ```text
193
- createSessionTokenProvider(initialToken?)
194
- createAureonClient({ baseUrl, apiKey, getAccessToken })
195
- ```
196
-
197
- Behavior:
198
-
199
- - **Issued API key** is fixed for the process lifetime (from env). It authenticates the control plane without a wallet handshake.
200
- - **Bearer token** is mutable. Auth tools (`aureon_verify_wallet`, `aureon_dev_login`) call `session.setToken(...)`. `aureon_logout` clears it.
201
- - `getAccessToken` is consulted per SDK request so mid-session verify/login takes effect without restarting the host.
202
- - MCP never persists tokens to disk. Memory only, for the child process lifetime.
203
-
204
- Recommended production posture: rely on an issued key for agent hosts; use wallet Bearer only when a human-driven verify flow is intentional.
205
-
206
- ---
207
-
208
- ## 6. Error mapping
209
-
210
- `errors.ts` converts failures into compact strings:
211
-
212
- | Input | Output shape |
213
- | --- | --- |
214
- | SDK `AureonError` | `[CODE] message` |
215
- | Generic `Error` | `message` |
216
- | Unknown throw | `String(err)` |
217
-
218
- Handlers mark tool responses with `isError: true` so hosts surface failures distinctly from JSON payloads.
219
-
220
- Agents should:
221
-
222
- - Treat `[UNAUTHORIZED]` / `[FORBIDDEN]` as credential or key-state problems (paused/revoked key, missing Bearer).
223
- - Treat `[VALIDATION]` as bad arguments — fix inputs, do not retry blindly.
224
- - Treat transport timeouts as transient; retry read tools carefully, avoid duplicate write tools without idempotency checks.
225
-
226
- MCP does not invent new error codes. Codes originate in the SDK / API so scripts and agents share vocabulary.
227
-
228
- ---
229
-
230
- ## 7. What lives in SDK vs MCP
231
-
232
- ### Lives in `@buildaureon/sdk`
233
-
234
- - HTTP transport to the resolved network URL (default 8788 / 4663, or the public testnet host).
235
- - Header composition (API key + Bearer).
236
- - Retries, timeouts, and typed client methods.
237
- - Shared types for objectives, health, restore plans, vault prepare results.
238
- - Session token provider factory.
239
- - Canonical error model (`isAureonError`, codes).
240
-
241
- ### Lives in `@buildaureon/mcp`
242
-
243
- - Process entry (`index.ts`) and stdio server bootstrap (`server.ts`).
244
- - Env loading / startup gates (`config.ts`).
245
- - Client bundle assembly for MCP (`client.ts`).
246
- - Tool catalog, Zod schemas, domain registration modules.
247
- - Agent-facing formatting (`format.ts`) and error text (`errors.ts`).
248
- - Examples of host MCP JSON configs (Cursor / Claude Desktop).
249
-
250
- ### Lives outside both packages
251
-
252
- - Private keys and hardware wallets.
253
- - Transaction broadcasting and gas payment.
254
- - Human approval UX in the host product.
255
- - Hosted policy engine, keepers, and vault contracts.
256
-
257
- ---
258
-
259
- ## 8. Conceptual file map
260
-
261
- | Path | Responsibility |
262
- | --- | --- |
263
- | `src/index.ts` | CLI / bin entry — starts the server |
264
- | `src/server.ts` | Config → client → register tools → stdio connect |
265
- | `src/config.ts` | Parse and validate `AUREON_*` env |
266
- | `src/client.ts` | `AureonClient` + `SessionTokenProvider` bundle |
267
- | `src/errors.ts` | SDK / unknown → agent-readable text |
268
- | `src/format.ts` | JSON formatting for tool results |
269
- | `src/tools/catalog.ts` | Ordered tool names and `TOOL_COUNT` |
270
- | `src/tools/handler.ts` | Shared success / failure response helpers |
271
- | `src/tools/index.ts` | Registers all domains onto `McpServer` |
272
- | `src/tools/read.ts` | Read-mostly control-plane queries |
273
- | `src/tools/compass.ts` | Restore plan and execution surface |
274
- | `src/tools/vault.ts` | Vault reads + unsigned prepare helpers |
275
- | `src/tools/auth.ts` | Auth handshake + session mutation |
276
- | `src/tools/objectives.ts` | Objective lifecycle writes |
277
- | `src/tools/portfolio.ts` | Capital Book mutations / sync |
278
- | `src/tools/market.ts` | Market presets, events, watchdog |
279
- | `src/tools/developer.ts` | Issued API key management |
280
-
281
- Supporting package docs (`setup`, `auth`, `tools`, `agent-guide`, `security`) describe usage; this file describes structure.
282
-
283
- ---
284
-
285
- ## 9. Versioning
286
-
287
- | Artifact | Version meaning |
288
- | --- | --- |
289
- | `@buildaureon/mcp` package version | Adapter release (tool catalog, schemas, formatting) |
290
- | MCP server `version` field | Mirrors package version reported to hosts |
291
- | `@buildaureon/sdk` dependency | Protocol / client contract with the API |
292
- | Public API `api.aureonlabs.network` | Server-side behavior on **testnet 46630**; may evolve independently |
293
-
294
- Compatibility expectations:
295
-
296
- - **Patch** MCP releases: formatting, docs, defensive validation no tool renames.
297
- - **Minor** MCP releases: new tools mirroring new SDK methods; existing names stay.
298
- - **Major** MCP releases: breaking tool renames or required auth model changes (rare; documented in release notes).
299
-
300
- Agents should pin a known MCP package version in host config when reproducibility matters. Prefer matching SDK majors that the MCP release was tested against.
301
-
302
- ---
303
-
304
- ## 10. Design principles
305
-
306
- 1. **Thin adapter** do not reimplement SDK validation or policy in MCP.
307
- 2. **One tool per SDK method** — keep discovery and docs mechanical.
308
- 3. **Honest settlement** — pass through `settlement` fields; never claim on-chain when staged.
309
- 4. **Non-custodial** — prepare tools stop at unsigned calldata.
310
- 5. **Local stdio** — not a multi-tenant public MCP HTTP service.
311
- 6. **Secrets stay out of logs** — formatters must not dump env or Authorization headers.
312
- 7. **Least surprise** — tool names and JSON shapes should match SDK method names closely enough that humans can map them without a glossary.
313
-
314
- ---
315
-
316
- ## 11. Host ownership and vault prepare
317
-
318
- Hosts declare the command (`npx` / `aureon-mcp`) plus env (`AUREON_API_KEY`, optional Bearer / API URL). The host owns which chats may invoke tools and how humans approve on-chain steps. MCP owns only the child process that answers tool calls.
319
-
320
- Vault prepare is intentionally incomplete from a settlement perspective:
321
-
322
- 1. Agent calls `aureon_prepare_vault_deposit` or `aureon_prepare_vault_withdraw`.
323
- 2. MCP → SDK → API returns unsigned steps / calldata descriptions.
324
- 3. A human or external signer reviews and broadcasts.
325
- 4. Later reads (`aureon_get_vault`, status tools) reflect chain state once confirmed.
326
-
327
- MCP never submits signed transactions. That boundary is load-bearing for the security model (see `security.md`).
328
-
329
- ---
330
-
331
- ## 12. FAQ
332
-
333
- **Is MCP a second API?**
334
- No. It is a stdio adapter over the same SDK client used by scripts.
335
-
336
- **Can I run MCP without an issued API key?**
337
- Only if a valid Bearer is supplied (env or verify/login tools). Issued keys are the recommended agent path.
338
-
339
- **Where does business logic run?**
340
- On the hosted API and chain. MCP formats and forwards.
341
-
342
- **Why Zod if the SDK already validates?**
343
- Early rejection at the tool boundary improves agent feedback. SDK validation remains authoritative for deeper rules.
344
-
345
- **Does MCP cache portfolio or health?**
346
- No long-lived cache. Each tool call hits the SDK/API (subject to normal HTTP behavior).
347
-
348
- **What happens if the host restarts?**
349
- The MCP child restarts; in-memory Bearer is lost. Issued key from env is reloaded.
350
-
351
- **How many tools are there?**
352
- See `tools/catalog.ts` (`TOOL_COUNT`) and `tools.md`.
353
-
354
- **Can I expose MCP over the public internet?**
355
- Do not. The trust model assumes a local host-spawned stdio process.
356
-
357
- **Where should I put custom agent workflows?**
358
- In prompts, host rules, or orchestration — not by forking business logic into MCP handlers.
359
-
360
- **How does this relate to the operator utility?**
361
- The utility remains a separate wallet-Bearer UI. MCP does not replace it.
362
-
363
- ---
364
-
365
- ## 13. Related documents
366
-
367
- - [Setup](./setup.md) install and host configuration patterns
368
- - [Authentication](./auth.md) API keys, Bearer handshake, session tools
369
- - [Tools](./tools.md) — full tool catalog
370
- - [Agent guide](./agent-guide.md) — recommended call sequences
371
- - [Security](./security.md) — threat model and operational hygiene
372
-
373
- ---
374
-
375
- ## 14. Summary
376
-
377
- `@buildaureon/mcp` is a **thin stdio adapter**: Host → MCP handlers/Zod → `@buildaureon/sdk` → resolved API (default 8788 / 4663; public host still 46630) vault/chain. Responsibilities are split so agents get a stable tool surface while all financial intelligence and custody boundaries remain outside the MCP process.
1
+ # Architecture
2
+
3
+ How `@buildaureon/mcp` sits on top of `@buildaureon/sdk` and the hosted AUREON API.
4
+
5
+ This document is for humans integrating the package and for AI agents that need a stable mental model of layers, ownership, and request flow. It describes the official adapter: a thin MCP server that forwards tool calls to the SDK. Two transports share that adapter — **local stdio** (`@buildaureon/mcp`) and **official hosted Streamable HTTP** (`https://mcp.aureonlabs.network/mcp`). Default API is `https://api.aureonlabs.network` on mainnet. `AUREON_NETWORK=testnet` stays on testnet on the same official host. Public Living Capital is still the testnet console.
6
+
7
+ ---
8
+
9
+ ## 1. Overview
10
+
11
+ **AUREON** exposes Financial Compass control-plane APIs (objectives, portfolio book, health, restore plans, vault prepare helpers, developer keys). Agents do not need to invent HTTP paths or auth headers when they can call named MCP tools instead.
12
+
13
+ **`@buildaureon/mcp`** is that named surface. It:
14
+
15
+ - Speaks Model Context Protocol to a host over **stdio** (npm package) or **Streamable HTTP** (official hosted URL `https://mcp.aureonlabs.network/mcp`).
16
+ - Validates tool arguments with **Zod** schemas at the handler boundary.
17
+ - Delegates every successful call to **`@buildaureon/sdk`** (`AureonClient`).
18
+ - Formats JSON results and maps SDK errors into short, agent-readable text.
19
+
20
+ It does **not** embed policy math, vault encoding, keeper logic, or chain broadcasting. Those live in the API, the chain contracts, and the operator’s own signing path.
21
+
22
+ ### Layer stack
23
+
24
+ ```
25
+ Host (Cursor / Claude / other MCP host)
26
+ → MCP JSON-RPC over stdio OR Streamable HTTP https://mcp.aureonlabs.network/mcp
27
+ → mcp handlers + Zod
28
+ → @buildaureon/sdk HTTP client
29
+ https://api.aureonlabs.network (mainnet default, or testnet with AUREON_NETWORK=testnet)
30
+ → vault / Robinhood Chain settlement path
31
+ ```
32
+
33
+ ### System context (mermaid)
34
+
35
+ ```mermaid
36
+ flowchart TB
37
+ subgraph hosts [MCP_hosts]
38
+ Cursor[Cursor]
39
+ Claude[Claude_Desktop]
40
+ Other[Other_MCP_hosts]
41
+ end
42
+
43
+ HostedURL["https://mcp.aureonlabs.network/mcp"]
44
+
45
+ subgraph mcpPkg ["adapter"]
46
+ Stdio[StdioServerTransport]
47
+ Registry[McpServer_tool_registry]
48
+ Handlers[Zod_handlers]
49
+ Format[format_and_errors]
50
+ Session[SessionTokenProvider]
51
+ Client[AureonClient_bundle]
52
+ end
53
+
54
+ subgraph sdkPkg ["@buildaureon/sdk"]
55
+ HTTP[HTTP_transport]
56
+ Types[Types_and_validation]
57
+ ErrModel[Error_codes]
58
+ end
59
+
60
+ API[official_api_aureonlabs_network]
61
+ Vault[Smart_Vault]
62
+ Chain[Robinhood_Chain]
63
+
64
+ Cursor --> Stdio
65
+ Cursor --> HostedURL
66
+ Claude --> Stdio
67
+ Claude --> HostedURL
68
+ Other --> Stdio
69
+ Other --> HostedURL
70
+ HostedURL --> Registry
71
+ Stdio --> Registry
72
+ Registry --> Handlers
73
+ Handlers --> Format
74
+ Handlers --> Client
75
+ Client --> Session
76
+ Client --> HTTP
77
+ HTTP --> Types
78
+ HTTP --> ErrModel
79
+ HTTP --> API
80
+ API --> Vault
81
+ Vault --> Chain
82
+ ```
83
+
84
+ The npm binary is a **local stdio adapter**. Hosts spawn it as a child process. The official hosted process is a separate Streamable HTTP server at `https://mcp.aureonlabs.network/mcp` (same tools, same SDK, same “no private key / no broadcast” rule). Do not publish **your own** stdio child as an open internet socket. Use the official hosted URL instead.
85
+
86
+ ---
87
+
88
+ ## 2. Responsibility table
89
+
90
+ | Concern | Owner | Notes |
91
+ | --- | --- | --- |
92
+ | Tool names and descriptions | MCP | One tool per public SDK method |
93
+ | Zod argument schemas | MCP | Reject bad shapes before network I/O |
94
+ | Pretty-print JSON for agents | MCP (`format.ts`) | Stable indentation / truncation hygiene |
95
+ | Map SDK errors → text | MCP (`errors.ts`) | Prefer `[CODE] message` form |
96
+ | Env config (`AUREON_*`) | MCP (`config.ts`) | Startup validation |
97
+ | stdio / MCP JSON-RPC | `@modelcontextprotocol/sdk` | Transport + server primitives |
98
+ | HTTPS client, retries, timeouts | SDK | Shared with non-MCP apps |
99
+ | Request/response types | SDK | Canonical TypeScript contracts |
100
+ | Input normalization | SDK | Amounts, ids, enums |
101
+ | Error codes (`UNAUTHORIZED`, …) | SDK | Cross-client consistency |
102
+ | Session token holder | SDK provider + MCP auth tools | Mutable Bearer in-process |
103
+ | Policy engine / restore planning | Hosted API | Not reimplemented in MCP |
104
+ | Vault calldata encoding | Hosted API | Prepare endpoints return unsigned steps |
105
+ | On-chain broadcast / signing | Operator / host wallet | Outside MCP process |
106
+ | Key pause / revoke | API + developer tools | Control-plane lifecycle |
107
+
108
+ Rule of thumb: if a change affects every AUREON client (CLI scripts, bots, MCP), put it in the **SDK or API**. If it only helps agents discover or call the surface, put it in **MCP**.
109
+
110
+ ---
111
+
112
+ ## 3. Request lifecycle
113
+
114
+ ### Process start
115
+
116
+ 1. Host launches `aureon-mcp` (or `npx -y @buildaureon/mcp`) with environment variables.
117
+ 2. `src/index.ts` calls `startServer()` from `server.ts`.
118
+ 3. `loadConfig()` uses `resolveAureonNetworkFromEnv()` (default official API / mainnet; `AUREON_NETWORK=testnet` to stay on testnet), plus `AUREON_API_KEY` and optional `AUREON_AUTH_TOKEN`.
119
+ 4. Startup requires at least one credential: issued API key and/or initial Bearer.
120
+ 5. `createClient()` builds a `SessionTokenProvider` and an `AureonClient` bound to that provider.
121
+ 6. `registerTools()` attaches the full tool catalog to an `McpServer` instance.
122
+ 7. `StdioServerTransport` connects; the process blocks on stdin/stdout until the host exits.
123
+
124
+ ### Per tool call
125
+
126
+ ```mermaid
127
+ sequenceDiagram
128
+ participant Host as MCP_host
129
+ participant MCP as aureon_mcp
130
+ participant Zod as Zod_schema
131
+ participant SDK as AureonClient
132
+ participant API as AUREON_API
133
+
134
+ Host->>MCP: tools/call name + args
135
+ MCP->>Zod: parse arguments
136
+ alt invalid
137
+ Zod-->>MCP: ZodError
138
+ MCP-->>Host: isError text
139
+ else valid
140
+ MCP->>SDK: matching method
141
+ SDK->>API: HTTPS + auth headers
142
+ alt API / transport failure
143
+ API-->>SDK: error
144
+ SDK-->>MCP: AureonError or Error
145
+ MCP-->>Host: fail mapped text
146
+ else success
147
+ API-->>SDK: JSON body
148
+ SDK-->>MCP: typed result
149
+ MCP-->>Host: ok formatted JSON
150
+ end
151
+ end
152
+ ```
153
+
154
+ Typical agent loop (restore):
155
+
156
+ 1. `aureon_get_health` — detect violation / drift.
157
+ 2. `aureon_get_restore_plan` — inspect proposed steps and settlement mode.
158
+ 3. `aureon_restore_objective` — execute plan; read `settlement: "vault" | "staged"`.
159
+ 4. Optionally `aureon_list_executions` / timeline tools for receipts.
160
+
161
+ Issued API keys travel as `X-Aureon-Api-Key`. Optional wallet Bearer uses `Authorization`. Neither is printed into tool results.
162
+
163
+ ---
164
+
165
+ ## 4. Tool registration
166
+
167
+ Registration is centralized and domain-split:
168
+
169
+ | Module | Role |
170
+ | --- | --- |
171
+ | `tools/catalog.ts` | Canonical ordered list of tool names / count |
172
+ | `tools/index.ts` | Calls each domain `register*` helper |
173
+ | `tools/handler.ts` | Shared `ok` / `fail` wrappers |
174
+ | `tools/read.ts` | Overview, portfolio read, health, timeline, … |
175
+ | `tools/compass.ts` | Restore plan, restore, executions |
176
+ | `tools/vault.ts` | Vault status + prepare deposit/withdraw |
177
+ | `tools/auth.ts` | Nonce, verify, login, logout, me |
178
+ | `tools/objectives.ts` | Create / update / pause / resume |
179
+ | `tools/portfolio.ts` | Set / clear / sync Capital Book |
180
+ | `tools/market.ts` | Presets, shocks, watchdog |
181
+ | `tools/developer.ts` | List / create / revoke / toggle API keys |
182
+
183
+ Design constraints:
184
+
185
+ 1. **One tool per SDK method** — predictable for agents and docs.
186
+ 2. **Names are stable** — `aureon_*` prefix; catalog is the source of truth for count.
187
+ 3. **Handlers stay thin** — parse → call → format; no second business layer.
188
+ 4. **Write tools are explicit** — agents must choose create/restore/prepare; nothing auto-trades.
189
+
190
+ When adding a new SDK method, the MCP checklist is: catalog entry, Zod schema, register helper, docs row in `tools.md`, and a short example in the agent guide if the workflow is non-obvious.
191
+
192
+ ---
193
+
194
+ ## 5. Session provider
195
+
196
+ `client.ts` wires:
197
+
198
+ ```text
199
+ createSessionTokenProvider(initialToken?)
200
+ createAureonClient({ baseUrl, apiKey, getAccessToken })
201
+ ```
202
+
203
+ Behavior:
204
+
205
+ - **Issued API key** is fixed for the process lifetime (from env). It authenticates the control plane without a wallet handshake.
206
+ - **Bearer token** is mutable. Auth tools (`aureon_verify_wallet`, `aureon_dev_login`) call `session.setToken(...)`. `aureon_logout` clears it.
207
+ - `getAccessToken` is consulted per SDK request so mid-session verify/login takes effect without restarting the host.
208
+ - MCP never persists tokens to disk. Memory only, for the child process lifetime.
209
+
210
+ Recommended production posture: rely on an issued key for agent hosts; use wallet Bearer only when a human-driven verify flow is intentional.
211
+
212
+ ---
213
+
214
+ ## 6. Error mapping
215
+
216
+ `errors.ts` converts failures into compact strings:
217
+
218
+ | Input | Output shape |
219
+ | --- | --- |
220
+ | SDK `AureonError` | `[CODE] message` |
221
+ | Generic `Error` | `message` |
222
+ | Unknown throw | `String(err)` |
223
+
224
+ Handlers mark tool responses with `isError: true` so hosts surface failures distinctly from JSON payloads.
225
+
226
+ Agents should:
227
+
228
+ - Treat `[UNAUTHORIZED]` / `[FORBIDDEN]` as credential or key-state problems (paused/revoked key, missing Bearer).
229
+ - Treat `[VALIDATION]` as bad arguments — fix inputs, do not retry blindly.
230
+ - Treat transport timeouts as transient; retry read tools carefully, avoid duplicate write tools without idempotency checks.
231
+
232
+ MCP does not invent new error codes. Codes originate in the SDK / API so scripts and agents share vocabulary.
233
+
234
+ ---
235
+
236
+ ## 7. What lives in SDK vs MCP
237
+
238
+ ### Lives in `@buildaureon/sdk`
239
+
240
+ - HTTP transport to the official API (default mainnet, or testnet when `AUREON_NETWORK=testnet`).
241
+ - Header composition (API key + Bearer).
242
+ - Retries, timeouts, and typed client methods.
243
+ - Shared types for objectives, health, restore plans, vault prepare results.
244
+ - Session token provider factory.
245
+ - Canonical error model (`isAureonError`, codes).
246
+
247
+ ### Lives in `@buildaureon/mcp`
248
+
249
+ - Process entry (`index.ts`) and stdio server bootstrap (`server.ts`).
250
+ - Env loading / startup gates (`config.ts`).
251
+ - Client bundle assembly for MCP (`client.ts`).
252
+ - Tool catalog, Zod schemas, domain registration modules.
253
+ - Agent-facing formatting (`format.ts`) and error text (`errors.ts`).
254
+ - Examples of host MCP JSON configs (Cursor / Claude Desktop).
255
+
256
+ ### Lives outside both packages
257
+
258
+ - Private keys and hardware wallets.
259
+ - Transaction broadcasting and gas payment.
260
+ - Human approval UX in the host product.
261
+ - Hosted policy engine, keepers, and vault contracts.
262
+
263
+ ---
264
+
265
+ ## 8. Conceptual file map
266
+
267
+ | Path | Responsibility |
268
+ | --- | --- |
269
+ | `src/index.ts` | CLI / bin entry starts the server |
270
+ | `src/server.ts` | Config client register tools → stdio connect |
271
+ | `src/config.ts` | Parse and validate `AUREON_*` env |
272
+ | `src/client.ts` | `AureonClient` + `SessionTokenProvider` bundle |
273
+ | `src/errors.ts` | SDK / unknown agent-readable text |
274
+ | `src/format.ts` | JSON formatting for tool results |
275
+ | `src/tools/catalog.ts` | Ordered tool names and `TOOL_COUNT` |
276
+ | `src/tools/handler.ts` | Shared success / failure response helpers |
277
+ | `src/tools/index.ts` | Registers all domains onto `McpServer` |
278
+ | `src/tools/read.ts` | Read-mostly control-plane queries |
279
+ | `src/tools/compass.ts` | Restore plan and execution surface |
280
+ | `src/tools/vault.ts` | Vault reads + unsigned prepare helpers |
281
+ | `src/tools/auth.ts` | Auth handshake + session mutation |
282
+ | `src/tools/objectives.ts` | Objective lifecycle writes |
283
+ | `src/tools/portfolio.ts` | Capital Book mutations / sync |
284
+ | `src/tools/market.ts` | Market presets, events, watchdog |
285
+ | `src/tools/developer.ts` | Issued API key management |
286
+
287
+ Supporting package docs (`setup`, `auth`, `tools`, `agent-guide`, `security`) describe usage; this file describes structure.
288
+
289
+ ---
290
+
291
+ ## 9. Versioning
292
+
293
+ | Artifact | Version meaning |
294
+ | --- | --- |
295
+ | `@buildaureon/mcp` package version | Adapter release (tool catalog, schemas, formatting) |
296
+ | MCP server `version` field | Mirrors package version reported to hosts |
297
+ | `@buildaureon/sdk` dependency | Protocol / client contract with the API |
298
+ | Public API `api.aureonlabs.network` | Server-side behavior on **mainnet** by omit, **testnet** when `X-Aureon-Network: testnet`; may evolve independently |
299
+
300
+ Compatibility expectations:
301
+
302
+ - **Patch** MCP releases: formatting, docs, defensive validation — no tool renames.
303
+ - **Minor** MCP releases: new tools mirroring new SDK methods; existing names stay.
304
+ - **Major** MCP releases: breaking tool renames or required auth model changes (rare; documented in release notes).
305
+
306
+ Agents should pin a known MCP package version in host config when reproducibility matters. Prefer matching SDK majors that the MCP release was tested against.
307
+
308
+ ---
309
+
310
+ ## 10. Design principles
311
+
312
+ 1. **Thin adapter** — do not reimplement SDK validation or policy in MCP.
313
+ 2. **One tool per SDK method** — keep discovery and docs mechanical.
314
+ 3. **Honest settlement** — pass through `settlement` fields; never claim on-chain when staged.
315
+ 4. **Non-custodial** — prepare tools stop at unsigned calldata.
316
+ 5. **Official hosted HTTP, or local stdio** — use `https://mcp.aureonlabs.network/mcp` for the official Streamable HTTP host. Do not expose your own stdio child on the public internet.
317
+ 6. **Secrets stay out of logs** — formatters must not dump env or Authorization headers.
318
+ 7. **Least surprise** tool names and JSON shapes should match SDK method names closely enough that humans can map them without a glossary.
319
+
320
+ ---
321
+
322
+ ## 11. Host ownership and vault prepare
323
+
324
+ Hosts declare the command (`npx` / `aureon-mcp`) plus env (`AUREON_API_KEY`, optional Bearer / API URL). The host owns which chats may invoke tools and how humans approve on-chain steps. MCP owns only the child process that answers tool calls.
325
+
326
+ Vault prepare is intentionally incomplete from a settlement perspective:
327
+
328
+ 1. Agent calls `aureon_prepare_vault_deposit` or `aureon_prepare_vault_withdraw`.
329
+ 2. MCP → SDK → API returns unsigned steps / calldata descriptions.
330
+ 3. A human or external signer reviews and broadcasts.
331
+ 4. Later reads (`aureon_get_vault`, status tools) reflect chain state once confirmed.
332
+
333
+ MCP never submits signed transactions. That boundary is load-bearing for the security model (see `security.md`).
334
+
335
+ ---
336
+
337
+ ## 12. FAQ
338
+
339
+ **Is MCP a second API?**
340
+ No. It is an adapter over the same SDK client used by scripts. Hosted HTTP and local stdio are transports, not a second control plane.
341
+
342
+ **Can I run MCP without an issued API key?**
343
+ Only if a valid Bearer is supplied (env or verify/login tools). Issued keys are the recommended agent path.
344
+
345
+ **Where does business logic run?**
346
+ On the hosted API and chain. MCP formats and forwards.
347
+
348
+ **Why Zod if the SDK already validates?**
349
+ Early rejection at the tool boundary improves agent feedback. SDK validation remains authoritative for deeper rules.
350
+
351
+ **Does MCP cache portfolio or health?**
352
+ No long-lived cache. Each tool call hits the SDK/API (subject to normal HTTP behavior).
353
+
354
+ **What happens if the host restarts?**
355
+ **stdio:** the MCP child restarts; in-memory Bearer is lost. Issued key from env is reloaded.
356
+ **hosted:** Cursor reconnects to the same URL. Open tools still work. Your wallet tools need `X-Aureon-Api-Key` again on that session.
357
+
358
+ **How many tools are there?**
359
+ See `tools/catalog.ts` (`TOOL_COUNT`) and `tools.md`.
360
+
361
+ **Can I expose my local stdio MCP over the public internet?**
362
+ Do not. Use the official hosted URL `https://mcp.aureonlabs.network/mcp` instead of publishing your own process.
363
+
364
+ **Where should I put custom agent workflows?**
365
+ In prompts, host rules, or orchestration — not by forking business logic into MCP handlers.
366
+
367
+ **How does this relate to the operator utility?**
368
+ The utility remains a separate wallet-Bearer UI. MCP does not replace it.
369
+
370
+ ---
371
+
372
+ ## 13. Related documents
373
+
374
+ - [Setup](./setup.md) — install and host configuration patterns
375
+ - [Authentication](./auth.md) — API keys, Bearer handshake, session tools
376
+ - [Tools](./tools.md) — full tool catalog
377
+ - [Agent guide](./agent-guide.md) recommended call sequences
378
+ - [Security](./security.md) — threat model and operational hygiene
379
+
380
+ ---
381
+
382
+ ## 14. Summary
383
+
384
+ `@buildaureon/mcp` is a **thin adapter** (stdio locally, Streamable HTTP on the official host): Host → MCP handlers/Zod → `@buildaureon/sdk` → official API (`https://api.aureonlabs.network`) → vault/chain. Responsibilities are split so agents get a stable tool surface while all financial intelligence and custody boundaries remain outside the MCP process.