@ctxprotocol/sdk 0.2.0 → 0.5.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.
- package/README.md +93 -7
- package/dist/index.d.cts +324 -0
- package/dist/index.d.ts +324 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -265,12 +265,20 @@ const result = await client.tools.execute({
|
|
|
265
265
|
|
|
266
266
|
```typescript
|
|
267
267
|
import type {
|
|
268
|
+
// Client types
|
|
268
269
|
ContextClientOptions,
|
|
269
270
|
Tool,
|
|
270
271
|
McpTool,
|
|
271
272
|
ExecuteOptions,
|
|
272
273
|
ExecutionResult,
|
|
273
274
|
ContextErrorCode,
|
|
275
|
+
// Context types (for MCP server contributors)
|
|
276
|
+
ToolRequirements,
|
|
277
|
+
ContextRequirementType,
|
|
278
|
+
HyperliquidContext,
|
|
279
|
+
PolymarketContext,
|
|
280
|
+
WalletContext,
|
|
281
|
+
UserContext,
|
|
274
282
|
} from "@ctxprotocol/sdk";
|
|
275
283
|
```
|
|
276
284
|
|
|
@@ -309,6 +317,18 @@ interface ExecutionResult<T = unknown> {
|
|
|
309
317
|
}
|
|
310
318
|
```
|
|
311
319
|
|
|
320
|
+
### ToolRequirements (MCP Server Contributors)
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
/** Context types supported by the marketplace */
|
|
324
|
+
type ContextRequirementType = "polymarket" | "hyperliquid" | "wallet";
|
|
325
|
+
|
|
326
|
+
/** Declare what context your tool needs */
|
|
327
|
+
interface ToolRequirements {
|
|
328
|
+
context?: ContextRequirementType[];
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
312
332
|
## Error Handling
|
|
313
333
|
|
|
314
334
|
The SDK throws `ContextError` with specific error codes. In an agentic context, you can feed errors back to your LLM so it can self-correct.
|
|
@@ -355,11 +375,13 @@ try {
|
|
|
355
375
|
|
|
356
376
|
## Building MCP Servers (Tool Contributors)
|
|
357
377
|
|
|
358
|
-
Want to earn money by contributing tools to the Context marketplace? Build a standard MCP server
|
|
378
|
+
Want to earn money by contributing tools to the Context marketplace? Build a standard MCP server that uses `outputSchema` and `structuredContent` from the [official MCP specification](https://modelcontextprotocol.io/specification/2025-11-25/server/tools#output-schema):
|
|
359
379
|
|
|
360
380
|
1. **`outputSchema`** in tool definitions — JSON Schema describing your response
|
|
361
381
|
2. **`structuredContent`** in responses — Machine-readable data matching the schema
|
|
362
382
|
|
|
383
|
+
> **Note:** These are standard MCP features defined in the [MCP Tools specification](https://modelcontextprotocol.io/specification/2025-11-25/server/tools#output-schema). While optional in vanilla MCP, Context requires them for payment verification, dispute resolution, and AI code generation.
|
|
384
|
+
|
|
363
385
|
### Why These Matter
|
|
364
386
|
|
|
365
387
|
| Requirement | Purpose |
|
|
@@ -367,15 +389,70 @@ Want to earn money by contributing tools to the Context marketplace? Build a sta
|
|
|
367
389
|
| `outputSchema` | AI agents use this to generate type-safe code. Context uses it for dispute resolution. |
|
|
368
390
|
| `structuredContent` | Agents parse this for programmatic access. Text `content` is for humans. |
|
|
369
391
|
|
|
370
|
-
###
|
|
392
|
+
### Context Injection (Portfolio Analysis Tools)
|
|
393
|
+
|
|
394
|
+
Building tools that analyze user portfolios? Context automatically injects user portfolio data into your tools—no authentication required.
|
|
371
395
|
|
|
372
|
-
|
|
396
|
+
**📖 Read the full guide: [Context Injection Architecture](./docs/context-injection.md)**
|
|
397
|
+
|
|
398
|
+
Key benefits:
|
|
399
|
+
- **No Auth Required** — User data is injected automatically from their linked wallets
|
|
400
|
+
- **Type-Safe** — Use SDK types like `PolymarketContext`, `HyperliquidContext`
|
|
401
|
+
- **Focus on Analysis** — You receive structured data, you provide insights
|
|
402
|
+
|
|
403
|
+
### Context Requirements Declaration
|
|
404
|
+
|
|
405
|
+
If your tool needs user portfolio data, you **MUST** declare this explicitly using `requirements.context`:
|
|
406
|
+
|
|
407
|
+
```typescript
|
|
408
|
+
import type { ToolRequirements } from "@ctxprotocol/sdk";
|
|
409
|
+
|
|
410
|
+
const TOOLS = [{
|
|
411
|
+
name: "analyze_my_positions",
|
|
412
|
+
description: "Analyze your positions with personalized insights",
|
|
413
|
+
|
|
414
|
+
// ⭐ REQUIRED: Explicit context requirements for portfolio tools
|
|
415
|
+
requirements: {
|
|
416
|
+
context: ["hyperliquid"], // or "polymarket", "wallet"
|
|
417
|
+
} satisfies ToolRequirements,
|
|
418
|
+
|
|
419
|
+
inputSchema: {
|
|
420
|
+
type: "object",
|
|
421
|
+
properties: {
|
|
422
|
+
portfolio: {
|
|
423
|
+
type: "object",
|
|
424
|
+
description: "Portfolio context (injected by platform)",
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
required: ["portfolio"],
|
|
428
|
+
},
|
|
429
|
+
outputSchema: { /* ... */ },
|
|
430
|
+
}];
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
**Available context types:**
|
|
434
|
+
|
|
435
|
+
| Type | Description | Injected Data |
|
|
436
|
+
|------|-------------|---------------|
|
|
437
|
+
| `"hyperliquid"` | Hyperliquid perpetuals & spot | `HyperliquidContext` |
|
|
438
|
+
| `"polymarket"` | Polymarket prediction markets | `PolymarketContext` |
|
|
439
|
+
| `"wallet"` | Generic EVM wallet | `WalletContext` |
|
|
440
|
+
|
|
441
|
+
**How it works:**
|
|
442
|
+
1. User links their wallet in Context app settings
|
|
443
|
+
2. When your tool is selected, platform checks `requirements.context`
|
|
444
|
+
3. Platform fetches user's portfolio data from protocol APIs
|
|
445
|
+
4. Data is injected as the `portfolio` argument to your tool
|
|
446
|
+
|
|
447
|
+
### Example: Standard MCP Server
|
|
448
|
+
|
|
449
|
+
Build your server with the standard `@modelcontextprotocol/sdk`:
|
|
373
450
|
|
|
374
451
|
```typescript
|
|
375
452
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
376
453
|
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
|
377
454
|
|
|
378
|
-
// Define tools with outputSchema (
|
|
455
|
+
// Define tools with outputSchema (standard MCP feature, required by Context)
|
|
379
456
|
const TOOLS = [{
|
|
380
457
|
name: "get_gas_price",
|
|
381
458
|
description: "Get current gas prices",
|
|
@@ -385,7 +462,7 @@ const TOOLS = [{
|
|
|
385
462
|
chainId: { type: "number", description: "EVM chain ID" },
|
|
386
463
|
},
|
|
387
464
|
},
|
|
388
|
-
// 👇
|
|
465
|
+
// 👇 Standard MCP feature (see: modelcontextprotocol.io/specification)
|
|
389
466
|
outputSchema: {
|
|
390
467
|
type: "object",
|
|
391
468
|
properties: {
|
|
@@ -409,9 +486,9 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
409
486
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
410
487
|
const data = await fetchGasData(request.params.arguments.chainId);
|
|
411
488
|
|
|
412
|
-
// 👇
|
|
489
|
+
// 👇 Standard MCP feature (see: modelcontextprotocol.io/specification)
|
|
413
490
|
return {
|
|
414
|
-
content: [{ type: "text", text: JSON.stringify(data) }],
|
|
491
|
+
content: [{ type: "text", text: JSON.stringify(data) }], // Backward compat
|
|
415
492
|
structuredContent: data, // Machine-readable, matches outputSchema
|
|
416
493
|
};
|
|
417
494
|
});
|
|
@@ -444,6 +521,15 @@ When you execute a tool:
|
|
|
444
521
|
3. **10%** goes to the protocol
|
|
445
522
|
4. Tool executes and returns results
|
|
446
523
|
|
|
524
|
+
## Documentation
|
|
525
|
+
|
|
526
|
+
| Document | Description |
|
|
527
|
+
|----------|-------------|
|
|
528
|
+
| [Context Injection Guide](./docs/context-injection.md) | Architecture guide for building portfolio analysis tools with automatic user data injection |
|
|
529
|
+
| [Polymarket Example](./examples/server/polymarket-contributor) | Complete MCP server for Polymarket intelligence |
|
|
530
|
+
| [Hyperliquid Example](./examples/server/hyperliquid-contributor) | Complete MCP server for Hyperliquid analytics |
|
|
531
|
+
| [Blocknative Example](./examples/server/blocknative-contributor) | Simple gas price MCP server |
|
|
532
|
+
|
|
447
533
|
## Links
|
|
448
534
|
|
|
449
535
|
- [Context Protocol](https://ctxprotocol.com) — Main website
|
package/dist/index.d.cts
CHANGED
|
@@ -1 +1,325 @@
|
|
|
1
1
|
export { ContextClient, ContextClientOptions, ContextError, ContextErrorCode, Discovery, ExecuteApiErrorResponse, ExecuteApiResponse, ExecuteApiSuccessResponse, ExecuteOptions, ExecutionResult, McpTool, SearchOptions, SearchResponse, Tool, Tools } from './client/index.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wallet context types for portfolio tracking.
|
|
5
|
+
*
|
|
6
|
+
* These types represent wallet and token holdings that can be
|
|
7
|
+
* injected into MCP tools for personalized analysis.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Base wallet context - address and chain info
|
|
13
|
+
*/
|
|
14
|
+
interface WalletContext {
|
|
15
|
+
/** Wallet address (checksummed) */
|
|
16
|
+
address: string;
|
|
17
|
+
/** Chain ID (137 for Polygon, 1 for Ethereum, etc.) */
|
|
18
|
+
chainId: number;
|
|
19
|
+
/** Native token balance in wei (string for precision) */
|
|
20
|
+
nativeBalance?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* ERC20 token holdings
|
|
24
|
+
*/
|
|
25
|
+
interface ERC20TokenBalance {
|
|
26
|
+
/** Token contract address */
|
|
27
|
+
address: string;
|
|
28
|
+
/** Token symbol (e.g., "USDC") */
|
|
29
|
+
symbol: string;
|
|
30
|
+
/** Token decimals */
|
|
31
|
+
decimals: number;
|
|
32
|
+
/** Balance in smallest unit (string for precision) */
|
|
33
|
+
balance: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Collection of ERC20 token balances
|
|
37
|
+
*/
|
|
38
|
+
interface ERC20Context {
|
|
39
|
+
/** Array of token balances */
|
|
40
|
+
tokens: ERC20TokenBalance[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Polymarket context types for portfolio tracking.
|
|
45
|
+
*
|
|
46
|
+
* These types represent Polymarket positions and orders that can be
|
|
47
|
+
* injected into MCP tools for personalized portfolio analysis.
|
|
48
|
+
*
|
|
49
|
+
* @packageDocumentation
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* A single Polymarket position
|
|
53
|
+
*/
|
|
54
|
+
interface PolymarketPosition {
|
|
55
|
+
/** The market's condition ID */
|
|
56
|
+
conditionId: string;
|
|
57
|
+
/** The specific outcome token ID */
|
|
58
|
+
tokenId: string;
|
|
59
|
+
/** Which outcome this position is for */
|
|
60
|
+
outcome: "YES" | "NO";
|
|
61
|
+
/** Number of shares held */
|
|
62
|
+
shares: number;
|
|
63
|
+
/** Average entry price (0-1 scale) */
|
|
64
|
+
avgEntryPrice: number;
|
|
65
|
+
/** Market question/title for display */
|
|
66
|
+
marketTitle?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* An open order on Polymarket
|
|
70
|
+
*/
|
|
71
|
+
interface PolymarketOrder {
|
|
72
|
+
/** Order ID */
|
|
73
|
+
orderId: string;
|
|
74
|
+
/** The market's condition ID */
|
|
75
|
+
conditionId: string;
|
|
76
|
+
/** Order side */
|
|
77
|
+
side: "BUY" | "SELL";
|
|
78
|
+
/** Which outcome this order is for */
|
|
79
|
+
outcome: "YES" | "NO";
|
|
80
|
+
/** Limit price (0-1 scale) */
|
|
81
|
+
price: number;
|
|
82
|
+
/** Order size in shares */
|
|
83
|
+
size: number;
|
|
84
|
+
/** Amount already filled */
|
|
85
|
+
filled: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Complete Polymarket portfolio context.
|
|
89
|
+
* This is what gets passed to MCP tools for personalized analysis.
|
|
90
|
+
*/
|
|
91
|
+
interface PolymarketContext {
|
|
92
|
+
/** The wallet address this context is for */
|
|
93
|
+
walletAddress: string;
|
|
94
|
+
/** All open positions */
|
|
95
|
+
positions: PolymarketPosition[];
|
|
96
|
+
/** All open orders */
|
|
97
|
+
openOrders: PolymarketOrder[];
|
|
98
|
+
/** Total portfolio value in USD (sum of position values) */
|
|
99
|
+
totalValue?: number;
|
|
100
|
+
/** When this context was fetched (ISO 8601 string) */
|
|
101
|
+
fetchedAt: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Hyperliquid context types for portfolio tracking.
|
|
106
|
+
*
|
|
107
|
+
* These types represent Hyperliquid perpetual positions, orders, and account
|
|
108
|
+
* data that can be injected into MCP tools for personalized portfolio analysis.
|
|
109
|
+
*
|
|
110
|
+
* @packageDocumentation
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Hyperliquid Perpetual Position
|
|
114
|
+
*/
|
|
115
|
+
interface HyperliquidPerpPosition {
|
|
116
|
+
/** Asset symbol (e.g., "ETH", "BTC") */
|
|
117
|
+
coin: string;
|
|
118
|
+
/** Position size (positive = long, negative = short) */
|
|
119
|
+
size: number;
|
|
120
|
+
/** Entry price */
|
|
121
|
+
entryPrice: number;
|
|
122
|
+
/** Current mark price */
|
|
123
|
+
markPrice?: number;
|
|
124
|
+
/** Unrealized PnL in USD */
|
|
125
|
+
unrealizedPnl: number;
|
|
126
|
+
/** Liquidation price */
|
|
127
|
+
liquidationPrice: number;
|
|
128
|
+
/** Position value in USD */
|
|
129
|
+
positionValue: number;
|
|
130
|
+
/** Leverage info */
|
|
131
|
+
leverage: {
|
|
132
|
+
type: "cross" | "isolated";
|
|
133
|
+
value: number;
|
|
134
|
+
};
|
|
135
|
+
/** Margin used for this position */
|
|
136
|
+
marginUsed: number;
|
|
137
|
+
/** Return on equity percentage */
|
|
138
|
+
returnOnEquity: number;
|
|
139
|
+
/** Cumulative funding paid/received */
|
|
140
|
+
cumFunding: {
|
|
141
|
+
allTime: number;
|
|
142
|
+
sinceOpen: number;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Hyperliquid Open Order
|
|
147
|
+
*/
|
|
148
|
+
interface HyperliquidOrder {
|
|
149
|
+
/** Order ID */
|
|
150
|
+
oid: number;
|
|
151
|
+
/** Asset symbol */
|
|
152
|
+
coin: string;
|
|
153
|
+
/** Order side: "B" = Buy, "A" = Ask/Sell */
|
|
154
|
+
side: "B" | "A";
|
|
155
|
+
/** Limit price */
|
|
156
|
+
limitPrice: number;
|
|
157
|
+
/** Order size */
|
|
158
|
+
size: number;
|
|
159
|
+
/** Original order size */
|
|
160
|
+
originalSize: number;
|
|
161
|
+
/** Order type */
|
|
162
|
+
orderType: "Limit" | "Market" | "Stop" | "TakeProfit";
|
|
163
|
+
/** Is reduce-only order */
|
|
164
|
+
reduceOnly: boolean;
|
|
165
|
+
/** Is trigger order */
|
|
166
|
+
isTrigger: boolean;
|
|
167
|
+
/** Trigger price (if trigger order) */
|
|
168
|
+
triggerPrice?: number;
|
|
169
|
+
/** Order timestamp */
|
|
170
|
+
timestamp: number;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Hyperliquid Spot Balance
|
|
174
|
+
*/
|
|
175
|
+
interface HyperliquidSpotBalance {
|
|
176
|
+
/** Token symbol */
|
|
177
|
+
token: string;
|
|
178
|
+
/** Token balance */
|
|
179
|
+
balance: number;
|
|
180
|
+
/** USD value */
|
|
181
|
+
usdValue?: number;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Hyperliquid Account Summary
|
|
185
|
+
*/
|
|
186
|
+
interface HyperliquidAccountSummary {
|
|
187
|
+
/** Total account value in USD */
|
|
188
|
+
accountValue: number;
|
|
189
|
+
/** Total margin used */
|
|
190
|
+
totalMarginUsed: number;
|
|
191
|
+
/** Total notional position value */
|
|
192
|
+
totalNotionalPosition: number;
|
|
193
|
+
/** Withdrawable amount */
|
|
194
|
+
withdrawable: number;
|
|
195
|
+
/** Cross margin summary */
|
|
196
|
+
crossMargin: {
|
|
197
|
+
accountValue: number;
|
|
198
|
+
totalMarginUsed: number;
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Complete Hyperliquid portfolio context.
|
|
203
|
+
* This is what gets passed to MCP tools for personalized analysis.
|
|
204
|
+
*/
|
|
205
|
+
interface HyperliquidContext {
|
|
206
|
+
/** The wallet address this context is for */
|
|
207
|
+
walletAddress: string;
|
|
208
|
+
/** Perpetual positions */
|
|
209
|
+
perpPositions: HyperliquidPerpPosition[];
|
|
210
|
+
/** Open orders */
|
|
211
|
+
openOrders: HyperliquidOrder[];
|
|
212
|
+
/** Spot balances */
|
|
213
|
+
spotBalances: HyperliquidSpotBalance[];
|
|
214
|
+
/** Account summary */
|
|
215
|
+
accountSummary: HyperliquidAccountSummary;
|
|
216
|
+
/** When this context was fetched (ISO 8601 string) */
|
|
217
|
+
fetchedAt: string;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Context types for portfolio and protocol data injection.
|
|
222
|
+
*
|
|
223
|
+
* These types allow MCP tools to receive personalized user context
|
|
224
|
+
* (wallet addresses, positions, balances) for analysis.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* import type { PolymarketContext, UserContext, ToolRequirements } from "@ctxprotocol/sdk";
|
|
229
|
+
*
|
|
230
|
+
* // Build context for a user's portfolio
|
|
231
|
+
* const context: UserContext = {
|
|
232
|
+
* wallet: { address: "0x...", chainId: 137 },
|
|
233
|
+
* polymarket: {
|
|
234
|
+
* walletAddress: "0x...",
|
|
235
|
+
* positions: [...],
|
|
236
|
+
* openOrders: [],
|
|
237
|
+
* fetchedAt: new Date().toISOString(),
|
|
238
|
+
* },
|
|
239
|
+
* };
|
|
240
|
+
*
|
|
241
|
+
* // Declare context requirements for a tool
|
|
242
|
+
* const requirements: ToolRequirements = {
|
|
243
|
+
* context: ["polymarket"],
|
|
244
|
+
* };
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* @packageDocumentation
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Context requirement types supported by the Context marketplace.
|
|
252
|
+
* Maps to protocol-specific context builders on the platform.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* // Tool that needs Hyperliquid positions
|
|
257
|
+
* requirements: {
|
|
258
|
+
* context: ["hyperliquid"]
|
|
259
|
+
* }
|
|
260
|
+
*
|
|
261
|
+
* // Tool that needs multiple context types
|
|
262
|
+
* requirements: {
|
|
263
|
+
* context: ["hyperliquid", "wallet"]
|
|
264
|
+
* }
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
type ContextRequirementType = "polymarket" | "hyperliquid" | "wallet";
|
|
268
|
+
/**
|
|
269
|
+
* Tool-level requirements declaration.
|
|
270
|
+
*
|
|
271
|
+
* MCP tools that need user portfolio data MUST declare this explicitly
|
|
272
|
+
* in their tool definition. The Context marketplace checks this field
|
|
273
|
+
* to determine what context to inject.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* const tool = {
|
|
278
|
+
* name: "analyze_my_positions",
|
|
279
|
+
* description: "Analyze your positions",
|
|
280
|
+
*
|
|
281
|
+
* // ⭐ REQUIRED for portfolio tools
|
|
282
|
+
* requirements: {
|
|
283
|
+
* context: ["hyperliquid"],
|
|
284
|
+
* } satisfies ToolRequirements,
|
|
285
|
+
*
|
|
286
|
+
* inputSchema: {
|
|
287
|
+
* type: "object",
|
|
288
|
+
* properties: {
|
|
289
|
+
* portfolio: {
|
|
290
|
+
* type: "object",
|
|
291
|
+
* description: "Portfolio context (injected by platform)",
|
|
292
|
+
* },
|
|
293
|
+
* },
|
|
294
|
+
* required: ["portfolio"],
|
|
295
|
+
* },
|
|
296
|
+
* };
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
interface ToolRequirements {
|
|
300
|
+
/**
|
|
301
|
+
* Context types required by this tool.
|
|
302
|
+
* - "polymarket": User's Polymarket positions (prediction markets)
|
|
303
|
+
* - "hyperliquid": User's Hyperliquid perp/spot positions
|
|
304
|
+
* - "wallet": Generic EVM wallet context (address, balances)
|
|
305
|
+
*/
|
|
306
|
+
context?: ContextRequirementType[];
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Composite context for tools that need multiple data sources.
|
|
310
|
+
*
|
|
311
|
+
* This is the unified structure that can be passed to MCP tools
|
|
312
|
+
* to provide comprehensive user context.
|
|
313
|
+
*/
|
|
314
|
+
interface UserContext {
|
|
315
|
+
/** Base wallet information */
|
|
316
|
+
wallet?: WalletContext;
|
|
317
|
+
/** ERC20 token holdings */
|
|
318
|
+
erc20?: ERC20Context;
|
|
319
|
+
/** Polymarket positions and orders */
|
|
320
|
+
polymarket?: PolymarketContext;
|
|
321
|
+
/** Hyperliquid perpetual positions and account data */
|
|
322
|
+
hyperliquid?: HyperliquidContext;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export type { ContextRequirementType, ERC20Context, ERC20TokenBalance, HyperliquidAccountSummary, HyperliquidContext, HyperliquidOrder, HyperliquidPerpPosition, HyperliquidSpotBalance, PolymarketContext, PolymarketOrder, PolymarketPosition, ToolRequirements, UserContext, WalletContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,325 @@
|
|
|
1
1
|
export { ContextClient, ContextClientOptions, ContextError, ContextErrorCode, Discovery, ExecuteApiErrorResponse, ExecuteApiResponse, ExecuteApiSuccessResponse, ExecuteOptions, ExecutionResult, McpTool, SearchOptions, SearchResponse, Tool, Tools } from './client/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wallet context types for portfolio tracking.
|
|
5
|
+
*
|
|
6
|
+
* These types represent wallet and token holdings that can be
|
|
7
|
+
* injected into MCP tools for personalized analysis.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Base wallet context - address and chain info
|
|
13
|
+
*/
|
|
14
|
+
interface WalletContext {
|
|
15
|
+
/** Wallet address (checksummed) */
|
|
16
|
+
address: string;
|
|
17
|
+
/** Chain ID (137 for Polygon, 1 for Ethereum, etc.) */
|
|
18
|
+
chainId: number;
|
|
19
|
+
/** Native token balance in wei (string for precision) */
|
|
20
|
+
nativeBalance?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* ERC20 token holdings
|
|
24
|
+
*/
|
|
25
|
+
interface ERC20TokenBalance {
|
|
26
|
+
/** Token contract address */
|
|
27
|
+
address: string;
|
|
28
|
+
/** Token symbol (e.g., "USDC") */
|
|
29
|
+
symbol: string;
|
|
30
|
+
/** Token decimals */
|
|
31
|
+
decimals: number;
|
|
32
|
+
/** Balance in smallest unit (string for precision) */
|
|
33
|
+
balance: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Collection of ERC20 token balances
|
|
37
|
+
*/
|
|
38
|
+
interface ERC20Context {
|
|
39
|
+
/** Array of token balances */
|
|
40
|
+
tokens: ERC20TokenBalance[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Polymarket context types for portfolio tracking.
|
|
45
|
+
*
|
|
46
|
+
* These types represent Polymarket positions and orders that can be
|
|
47
|
+
* injected into MCP tools for personalized portfolio analysis.
|
|
48
|
+
*
|
|
49
|
+
* @packageDocumentation
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* A single Polymarket position
|
|
53
|
+
*/
|
|
54
|
+
interface PolymarketPosition {
|
|
55
|
+
/** The market's condition ID */
|
|
56
|
+
conditionId: string;
|
|
57
|
+
/** The specific outcome token ID */
|
|
58
|
+
tokenId: string;
|
|
59
|
+
/** Which outcome this position is for */
|
|
60
|
+
outcome: "YES" | "NO";
|
|
61
|
+
/** Number of shares held */
|
|
62
|
+
shares: number;
|
|
63
|
+
/** Average entry price (0-1 scale) */
|
|
64
|
+
avgEntryPrice: number;
|
|
65
|
+
/** Market question/title for display */
|
|
66
|
+
marketTitle?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* An open order on Polymarket
|
|
70
|
+
*/
|
|
71
|
+
interface PolymarketOrder {
|
|
72
|
+
/** Order ID */
|
|
73
|
+
orderId: string;
|
|
74
|
+
/** The market's condition ID */
|
|
75
|
+
conditionId: string;
|
|
76
|
+
/** Order side */
|
|
77
|
+
side: "BUY" | "SELL";
|
|
78
|
+
/** Which outcome this order is for */
|
|
79
|
+
outcome: "YES" | "NO";
|
|
80
|
+
/** Limit price (0-1 scale) */
|
|
81
|
+
price: number;
|
|
82
|
+
/** Order size in shares */
|
|
83
|
+
size: number;
|
|
84
|
+
/** Amount already filled */
|
|
85
|
+
filled: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Complete Polymarket portfolio context.
|
|
89
|
+
* This is what gets passed to MCP tools for personalized analysis.
|
|
90
|
+
*/
|
|
91
|
+
interface PolymarketContext {
|
|
92
|
+
/** The wallet address this context is for */
|
|
93
|
+
walletAddress: string;
|
|
94
|
+
/** All open positions */
|
|
95
|
+
positions: PolymarketPosition[];
|
|
96
|
+
/** All open orders */
|
|
97
|
+
openOrders: PolymarketOrder[];
|
|
98
|
+
/** Total portfolio value in USD (sum of position values) */
|
|
99
|
+
totalValue?: number;
|
|
100
|
+
/** When this context was fetched (ISO 8601 string) */
|
|
101
|
+
fetchedAt: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Hyperliquid context types for portfolio tracking.
|
|
106
|
+
*
|
|
107
|
+
* These types represent Hyperliquid perpetual positions, orders, and account
|
|
108
|
+
* data that can be injected into MCP tools for personalized portfolio analysis.
|
|
109
|
+
*
|
|
110
|
+
* @packageDocumentation
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Hyperliquid Perpetual Position
|
|
114
|
+
*/
|
|
115
|
+
interface HyperliquidPerpPosition {
|
|
116
|
+
/** Asset symbol (e.g., "ETH", "BTC") */
|
|
117
|
+
coin: string;
|
|
118
|
+
/** Position size (positive = long, negative = short) */
|
|
119
|
+
size: number;
|
|
120
|
+
/** Entry price */
|
|
121
|
+
entryPrice: number;
|
|
122
|
+
/** Current mark price */
|
|
123
|
+
markPrice?: number;
|
|
124
|
+
/** Unrealized PnL in USD */
|
|
125
|
+
unrealizedPnl: number;
|
|
126
|
+
/** Liquidation price */
|
|
127
|
+
liquidationPrice: number;
|
|
128
|
+
/** Position value in USD */
|
|
129
|
+
positionValue: number;
|
|
130
|
+
/** Leverage info */
|
|
131
|
+
leverage: {
|
|
132
|
+
type: "cross" | "isolated";
|
|
133
|
+
value: number;
|
|
134
|
+
};
|
|
135
|
+
/** Margin used for this position */
|
|
136
|
+
marginUsed: number;
|
|
137
|
+
/** Return on equity percentage */
|
|
138
|
+
returnOnEquity: number;
|
|
139
|
+
/** Cumulative funding paid/received */
|
|
140
|
+
cumFunding: {
|
|
141
|
+
allTime: number;
|
|
142
|
+
sinceOpen: number;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Hyperliquid Open Order
|
|
147
|
+
*/
|
|
148
|
+
interface HyperliquidOrder {
|
|
149
|
+
/** Order ID */
|
|
150
|
+
oid: number;
|
|
151
|
+
/** Asset symbol */
|
|
152
|
+
coin: string;
|
|
153
|
+
/** Order side: "B" = Buy, "A" = Ask/Sell */
|
|
154
|
+
side: "B" | "A";
|
|
155
|
+
/** Limit price */
|
|
156
|
+
limitPrice: number;
|
|
157
|
+
/** Order size */
|
|
158
|
+
size: number;
|
|
159
|
+
/** Original order size */
|
|
160
|
+
originalSize: number;
|
|
161
|
+
/** Order type */
|
|
162
|
+
orderType: "Limit" | "Market" | "Stop" | "TakeProfit";
|
|
163
|
+
/** Is reduce-only order */
|
|
164
|
+
reduceOnly: boolean;
|
|
165
|
+
/** Is trigger order */
|
|
166
|
+
isTrigger: boolean;
|
|
167
|
+
/** Trigger price (if trigger order) */
|
|
168
|
+
triggerPrice?: number;
|
|
169
|
+
/** Order timestamp */
|
|
170
|
+
timestamp: number;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Hyperliquid Spot Balance
|
|
174
|
+
*/
|
|
175
|
+
interface HyperliquidSpotBalance {
|
|
176
|
+
/** Token symbol */
|
|
177
|
+
token: string;
|
|
178
|
+
/** Token balance */
|
|
179
|
+
balance: number;
|
|
180
|
+
/** USD value */
|
|
181
|
+
usdValue?: number;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Hyperliquid Account Summary
|
|
185
|
+
*/
|
|
186
|
+
interface HyperliquidAccountSummary {
|
|
187
|
+
/** Total account value in USD */
|
|
188
|
+
accountValue: number;
|
|
189
|
+
/** Total margin used */
|
|
190
|
+
totalMarginUsed: number;
|
|
191
|
+
/** Total notional position value */
|
|
192
|
+
totalNotionalPosition: number;
|
|
193
|
+
/** Withdrawable amount */
|
|
194
|
+
withdrawable: number;
|
|
195
|
+
/** Cross margin summary */
|
|
196
|
+
crossMargin: {
|
|
197
|
+
accountValue: number;
|
|
198
|
+
totalMarginUsed: number;
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Complete Hyperliquid portfolio context.
|
|
203
|
+
* This is what gets passed to MCP tools for personalized analysis.
|
|
204
|
+
*/
|
|
205
|
+
interface HyperliquidContext {
|
|
206
|
+
/** The wallet address this context is for */
|
|
207
|
+
walletAddress: string;
|
|
208
|
+
/** Perpetual positions */
|
|
209
|
+
perpPositions: HyperliquidPerpPosition[];
|
|
210
|
+
/** Open orders */
|
|
211
|
+
openOrders: HyperliquidOrder[];
|
|
212
|
+
/** Spot balances */
|
|
213
|
+
spotBalances: HyperliquidSpotBalance[];
|
|
214
|
+
/** Account summary */
|
|
215
|
+
accountSummary: HyperliquidAccountSummary;
|
|
216
|
+
/** When this context was fetched (ISO 8601 string) */
|
|
217
|
+
fetchedAt: string;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Context types for portfolio and protocol data injection.
|
|
222
|
+
*
|
|
223
|
+
* These types allow MCP tools to receive personalized user context
|
|
224
|
+
* (wallet addresses, positions, balances) for analysis.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* import type { PolymarketContext, UserContext, ToolRequirements } from "@ctxprotocol/sdk";
|
|
229
|
+
*
|
|
230
|
+
* // Build context for a user's portfolio
|
|
231
|
+
* const context: UserContext = {
|
|
232
|
+
* wallet: { address: "0x...", chainId: 137 },
|
|
233
|
+
* polymarket: {
|
|
234
|
+
* walletAddress: "0x...",
|
|
235
|
+
* positions: [...],
|
|
236
|
+
* openOrders: [],
|
|
237
|
+
* fetchedAt: new Date().toISOString(),
|
|
238
|
+
* },
|
|
239
|
+
* };
|
|
240
|
+
*
|
|
241
|
+
* // Declare context requirements for a tool
|
|
242
|
+
* const requirements: ToolRequirements = {
|
|
243
|
+
* context: ["polymarket"],
|
|
244
|
+
* };
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* @packageDocumentation
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Context requirement types supported by the Context marketplace.
|
|
252
|
+
* Maps to protocol-specific context builders on the platform.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* // Tool that needs Hyperliquid positions
|
|
257
|
+
* requirements: {
|
|
258
|
+
* context: ["hyperliquid"]
|
|
259
|
+
* }
|
|
260
|
+
*
|
|
261
|
+
* // Tool that needs multiple context types
|
|
262
|
+
* requirements: {
|
|
263
|
+
* context: ["hyperliquid", "wallet"]
|
|
264
|
+
* }
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
type ContextRequirementType = "polymarket" | "hyperliquid" | "wallet";
|
|
268
|
+
/**
|
|
269
|
+
* Tool-level requirements declaration.
|
|
270
|
+
*
|
|
271
|
+
* MCP tools that need user portfolio data MUST declare this explicitly
|
|
272
|
+
* in their tool definition. The Context marketplace checks this field
|
|
273
|
+
* to determine what context to inject.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* const tool = {
|
|
278
|
+
* name: "analyze_my_positions",
|
|
279
|
+
* description: "Analyze your positions",
|
|
280
|
+
*
|
|
281
|
+
* // ⭐ REQUIRED for portfolio tools
|
|
282
|
+
* requirements: {
|
|
283
|
+
* context: ["hyperliquid"],
|
|
284
|
+
* } satisfies ToolRequirements,
|
|
285
|
+
*
|
|
286
|
+
* inputSchema: {
|
|
287
|
+
* type: "object",
|
|
288
|
+
* properties: {
|
|
289
|
+
* portfolio: {
|
|
290
|
+
* type: "object",
|
|
291
|
+
* description: "Portfolio context (injected by platform)",
|
|
292
|
+
* },
|
|
293
|
+
* },
|
|
294
|
+
* required: ["portfolio"],
|
|
295
|
+
* },
|
|
296
|
+
* };
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
interface ToolRequirements {
|
|
300
|
+
/**
|
|
301
|
+
* Context types required by this tool.
|
|
302
|
+
* - "polymarket": User's Polymarket positions (prediction markets)
|
|
303
|
+
* - "hyperliquid": User's Hyperliquid perp/spot positions
|
|
304
|
+
* - "wallet": Generic EVM wallet context (address, balances)
|
|
305
|
+
*/
|
|
306
|
+
context?: ContextRequirementType[];
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Composite context for tools that need multiple data sources.
|
|
310
|
+
*
|
|
311
|
+
* This is the unified structure that can be passed to MCP tools
|
|
312
|
+
* to provide comprehensive user context.
|
|
313
|
+
*/
|
|
314
|
+
interface UserContext {
|
|
315
|
+
/** Base wallet information */
|
|
316
|
+
wallet?: WalletContext;
|
|
317
|
+
/** ERC20 token holdings */
|
|
318
|
+
erc20?: ERC20Context;
|
|
319
|
+
/** Polymarket positions and orders */
|
|
320
|
+
polymarket?: PolymarketContext;
|
|
321
|
+
/** Hyperliquid perpetual positions and account data */
|
|
322
|
+
hyperliquid?: HyperliquidContext;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export type { ContextRequirementType, ERC20Context, ERC20TokenBalance, HyperliquidAccountSummary, HyperliquidContext, HyperliquidOrder, HyperliquidPerpPosition, HyperliquidSpotBalance, PolymarketContext, PolymarketOrder, PolymarketPosition, ToolRequirements, UserContext, WalletContext };
|
package/package.json
CHANGED