@guiie/buda-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/client.d.ts +15 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +56 -52
- package/dist/http.js +30 -148
- package/dist/index.js +2 -1
- package/dist/tools/balances.d.ts +8 -0
- package/dist/tools/balances.d.ts.map +1 -1
- package/dist/tools/balances.js +11 -3
- package/dist/tools/cancel_order.d.ts +30 -0
- package/dist/tools/cancel_order.d.ts.map +1 -1
- package/dist/tools/cancel_order.js +59 -38
- package/dist/tools/compare_markets.d.ts +14 -0
- package/dist/tools/compare_markets.d.ts.map +1 -1
- package/dist/tools/compare_markets.js +17 -3
- package/dist/tools/markets.d.ts +13 -0
- package/dist/tools/markets.d.ts.map +1 -1
- package/dist/tools/markets.js +23 -2
- package/dist/tools/orderbook.d.ts +18 -0
- package/dist/tools/orderbook.d.ts.map +1 -1
- package/dist/tools/orderbook.js +28 -2
- package/dist/tools/orders.d.ts +26 -0
- package/dist/tools/orders.d.ts.map +1 -1
- package/dist/tools/orders.js +36 -2
- package/dist/tools/place_order.d.ts +50 -0
- package/dist/tools/place_order.d.ts.map +1 -1
- package/dist/tools/place_order.js +104 -58
- package/dist/tools/price_history.d.ts +22 -0
- package/dist/tools/price_history.d.ts.map +1 -1
- package/dist/tools/price_history.js +42 -7
- package/dist/tools/spread.d.ts +14 -0
- package/dist/tools/spread.d.ts.map +1 -1
- package/dist/tools/spread.js +24 -2
- package/dist/tools/ticker.d.ts +14 -0
- package/dist/tools/ticker.d.ts.map +1 -1
- package/dist/tools/ticker.js +24 -2
- package/dist/tools/trades.d.ts +22 -0
- package/dist/tools/trades.d.ts.map +1 -1
- package/dist/tools/trades.js +32 -2
- package/dist/tools/volume.d.ts +14 -0
- package/dist/tools/volume.d.ts.map +1 -1
- package/dist/tools/volume.js +24 -2
- package/dist/validation.d.ts +6 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +14 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export declare class BudaApiError extends Error {
|
|
2
2
|
readonly status: number;
|
|
3
3
|
readonly path: string;
|
|
4
|
-
|
|
4
|
+
readonly retryAfterMs?: number | undefined;
|
|
5
|
+
constructor(status: number, path: string, message: string, retryAfterMs?: number | undefined);
|
|
5
6
|
}
|
|
6
7
|
export declare class BudaClient {
|
|
7
8
|
private readonly baseUrl;
|
|
@@ -12,6 +13,19 @@ export declare class BudaClient {
|
|
|
12
13
|
private nonce;
|
|
13
14
|
private sign;
|
|
14
15
|
private authHeaders;
|
|
16
|
+
/**
|
|
17
|
+
* Parses the Retry-After header value into milliseconds.
|
|
18
|
+
* Per RFC 7231, Retry-After is an integer number of seconds.
|
|
19
|
+
* Defaults to 1000ms (1 second) if absent or unparseable.
|
|
20
|
+
*/
|
|
21
|
+
private parseRetryAfterMs;
|
|
22
|
+
/**
|
|
23
|
+
* Executes a fetch call with a single 429 retry.
|
|
24
|
+
* On the first 429, waits for Retry-After seconds (default 1s), then retries once.
|
|
25
|
+
* If the retry also returns 429, throws a BudaApiError with retryAfterMs set.
|
|
26
|
+
*/
|
|
27
|
+
private fetchWithRetry;
|
|
28
|
+
private handleResponse;
|
|
15
29
|
get<T>(path: string, params?: Record<string, string | number>): Promise<T>;
|
|
16
30
|
post<T>(path: string, payload: unknown): Promise<T>;
|
|
17
31
|
put<T>(path: string, payload: unknown): Promise<T>;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAKA,qBAAa,YAAa,SAAQ,KAAK;aAEnB,MAAM,EAAE,MAAM;aACd,IAAI,EAAE,MAAM;aAEZ,YAAY,CAAC,EAAE,MAAM;gBAHrB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EAC5B,OAAO,EAAE,MAAM,EACC,YAAY,CAAC,EAAE,MAAM,YAAA;CAKxC;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;gBAG7C,OAAO,GAAE,MAAiB,EAC1B,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM;IAOpB,OAAO,IAAI,OAAO;IAIlB,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,IAAI;IASZ,OAAO,CAAC,WAAW;IAWnB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAOzB;;;;OAIG;YACW,cAAc;YA2Bd,cAAc;IActB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAoB1E,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAmBnD,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAkBzD"}
|
package/dist/client.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { createHmac } from "crypto";
|
|
2
|
+
import { VERSION } from "./version.js";
|
|
2
3
|
const BASE_URL = "https://www.buda.com/api/v2";
|
|
3
4
|
export class BudaApiError extends Error {
|
|
4
5
|
status;
|
|
5
6
|
path;
|
|
6
|
-
|
|
7
|
+
retryAfterMs;
|
|
8
|
+
constructor(status, path, message, retryAfterMs) {
|
|
7
9
|
super(message);
|
|
8
10
|
this.status = status;
|
|
9
11
|
this.path = path;
|
|
12
|
+
this.retryAfterMs = retryAfterMs;
|
|
10
13
|
this.name = "BudaApiError";
|
|
11
14
|
}
|
|
12
15
|
}
|
|
@@ -45,20 +48,37 @@ export class BudaClient {
|
|
|
45
48
|
"X-SBTC-SIGNATURE": signature,
|
|
46
49
|
};
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Parses the Retry-After header value into milliseconds.
|
|
53
|
+
* Per RFC 7231, Retry-After is an integer number of seconds.
|
|
54
|
+
* Defaults to 1000ms (1 second) if absent or unparseable.
|
|
55
|
+
*/
|
|
56
|
+
parseRetryAfterMs(headers) {
|
|
57
|
+
const raw = headers.get("Retry-After");
|
|
58
|
+
if (!raw)
|
|
59
|
+
return 1000;
|
|
60
|
+
const secs = parseInt(raw, 10);
|
|
61
|
+
return isNaN(secs) ? 1000 : secs * 1000;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Executes a fetch call with a single 429 retry.
|
|
65
|
+
* On the first 429, waits for Retry-After seconds (default 1s), then retries once.
|
|
66
|
+
* If the retry also returns 429, throws a BudaApiError with retryAfterMs set.
|
|
67
|
+
*/
|
|
68
|
+
async fetchWithRetry(url, options, path) {
|
|
69
|
+
const response = await fetch(url.toString(), options);
|
|
70
|
+
if (response.status !== 429)
|
|
71
|
+
return response;
|
|
72
|
+
const retryAfterMs = this.parseRetryAfterMs(response.headers);
|
|
73
|
+
await new Promise((r) => setTimeout(r, retryAfterMs));
|
|
74
|
+
const retry = await fetch(url.toString(), options);
|
|
75
|
+
if (retry.status === 429) {
|
|
76
|
+
const retryAgainMs = this.parseRetryAfterMs(retry.headers);
|
|
77
|
+
throw new BudaApiError(429, path, `Buda API rate limit exceeded. Retry after ${retryAgainMs}ms.`, retryAgainMs);
|
|
54
78
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"User-Agent": "buda-mcp/1.1.1",
|
|
59
|
-
...this.authHeaders("GET", urlPath),
|
|
60
|
-
};
|
|
61
|
-
const response = await fetch(url.toString(), { headers });
|
|
79
|
+
return retry;
|
|
80
|
+
}
|
|
81
|
+
async handleResponse(response, path) {
|
|
62
82
|
if (!response.ok) {
|
|
63
83
|
let detail = response.statusText;
|
|
64
84
|
try {
|
|
@@ -73,6 +93,22 @@ export class BudaClient {
|
|
|
73
93
|
}
|
|
74
94
|
return response.json();
|
|
75
95
|
}
|
|
96
|
+
async get(path, params) {
|
|
97
|
+
const url = new URL(`${this.baseUrl}${path}.json`);
|
|
98
|
+
if (params) {
|
|
99
|
+
for (const [key, value] of Object.entries(params)) {
|
|
100
|
+
url.searchParams.set(key, String(value));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const urlPath = url.pathname + url.search;
|
|
104
|
+
const headers = {
|
|
105
|
+
Accept: "application/json",
|
|
106
|
+
"User-Agent": `buda-mcp/${VERSION}`,
|
|
107
|
+
...this.authHeaders("GET", urlPath),
|
|
108
|
+
};
|
|
109
|
+
const response = await this.fetchWithRetry(url, { headers }, path);
|
|
110
|
+
return this.handleResponse(response, path);
|
|
111
|
+
}
|
|
76
112
|
async post(path, payload) {
|
|
77
113
|
const url = new URL(`${this.baseUrl}${path}.json`);
|
|
78
114
|
const bodyStr = JSON.stringify(payload);
|
|
@@ -80,27 +116,11 @@ export class BudaClient {
|
|
|
80
116
|
const headers = {
|
|
81
117
|
Accept: "application/json",
|
|
82
118
|
"Content-Type": "application/json",
|
|
83
|
-
"User-Agent":
|
|
119
|
+
"User-Agent": `buda-mcp/${VERSION}`,
|
|
84
120
|
...this.authHeaders("POST", urlPath, bodyStr),
|
|
85
121
|
};
|
|
86
|
-
const response = await
|
|
87
|
-
|
|
88
|
-
headers,
|
|
89
|
-
body: bodyStr,
|
|
90
|
-
});
|
|
91
|
-
if (!response.ok) {
|
|
92
|
-
let detail = response.statusText;
|
|
93
|
-
try {
|
|
94
|
-
const body = (await response.json());
|
|
95
|
-
if (body.message)
|
|
96
|
-
detail = body.message;
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
// ignore parse error, use statusText
|
|
100
|
-
}
|
|
101
|
-
throw new BudaApiError(response.status, path, `Buda API ${response.status}: ${detail}`);
|
|
102
|
-
}
|
|
103
|
-
return response.json();
|
|
122
|
+
const response = await this.fetchWithRetry(url, { method: "POST", headers, body: bodyStr }, path);
|
|
123
|
+
return this.handleResponse(response, path);
|
|
104
124
|
}
|
|
105
125
|
async put(path, payload) {
|
|
106
126
|
const url = new URL(`${this.baseUrl}${path}.json`);
|
|
@@ -109,27 +129,11 @@ export class BudaClient {
|
|
|
109
129
|
const headers = {
|
|
110
130
|
Accept: "application/json",
|
|
111
131
|
"Content-Type": "application/json",
|
|
112
|
-
"User-Agent":
|
|
132
|
+
"User-Agent": `buda-mcp/${VERSION}`,
|
|
113
133
|
...this.authHeaders("PUT", urlPath, bodyStr),
|
|
114
134
|
};
|
|
115
|
-
const response = await
|
|
116
|
-
|
|
117
|
-
headers,
|
|
118
|
-
body: bodyStr,
|
|
119
|
-
});
|
|
120
|
-
if (!response.ok) {
|
|
121
|
-
let detail = response.statusText;
|
|
122
|
-
try {
|
|
123
|
-
const body = (await response.json());
|
|
124
|
-
if (body.message)
|
|
125
|
-
detail = body.message;
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
// ignore parse error, use statusText
|
|
129
|
-
}
|
|
130
|
-
throw new BudaApiError(response.status, path, `Buda API ${response.status}: ${detail}`);
|
|
131
|
-
}
|
|
132
|
-
return response.json();
|
|
135
|
+
const response = await this.fetchWithRetry(url, { method: "PUT", headers, body: bodyStr }, path);
|
|
136
|
+
return this.handleResponse(response, path);
|
|
133
137
|
}
|
|
134
138
|
}
|
|
135
139
|
//# sourceMappingURL=client.js.map
|
package/dist/http.js
CHANGED
|
@@ -3,6 +3,7 @@ import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mc
|
|
|
3
3
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
4
4
|
import { BudaClient } from "./client.js";
|
|
5
5
|
import { MemoryCache, CACHE_TTL } from "./cache.js";
|
|
6
|
+
import { VERSION } from "./version.js";
|
|
6
7
|
import * as markets from "./tools/markets.js";
|
|
7
8
|
import * as ticker from "./tools/ticker.js";
|
|
8
9
|
import * as orderbook from "./tools/orderbook.js";
|
|
@@ -18,8 +19,26 @@ import * as cancelOrder from "./tools/cancel_order.js";
|
|
|
18
19
|
const PORT = parseInt(process.env.PORT ?? "3000", 10);
|
|
19
20
|
const client = new BudaClient(undefined, process.env.BUDA_API_KEY, process.env.BUDA_API_SECRET);
|
|
20
21
|
const authEnabled = client.hasAuth();
|
|
22
|
+
// Schemas for the Smithery server-card — assembled from the same definitions used in register().
|
|
23
|
+
// Adding a new tool only requires exporting its toolSchema; no changes needed here.
|
|
24
|
+
const PUBLIC_TOOL_SCHEMAS = [
|
|
25
|
+
markets.toolSchema,
|
|
26
|
+
ticker.toolSchema,
|
|
27
|
+
orderbook.toolSchema,
|
|
28
|
+
trades.toolSchema,
|
|
29
|
+
volume.toolSchema,
|
|
30
|
+
spread.toolSchema,
|
|
31
|
+
compareMarkets.toolSchema,
|
|
32
|
+
priceHistory.toolSchema,
|
|
33
|
+
];
|
|
34
|
+
const AUTH_TOOL_SCHEMAS = [
|
|
35
|
+
balances.toolSchema,
|
|
36
|
+
orders.toolSchema,
|
|
37
|
+
placeOrder.toolSchema,
|
|
38
|
+
cancelOrder.toolSchema,
|
|
39
|
+
];
|
|
21
40
|
function createServer() {
|
|
22
|
-
const server = new McpServer({ name: "buda-mcp", version:
|
|
41
|
+
const server = new McpServer({ name: "buda-mcp", version: VERSION });
|
|
23
42
|
// Per-request cache so caching works correctly for stateless HTTP
|
|
24
43
|
const reqCache = new MemoryCache();
|
|
25
44
|
markets.register(server, client, reqCache);
|
|
@@ -68,157 +87,20 @@ const app = express();
|
|
|
68
87
|
app.use(express.json());
|
|
69
88
|
// Health check for Railway / uptime monitors
|
|
70
89
|
app.get("/health", (_req, res) => {
|
|
71
|
-
res.json({
|
|
90
|
+
res.json({
|
|
91
|
+
status: "ok",
|
|
92
|
+
server: "buda-mcp",
|
|
93
|
+
version: VERSION,
|
|
94
|
+
auth_mode: authEnabled ? "authenticated" : "public",
|
|
95
|
+
});
|
|
72
96
|
});
|
|
73
|
-
// Smithery static server card —
|
|
97
|
+
// Smithery static server card — assembled programmatically from tool definitions.
|
|
98
|
+
// Adding a new tool only requires exporting its toolSchema; this handler needs no changes.
|
|
74
99
|
app.get("/.well-known/mcp/server-card.json", (_req, res) => {
|
|
75
|
-
const publicTools = [
|
|
76
|
-
{
|
|
77
|
-
name: "get_markets",
|
|
78
|
-
description: "List all available trading pairs on Buda.com, or get details for a specific market.",
|
|
79
|
-
inputSchema: {
|
|
80
|
-
type: "object",
|
|
81
|
-
properties: {
|
|
82
|
-
market_id: { type: "string", description: "Optional market ID (e.g. BTC-CLP)" },
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: "get_ticker",
|
|
88
|
-
description: "Get current price, bid/ask, volume, and price change for a Buda.com market.",
|
|
89
|
-
inputSchema: {
|
|
90
|
-
type: "object",
|
|
91
|
-
properties: {
|
|
92
|
-
market_id: { type: "string", description: "Market ID (e.g. BTC-CLP)" },
|
|
93
|
-
},
|
|
94
|
-
required: ["market_id"],
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
name: "get_orderbook",
|
|
99
|
-
description: "Get the full order book (bids and asks) for a Buda.com market.",
|
|
100
|
-
inputSchema: {
|
|
101
|
-
type: "object",
|
|
102
|
-
properties: {
|
|
103
|
-
market_id: { type: "string", description: "Market ID (e.g. BTC-CLP)" },
|
|
104
|
-
limit: { type: "number", description: "Max levels per side" },
|
|
105
|
-
},
|
|
106
|
-
required: ["market_id"],
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: "get_trades",
|
|
111
|
-
description: "Get recent trade history for a Buda.com market.",
|
|
112
|
-
inputSchema: {
|
|
113
|
-
type: "object",
|
|
114
|
-
properties: {
|
|
115
|
-
market_id: { type: "string", description: "Market ID (e.g. BTC-CLP)" },
|
|
116
|
-
limit: { type: "number", description: "Number of trades (max 100)" },
|
|
117
|
-
timestamp: { type: "number", description: "Unix timestamp for pagination" },
|
|
118
|
-
},
|
|
119
|
-
required: ["market_id"],
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
name: "get_market_volume",
|
|
124
|
-
description: "Get 24h and 7-day transacted volume for a Buda.com market.",
|
|
125
|
-
inputSchema: {
|
|
126
|
-
type: "object",
|
|
127
|
-
properties: {
|
|
128
|
-
market_id: { type: "string", description: "Market ID (e.g. BTC-CLP)" },
|
|
129
|
-
},
|
|
130
|
-
required: ["market_id"],
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
name: "get_spread",
|
|
135
|
-
description: "Calculate bid/ask spread (absolute and percentage) for a Buda.com market.",
|
|
136
|
-
inputSchema: {
|
|
137
|
-
type: "object",
|
|
138
|
-
properties: {
|
|
139
|
-
market_id: { type: "string", description: "Market ID (e.g. BTC-CLP)" },
|
|
140
|
-
},
|
|
141
|
-
required: ["market_id"],
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
name: "compare_markets",
|
|
146
|
-
description: "Compare ticker data for all trading pairs of a given base currency side by side.",
|
|
147
|
-
inputSchema: {
|
|
148
|
-
type: "object",
|
|
149
|
-
properties: {
|
|
150
|
-
base_currency: { type: "string", description: "Base currency (e.g. BTC, ETH)" },
|
|
151
|
-
},
|
|
152
|
-
required: ["base_currency"],
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
name: "get_price_history",
|
|
157
|
-
description: "Get OHLCV price history for a market, derived from recent trade history.",
|
|
158
|
-
inputSchema: {
|
|
159
|
-
type: "object",
|
|
160
|
-
properties: {
|
|
161
|
-
market_id: { type: "string", description: "Market ID (e.g. BTC-CLP)" },
|
|
162
|
-
period: { type: "string", enum: ["1h", "4h", "1d"], description: "Candle period" },
|
|
163
|
-
limit: { type: "number", description: "Raw trades to fetch (max 100)" },
|
|
164
|
-
},
|
|
165
|
-
required: ["market_id"],
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
];
|
|
169
|
-
const authTools = authEnabled
|
|
170
|
-
? [
|
|
171
|
-
{
|
|
172
|
-
name: "get_balances",
|
|
173
|
-
description: "Get all currency balances for the authenticated account.",
|
|
174
|
-
inputSchema: { type: "object", properties: {} },
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
name: "get_orders",
|
|
178
|
-
description: "Get orders for a given market.",
|
|
179
|
-
inputSchema: {
|
|
180
|
-
type: "object",
|
|
181
|
-
properties: {
|
|
182
|
-
market_id: { type: "string" },
|
|
183
|
-
state: { type: "string" },
|
|
184
|
-
},
|
|
185
|
-
required: ["market_id"],
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
name: "place_order",
|
|
190
|
-
description: "Place a limit or market order. Requires confirmation_token='CONFIRM'.",
|
|
191
|
-
inputSchema: {
|
|
192
|
-
type: "object",
|
|
193
|
-
properties: {
|
|
194
|
-
market_id: { type: "string" },
|
|
195
|
-
type: { type: "string", enum: ["Bid", "Ask"] },
|
|
196
|
-
price_type: { type: "string", enum: ["limit", "market"] },
|
|
197
|
-
amount: { type: "number" },
|
|
198
|
-
limit_price: { type: "number" },
|
|
199
|
-
confirmation_token: { type: "string" },
|
|
200
|
-
},
|
|
201
|
-
required: ["market_id", "type", "price_type", "amount", "confirmation_token"],
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
name: "cancel_order",
|
|
206
|
-
description: "Cancel an order by ID. Requires confirmation_token='CONFIRM'.",
|
|
207
|
-
inputSchema: {
|
|
208
|
-
type: "object",
|
|
209
|
-
properties: {
|
|
210
|
-
order_id: { type: "number" },
|
|
211
|
-
confirmation_token: { type: "string" },
|
|
212
|
-
},
|
|
213
|
-
required: ["order_id", "confirmation_token"],
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
]
|
|
217
|
-
: [];
|
|
218
100
|
res.json({
|
|
219
|
-
serverInfo: { name: "buda-mcp", version:
|
|
101
|
+
serverInfo: { name: "buda-mcp", version: VERSION },
|
|
220
102
|
authentication: { required: authEnabled },
|
|
221
|
-
tools: [...
|
|
103
|
+
tools: [...PUBLIC_TOOL_SCHEMAS, ...(authEnabled ? AUTH_TOOL_SCHEMAS : [])],
|
|
222
104
|
resources: [
|
|
223
105
|
{ uri: "buda://markets", name: "All Buda.com markets", mimeType: "application/json" },
|
|
224
106
|
{ uri: "buda://ticker/{market}", name: "Ticker for a specific market", mimeType: "application/json" },
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
3
3
|
import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
4
|
import { BudaClient } from "./client.js";
|
|
5
5
|
import { cache, CACHE_TTL } from "./cache.js";
|
|
6
|
+
import { VERSION } from "./version.js";
|
|
6
7
|
import * as markets from "./tools/markets.js";
|
|
7
8
|
import * as ticker from "./tools/ticker.js";
|
|
8
9
|
import * as orderbook from "./tools/orderbook.js";
|
|
@@ -18,7 +19,7 @@ import * as cancelOrder from "./tools/cancel_order.js";
|
|
|
18
19
|
const client = new BudaClient(undefined, process.env.BUDA_API_KEY, process.env.BUDA_API_SECRET);
|
|
19
20
|
const server = new McpServer({
|
|
20
21
|
name: "buda-mcp",
|
|
21
|
-
version:
|
|
22
|
+
version: VERSION,
|
|
22
23
|
});
|
|
23
24
|
// Public tools
|
|
24
25
|
markets.register(server, client, cache);
|
package/dist/tools/balances.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { BudaClient } from "../client.js";
|
|
3
|
+
export declare const toolSchema: {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
inputSchema: {
|
|
7
|
+
type: "object";
|
|
8
|
+
properties: {};
|
|
9
|
+
};
|
|
10
|
+
};
|
|
3
11
|
export declare function register(server: McpServer, client: BudaClient): void;
|
|
4
12
|
//# sourceMappingURL=balances.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"balances.d.ts","sourceRoot":"","sources":["../../src/tools/balances.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,UAAU,EAAgB,MAAM,cAAc,CAAC;AAGxD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"balances.d.ts","sourceRoot":"","sources":["../../src/tools/balances.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,UAAU,EAAgB,MAAM,cAAc,CAAC;AAGxD,eAAO,MAAM,UAAU;;;;;;;CAUtB,CAAC;AAEF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAuBpE"}
|
package/dist/tools/balances.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { BudaApiError } from "../client.js";
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export const toolSchema = {
|
|
3
|
+
name: "get_balances",
|
|
4
|
+
description: "Get all currency balances for the authenticated Buda.com account. " +
|
|
4
5
|
"Returns total, available, frozen, and pending withdrawal amounts per currency. " +
|
|
5
|
-
"Requires BUDA_API_KEY and BUDA_API_SECRET environment variables.",
|
|
6
|
+
"Requires BUDA_API_KEY and BUDA_API_SECRET environment variables.",
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: {},
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
export function register(server, client) {
|
|
13
|
+
server.tool(toolSchema.name, toolSchema.description, {}, async () => {
|
|
6
14
|
try {
|
|
7
15
|
const data = await client.get("/balances");
|
|
8
16
|
return {
|
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { BudaClient } from "../client.js";
|
|
3
|
+
export declare const toolSchema: {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
inputSchema: {
|
|
7
|
+
type: "object";
|
|
8
|
+
properties: {
|
|
9
|
+
order_id: {
|
|
10
|
+
type: string;
|
|
11
|
+
description: string;
|
|
12
|
+
};
|
|
13
|
+
confirmation_token: {
|
|
14
|
+
type: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
required: string[];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
type CancelOrderArgs = {
|
|
22
|
+
order_id: number;
|
|
23
|
+
confirmation_token: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function handleCancelOrder(args: CancelOrderArgs, client: BudaClient): Promise<{
|
|
26
|
+
content: Array<{
|
|
27
|
+
type: "text";
|
|
28
|
+
text: string;
|
|
29
|
+
}>;
|
|
30
|
+
isError?: boolean;
|
|
31
|
+
}>;
|
|
3
32
|
export declare function register(server: McpServer, client: BudaClient): void;
|
|
33
|
+
export {};
|
|
4
34
|
//# sourceMappingURL=cancel_order.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cancel_order.d.ts","sourceRoot":"","sources":["../../src/tools/cancel_order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAgB,MAAM,cAAc,CAAC;AAGxD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"cancel_order.d.ts","sourceRoot":"","sources":["../../src/tools/cancel_order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAgB,MAAM,cAAc,CAAC;AAGxD,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;CAuBtB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,eAAe,EACrB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAuChF;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAmBpE"}
|
|
@@ -1,10 +1,65 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { BudaApiError } from "../client.js";
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export const toolSchema = {
|
|
4
|
+
name: "cancel_order",
|
|
5
|
+
description: "Cancel an open order by ID on Buda.com. " +
|
|
5
6
|
"IMPORTANT: To prevent accidental cancellation from ambiguous prompts, you must pass " +
|
|
6
7
|
"confirmation_token='CONFIRM' to execute. " +
|
|
7
|
-
"Requires BUDA_API_KEY and BUDA_API_SECRET environment variables.",
|
|
8
|
+
"Requires BUDA_API_KEY and BUDA_API_SECRET environment variables.",
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
order_id: {
|
|
13
|
+
type: "number",
|
|
14
|
+
description: "The numeric ID of the order to cancel.",
|
|
15
|
+
},
|
|
16
|
+
confirmation_token: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Safety confirmation. Must equal exactly 'CONFIRM' (case-sensitive) to cancel the order. " +
|
|
19
|
+
"Any other value will reject the request without canceling.",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
required: ["order_id", "confirmation_token"],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
export async function handleCancelOrder(args, client) {
|
|
26
|
+
const { order_id, confirmation_token } = args;
|
|
27
|
+
if (confirmation_token !== "CONFIRM") {
|
|
28
|
+
return {
|
|
29
|
+
content: [
|
|
30
|
+
{
|
|
31
|
+
type: "text",
|
|
32
|
+
text: JSON.stringify({
|
|
33
|
+
error: "Order not canceled. confirmation_token must equal 'CONFIRM' to execute. " +
|
|
34
|
+
"Verify the order ID and set confirmation_token='CONFIRM' to proceed.",
|
|
35
|
+
code: "CONFIRMATION_REQUIRED",
|
|
36
|
+
order_id,
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
isError: true,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const data = await client.put(`/orders/${order_id}`, {
|
|
45
|
+
state: "canceling",
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
content: [{ type: "text", text: JSON.stringify(data.order, null, 2) }],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
const msg = err instanceof BudaApiError
|
|
53
|
+
? { error: err.message, code: err.status, path: err.path }
|
|
54
|
+
: { error: String(err), code: "UNKNOWN" };
|
|
55
|
+
return {
|
|
56
|
+
content: [{ type: "text", text: JSON.stringify(msg) }],
|
|
57
|
+
isError: true,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export function register(server, client) {
|
|
62
|
+
server.tool(toolSchema.name, toolSchema.description, {
|
|
8
63
|
order_id: z
|
|
9
64
|
.number()
|
|
10
65
|
.int()
|
|
@@ -14,40 +69,6 @@ export function register(server, client) {
|
|
|
14
69
|
.string()
|
|
15
70
|
.describe("Safety confirmation. Must equal exactly 'CONFIRM' (case-sensitive) to cancel the order. " +
|
|
16
71
|
"Any other value will reject the request without canceling."),
|
|
17
|
-
},
|
|
18
|
-
if (confirmation_token !== "CONFIRM") {
|
|
19
|
-
return {
|
|
20
|
-
content: [
|
|
21
|
-
{
|
|
22
|
-
type: "text",
|
|
23
|
-
text: JSON.stringify({
|
|
24
|
-
error: "Order not canceled. confirmation_token must equal 'CONFIRM' to execute. " +
|
|
25
|
-
"Verify the order ID and set confirmation_token='CONFIRM' to proceed.",
|
|
26
|
-
code: "CONFIRMATION_REQUIRED",
|
|
27
|
-
order_id,
|
|
28
|
-
}),
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
isError: true,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
try {
|
|
35
|
-
const data = await client.put(`/orders/${order_id}`, {
|
|
36
|
-
state: "canceling",
|
|
37
|
-
});
|
|
38
|
-
return {
|
|
39
|
-
content: [{ type: "text", text: JSON.stringify(data.order, null, 2) }],
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
const msg = err instanceof BudaApiError
|
|
44
|
-
? { error: err.message, code: err.status, path: err.path }
|
|
45
|
-
: { error: String(err), code: "UNKNOWN" };
|
|
46
|
-
return {
|
|
47
|
-
content: [{ type: "text", text: JSON.stringify(msg) }],
|
|
48
|
-
isError: true,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
});
|
|
72
|
+
}, (args) => handleCancelOrder(args, client));
|
|
52
73
|
}
|
|
53
74
|
//# sourceMappingURL=cancel_order.js.map
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { BudaClient } from "../client.js";
|
|
3
3
|
import { MemoryCache } from "../cache.js";
|
|
4
|
+
export declare const toolSchema: {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: "object";
|
|
9
|
+
properties: {
|
|
10
|
+
base_currency: {
|
|
11
|
+
type: string;
|
|
12
|
+
description: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
required: string[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
4
18
|
export declare function register(server: McpServer, client: BudaClient, cache: MemoryCache): void;
|
|
5
19
|
//# sourceMappingURL=compare_markets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compare_markets.d.ts","sourceRoot":"","sources":["../../src/tools/compare_markets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAgB,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,WAAW,EAAa,MAAM,aAAa,CAAC;AAGrD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"compare_markets.d.ts","sourceRoot":"","sources":["../../src/tools/compare_markets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAgB,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,WAAW,EAAa,MAAM,aAAa,CAAC;AAGrD,eAAO,MAAM,UAAU;;;;;;;;;;;;;CAiBtB,CAAC;AAEF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAyExF"}
|
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { BudaApiError } from "../client.js";
|
|
3
3
|
import { CACHE_TTL } from "../cache.js";
|
|
4
|
-
export
|
|
5
|
-
|
|
4
|
+
export const toolSchema = {
|
|
5
|
+
name: "compare_markets",
|
|
6
|
+
description: "Compare ticker data for all trading pairs of a given base currency across Buda.com's " +
|
|
6
7
|
"supported quote currencies (CLP, COP, PEN, BTC, USDC, ETH). " +
|
|
7
|
-
"For example, passing 'BTC' returns side-by-side data for BTC-CLP, BTC-COP, BTC-PEN, etc.",
|
|
8
|
+
"For example, passing 'BTC' returns side-by-side data for BTC-CLP, BTC-COP, BTC-PEN, etc.",
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
base_currency: {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "Base currency to compare across all available markets (e.g. 'BTC', 'ETH', 'XRP').",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
required: ["base_currency"],
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export function register(server, client, cache) {
|
|
21
|
+
server.tool(toolSchema.name, toolSchema.description, {
|
|
8
22
|
base_currency: z
|
|
9
23
|
.string()
|
|
10
24
|
.describe("Base currency to compare across all available markets (e.g. 'BTC', 'ETH', 'XRP')."),
|