@definitive-fi/mcp 1.2.0 → 1.2.1
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/dist/server.js +27 -28
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -76,16 +76,28 @@ function createClient(baseUrl, apiKey, apiSecret) {
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
if (!response.ok) {
|
|
79
|
+
const issues = validationIssues(response.status, json);
|
|
79
80
|
return {
|
|
80
81
|
error: true,
|
|
81
82
|
status_code: response.status,
|
|
82
|
-
message: typeof json === "object" && json !== null && "message" in json ? String(json.message) : response.statusText
|
|
83
|
+
message: typeof json === "object" && json !== null && "message" in json ? String(json.message) : response.statusText,
|
|
84
|
+
...issues && { details: issues }
|
|
83
85
|
};
|
|
84
86
|
}
|
|
85
87
|
return json;
|
|
86
88
|
}
|
|
87
89
|
};
|
|
88
90
|
}
|
|
91
|
+
function validationIssues(status, json) {
|
|
92
|
+
if (status !== 400 || typeof json !== "object" || json === null) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const error = "error" in json ? json.error : undefined;
|
|
96
|
+
if (typeof error !== "object" || error === null || !("issues" in error)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
return Array.isArray(error.issues) ? error.issues : undefined;
|
|
100
|
+
}
|
|
89
101
|
|
|
90
102
|
|
|
91
103
|
function resolvePortfolioRoute(keyType, suffix, portfolioId, defaultPortfolioId) {
|
|
@@ -103,25 +115,12 @@ function resolvePortfolioRoute(keyType, suffix, portfolioId, defaultPortfolioId)
|
|
|
103
115
|
import { z } from "zod";
|
|
104
116
|
var zUUID = z.string().uuid();
|
|
105
117
|
var portfolioIdParam = zUUID.optional().describe("Portfolio UUID (required for organization keys without a default)");
|
|
106
|
-
var
|
|
107
|
-
"arbitrum",
|
|
108
|
-
"avalanche",
|
|
109
|
-
"base",
|
|
110
|
-
"blast",
|
|
111
|
-
"bsc",
|
|
112
|
-
"ethereum",
|
|
113
|
-
"optimism",
|
|
114
|
-
"polygon",
|
|
115
|
-
"solana",
|
|
116
|
-
"hyperevm",
|
|
117
|
-
"plasma",
|
|
118
|
-
"monad",
|
|
119
|
-
"robinhood",
|
|
120
|
-
"ink"
|
|
121
|
-
]);
|
|
118
|
+
var chainParam = (label) => z.string().min(1).describe(`${label}, lowercase (e.g. ethereum, base, arbitrum, solana)`);
|
|
122
119
|
var jsonResult = (result) => ({
|
|
123
|
-
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
120
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
121
|
+
...isErrorResult(result) && { isError: true }
|
|
124
122
|
});
|
|
123
|
+
var isErrorResult = (result) => typeof result === "object" && result !== null && ("error" in result) && result.error === true;
|
|
125
124
|
|
|
126
125
|
|
|
127
126
|
import { z as z2 } from "zod";
|
|
@@ -294,7 +293,7 @@ function registerReadTools(server, client, keyType, defaultPortfolioId) {
|
|
|
294
293
|
return jsonResult(result);
|
|
295
294
|
});
|
|
296
295
|
server.tool("get_deposit_address", "Get a deposit address for a specific blockchain. Creates a vault if one doesn't exist for that chain.", {
|
|
297
|
-
chain:
|
|
296
|
+
chain: chainParam("Blockchain network name"),
|
|
298
297
|
wallet_address: z3.string().min(1).describe("User's wallet address on this chain — ask the user if not provided"),
|
|
299
298
|
portfolio_id: portfolioIdParam
|
|
300
299
|
}, async ({ chain, wallet_address, portfolio_id }) => {
|
|
@@ -374,7 +373,7 @@ function registerWriteTools(server, client, keyType, defaultPortfolioId) {
|
|
|
374
373
|
const resolve = (suffix, portfolioId) => resolvePortfolioRoute(keyType, suffix, portfolioId, defaultPortfolioId);
|
|
375
374
|
server.tool("get_trade_quote", "Get a price quote for a trade order. This is the DEFAULT tool for all trades — use this unless the user explicitly asks for a QuickTrade. Supports market, limit, TWAP, stop, stop-loss, and take-profit order types. This does not execute any trade. Use the returned quote ID with submit_trade to execute.", {
|
|
376
375
|
type: OrderTypeEnum.describe("Order type"),
|
|
377
|
-
chain:
|
|
376
|
+
chain: chainParam("Blockchain network name"),
|
|
378
377
|
target_asset: z4.string().min(1).describe("Target asset contract address"),
|
|
379
378
|
contra_asset: z4.string().min(1).describe("Contra (quote) asset contract address"),
|
|
380
379
|
qty: z4.string().min(1).describe("Order quantity as a decimal string"),
|
|
@@ -444,7 +443,7 @@ function registerWriteTools(server, client, keyType, defaultPortfolioId) {
|
|
|
444
443
|
server.tool("get_quicktrade_quote", "Get a price quote for a QuickTrade market swap. Only use when the user explicitly requests a QuickTrade. This does not execute any trade. Review the quote before executing with the quicktrade tool.", {
|
|
445
444
|
target_asset: z4.string().min(1).describe("Target asset contract address"),
|
|
446
445
|
contra_asset: z4.string().min(1).describe("Contra (quote) asset contract address"),
|
|
447
|
-
chain:
|
|
446
|
+
chain: chainParam("Blockchain network name"),
|
|
448
447
|
qty: z4.string().min(1).describe("Order quantity as a decimal string"),
|
|
449
448
|
order_side: OrderSideEnum.describe("Buy or sell"),
|
|
450
449
|
portfolio_id: portfolioIdParam
|
|
@@ -470,9 +469,9 @@ function registerWriteTools(server, client, keyType, defaultPortfolioId) {
|
|
|
470
469
|
});
|
|
471
470
|
server.tool("bridge_quote", "Get a quote for a cross-chain bridge transfer. This does not move any funds. Review the routes and select a route_id before executing with bridge_submit.", {
|
|
472
471
|
from_asset_address: z4.string().min(1).describe("Source asset contract address"),
|
|
473
|
-
from_chain:
|
|
472
|
+
from_chain: chainParam("Source blockchain network"),
|
|
474
473
|
to_asset_address: z4.string().min(1).describe("Destination asset contract address"),
|
|
475
|
-
to_chain:
|
|
474
|
+
to_chain: chainParam("Destination blockchain network"),
|
|
476
475
|
from_amount: z4.string().min(1).describe("Amount to bridge as a decimal string"),
|
|
477
476
|
portfolio_id: portfolioIdParam
|
|
478
477
|
}, { readOnlyHint: true }, async ({
|
|
@@ -519,7 +518,7 @@ function registerWriteTools(server, client, keyType, defaultPortfolioId) {
|
|
|
519
518
|
server.tool("submit_trade", "Submit a trade order using a quote from get_trade_quote. This is irreversible — all order types (market, limit, stop, TWAP) may execute immediately. Always show the user the quote details and get confirmation before calling this tool. Pass the same parameters you used for get_trade_quote plus the quote_id.", {
|
|
520
519
|
quote_id: zUUID.describe("Quote UUID from get_trade_quote response (found in quote.quote.id)"),
|
|
521
520
|
type: OrderTypeEnum.describe("Order type"),
|
|
522
|
-
chain:
|
|
521
|
+
chain: chainParam("Blockchain network name"),
|
|
523
522
|
target_asset: z4.string().min(1).describe("Target asset contract address"),
|
|
524
523
|
contra_asset: z4.string().min(1).describe("Contra (quote) asset contract address"),
|
|
525
524
|
qty: z4.string().min(1).describe("Order quantity as a decimal string"),
|
|
@@ -595,7 +594,7 @@ function registerWriteTools(server, client, keyType, defaultPortfolioId) {
|
|
|
595
594
|
server.tool("quicktrade", "Execute a QuickTrade market swap immediately. Only use when the user explicitly requests a QuickTrade. This is irreversible — funds move on-chain once submitted. Call get_quicktrade_quote first and confirm details with the user before executing, unless the user requests to skip the quote step.", {
|
|
596
595
|
target_asset: z4.string().min(1).describe("Target asset contract address"),
|
|
597
596
|
contra_asset: z4.string().min(1).describe("Contra (quote) asset contract address"),
|
|
598
|
-
chain:
|
|
597
|
+
chain: chainParam("Blockchain network name"),
|
|
599
598
|
qty: z4.string().min(1).describe("Order quantity as a decimal string"),
|
|
600
599
|
order_side: OrderSideEnum.describe("Buy or sell"),
|
|
601
600
|
slippage_tolerance: z4.string().optional().describe("Slippage tolerance as a decimal string (e.g. '0.01' for 1%)"),
|
|
@@ -636,8 +635,8 @@ function registerWriteTools(server, client, keyType, defaultPortfolioId) {
|
|
|
636
635
|
return jsonResult(result);
|
|
637
636
|
});
|
|
638
637
|
server.tool("bridge_submit", "Execute a cross-chain bridge transfer. This is irreversible — funds are sent from the source chain to the destination chain. Always call bridge_quote first and confirm the details with the user before executing.", {
|
|
639
|
-
from_chain:
|
|
640
|
-
to_chain:
|
|
638
|
+
from_chain: chainParam("Source blockchain network"),
|
|
639
|
+
to_chain: chainParam("Destination blockchain network"),
|
|
641
640
|
from_asset_address: z4.string().min(1).describe("Source asset contract address"),
|
|
642
641
|
to_asset_address: z4.string().min(1).describe("Destination asset contract address"),
|
|
643
642
|
from_amount: z4.string().min(1).describe("Amount to bridge as a decimal string"),
|
|
@@ -692,7 +691,7 @@ var McpEnvSchema = z5.object({
|
|
|
692
691
|
});
|
|
693
692
|
var env = McpEnvSchema.parse(process.env);
|
|
694
693
|
var client = createClient(env.DEFINITIVE_BASE_URL, env.DEFINITIVE_API_KEY, env.DEFINITIVE_API_SECRET);
|
|
695
|
-
var server = new McpServer({ name: "Definitive", version: "1.2.
|
|
694
|
+
var server = new McpServer({ name: "Definitive", version: "1.2.1" }, {
|
|
696
695
|
instructions: "MCP server for the Definitive on-chain trading platform. Provides unified tools for portfolio management, trading (market/limit/TWAP/stop orders), QuickTrade execution across multiple blockchains, and read-only perps (perpetual futures) market data and account state. Tools auto-route to the correct API based on the configured key type (portfolio or organization). For organization keys, pass portfolio_id to target a specific portfolio, or set DEFINITIVE_PORTFOLIO_ID as default. TRADING: Default to get_trade_quote + submit_trade for trades unless the user specifies QuickTrade."
|
|
697
696
|
});
|
|
698
697
|
registerReadTools(server, client, env.DEFINITIVE_API_KEY_TYPE, env.DEFINITIVE_PORTFOLIO_ID);
|