@ctxprotocol/sdk 0.1.3 → 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 +97 -0
- package/dist/client/index.cjs +194 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +277 -0
- package/dist/client/index.d.ts +277 -0
- package/dist/client/index.js +189 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +211 -226
- package/dist/index.d.ts +211 -226
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +13 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,277 +1,262 @@
|
|
|
1
|
+
export { ContextClient, ContextClientOptions, ContextError, ContextErrorCode, Discovery, ExecuteApiErrorResponse, ExecuteApiResponse, ExecuteApiSuccessResponse, ExecuteOptions, ExecutionResult, McpTool, SearchOptions, SearchResponse, Tool, Tools } from './client/index.cjs';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
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
|
|
3
10
|
*/
|
|
4
|
-
interface ContextClientOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Your Context Protocol API key
|
|
7
|
-
* @example "sk_live_abc123..."
|
|
8
|
-
*/
|
|
9
|
-
apiKey: string;
|
|
10
|
-
/**
|
|
11
|
-
* Base URL for the Context Protocol API
|
|
12
|
-
* @default "https://ctxprotocol.com"
|
|
13
|
-
*/
|
|
14
|
-
baseUrl?: string;
|
|
15
|
-
}
|
|
16
11
|
/**
|
|
17
|
-
*
|
|
12
|
+
* Base wallet context - address and chain info
|
|
18
13
|
*/
|
|
19
|
-
interface
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
* Used by LLMs to generate correct arguments.
|
|
27
|
-
*/
|
|
28
|
-
inputSchema?: Record<string, unknown>;
|
|
29
|
-
/**
|
|
30
|
-
* JSON Schema for the output this tool returns.
|
|
31
|
-
* Used by LLMs to understand the response structure.
|
|
32
|
-
*/
|
|
33
|
-
outputSchema?: Record<string, unknown>;
|
|
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;
|
|
34
21
|
}
|
|
35
22
|
/**
|
|
36
|
-
*
|
|
23
|
+
* ERC20 token holdings
|
|
37
24
|
*/
|
|
38
|
-
interface
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
/** Tool category (e.g., "defi", "nft") */
|
|
48
|
-
category?: string;
|
|
49
|
-
/** Whether the tool is verified by Context Protocol */
|
|
50
|
-
isVerified?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Available MCP tool methods
|
|
53
|
-
* Use items from this array as `toolName` when executing
|
|
54
|
-
*/
|
|
55
|
-
mcpTools?: McpTool[];
|
|
56
|
-
/** Creation timestamp */
|
|
57
|
-
createdAt?: string;
|
|
58
|
-
/** Last update timestamp */
|
|
59
|
-
updatedAt?: string;
|
|
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;
|
|
60
34
|
}
|
|
61
35
|
/**
|
|
62
|
-
*
|
|
36
|
+
* Collection of ERC20 token balances
|
|
63
37
|
*/
|
|
64
|
-
interface
|
|
65
|
-
/** Array of
|
|
66
|
-
|
|
67
|
-
/** The search query that was used */
|
|
68
|
-
query: string;
|
|
69
|
-
/** Total number of results */
|
|
70
|
-
count: number;
|
|
38
|
+
interface ERC20Context {
|
|
39
|
+
/** Array of token balances */
|
|
40
|
+
tokens: ERC20TokenBalance[];
|
|
71
41
|
}
|
|
42
|
+
|
|
72
43
|
/**
|
|
73
|
-
*
|
|
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
|
|
74
50
|
*/
|
|
75
|
-
interface SearchOptions {
|
|
76
|
-
/** Search query (semantic search) */
|
|
77
|
-
query?: string;
|
|
78
|
-
/** Maximum number of results (1-50, default 10) */
|
|
79
|
-
limit?: number;
|
|
80
|
-
}
|
|
81
51
|
/**
|
|
82
|
-
*
|
|
52
|
+
* A single Polymarket position
|
|
83
53
|
*/
|
|
84
|
-
interface
|
|
85
|
-
/** The
|
|
86
|
-
|
|
87
|
-
/** The specific
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
|
|
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;
|
|
91
67
|
}
|
|
92
68
|
/**
|
|
93
|
-
*
|
|
69
|
+
* An open order on Polymarket
|
|
94
70
|
*/
|
|
95
|
-
interface
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
|
|
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;
|
|
106
86
|
}
|
|
107
87
|
/**
|
|
108
|
-
*
|
|
88
|
+
* Complete Polymarket portfolio context.
|
|
89
|
+
* This is what gets passed to MCP tools for personalized analysis.
|
|
109
90
|
*/
|
|
110
|
-
interface
|
|
111
|
-
/**
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
|
|
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;
|
|
117
102
|
}
|
|
103
|
+
|
|
118
104
|
/**
|
|
119
|
-
*
|
|
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
|
|
120
111
|
*/
|
|
121
|
-
type ExecuteApiResponse = ExecuteApiSuccessResponse | ExecuteApiErrorResponse;
|
|
122
112
|
/**
|
|
123
|
-
*
|
|
113
|
+
* Hyperliquid Perpetual Position
|
|
124
114
|
*/
|
|
125
|
-
interface
|
|
126
|
-
/**
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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;
|
|
132
143
|
};
|
|
133
|
-
/** Execution duration in milliseconds */
|
|
134
|
-
durationMs: number;
|
|
135
144
|
}
|
|
136
145
|
/**
|
|
137
|
-
*
|
|
146
|
+
* Hyperliquid Open Order
|
|
138
147
|
*/
|
|
139
|
-
|
|
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
|
+
}
|
|
140
172
|
/**
|
|
141
|
-
*
|
|
173
|
+
* Hyperliquid Spot Balance
|
|
142
174
|
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
175
|
+
interface HyperliquidSpotBalance {
|
|
176
|
+
/** Token symbol */
|
|
177
|
+
token: string;
|
|
178
|
+
/** Token balance */
|
|
179
|
+
balance: number;
|
|
180
|
+
/** USD value */
|
|
181
|
+
usdValue?: number;
|
|
148
182
|
}
|
|
149
|
-
|
|
150
183
|
/**
|
|
151
|
-
*
|
|
184
|
+
* Hyperliquid Account Summary
|
|
152
185
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
* console.log(tools[0].mcpTools); // Available methods
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
search(query: string, limit?: number): Promise<Tool[]>;
|
|
171
|
-
/**
|
|
172
|
-
* Get featured/popular tools (empty query search)
|
|
173
|
-
*
|
|
174
|
-
* @param limit - Maximum number of results (1-50, default 10)
|
|
175
|
-
* @returns Array of featured tools
|
|
176
|
-
*
|
|
177
|
-
* @example
|
|
178
|
-
* ```typescript
|
|
179
|
-
* const featured = await client.discovery.getFeatured(5);
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
getFeatured(limit?: number): Promise<Tool[]>;
|
|
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
|
+
};
|
|
183
200
|
}
|
|
184
|
-
|
|
185
201
|
/**
|
|
186
|
-
*
|
|
202
|
+
* Complete Hyperliquid portfolio context.
|
|
203
|
+
* This is what gets passed to MCP tools for personalized analysis.
|
|
187
204
|
*/
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
* @throws {ContextError} With code `insufficient_allowance` if Auto Pay not enabled
|
|
202
|
-
* @throws {ContextError} With code `payment_failed` if on-chain payment fails
|
|
203
|
-
* @throws {ContextError} With code `execution_failed` if tool execution fails
|
|
204
|
-
*
|
|
205
|
-
* @example
|
|
206
|
-
* ```typescript
|
|
207
|
-
* // First, search for a tool
|
|
208
|
-
* const tools = await client.discovery.search("gas prices");
|
|
209
|
-
* const tool = tools[0];
|
|
210
|
-
*
|
|
211
|
-
* // Execute a specific method from the tool's mcpTools
|
|
212
|
-
* const result = await client.tools.execute({
|
|
213
|
-
* toolId: tool.id,
|
|
214
|
-
* toolName: tool.mcpTools[0].name, // e.g., "get_gas_prices"
|
|
215
|
-
* args: { chainId: 1 }
|
|
216
|
-
* });
|
|
217
|
-
*
|
|
218
|
-
* console.log(result.result); // The tool's output
|
|
219
|
-
* console.log(result.durationMs); // Execution time
|
|
220
|
-
* ```
|
|
221
|
-
*/
|
|
222
|
-
execute<T = unknown>(options: ExecuteOptions): Promise<ExecutionResult<T>>;
|
|
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;
|
|
223
218
|
}
|
|
224
219
|
|
|
225
220
|
/**
|
|
226
|
-
*
|
|
221
|
+
* Context types for portfolio and protocol data injection.
|
|
227
222
|
*
|
|
228
|
-
*
|
|
223
|
+
* These types allow MCP tools to receive personalized user context
|
|
224
|
+
* (wallet addresses, positions, balances) for analysis.
|
|
229
225
|
*
|
|
230
226
|
* @example
|
|
231
227
|
* ```typescript
|
|
232
|
-
* import {
|
|
228
|
+
* import type { PolymarketContext, UserContext } from "@ctxprotocol/sdk";
|
|
233
229
|
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* }
|
|
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
|
+
* ```
|
|
237
241
|
*
|
|
238
|
-
*
|
|
239
|
-
|
|
242
|
+
* @packageDocumentation
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Composite context for tools that need multiple data sources.
|
|
240
247
|
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* toolId: tools[0].id,
|
|
244
|
-
* toolName: tools[0].mcpTools[0].name,
|
|
245
|
-
* args: { chainId: 1 }
|
|
246
|
-
* });
|
|
247
|
-
* ```
|
|
248
|
+
* This is the unified structure that can be passed to MCP tools
|
|
249
|
+
* to provide comprehensive user context.
|
|
248
250
|
*/
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
|
|
258
|
-
*/
|
|
259
|
-
readonly tools: Tools;
|
|
260
|
-
/**
|
|
261
|
-
* Creates a new Context Protocol client
|
|
262
|
-
*
|
|
263
|
-
* @param options - Client configuration options
|
|
264
|
-
* @param options.apiKey - Your Context Protocol API key (format: sk_live_...)
|
|
265
|
-
* @param options.baseUrl - Optional base URL override (defaults to https://ctxprotocol.com)
|
|
266
|
-
*/
|
|
267
|
-
constructor(options: ContextClientOptions);
|
|
268
|
-
/**
|
|
269
|
-
* Internal method for making authenticated HTTP requests
|
|
270
|
-
* All requests include the Authorization header with the API key
|
|
271
|
-
*
|
|
272
|
-
* @internal
|
|
273
|
-
*/
|
|
274
|
-
fetch<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
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;
|
|
275
260
|
}
|
|
276
261
|
|
|
277
|
-
export
|
|
262
|
+
export type { ERC20Context, ERC20TokenBalance, HyperliquidAccountSummary, HyperliquidContext, HyperliquidOrder, HyperliquidPerpPosition, HyperliquidSpotBalance, PolymarketContext, PolymarketOrder, PolymarketPosition, UserContext, WalletContext };
|