@levitating/tensor-mcp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +149 -0
  2. package/dist/index.js +765 -0
  3. package/package.json +44 -0
package/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # Tensor MCP
2
+
3
+ Model Context Protocol server that exposes the full Tensor wealth management API as 53 tools for AI assistants. Same Clerk API key, same scopes, same deny-by-default rules as the REST API.
4
+
5
+ See the full docs at [tensor.levitating.org/docs/mcp](https://tensor.levitating.org/docs/mcp).
6
+
7
+ ## Setup
8
+
9
+ ```bash
10
+ # From the project root
11
+ npm install
12
+ ```
13
+
14
+ ## Configuration
15
+
16
+ Set two environment variables:
17
+
18
+ | Variable | Description |
19
+ |----------|-------------|
20
+ | `TENSOR_API_KEY` | Your Clerk API key with Tensor scopes (create in Developer > API Keys) |
21
+ | `TENSOR_BASE_URL` | Tensor instance URL (default: `http://localhost:5000`) |
22
+
23
+ ## Running standalone
24
+
25
+ ```bash
26
+ TENSOR_API_KEY=ak_live_xxxxxxxxxxxx \
27
+ TENSOR_BASE_URL=https://tensor.levitating.org \
28
+ npx tsx mcp-server/index.ts
29
+ ```
30
+
31
+ ## Claude Code integration
32
+
33
+ Add to your `~/.claude.json` or project `.claude.json`:
34
+
35
+ ```json
36
+ {
37
+ "mcpServers": {
38
+ "tensor": {
39
+ "type": "stdio",
40
+ "command": "npx",
41
+ "args": ["tsx", "mcp-server/index.ts"],
42
+ "env": {
43
+ "TENSOR_API_KEY": "sk_your_key_here",
44
+ "TENSOR_BASE_URL": "https://your-instance.example.com"
45
+ }
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ ## Claude Desktop integration
52
+
53
+ Add to your Claude Desktop config (`~/Library/Application Support/Claude/claude_desktop_config.json`):
54
+
55
+ ```json
56
+ {
57
+ "mcpServers": {
58
+ "tensor": {
59
+ "command": "npx",
60
+ "args": ["tsx", "/path/to/tensor/mcp-server/index.ts"],
61
+ "env": {
62
+ "TENSOR_API_KEY": "sk_your_key_here",
63
+ "TENSOR_BASE_URL": "https://your-instance.example.com"
64
+ }
65
+ }
66
+ }
67
+ }
68
+ ```
69
+
70
+ ## Available Tools
71
+
72
+ ### Portfolio
73
+
74
+ | Tool | Description |
75
+ |------|-------------|
76
+ | `list_entities` | List all entities (people, trusts, companies) |
77
+ | `create_entity` | Create a new entity |
78
+ | `update_entity` | Update an entity |
79
+ | `delete_entity` | Delete an entity |
80
+ | `list_entity_relationships` | List entity relationships |
81
+ | `create_entity_relationship` | Link two entities |
82
+ | `update_entity_relationship` | Update a relationship |
83
+ | `delete_entity_relationship` | Remove a relationship |
84
+ | `list_accounts` | List all accounts |
85
+ | `create_account` | Create a new account |
86
+ | `update_account` | Update an account |
87
+ | `delete_account` | Delete an account |
88
+ | `list_assets` | List all assets |
89
+ | `get_asset` | Get a single asset |
90
+ | `create_asset` | Create a new asset |
91
+ | `update_asset` | Update an asset |
92
+ | `delete_asset` | Delete an asset |
93
+ | `list_asset_prices` | List historical prices |
94
+ | `update_asset_price` | Record a new price |
95
+ | `list_positions` | List all positions |
96
+ | `create_position` | Open a new position |
97
+ | `update_position` | Update a position |
98
+ | `delete_position` | Delete a position |
99
+ | `sell_all_position` | Close/sell a position |
100
+ | `list_position_relations` | List position relations |
101
+ | `create_position_relation` | Link positions |
102
+ | `delete_position_relation` | Remove a relation |
103
+ | `list_transactions` | List all transactions |
104
+ | `create_transaction` | Record a transaction |
105
+
106
+ ### Reference Data
107
+
108
+ | Tool | Description |
109
+ |------|-------------|
110
+ | `list_institutions` | List institutions |
111
+ | `create_institution` | Create an institution |
112
+ | `update_institution` | Update an institution |
113
+ | `delete_institution` | Delete an institution |
114
+ | `list_entity_types` | List entity types |
115
+ | `create_entity_type` | Create an entity type |
116
+ | `update_entity_type` | Update an entity type |
117
+ | `delete_entity_type` | Delete an entity type |
118
+ | `list_role_types` | List role types |
119
+ | `create_role_type` | Create a role type |
120
+ | `update_role_type` | Update a role type |
121
+ | `delete_role_type` | Delete a role type |
122
+ | `list_account_types` | List account types |
123
+ | `create_account_type` | Create an account type |
124
+ | `update_account_type` | Update an account type |
125
+ | `delete_account_type` | Delete an account type |
126
+ | `list_asset_classes` | List asset classes |
127
+ | `create_asset_class` | Create an asset class |
128
+ | `update_asset_class` | Update an asset class |
129
+ | `delete_asset_class` | Delete an asset class |
130
+
131
+ ### Data Pipeline
132
+
133
+ | Tool | Description |
134
+ |------|-------------|
135
+ | `data_dry_run` | Preview a batch import (validates without applying) |
136
+ | `data_apply` | Apply a batch import |
137
+
138
+ ## Scopes
139
+
140
+ Your API key needs the following Clerk scopes depending on what you want to do:
141
+
142
+ | Scope | Grants |
143
+ |-------|--------|
144
+ | `tensor:portfolio:read` | Read entities, accounts, assets, positions, transactions |
145
+ | `tensor:portfolio:write` | Create/update/delete portfolio resources |
146
+ | `tensor:reference:read` | Read institutions, entity types, role types, account types, asset classes |
147
+ | `tensor:reference:write` | Create/update/delete reference data |
148
+ | `tensor:data:dry_run` | Run data pipeline dry-runs |
149
+ | `tensor:data:apply` | Apply data pipeline operations |
package/dist/index.js ADDED
@@ -0,0 +1,765 @@
1
+ #!/usr/bin/env node
2
+
3
+ // index.ts
4
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
5
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
+
7
+ // tools.ts
8
+ import { z } from "zod";
9
+ function registerAllTools(server2, api) {
10
+ server2.tool(
11
+ "list_entities",
12
+ "List all entities (people, trusts, companies) in the organization",
13
+ { limit: z.number().optional().describe("Max results to return"), offset: z.number().optional().describe("Pagination offset") },
14
+ async ({ limit, offset }) => {
15
+ const params = new URLSearchParams();
16
+ if (limit) params.set("limit", String(limit));
17
+ if (offset) params.set("offset", String(offset));
18
+ const qs = params.toString();
19
+ const data = await api("GET", `/api/entities${qs ? `?${qs}` : ""}`);
20
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
21
+ }
22
+ );
23
+ server2.tool(
24
+ "create_entity",
25
+ "Create a new entity (person, trust, or company)",
26
+ {
27
+ name: z.string().describe("Entity name"),
28
+ type: z.string().describe("Entity type key (e.g. 'Individual', 'Trust', 'LLC'). Must match an existing entity-types row."),
29
+ jurisdiction: z.string().optional().describe("Legal jurisdiction (e.g. 'Delaware', 'California')"),
30
+ formedDate: z.string().optional().describe("Formation/birth date in ISO format YYYY-MM-DD"),
31
+ tags: z.array(z.string()).optional().describe("Array of tag strings (max 32 tags, each max 64 chars)"),
32
+ showInPortfolio: z.boolean().optional().describe("Whether to include in portfolio views. Default: true"),
33
+ notes: z.string().optional().describe("Free-form notes")
34
+ },
35
+ async (params) => {
36
+ const data = await api("POST", "/api/entities", params);
37
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
38
+ }
39
+ );
40
+ server2.tool(
41
+ "update_entity",
42
+ "Update an existing entity (partial update)",
43
+ {
44
+ id: z.number().describe("Entity ID to update"),
45
+ name: z.string().optional().describe("New entity name"),
46
+ type: z.string().optional().describe("New entity type key"),
47
+ jurisdiction: z.string().optional().describe("Legal jurisdiction"),
48
+ formedDate: z.string().optional().describe("Formation/birth date YYYY-MM-DD"),
49
+ tags: z.array(z.string()).optional(),
50
+ showInPortfolio: z.boolean().optional(),
51
+ notes: z.string().optional()
52
+ },
53
+ async ({ id, ...body }) => {
54
+ const data = await api("PATCH", `/api/entities/${id}`, body);
55
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
56
+ }
57
+ );
58
+ server2.tool(
59
+ "delete_entity",
60
+ "Delete an entity by ID",
61
+ { id: z.number().describe("Entity ID to delete") },
62
+ async ({ id }) => {
63
+ const data = await api("DELETE", `/api/entities/${id}`);
64
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
65
+ }
66
+ );
67
+ server2.tool(
68
+ "list_entity_relationships",
69
+ "List all entity relationships (ownership, beneficiary, etc.)",
70
+ { limit: z.number().optional(), offset: z.number().optional() },
71
+ async ({ limit, offset }) => {
72
+ const params = new URLSearchParams();
73
+ if (limit) params.set("limit", String(limit));
74
+ if (offset) params.set("offset", String(offset));
75
+ const qs = params.toString();
76
+ const data = await api("GET", `/api/entity-relationships${qs ? `?${qs}` : ""}`);
77
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
78
+ }
79
+ );
80
+ server2.tool(
81
+ "create_entity_relationship",
82
+ "Create a relationship between two entities (ownership, beneficiary, trustee, etc.)",
83
+ {
84
+ sourceEntityId: z.number().describe("Source entity ID (the parent/owner)"),
85
+ targetEntityId: z.number().describe("Target entity ID (the child/owned)"),
86
+ relationshipType: z.string().optional().describe("Relationship type. Default: 'ownership'"),
87
+ roleType: z.string().optional().describe("Role type key (e.g. 'Trustee', 'Beneficiary'). Free-form string keyed against role-types catalog."),
88
+ ownershipPercent: z.number().optional().describe("Ownership percentage as a number (e.g. 51.5 for 51.5%)"),
89
+ title: z.string().optional().describe("Display title for this relationship"),
90
+ label: z.string().optional().describe("Short label"),
91
+ effectiveDate: z.string().optional().describe("Effective date YYYY-MM-DD"),
92
+ notes: z.string().optional()
93
+ },
94
+ async (params) => {
95
+ const data = await api("POST", "/api/entity-relationships", params);
96
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
97
+ }
98
+ );
99
+ server2.tool(
100
+ "update_entity_relationship",
101
+ "Update an entity relationship (partial update)",
102
+ {
103
+ id: z.number().describe("Relationship ID"),
104
+ sourceEntityId: z.number().optional(),
105
+ targetEntityId: z.number().optional(),
106
+ relationshipType: z.string().optional(),
107
+ roleType: z.string().optional(),
108
+ ownershipPercent: z.number().optional(),
109
+ title: z.string().optional(),
110
+ label: z.string().optional(),
111
+ effectiveDate: z.string().optional(),
112
+ notes: z.string().optional()
113
+ },
114
+ async ({ id, ...body }) => {
115
+ const data = await api("PATCH", `/api/entity-relationships/${id}`, body);
116
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
117
+ }
118
+ );
119
+ server2.tool(
120
+ "delete_entity_relationship",
121
+ "Delete an entity relationship",
122
+ { id: z.number().describe("Relationship ID to delete") },
123
+ async ({ id }) => {
124
+ const data = await api("DELETE", `/api/entity-relationships/${id}`);
125
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
126
+ }
127
+ );
128
+ server2.tool(
129
+ "list_accounts",
130
+ "List all accounts (brokerage, bank, retirement, etc.) in the organization",
131
+ { limit: z.number().optional(), offset: z.number().optional() },
132
+ async ({ limit, offset }) => {
133
+ const params = new URLSearchParams();
134
+ if (limit) params.set("limit", String(limit));
135
+ if (offset) params.set("offset", String(offset));
136
+ const qs = params.toString();
137
+ const data = await api("GET", `/api/accounts${qs ? `?${qs}` : ""}`);
138
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
139
+ }
140
+ );
141
+ server2.tool(
142
+ "create_account",
143
+ "Create a new account (brokerage, bank, retirement, etc.)",
144
+ {
145
+ name: z.string().describe("Account name"),
146
+ entityId: z.number().describe("Owner entity ID"),
147
+ accountType: z.string().describe("Account type key (e.g. 'Brokerage', 'Bank', 'Retirement'). Must match an existing account-types row."),
148
+ institution: z.string().optional().describe("Institution name as free-form text (e.g. 'Charles Schwab', 'Fidelity'). Not an ID."),
149
+ currency: z.string().optional().describe("Currency code (e.g. USD, EUR). Default: USD"),
150
+ notes: z.string().optional()
151
+ },
152
+ async (params) => {
153
+ const data = await api("POST", "/api/accounts", params);
154
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
155
+ }
156
+ );
157
+ server2.tool(
158
+ "update_account",
159
+ "Update an existing account (partial update)",
160
+ {
161
+ id: z.number().describe("Account ID to update"),
162
+ name: z.string().optional(),
163
+ entityId: z.number().optional(),
164
+ accountType: z.string().optional().describe("Account type key"),
165
+ institution: z.string().optional().describe("Institution name as free-form text"),
166
+ currency: z.string().optional(),
167
+ notes: z.string().optional()
168
+ },
169
+ async ({ id, ...body }) => {
170
+ const data = await api("PATCH", `/api/accounts/${id}`, body);
171
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
172
+ }
173
+ );
174
+ server2.tool(
175
+ "delete_account",
176
+ "Delete an account by ID",
177
+ { id: z.number().describe("Account ID to delete") },
178
+ async ({ id }) => {
179
+ const data = await api("DELETE", `/api/accounts/${id}`);
180
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
181
+ }
182
+ );
183
+ server2.tool(
184
+ "list_assets",
185
+ "List all assets (stocks, bonds, crypto, real estate, etc.)",
186
+ { limit: z.number().optional(), offset: z.number().optional() },
187
+ async ({ limit, offset }) => {
188
+ const params = new URLSearchParams();
189
+ if (limit) params.set("limit", String(limit));
190
+ if (offset) params.set("offset", String(offset));
191
+ const qs = params.toString();
192
+ const data = await api("GET", `/api/assets${qs ? `?${qs}` : ""}`);
193
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
194
+ }
195
+ );
196
+ server2.tool(
197
+ "get_asset",
198
+ "Get a single asset by ID",
199
+ { id: z.number().describe("Asset ID") },
200
+ async ({ id }) => {
201
+ const data = await api("GET", `/api/assets/${id}`);
202
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
203
+ }
204
+ );
205
+ server2.tool(
206
+ "create_asset",
207
+ "Create a new asset (stock, bond, crypto, real estate, etc.)",
208
+ {
209
+ name: z.string().describe("Asset name"),
210
+ assetClass: z.string().describe("Asset class key (e.g. 'Equity', 'Bond', 'Crypto', 'Real Estate'). Must match an existing asset-classes row."),
211
+ symbol: z.string().optional().describe("Ticker/symbol (e.g. 'AAPL', 'BTC')"),
212
+ defaultCurrency: z.string().optional().describe("Default currency code. Default: USD"),
213
+ currentPrice: z.number().optional().describe("Current price per unit as a number"),
214
+ notes: z.string().optional()
215
+ },
216
+ async (params) => {
217
+ const data = await api("POST", "/api/assets", params);
218
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
219
+ }
220
+ );
221
+ server2.tool(
222
+ "update_asset",
223
+ "Update an existing asset (partial update)",
224
+ {
225
+ id: z.number().describe("Asset ID to update"),
226
+ name: z.string().optional(),
227
+ assetClass: z.string().optional(),
228
+ symbol: z.string().optional(),
229
+ defaultCurrency: z.string().optional(),
230
+ currentPrice: z.number().optional(),
231
+ notes: z.string().optional()
232
+ },
233
+ async ({ id, ...body }) => {
234
+ const data = await api("PATCH", `/api/assets/${id}`, body);
235
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
236
+ }
237
+ );
238
+ server2.tool(
239
+ "delete_asset",
240
+ "Delete an asset by ID",
241
+ { id: z.number().describe("Asset ID to delete") },
242
+ async ({ id }) => {
243
+ const data = await api("DELETE", `/api/assets/${id}`);
244
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
245
+ }
246
+ );
247
+ server2.tool(
248
+ "list_asset_prices",
249
+ "List historical prices for an asset",
250
+ {
251
+ id: z.number().describe("Asset ID"),
252
+ limit: z.number().optional(),
253
+ offset: z.number().optional()
254
+ },
255
+ async ({ id, limit, offset }) => {
256
+ const params = new URLSearchParams();
257
+ if (limit) params.set("limit", String(limit));
258
+ if (offset) params.set("offset", String(offset));
259
+ const qs = params.toString();
260
+ const data = await api("GET", `/api/assets/${id}/prices${qs ? `?${qs}` : ""}`);
261
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
262
+ }
263
+ );
264
+ server2.tool(
265
+ "update_asset_price",
266
+ "Record a new price for an asset",
267
+ {
268
+ id: z.number().describe("Asset ID"),
269
+ price: z.number().describe("New price value"),
270
+ memo: z.string().optional().describe("Price update memo"),
271
+ source: z.string().optional().describe("Price source (e.g. manual, bloomberg)")
272
+ },
273
+ async ({ id, ...body }) => {
274
+ const data = await api("POST", `/api/assets/${id}/prices`, body);
275
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
276
+ }
277
+ );
278
+ server2.tool(
279
+ "list_positions",
280
+ "List all positions (holdings) across accounts",
281
+ { limit: z.number().optional(), offset: z.number().optional() },
282
+ async ({ limit, offset }) => {
283
+ const params = new URLSearchParams();
284
+ if (limit) params.set("limit", String(limit));
285
+ if (offset) params.set("offset", String(offset));
286
+ const qs = params.toString();
287
+ const data = await api("GET", `/api/positions${qs ? `?${qs}` : ""}`);
288
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
289
+ }
290
+ );
291
+ server2.tool(
292
+ "create_position",
293
+ "Create a new position (a holding of an asset, owned by an entity, optionally in an account)",
294
+ {
295
+ entityId: z.number().describe("Owner entity ID"),
296
+ label: z.string().describe("Display label for this position (e.g. 'AAPL @ Schwab', 'Brooklyn rental')"),
297
+ assetClass: z.string().describe("Asset class key (e.g. 'Equity', 'Real Estate', 'Cash')"),
298
+ currentValue: z.number().describe("Current value of the position (in `currency`). Negative for liabilities."),
299
+ accountId: z.number().optional().describe("Optional account ID this position lives in"),
300
+ assetId: z.number().optional().describe("Optional asset ID this position references"),
301
+ liability: z.boolean().optional().describe("True if this is a liability (mortgage, loan). Default: false"),
302
+ quantity: z.number().optional().describe("Quantity held (e.g. shares, units)"),
303
+ currentPrice: z.number().optional().describe("Current price per unit"),
304
+ averageCost: z.number().optional().describe("Average cost per unit"),
305
+ realizedGain: z.number().optional().describe("Realized gain to date. Default: 0"),
306
+ status: z.string().optional().describe("'active' or 'closed'. Default: 'active'"),
307
+ currency: z.string().optional().describe("Currency code. Default: USD"),
308
+ notes: z.string().optional()
309
+ },
310
+ async (params) => {
311
+ const data = await api("POST", "/api/positions", params);
312
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
313
+ }
314
+ );
315
+ server2.tool(
316
+ "update_position",
317
+ "Update an existing position (partial update)",
318
+ {
319
+ id: z.number().describe("Position ID to update"),
320
+ entityId: z.number().optional(),
321
+ accountId: z.number().optional(),
322
+ assetId: z.number().optional(),
323
+ label: z.string().optional(),
324
+ assetClass: z.string().optional(),
325
+ liability: z.boolean().optional(),
326
+ quantity: z.number().optional(),
327
+ currentPrice: z.number().optional(),
328
+ currentValue: z.number().optional(),
329
+ averageCost: z.number().optional(),
330
+ realizedGain: z.number().optional(),
331
+ status: z.string().optional(),
332
+ currency: z.string().optional(),
333
+ notes: z.string().optional()
334
+ },
335
+ async ({ id, ...body }) => {
336
+ const data = await api("PATCH", `/api/positions/${id}`, body);
337
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
338
+ }
339
+ );
340
+ server2.tool(
341
+ "delete_position",
342
+ "Delete a position",
343
+ { id: z.number().describe("Position ID to delete") },
344
+ async ({ id }) => {
345
+ const data = await api("DELETE", `/api/positions/${id}`);
346
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
347
+ }
348
+ );
349
+ server2.tool(
350
+ "sell_all_position",
351
+ "Close/sell all of a position (creates a sell transaction)",
352
+ {
353
+ id: z.number().describe("Position ID to sell"),
354
+ price: z.number().optional().describe("Sale price per unit"),
355
+ amount: z.number().optional().describe("Total sale amount"),
356
+ fees: z.number().optional().describe("Transaction fees"),
357
+ memo: z.string().optional().describe("Sale memo"),
358
+ quantity: z.number().optional().describe("Quantity to sell (defaults to all)")
359
+ },
360
+ async ({ id, ...body }) => {
361
+ const data = await api("POST", `/api/positions/${id}/sell-all`, body);
362
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
363
+ }
364
+ );
365
+ server2.tool(
366
+ "list_position_events",
367
+ "List valuation events for a specific position (append-only history)",
368
+ {
369
+ id: z.number().describe("Position ID"),
370
+ limit: z.number().optional(),
371
+ offset: z.number().optional()
372
+ },
373
+ async ({ id, limit, offset }) => {
374
+ const params = new URLSearchParams();
375
+ if (limit) params.set("limit", String(limit));
376
+ if (offset) params.set("offset", String(offset));
377
+ const qs = params.toString();
378
+ const data = await api("GET", `/api/positions/${id}/events${qs ? `?${qs}` : ""}`);
379
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
380
+ }
381
+ );
382
+ server2.tool(
383
+ "list_events",
384
+ "List valuation events across all positions in the organization",
385
+ { limit: z.number().optional(), offset: z.number().optional() },
386
+ async ({ limit, offset }) => {
387
+ const params = new URLSearchParams();
388
+ if (limit) params.set("limit", String(limit));
389
+ if (offset) params.set("offset", String(offset));
390
+ const qs = params.toString();
391
+ const data = await api("GET", `/api/events${qs ? `?${qs}` : ""}`);
392
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
393
+ }
394
+ );
395
+ server2.tool(
396
+ "list_position_relations",
397
+ "List all position relations (linked/related positions)",
398
+ { limit: z.number().optional(), offset: z.number().optional() },
399
+ async ({ limit, offset }) => {
400
+ const params = new URLSearchParams();
401
+ if (limit) params.set("limit", String(limit));
402
+ if (offset) params.set("offset", String(offset));
403
+ const qs = params.toString();
404
+ const data = await api("GET", `/api/position-relations${qs ? `?${qs}` : ""}`);
405
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
406
+ }
407
+ );
408
+ server2.tool(
409
+ "create_position_relation",
410
+ "Link two positions together",
411
+ {
412
+ positionId: z.number().describe("First position ID"),
413
+ relatedPositionId: z.number().describe("Related position ID")
414
+ },
415
+ async (params) => {
416
+ const data = await api("POST", "/api/position-relations", params);
417
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
418
+ }
419
+ );
420
+ server2.tool(
421
+ "delete_position_relation",
422
+ "Remove a position relation",
423
+ { id: z.number().describe("Position relation ID to delete") },
424
+ async ({ id }) => {
425
+ const data = await api("DELETE", `/api/position-relations/${id}`);
426
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
427
+ }
428
+ );
429
+ server2.tool(
430
+ "list_transactions",
431
+ "List all transactions (buys, sells, dividends, fees, etc.)",
432
+ { limit: z.number().optional(), offset: z.number().optional() },
433
+ async ({ limit, offset }) => {
434
+ const params = new URLSearchParams();
435
+ if (limit) params.set("limit", String(limit));
436
+ if (offset) params.set("offset", String(offset));
437
+ const qs = params.toString();
438
+ const data = await api("GET", `/api/transactions${qs ? `?${qs}` : ""}`);
439
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
440
+ }
441
+ );
442
+ server2.tool(
443
+ "create_transaction",
444
+ "Create a new transaction (buy, sell, dividend, fee, etc.)",
445
+ {
446
+ positionId: z.number().describe("Position ID this transaction belongs to"),
447
+ transactionType: z.string().describe("Transaction type key (e.g. 'buy', 'sell', 'dividend', 'fee', 'distribution')"),
448
+ quantity: z.number().describe("Quantity (use 0 for cash transactions like dividends or fees)"),
449
+ amount: z.number().describe("Total cash amount of the transaction. Positive for inflows, negative for outflows."),
450
+ price: z.number().optional().describe("Price per unit (for buys/sells)"),
451
+ fees: z.number().optional().describe("Fee amount. Default: 0"),
452
+ timestamp: z.number().optional().describe("Transaction time as epoch milliseconds. Default: now."),
453
+ memo: z.string().optional()
454
+ },
455
+ async (params) => {
456
+ const data = await api("POST", "/api/transactions", params);
457
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
458
+ }
459
+ );
460
+ server2.tool(
461
+ "list_institutions",
462
+ "List all institutions (banks, brokers, custodians)",
463
+ {},
464
+ async () => {
465
+ const data = await api("GET", "/api/institutions");
466
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
467
+ }
468
+ );
469
+ server2.tool(
470
+ "create_institution",
471
+ "Create a new institution",
472
+ {
473
+ name: z.string().describe("Institution name"),
474
+ notes: z.string().optional()
475
+ },
476
+ async (params) => {
477
+ const data = await api("POST", "/api/institutions", params);
478
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
479
+ }
480
+ );
481
+ server2.tool(
482
+ "update_institution",
483
+ "Update an institution",
484
+ {
485
+ id: z.number().describe("Institution ID"),
486
+ name: z.string().optional(),
487
+ notes: z.string().optional()
488
+ },
489
+ async ({ id, ...body }) => {
490
+ const data = await api("PATCH", `/api/institutions/${id}`, body);
491
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
492
+ }
493
+ );
494
+ server2.tool(
495
+ "delete_institution",
496
+ "Delete an institution",
497
+ { id: z.number().describe("Institution ID to delete") },
498
+ async ({ id }) => {
499
+ const data = await api("DELETE", `/api/institutions/${id}`);
500
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
501
+ }
502
+ );
503
+ server2.tool(
504
+ "list_entity_types",
505
+ "List all entity types (Individual, Trust, Corporation, etc.)",
506
+ {},
507
+ async () => {
508
+ const data = await api("GET", "/api/entity-types");
509
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
510
+ }
511
+ );
512
+ server2.tool(
513
+ "create_entity_type",
514
+ "Create a new entity type catalog entry",
515
+ {
516
+ key: z.string().describe("Stable key referenced by entities.type (e.g. 'Individual', 'Trust')"),
517
+ label: z.string().describe("Human-readable display label"),
518
+ notes: z.string().optional()
519
+ },
520
+ async (params) => {
521
+ const data = await api("POST", "/api/entity-types", params);
522
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
523
+ }
524
+ );
525
+ server2.tool(
526
+ "update_entity_type",
527
+ "Update an entity type catalog entry (partial update)",
528
+ {
529
+ id: z.number().describe("Entity type ID"),
530
+ key: z.string().optional(),
531
+ label: z.string().optional(),
532
+ notes: z.string().optional()
533
+ },
534
+ async ({ id, ...body }) => {
535
+ const data = await api("PATCH", `/api/entity-types/${id}`, body);
536
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
537
+ }
538
+ );
539
+ server2.tool(
540
+ "delete_entity_type",
541
+ "Delete an entity type",
542
+ { id: z.number().describe("Entity type ID to delete") },
543
+ async ({ id }) => {
544
+ const data = await api("DELETE", `/api/entity-types/${id}`);
545
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
546
+ }
547
+ );
548
+ server2.tool(
549
+ "list_role_types",
550
+ "List all role types (Owner, Beneficiary, Trustee, etc.)",
551
+ {},
552
+ async () => {
553
+ const data = await api("GET", "/api/role-types");
554
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
555
+ }
556
+ );
557
+ server2.tool(
558
+ "create_role_type",
559
+ "Create a new role type catalog entry",
560
+ {
561
+ key: z.string().describe("Stable key (e.g. 'Owner', 'Trustee', 'Beneficiary')"),
562
+ label: z.string().describe("Human-readable display label"),
563
+ notes: z.string().optional()
564
+ },
565
+ async (params) => {
566
+ const data = await api("POST", "/api/role-types", params);
567
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
568
+ }
569
+ );
570
+ server2.tool(
571
+ "update_role_type",
572
+ "Update a role type catalog entry (partial update)",
573
+ {
574
+ id: z.number().describe("Role type ID"),
575
+ key: z.string().optional(),
576
+ label: z.string().optional(),
577
+ notes: z.string().optional()
578
+ },
579
+ async ({ id, ...body }) => {
580
+ const data = await api("PATCH", `/api/role-types/${id}`, body);
581
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
582
+ }
583
+ );
584
+ server2.tool(
585
+ "delete_role_type",
586
+ "Delete a role type",
587
+ { id: z.number().describe("Role type ID to delete") },
588
+ async ({ id }) => {
589
+ const data = await api("DELETE", `/api/role-types/${id}`);
590
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
591
+ }
592
+ );
593
+ server2.tool(
594
+ "list_account_types",
595
+ "List all account types (Brokerage, Checking, IRA, 401k, etc.)",
596
+ {},
597
+ async () => {
598
+ const data = await api("GET", "/api/account-types");
599
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
600
+ }
601
+ );
602
+ server2.tool(
603
+ "create_account_type",
604
+ "Create a new account type catalog entry",
605
+ {
606
+ key: z.string().describe("Stable key referenced by accounts.accountType (e.g. 'Brokerage', 'Bank')"),
607
+ label: z.string().describe("Human-readable display label"),
608
+ notes: z.string().optional()
609
+ },
610
+ async (params) => {
611
+ const data = await api("POST", "/api/account-types", params);
612
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
613
+ }
614
+ );
615
+ server2.tool(
616
+ "update_account_type",
617
+ "Update an account type catalog entry (partial update)",
618
+ {
619
+ id: z.number().describe("Account type ID"),
620
+ key: z.string().optional(),
621
+ label: z.string().optional(),
622
+ notes: z.string().optional()
623
+ },
624
+ async ({ id, ...body }) => {
625
+ const data = await api("PATCH", `/api/account-types/${id}`, body);
626
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
627
+ }
628
+ );
629
+ server2.tool(
630
+ "delete_account_type",
631
+ "Delete an account type",
632
+ { id: z.number().describe("Account type ID to delete") },
633
+ async ({ id }) => {
634
+ const data = await api("DELETE", `/api/account-types/${id}`);
635
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
636
+ }
637
+ );
638
+ server2.tool(
639
+ "list_asset_classes",
640
+ "List all asset classes (Equities, Fixed Income, Real Estate, etc.)",
641
+ {},
642
+ async () => {
643
+ const data = await api("GET", "/api/asset-classes");
644
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
645
+ }
646
+ );
647
+ server2.tool(
648
+ "create_asset_class",
649
+ "Create a new asset class catalog entry",
650
+ {
651
+ key: z.string().describe("Stable key referenced by assets.assetClass (e.g. 'Equity', 'Real Estate')"),
652
+ label: z.string().describe("Human-readable display label"),
653
+ treatment: z.string().optional().describe("Accounting treatment. Default: 'asset'. Use 'liability' for debt classes."),
654
+ notes: z.string().optional()
655
+ },
656
+ async (params) => {
657
+ const data = await api("POST", "/api/asset-classes", params);
658
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
659
+ }
660
+ );
661
+ server2.tool(
662
+ "update_asset_class",
663
+ "Update an asset class catalog entry (partial update)",
664
+ {
665
+ id: z.number().describe("Asset class ID"),
666
+ key: z.string().optional(),
667
+ label: z.string().optional(),
668
+ treatment: z.string().optional(),
669
+ notes: z.string().optional()
670
+ },
671
+ async ({ id, ...body }) => {
672
+ const data = await api("PATCH", `/api/asset-classes/${id}`, body);
673
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
674
+ }
675
+ );
676
+ server2.tool(
677
+ "delete_asset_class",
678
+ "Delete an asset class",
679
+ { id: z.number().describe("Asset class ID to delete") },
680
+ async ({ id }) => {
681
+ const data = await api("DELETE", `/api/asset-classes/${id}`);
682
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
683
+ }
684
+ );
685
+ server2.tool(
686
+ "data_dry_run",
687
+ "Dry-run a batch data import (validates without applying changes). Returns a preview of what would change.",
688
+ {
689
+ operations: z.array(z.object({
690
+ action: z.enum(["create", "update", "delete"]).describe("Operation type"),
691
+ resource: z.string().describe("Resource type (entity, account, asset, position, transaction, institution, entity-type, role-type, account-type, asset-class)"),
692
+ data: z.record(z.unknown()).optional().describe("Resource data for create/update"),
693
+ id: z.number().optional().describe("Resource ID for update/delete")
694
+ })).describe("Array of operations to preview")
695
+ },
696
+ async ({ operations }) => {
697
+ const data = await api("POST", "/api/data/dry-run", { operations });
698
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
699
+ }
700
+ );
701
+ server2.tool(
702
+ "data_apply",
703
+ "Apply a batch data import (creates, updates, or deletes resources). Use data_dry_run first to preview.",
704
+ {
705
+ operations: z.array(z.object({
706
+ action: z.enum(["create", "update", "delete"]).describe("Operation type"),
707
+ resource: z.string().describe("Resource type"),
708
+ data: z.record(z.unknown()).optional().describe("Resource data for create/update"),
709
+ id: z.number().optional().describe("Resource ID for update/delete")
710
+ })).describe("Array of operations to apply")
711
+ },
712
+ async ({ operations }) => {
713
+ const data = await api("POST", "/api/data/apply", { operations });
714
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
715
+ }
716
+ );
717
+ }
718
+ function createApiClient(opts) {
719
+ const baseUrl = opts.baseUrl.replace(/\/+$/, "");
720
+ const apiKey = opts.apiKey;
721
+ return async (method, path, body) => {
722
+ const headers = {
723
+ Authorization: `Bearer ${apiKey}`,
724
+ Accept: "application/json"
725
+ };
726
+ if (body !== void 0) {
727
+ headers["Content-Type"] = "application/json";
728
+ }
729
+ const res = await fetch(`${baseUrl}${path}`, {
730
+ method,
731
+ headers,
732
+ body: body !== void 0 ? JSON.stringify(body) : void 0
733
+ });
734
+ const text = await res.text();
735
+ if (!res.ok) {
736
+ throw new Error(`Tensor API ${method} ${path} \u2192 ${res.status}: ${text}`);
737
+ }
738
+ try {
739
+ return JSON.parse(text);
740
+ } catch {
741
+ return text;
742
+ }
743
+ };
744
+ }
745
+
746
+ // index.ts
747
+ var BASE_URL = (process.env.TENSOR_BASE_URL || "http://localhost:5000").trim();
748
+ var API_KEY = (process.env.TENSOR_API_KEY || "").trim();
749
+ if (!API_KEY) {
750
+ console.error("[tensor-mcp] TENSOR_API_KEY is required. Set it in your environment.");
751
+ process.exit(1);
752
+ }
753
+ var server = new McpServer({
754
+ name: "tensor",
755
+ version: "1.0.0"
756
+ });
757
+ registerAllTools(server, createApiClient({ apiKey: API_KEY, baseUrl: BASE_URL }));
758
+ async function main() {
759
+ const transport = new StdioServerTransport();
760
+ await server.connect(transport);
761
+ }
762
+ main().catch((err) => {
763
+ console.error("[tensor-mcp] Fatal:", err);
764
+ process.exit(1);
765
+ });
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@levitating/tensor-mcp",
3
+ "version": "1.0.0",
4
+ "description": "Tensor MCP — Model Context Protocol server for the Tensor wealth management API. Exposes the full Tensor API as 53 tools for Claude, Cursor, Codex, and any MCP-aware client.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "bin": {
8
+ "tensor-mcp": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "build": "esbuild index.ts --bundle --platform=node --target=node20 --format=esm --outfile=dist/index.js --banner:js=\"#!/usr/bin/env node\" --packages=external && chmod +x dist/index.js",
16
+ "prepublishOnly": "npm run build"
17
+ },
18
+ "engines": {
19
+ "node": ">=20"
20
+ },
21
+ "keywords": [
22
+ "mcp",
23
+ "model-context-protocol",
24
+ "tensor",
25
+ "wealth-management",
26
+ "claude",
27
+ "ai-tools"
28
+ ],
29
+ "homepage": "https://tensor.levitating.org/docs/mcp",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/charleswayn/tensor.git",
33
+ "directory": "mcp-server"
34
+ },
35
+ "license": "UNLICENSED",
36
+ "dependencies": {
37
+ "@modelcontextprotocol/sdk": "^1.29.0",
38
+ "zod": "^3.24.2"
39
+ },
40
+ "devDependencies": {
41
+ "esbuild": "^0.24.0",
42
+ "typescript": "^5.6.0"
43
+ }
44
+ }