@ctxprotocol/sdk 0.4.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 +84 -0
- package/dist/index.d.cts +65 -2
- package/dist/index.d.ts +65 -2
- 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.
|
|
@@ -369,6 +389,61 @@ Want to earn money by contributing tools to the Context marketplace? Build a sta
|
|
|
369
389
|
| `outputSchema` | AI agents use this to generate type-safe code. Context uses it for dispute resolution. |
|
|
370
390
|
| `structuredContent` | Agents parse this for programmatic access. Text `content` is for humans. |
|
|
371
391
|
|
|
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.
|
|
395
|
+
|
|
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
|
+
|
|
372
447
|
### Example: Standard MCP Server
|
|
373
448
|
|
|
374
449
|
Build your server with the standard `@modelcontextprotocol/sdk`:
|
|
@@ -446,6 +521,15 @@ When you execute a tool:
|
|
|
446
521
|
3. **10%** goes to the protocol
|
|
447
522
|
4. Tool executes and returns results
|
|
448
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
|
+
|
|
449
533
|
## Links
|
|
450
534
|
|
|
451
535
|
- [Context Protocol](https://ctxprotocol.com) β Main website
|
package/dist/index.d.cts
CHANGED
|
@@ -225,7 +225,7 @@ interface HyperliquidContext {
|
|
|
225
225
|
*
|
|
226
226
|
* @example
|
|
227
227
|
* ```typescript
|
|
228
|
-
* import type { PolymarketContext, UserContext } from "@ctxprotocol/sdk";
|
|
228
|
+
* import type { PolymarketContext, UserContext, ToolRequirements } from "@ctxprotocol/sdk";
|
|
229
229
|
*
|
|
230
230
|
* // Build context for a user's portfolio
|
|
231
231
|
* const context: UserContext = {
|
|
@@ -237,11 +237,74 @@ interface HyperliquidContext {
|
|
|
237
237
|
* fetchedAt: new Date().toISOString(),
|
|
238
238
|
* },
|
|
239
239
|
* };
|
|
240
|
+
*
|
|
241
|
+
* // Declare context requirements for a tool
|
|
242
|
+
* const requirements: ToolRequirements = {
|
|
243
|
+
* context: ["polymarket"],
|
|
244
|
+
* };
|
|
240
245
|
* ```
|
|
241
246
|
*
|
|
242
247
|
* @packageDocumentation
|
|
243
248
|
*/
|
|
244
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
|
+
}
|
|
245
308
|
/**
|
|
246
309
|
* Composite context for tools that need multiple data sources.
|
|
247
310
|
*
|
|
@@ -259,4 +322,4 @@ interface UserContext {
|
|
|
259
322
|
hyperliquid?: HyperliquidContext;
|
|
260
323
|
}
|
|
261
324
|
|
|
262
|
-
export type { ERC20Context, ERC20TokenBalance, HyperliquidAccountSummary, HyperliquidContext, HyperliquidOrder, HyperliquidPerpPosition, HyperliquidSpotBalance, PolymarketContext, PolymarketOrder, PolymarketPosition, UserContext, WalletContext };
|
|
325
|
+
export type { ContextRequirementType, ERC20Context, ERC20TokenBalance, HyperliquidAccountSummary, HyperliquidContext, HyperliquidOrder, HyperliquidPerpPosition, HyperliquidSpotBalance, PolymarketContext, PolymarketOrder, PolymarketPosition, ToolRequirements, UserContext, WalletContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -225,7 +225,7 @@ interface HyperliquidContext {
|
|
|
225
225
|
*
|
|
226
226
|
* @example
|
|
227
227
|
* ```typescript
|
|
228
|
-
* import type { PolymarketContext, UserContext } from "@ctxprotocol/sdk";
|
|
228
|
+
* import type { PolymarketContext, UserContext, ToolRequirements } from "@ctxprotocol/sdk";
|
|
229
229
|
*
|
|
230
230
|
* // Build context for a user's portfolio
|
|
231
231
|
* const context: UserContext = {
|
|
@@ -237,11 +237,74 @@ interface HyperliquidContext {
|
|
|
237
237
|
* fetchedAt: new Date().toISOString(),
|
|
238
238
|
* },
|
|
239
239
|
* };
|
|
240
|
+
*
|
|
241
|
+
* // Declare context requirements for a tool
|
|
242
|
+
* const requirements: ToolRequirements = {
|
|
243
|
+
* context: ["polymarket"],
|
|
244
|
+
* };
|
|
240
245
|
* ```
|
|
241
246
|
*
|
|
242
247
|
* @packageDocumentation
|
|
243
248
|
*/
|
|
244
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
|
+
}
|
|
245
308
|
/**
|
|
246
309
|
* Composite context for tools that need multiple data sources.
|
|
247
310
|
*
|
|
@@ -259,4 +322,4 @@ interface UserContext {
|
|
|
259
322
|
hyperliquid?: HyperliquidContext;
|
|
260
323
|
}
|
|
261
324
|
|
|
262
|
-
export type { ERC20Context, ERC20TokenBalance, HyperliquidAccountSummary, HyperliquidContext, HyperliquidOrder, HyperliquidPerpPosition, HyperliquidSpotBalance, PolymarketContext, PolymarketOrder, PolymarketPosition, UserContext, WalletContext };
|
|
325
|
+
export type { ContextRequirementType, ERC20Context, ERC20TokenBalance, HyperliquidAccountSummary, HyperliquidContext, HyperliquidOrder, HyperliquidPerpPosition, HyperliquidSpotBalance, PolymarketContext, PolymarketOrder, PolymarketPosition, ToolRequirements, UserContext, WalletContext };
|
package/package.json
CHANGED