@ctxprotocol/sdk 0.2.0 → 0.4.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 +9 -7
- package/dist/index.d.cts +261 -0
- package/dist/index.d.ts +261 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -355,11 +355,13 @@ try {
|
|
|
355
355
|
|
|
356
356
|
## Building MCP Servers (Tool Contributors)
|
|
357
357
|
|
|
358
|
-
Want to earn money by contributing tools to the Context marketplace? Build a standard MCP server
|
|
358
|
+
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
359
|
|
|
360
360
|
1. **`outputSchema`** in tool definitions — JSON Schema describing your response
|
|
361
361
|
2. **`structuredContent`** in responses — Machine-readable data matching the schema
|
|
362
362
|
|
|
363
|
+
> **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.
|
|
364
|
+
|
|
363
365
|
### Why These Matter
|
|
364
366
|
|
|
365
367
|
| Requirement | Purpose |
|
|
@@ -367,15 +369,15 @@ Want to earn money by contributing tools to the Context marketplace? Build a sta
|
|
|
367
369
|
| `outputSchema` | AI agents use this to generate type-safe code. Context uses it for dispute resolution. |
|
|
368
370
|
| `structuredContent` | Agents parse this for programmatic access. Text `content` is for humans. |
|
|
369
371
|
|
|
370
|
-
### Example: Standard MCP Server
|
|
372
|
+
### Example: Standard MCP Server
|
|
371
373
|
|
|
372
|
-
Build your server with the standard `@modelcontextprotocol/sdk
|
|
374
|
+
Build your server with the standard `@modelcontextprotocol/sdk`:
|
|
373
375
|
|
|
374
376
|
```typescript
|
|
375
377
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
376
378
|
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
|
377
379
|
|
|
378
|
-
// Define tools with outputSchema (
|
|
380
|
+
// Define tools with outputSchema (standard MCP feature, required by Context)
|
|
379
381
|
const TOOLS = [{
|
|
380
382
|
name: "get_gas_price",
|
|
381
383
|
description: "Get current gas prices",
|
|
@@ -385,7 +387,7 @@ const TOOLS = [{
|
|
|
385
387
|
chainId: { type: "number", description: "EVM chain ID" },
|
|
386
388
|
},
|
|
387
389
|
},
|
|
388
|
-
// 👇
|
|
390
|
+
// 👇 Standard MCP feature (see: modelcontextprotocol.io/specification)
|
|
389
391
|
outputSchema: {
|
|
390
392
|
type: "object",
|
|
391
393
|
properties: {
|
|
@@ -409,9 +411,9 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
409
411
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
410
412
|
const data = await fetchGasData(request.params.arguments.chainId);
|
|
411
413
|
|
|
412
|
-
// 👇
|
|
414
|
+
// 👇 Standard MCP feature (see: modelcontextprotocol.io/specification)
|
|
413
415
|
return {
|
|
414
|
-
content: [{ type: "text", text: JSON.stringify(data) }],
|
|
416
|
+
content: [{ type: "text", text: JSON.stringify(data) }], // Backward compat
|
|
415
417
|
structuredContent: data, // Machine-readable, matches outputSchema
|
|
416
418
|
};
|
|
417
419
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1 +1,262 @@
|
|
|
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 } 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
|
+
*
|
|
242
|
+
* @packageDocumentation
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Composite context for tools that need multiple data sources.
|
|
247
|
+
*
|
|
248
|
+
* This is the unified structure that can be passed to MCP tools
|
|
249
|
+
* to provide comprehensive user context.
|
|
250
|
+
*/
|
|
251
|
+
interface UserContext {
|
|
252
|
+
/** Base wallet information */
|
|
253
|
+
wallet?: WalletContext;
|
|
254
|
+
/** ERC20 token holdings */
|
|
255
|
+
erc20?: ERC20Context;
|
|
256
|
+
/** Polymarket positions and orders */
|
|
257
|
+
polymarket?: PolymarketContext;
|
|
258
|
+
/** Hyperliquid perpetual positions and account data */
|
|
259
|
+
hyperliquid?: HyperliquidContext;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export type { ERC20Context, ERC20TokenBalance, HyperliquidAccountSummary, HyperliquidContext, HyperliquidOrder, HyperliquidPerpPosition, HyperliquidSpotBalance, PolymarketContext, PolymarketOrder, PolymarketPosition, UserContext, WalletContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,262 @@
|
|
|
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 } 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
|
+
*
|
|
242
|
+
* @packageDocumentation
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Composite context for tools that need multiple data sources.
|
|
247
|
+
*
|
|
248
|
+
* This is the unified structure that can be passed to MCP tools
|
|
249
|
+
* to provide comprehensive user context.
|
|
250
|
+
*/
|
|
251
|
+
interface UserContext {
|
|
252
|
+
/** Base wallet information */
|
|
253
|
+
wallet?: WalletContext;
|
|
254
|
+
/** ERC20 token holdings */
|
|
255
|
+
erc20?: ERC20Context;
|
|
256
|
+
/** Polymarket positions and orders */
|
|
257
|
+
polymarket?: PolymarketContext;
|
|
258
|
+
/** Hyperliquid perpetual positions and account data */
|
|
259
|
+
hyperliquid?: HyperliquidContext;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export type { ERC20Context, ERC20TokenBalance, HyperliquidAccountSummary, HyperliquidContext, HyperliquidOrder, HyperliquidPerpPosition, HyperliquidSpotBalance, PolymarketContext, PolymarketOrder, PolymarketPosition, UserContext, WalletContext };
|
package/package.json
CHANGED