@zebpay_rajesh/zebpay-mcp-server 0.1.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.
Potentially problematic release.
This version of @zebpay_rajesh/zebpay-mcp-server might be problematic. Click here for more details.
- package/.env.example +14 -0
- package/README.md +223 -0
- package/dist/__tests__/errors.test.d.ts +5 -0
- package/dist/__tests__/errors.test.js +147 -0
- package/dist/__tests__/errors.test.js.map +1 -0
- package/dist/__tests__/prompts.test.d.ts +1 -0
- package/dist/__tests__/prompts.test.js +73 -0
- package/dist/__tests__/prompts.test.js.map +1 -0
- package/dist/__tests__/resources.test.d.ts +1 -0
- package/dist/__tests__/resources.test.js +79 -0
- package/dist/__tests__/resources.test.js.map +1 -0
- package/dist/__tests__/validation.test.d.ts +15 -0
- package/dist/__tests__/validation.test.js +64 -0
- package/dist/__tests__/validation.test.js.map +1 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.js +81 -0
- package/dist/config.js.map +1 -0
- package/dist/http/httpClient.d.ts +40 -0
- package/dist/http/httpClient.js +341 -0
- package/dist/http/httpClient.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/errors.d.ts +21 -0
- package/dist/mcp/errors.js +214 -0
- package/dist/mcp/errors.js.map +1 -0
- package/dist/mcp/logging.d.ts +21 -0
- package/dist/mcp/logging.js +241 -0
- package/dist/mcp/logging.js.map +1 -0
- package/dist/mcp/prompts.d.ts +9 -0
- package/dist/mcp/prompts.js +165 -0
- package/dist/mcp/prompts.js.map +1 -0
- package/dist/mcp/resources.d.ts +9 -0
- package/dist/mcp/resources.js +125 -0
- package/dist/mcp/resources.js.map +1 -0
- package/dist/mcp/tools_futures.d.ts +5 -0
- package/dist/mcp/tools_futures.js +694 -0
- package/dist/mcp/tools_futures.js.map +1 -0
- package/dist/mcp/tools_spot.d.ts +11 -0
- package/dist/mcp/tools_spot.js +2225 -0
- package/dist/mcp/tools_spot.js.map +1 -0
- package/dist/private/FuturesClient.d.ts +57 -0
- package/dist/private/FuturesClient.js +181 -0
- package/dist/private/FuturesClient.js.map +1 -0
- package/dist/private/SpotClient.d.ts +44 -0
- package/dist/private/SpotClient.js +201 -0
- package/dist/private/SpotClient.js.map +1 -0
- package/dist/private/ZebpayAPI.d.ts +19 -0
- package/dist/private/ZebpayAPI.js +172 -0
- package/dist/private/ZebpayAPI.js.map +1 -0
- package/dist/public/PublicClient.d.ts +79 -0
- package/dist/public/PublicClient.js +283 -0
- package/dist/public/PublicClient.js.map +1 -0
- package/dist/public/PublicFuturesClient.d.ts +27 -0
- package/dist/public/PublicFuturesClient.js +187 -0
- package/dist/public/PublicFuturesClient.js.map +1 -0
- package/dist/security/credentials.d.ts +42 -0
- package/dist/security/credentials.js +80 -0
- package/dist/security/credentials.js.map +1 -0
- package/dist/security/signing.d.ts +33 -0
- package/dist/security/signing.js +56 -0
- package/dist/security/signing.js.map +1 -0
- package/dist/types/responses.d.ts +130 -0
- package/dist/types/responses.js +6 -0
- package/dist/types/responses.js.map +1 -0
- package/dist/utils/cache.d.ts +29 -0
- package/dist/utils/cache.js +72 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/fileLogger.d.ts +10 -0
- package/dist/utils/fileLogger.js +81 -0
- package/dist/utils/fileLogger.js.map +1 -0
- package/dist/utils/metrics.d.ts +35 -0
- package/dist/utils/metrics.js +94 -0
- package/dist/utils/metrics.js.map +1 -0
- package/dist/utils/responseFormatter.d.ts +93 -0
- package/dist/utils/responseFormatter.js +268 -0
- package/dist/utils/responseFormatter.js.map +1 -0
- package/dist/validation/schemas.d.ts +70 -0
- package/dist/validation/schemas.js +48 -0
- package/dist/validation/schemas.js.map +1 -0
- package/dist/validation/validators.d.ts +28 -0
- package/dist/validation/validators.js +129 -0
- package/dist/validation/validators.js.map +1 -0
- package/docs/LOGGING.md +371 -0
- package/docs/zebpay-ai-trading-beginner.png +0 -0
- package/mcp-config.json.example +20 -0
- package/package.json +54 -0
- package/scripts/README.md +103 -0
- package/scripts/clear-logs.js +52 -0
- package/scripts/log-stats.js +264 -0
- package/scripts/log-viewer.js +288 -0
- package/server.json +31 -0
- package/src/__tests__/errors.test.ts +180 -0
- package/src/__tests__/prompts.test.ts +89 -0
- package/src/__tests__/resources.test.ts +95 -0
- package/src/__tests__/validation.test.ts +88 -0
- package/src/config.ts +108 -0
- package/src/http/httpClient.ts +398 -0
- package/src/index.ts +71 -0
- package/src/mcp/errors.ts +262 -0
- package/src/mcp/logging.ts +284 -0
- package/src/mcp/prompts.ts +206 -0
- package/src/mcp/resources.ts +163 -0
- package/src/mcp/tools_futures.ts +874 -0
- package/src/mcp/tools_spot.ts +2702 -0
- package/src/private/FuturesClient.ts +189 -0
- package/src/private/SpotClient.ts +250 -0
- package/src/private/ZebpayAPI.ts +205 -0
- package/src/public/PublicClient.ts +381 -0
- package/src/public/PublicFuturesClient.ts +228 -0
- package/src/security/credentials.ts +114 -0
- package/src/security/signing.ts +98 -0
- package/src/types/responses.ts +146 -0
- package/src/utils/cache.ts +90 -0
- package/src/utils/fileLogger.ts +88 -0
- package/src/utils/metrics.ts +135 -0
- package/src/utils/responseFormatter.ts +361 -0
- package/src/validation/schemas.ts +66 -0
- package/src/validation/validators.ts +189 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const sideEnum: z.ZodEnum<{
|
|
3
|
+
buy: "buy";
|
|
4
|
+
sell: "sell";
|
|
5
|
+
}>;
|
|
6
|
+
export declare const orderTypeEnum: z.ZodEnum<{
|
|
7
|
+
limit: "limit";
|
|
8
|
+
market: "market";
|
|
9
|
+
}>;
|
|
10
|
+
export declare const spotPlaceOrderInput: z.ZodObject<{
|
|
11
|
+
symbol: z.ZodString;
|
|
12
|
+
side: z.ZodEnum<{
|
|
13
|
+
buy: "buy";
|
|
14
|
+
sell: "sell";
|
|
15
|
+
}>;
|
|
16
|
+
type: z.ZodEnum<{
|
|
17
|
+
limit: "limit";
|
|
18
|
+
market: "market";
|
|
19
|
+
}>;
|
|
20
|
+
quantity: z.ZodString;
|
|
21
|
+
price: z.ZodOptional<z.ZodString>;
|
|
22
|
+
clientOrderId: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
export declare const spotCancelOrderInput: z.ZodObject<{
|
|
25
|
+
orderId: z.ZodString;
|
|
26
|
+
symbol: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export declare const spotBalancesOutput: z.ZodObject<{
|
|
29
|
+
balances: z.ZodArray<z.ZodObject<{
|
|
30
|
+
asset: z.ZodString;
|
|
31
|
+
free: z.ZodString;
|
|
32
|
+
locked: z.ZodString;
|
|
33
|
+
}, z.core.$strip>>;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
export declare const futuresPlaceOrderInput: z.ZodObject<{
|
|
36
|
+
symbol: z.ZodString;
|
|
37
|
+
side: z.ZodEnum<{
|
|
38
|
+
buy: "buy";
|
|
39
|
+
sell: "sell";
|
|
40
|
+
}>;
|
|
41
|
+
type: z.ZodEnum<{
|
|
42
|
+
limit: "limit";
|
|
43
|
+
market: "market";
|
|
44
|
+
}>;
|
|
45
|
+
quantity: z.ZodString;
|
|
46
|
+
price: z.ZodOptional<z.ZodString>;
|
|
47
|
+
leverage: z.ZodOptional<z.ZodNumber>;
|
|
48
|
+
clientOrderId: z.ZodOptional<z.ZodString>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
export declare const futuresCancelOrderInput: z.ZodObject<{
|
|
51
|
+
orderId: z.ZodString;
|
|
52
|
+
symbol: z.ZodOptional<z.ZodString>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
export declare const futuresPositionsOutput: z.ZodObject<{
|
|
55
|
+
positions: z.ZodArray<z.ZodObject<{
|
|
56
|
+
symbol: z.ZodString;
|
|
57
|
+
positionSide: z.ZodOptional<z.ZodEnum<{
|
|
58
|
+
long: "long";
|
|
59
|
+
short: "short";
|
|
60
|
+
}>>;
|
|
61
|
+
quantity: z.ZodString;
|
|
62
|
+
entryPrice: z.ZodOptional<z.ZodString>;
|
|
63
|
+
unrealizedPnl: z.ZodOptional<z.ZodString>;
|
|
64
|
+
leverage: z.ZodOptional<z.ZodNumber>;
|
|
65
|
+
}, z.core.$strip>>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
export type SpotPlaceOrderInput = z.infer<typeof spotPlaceOrderInput>;
|
|
68
|
+
export type SpotCancelOrderInput = z.infer<typeof spotCancelOrderInput>;
|
|
69
|
+
export type FuturesPlaceOrderInput = z.infer<typeof futuresPlaceOrderInput>;
|
|
70
|
+
export type FuturesCancelOrderInput = z.infer<typeof futuresCancelOrderInput>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Zod schemas for inputs/outputs. These validate tool params and normalize outputs.
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
// Shared enums
|
|
6
|
+
export const sideEnum = z.enum(["buy", "sell"]);
|
|
7
|
+
export const orderTypeEnum = z.enum(["market", "limit"]);
|
|
8
|
+
// Spot
|
|
9
|
+
export const spotPlaceOrderInput = z.object({
|
|
10
|
+
symbol: z.string().min(1),
|
|
11
|
+
side: sideEnum,
|
|
12
|
+
type: orderTypeEnum,
|
|
13
|
+
quantity: z.string().min(1),
|
|
14
|
+
price: z.string().optional(),
|
|
15
|
+
clientOrderId: z.string().optional(),
|
|
16
|
+
});
|
|
17
|
+
export const spotCancelOrderInput = z.object({
|
|
18
|
+
orderId: z.string().min(1),
|
|
19
|
+
symbol: z.string().optional(),
|
|
20
|
+
});
|
|
21
|
+
export const spotBalancesOutput = z.object({
|
|
22
|
+
balances: z.array(z.object({ asset: z.string(), free: z.string(), locked: z.string() })),
|
|
23
|
+
});
|
|
24
|
+
// Futures
|
|
25
|
+
export const futuresPlaceOrderInput = z.object({
|
|
26
|
+
symbol: z.string().min(1),
|
|
27
|
+
side: sideEnum,
|
|
28
|
+
type: orderTypeEnum,
|
|
29
|
+
quantity: z.string().min(1),
|
|
30
|
+
price: z.string().optional(),
|
|
31
|
+
leverage: z.number().int().positive().max(125).optional(),
|
|
32
|
+
clientOrderId: z.string().optional(),
|
|
33
|
+
});
|
|
34
|
+
export const futuresCancelOrderInput = z.object({
|
|
35
|
+
orderId: z.string().min(1),
|
|
36
|
+
symbol: z.string().optional(),
|
|
37
|
+
});
|
|
38
|
+
export const futuresPositionsOutput = z.object({
|
|
39
|
+
positions: z.array(z.object({
|
|
40
|
+
symbol: z.string(),
|
|
41
|
+
positionSide: z.enum(["long", "short"]).optional(),
|
|
42
|
+
quantity: z.string(),
|
|
43
|
+
entryPrice: z.string().optional(),
|
|
44
|
+
unrealizedPnl: z.string().optional(),
|
|
45
|
+
leverage: z.number().int().positive().optional(),
|
|
46
|
+
})),
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/validation/schemas.ts"],"names":[],"mappings":"AAAA;;EAEE;AAEF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAe;AACf,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAChD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAEzD,OAAO;AACP,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACzB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,aAAa;IACnB,QAAQ,EAAE,CAAC,CA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CAAC;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,SAAS,EAAE,CAAC,CAAC,KAAK,CAChB,CAAC,CAAC,MAAM,CAAC;QACP,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;QAClB,YAAY,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE;QAClD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;QACpB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QACjC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QACpC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;KACjD,CAAC,CACH;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Validates trading pair symbol format (BASE-QUOTE)
|
|
4
|
+
* Examples: BTC-INR, ETH-INR, BTC-USDT
|
|
5
|
+
*/
|
|
6
|
+
export declare function validateSymbol(symbol: string): void;
|
|
7
|
+
/**
|
|
8
|
+
* Validates quantity string format
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateQuantity(quantity: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Zod schema for symbol validation
|
|
13
|
+
*/
|
|
14
|
+
export declare const symbolSchema: z.ZodString;
|
|
15
|
+
/**
|
|
16
|
+
* Zod schema for quantity validation
|
|
17
|
+
*/
|
|
18
|
+
export declare const quantitySchema: z.ZodString;
|
|
19
|
+
/**
|
|
20
|
+
* Validates clientOrderId format
|
|
21
|
+
* Must contain only letters, numbers, dots, colons, slashes, underscores, and hyphens
|
|
22
|
+
* Length must be between 1-36 characters
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateClientOrderId(clientOrderId: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Zod schema for clientOrderId validation
|
|
27
|
+
*/
|
|
28
|
+
export declare const clientOrderIdSchema: z.ZodString;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Input validation helpers with helpful error messages for LLMs.
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { createInvalidParamsError } from "../mcp/errors.js";
|
|
6
|
+
/**
|
|
7
|
+
* Validates trading pair symbol format (BASE-QUOTE)
|
|
8
|
+
* Examples: BTC-INR, ETH-INR, BTC-USDT
|
|
9
|
+
*/
|
|
10
|
+
export function validateSymbol(symbol) {
|
|
11
|
+
if (!symbol || typeof symbol !== "string") {
|
|
12
|
+
throw createInvalidParamsError(`Invalid symbol: must be a non-empty string. Expected format: BASE-QUOTE (e.g., "BTC-INR", "ETH-INR")`);
|
|
13
|
+
}
|
|
14
|
+
const trimmed = symbol.trim().toUpperCase();
|
|
15
|
+
const parts = trimmed.split("-");
|
|
16
|
+
if (parts.length !== 2) {
|
|
17
|
+
throw createInvalidParamsError(`Invalid symbol format: "${symbol}". Expected format: BASE-QUOTE (e.g., "BTC-INR", "ETH-INR", "BTC-USDT"). Use uppercase currency codes separated by a single hyphen.`);
|
|
18
|
+
}
|
|
19
|
+
const [base, quote] = parts;
|
|
20
|
+
if (!base || base.length === 0) {
|
|
21
|
+
throw createInvalidParamsError(`Invalid symbol: base currency is missing. Expected format: BASE-QUOTE (e.g., "BTC-INR")`);
|
|
22
|
+
}
|
|
23
|
+
if (!quote || quote.length === 0) {
|
|
24
|
+
throw createInvalidParamsError(`Invalid symbol: quote currency is missing. Expected format: BASE-QUOTE (e.g., "BTC-INR")`);
|
|
25
|
+
}
|
|
26
|
+
// Check for valid currency code format (alphanumeric, typically 2-10 characters)
|
|
27
|
+
const currencyCodeRegex = /^[A-Z0-9]{2,10}$/;
|
|
28
|
+
if (!currencyCodeRegex.test(base)) {
|
|
29
|
+
throw createInvalidParamsError(`Invalid base currency code: "${base}". Currency codes should be 2-10 uppercase alphanumeric characters (e.g., "BTC", "ETH", "USDT")`);
|
|
30
|
+
}
|
|
31
|
+
if (!currencyCodeRegex.test(quote)) {
|
|
32
|
+
throw createInvalidParamsError(`Invalid quote currency code: "${quote}". Currency codes should be 2-10 uppercase alphanumeric characters (e.g., "INR", "USDT", "BTC")`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Validates quantity string format
|
|
37
|
+
*/
|
|
38
|
+
export function validateQuantity(quantity) {
|
|
39
|
+
if (!quantity || typeof quantity !== "string") {
|
|
40
|
+
throw createInvalidParamsError(`Invalid quantity: must be a non-empty string. This prevents floating-point precision issues. Example: "0.001" or "100"`);
|
|
41
|
+
}
|
|
42
|
+
const trimmed = quantity.trim();
|
|
43
|
+
if (trimmed.length === 0) {
|
|
44
|
+
throw createInvalidParamsError(`Invalid quantity: cannot be empty. Provide a positive number as a string (e.g., "0.001", "100", "0.5")`);
|
|
45
|
+
}
|
|
46
|
+
// Check if it's a valid number format
|
|
47
|
+
const numberRegex = /^-?\d+(\.\d+)?$/;
|
|
48
|
+
if (!numberRegex.test(trimmed)) {
|
|
49
|
+
throw createInvalidParamsError(`Invalid quantity format: "${quantity}". Expected a positive number as a string. Examples: "0.001", "100", "0.5". Do not include commas or other formatting.`);
|
|
50
|
+
}
|
|
51
|
+
// Check if it's positive
|
|
52
|
+
const numValue = parseFloat(trimmed);
|
|
53
|
+
if (isNaN(numValue)) {
|
|
54
|
+
throw createInvalidParamsError(`Invalid quantity: "${quantity}" is not a valid number. Provide a positive number as a string (e.g., "0.001")`);
|
|
55
|
+
}
|
|
56
|
+
if (numValue <= 0) {
|
|
57
|
+
throw createInvalidParamsError(`Invalid quantity: "${quantity}" must be greater than zero. Provide a positive number as a string (e.g., "0.001", "100")`);
|
|
58
|
+
}
|
|
59
|
+
// Check for reasonable precision (typically up to 8 decimal places for crypto)
|
|
60
|
+
const decimalParts = trimmed.split(".");
|
|
61
|
+
if (decimalParts.length === 2 && decimalParts[1].length > 18) {
|
|
62
|
+
throw createInvalidParamsError(`Invalid quantity precision: "${quantity}" has too many decimal places (max 18). Example: "0.001" or "100.123456789012345678"`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Zod schema for symbol validation
|
|
67
|
+
*/
|
|
68
|
+
export const symbolSchema = z.string().min(1).refine((val) => {
|
|
69
|
+
try {
|
|
70
|
+
validateSymbol(val);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
77
|
+
message: 'Invalid symbol format. Expected BASE-QUOTE (e.g., "BTC-INR", "ETH-INR")',
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* Zod schema for quantity validation
|
|
81
|
+
*/
|
|
82
|
+
export const quantitySchema = z.string().min(1).refine((val) => {
|
|
83
|
+
try {
|
|
84
|
+
validateQuantity(val);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
message: 'Invalid quantity format. Expected a positive number as a string (e.g., "0.001", "100")',
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* Validates clientOrderId format
|
|
95
|
+
* Must contain only letters, numbers, dots, colons, slashes, underscores, and hyphens
|
|
96
|
+
* Length must be between 1-36 characters
|
|
97
|
+
*/
|
|
98
|
+
export function validateClientOrderId(clientOrderId) {
|
|
99
|
+
if (!clientOrderId || typeof clientOrderId !== "string") {
|
|
100
|
+
throw createInvalidParamsError(`Invalid clientOrderId: must be a non-empty string`);
|
|
101
|
+
}
|
|
102
|
+
const trimmed = clientOrderId.trim();
|
|
103
|
+
if (trimmed.length === 0) {
|
|
104
|
+
throw createInvalidParamsError(`Invalid clientOrderId: cannot be empty`);
|
|
105
|
+
}
|
|
106
|
+
if (trimmed.length > 36) {
|
|
107
|
+
throw createInvalidParamsError(`Invalid clientOrderId: "${clientOrderId}" exceeds maximum length of 36 characters (current: ${trimmed.length})`);
|
|
108
|
+
}
|
|
109
|
+
// Must contain only letters, numbers, dots, colons, slashes, underscores, and hyphens
|
|
110
|
+
const validFormat = /^[a-zA-Z0-9.:/_\-]+$/;
|
|
111
|
+
if (!validFormat.test(trimmed)) {
|
|
112
|
+
throw createInvalidParamsError(`Invalid clientOrderId format: "${clientOrderId}". Must contain only letters, numbers, dots, colons, slashes, underscores, and hyphens. Examples: "my-order-123", "order:2024/01/15_001", "trade.abc-123"`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Zod schema for clientOrderId validation
|
|
117
|
+
*/
|
|
118
|
+
export const clientOrderIdSchema = z.string().min(1).max(36).refine((val) => {
|
|
119
|
+
try {
|
|
120
|
+
validateClientOrderId(val);
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}, {
|
|
127
|
+
message: 'Invalid clientOrderId format. Must be 1-36 characters and contain only letters, numbers, dots, colons, slashes, underscores, and hyphens',
|
|
128
|
+
});
|
|
129
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/validation/validators.ts"],"names":[],"mappings":"AAAA;;EAEE;AAEF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AA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,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,MAAM,CACjE,CAAC,GAAG,EAAE,EAAE;IACN,IAAI,CAAC;QACH,qBAAqB,CAAC,GAAG,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,EACD;IACE,OAAO,EAAE,0IAA0I;CACpJ,CACF,CAAC"}
|
package/docs/LOGGING.md
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
# 📋 Logging & Request/Response Tracking Guide
|
|
2
|
+
|
|
3
|
+
This guide shows you how to easily track and analyze all API requests and responses without dealing with messy console.log output.
|
|
4
|
+
|
|
5
|
+
## 🚀 Quick Start
|
|
6
|
+
|
|
7
|
+
### View All Logs (Pretty Format)
|
|
8
|
+
```bash
|
|
9
|
+
npm run logs
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### Watch Logs in Real-Time (Live Updates)
|
|
13
|
+
```bash
|
|
14
|
+
npm run logs:watch
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### View Only Errors
|
|
18
|
+
```bash
|
|
19
|
+
npm run logs:errors
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### View Statistics Dashboard
|
|
23
|
+
```bash
|
|
24
|
+
npm run logs:stats
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 📊 Log Viewer Commands
|
|
30
|
+
|
|
31
|
+
The log viewer provides powerful filtering and formatting capabilities:
|
|
32
|
+
|
|
33
|
+
### Basic Usage
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# View all logs (formatted and colored)
|
|
37
|
+
npm run logs
|
|
38
|
+
|
|
39
|
+
# View only HTTP requests/responses
|
|
40
|
+
npm run logs:http
|
|
41
|
+
|
|
42
|
+
# View only MCP tool calls
|
|
43
|
+
npm run logs:mcp
|
|
44
|
+
|
|
45
|
+
# View only errors
|
|
46
|
+
npm run logs:errors
|
|
47
|
+
|
|
48
|
+
# Watch logs live (tail -f style)
|
|
49
|
+
npm run logs:watch
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Advanced Filtering
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Filter by trading symbol
|
|
56
|
+
node scripts/log-viewer.js --symbol=BTC-INR
|
|
57
|
+
|
|
58
|
+
# Filter by specific tool
|
|
59
|
+
node scripts/log-viewer.js --tool=zebpay_spot_placeMarketOrder
|
|
60
|
+
|
|
61
|
+
# Show last 50 entries
|
|
62
|
+
node scripts/log-viewer.js --last=50
|
|
63
|
+
|
|
64
|
+
# Filter by correlation ID (track a specific request through the system)
|
|
65
|
+
node scripts/log-viewer.js --correlation=abc123def456
|
|
66
|
+
|
|
67
|
+
# Combine filters
|
|
68
|
+
node scripts/log-viewer.js --type=http --errors --last=20
|
|
69
|
+
|
|
70
|
+
# Watch with filters
|
|
71
|
+
node scripts/log-viewer.js --symbol=BTC-INR --watch
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Output Options
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Raw JSON output (for piping to other tools)
|
|
78
|
+
node scripts/log-viewer.js --raw
|
|
79
|
+
|
|
80
|
+
# Show help
|
|
81
|
+
node scripts/log-viewer.js --help
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 📈 Log Statistics Dashboard
|
|
87
|
+
|
|
88
|
+
Get a comprehensive overview of all API activity:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm run logs:stats
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Shows:**
|
|
95
|
+
- 📊 Total requests, responses, and errors
|
|
96
|
+
- 🌐 HTTP statistics (by method, status code, average duration)
|
|
97
|
+
- 🔧 MCP tool usage statistics
|
|
98
|
+
- 📈 Trading symbols usage
|
|
99
|
+
- ⚠️ Recent errors with details
|
|
100
|
+
|
|
101
|
+
**JSON Output for Integration:**
|
|
102
|
+
```bash
|
|
103
|
+
node scripts/log-stats.js --json > stats.json
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 🧹 Log Management
|
|
109
|
+
|
|
110
|
+
### Archive and Clear Logs
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# Archive current logs and start fresh
|
|
114
|
+
npm run logs:clear
|
|
115
|
+
|
|
116
|
+
# Force delete without archiving
|
|
117
|
+
node scripts/clear-logs.js --force
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## 💡 Common Use Cases
|
|
123
|
+
|
|
124
|
+
### 1. **Debug a Failing Order**
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Find all errors related to BTC-INR
|
|
128
|
+
node scripts/log-viewer.js --symbol=BTC-INR --errors
|
|
129
|
+
|
|
130
|
+
# Watch for new orders on BTC-INR
|
|
131
|
+
node scripts/log-viewer.js --symbol=BTC-INR --watch
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 2. **Track Specific Request**
|
|
135
|
+
|
|
136
|
+
Every request gets a `correlationId`. Use it to track the request through the entire system:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# Copy correlation ID from error message, then:
|
|
140
|
+
node scripts/log-viewer.js --correlation=abc123def456
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
This shows:
|
|
144
|
+
1. MCP request (tool call)
|
|
145
|
+
2. HTTP request (to Zebpay API)
|
|
146
|
+
3. HTTP response (from Zebpay)
|
|
147
|
+
4. MCP response (back to client)
|
|
148
|
+
|
|
149
|
+
### 3. **Monitor API Performance**
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# View statistics
|
|
153
|
+
npm run logs:stats
|
|
154
|
+
|
|
155
|
+
# Watch HTTP requests live
|
|
156
|
+
node scripts/log-viewer.js --type=http_response --watch
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### 4. **Debug Authentication Issues**
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# View all HTTP errors
|
|
163
|
+
node scripts/log-viewer.js --type=http_error
|
|
164
|
+
|
|
165
|
+
# Filter for authentication-related errors
|
|
166
|
+
node scripts/log-viewer.js --errors | grep -i "auth\|401\|403"
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 5. **Track Specific Tool Usage**
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
# See all calls to a specific tool
|
|
173
|
+
node scripts/log-viewer.js --tool=zebpay_spot_placeMarketOrder
|
|
174
|
+
|
|
175
|
+
# Watch for new market orders
|
|
176
|
+
node scripts/log-viewer.js --tool=zebpay_spot_placeMarketOrder --watch
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## 📝 Log Format
|
|
182
|
+
|
|
183
|
+
All logs are stored as **newline-delimited JSON** in `logs/mcp-server.log`.
|
|
184
|
+
|
|
185
|
+
### Log Types
|
|
186
|
+
|
|
187
|
+
#### 1. **HTTP Request**
|
|
188
|
+
```json
|
|
189
|
+
{
|
|
190
|
+
"level": "info",
|
|
191
|
+
"type": "http_request",
|
|
192
|
+
"timestamp": "2024-01-15T10:30:45.123Z",
|
|
193
|
+
"method": "POST",
|
|
194
|
+
"url": "https://api.zebpay.com/api/v2/ex/orders",
|
|
195
|
+
"headers": { "..." },
|
|
196
|
+
"body": { "symbol": "BTC-INR", "side": "BUY", "..." }
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
#### 2. **HTTP Response**
|
|
201
|
+
```json
|
|
202
|
+
{
|
|
203
|
+
"level": "info",
|
|
204
|
+
"type": "http_response",
|
|
205
|
+
"timestamp": "2024-01-15T10:30:45.456Z",
|
|
206
|
+
"method": "POST",
|
|
207
|
+
"url": "https://api.zebpay.com/api/v2/ex/orders",
|
|
208
|
+
"status": 200,
|
|
209
|
+
"durationMs": 333,
|
|
210
|
+
"body": { "data": { "orderId": "123", "..." } }
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
#### 3. **MCP Request** (Tool Call)
|
|
215
|
+
```json
|
|
216
|
+
{
|
|
217
|
+
"level": "info",
|
|
218
|
+
"type": "mcp_request",
|
|
219
|
+
"timestamp": "2024-01-15T10:30:45.000Z",
|
|
220
|
+
"tool": "zebpay_spot_placeMarketOrder",
|
|
221
|
+
"correlationId": "abc123def456",
|
|
222
|
+
"params": { "symbol": "BTC-INR", "side": "BUY", "..." }
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### 4. **MCP Response**
|
|
227
|
+
```json
|
|
228
|
+
{
|
|
229
|
+
"level": "info",
|
|
230
|
+
"type": "mcp_response",
|
|
231
|
+
"timestamp": "2024-01-15T10:30:45.500Z",
|
|
232
|
+
"tool": "zebpay_spot_placeMarketOrder",
|
|
233
|
+
"correlationId": "abc123def456",
|
|
234
|
+
"success": true,
|
|
235
|
+
"durationMs": 500,
|
|
236
|
+
"result": { "..." }
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
#### 5. **Errors**
|
|
241
|
+
```json
|
|
242
|
+
{
|
|
243
|
+
"level": "error",
|
|
244
|
+
"type": "mcp_error" | "http_error",
|
|
245
|
+
"timestamp": "2024-01-15T10:30:45.500Z",
|
|
246
|
+
"error": "Error message",
|
|
247
|
+
"errorCode": 400,
|
|
248
|
+
"stack": "...",
|
|
249
|
+
"..."
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## 🎨 Color-Coded Output
|
|
256
|
+
|
|
257
|
+
The log viewer uses colors to make logs easier to read:
|
|
258
|
+
|
|
259
|
+
- 🟢 **Green**: Success (2xx status codes, INFO level)
|
|
260
|
+
- 🔴 **Red**: Errors (4xx/5xx status codes, ERROR level)
|
|
261
|
+
- 🟡 **Yellow**: Warnings
|
|
262
|
+
- 🔵 **Blue**: Debug information
|
|
263
|
+
- 🟣 **Magenta**: MCP tool calls
|
|
264
|
+
- 🔷 **Cyan**: HTTP requests/responses
|
|
265
|
+
- ⚪ **Gray**: Timestamps and metadata
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## 🔧 Integration with External Tools
|
|
270
|
+
|
|
271
|
+
### Export to JSON for Analysis
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
# Export last 100 entries as JSON
|
|
275
|
+
node scripts/log-viewer.js --last=100 --raw > logs/export.json
|
|
276
|
+
|
|
277
|
+
# Export statistics
|
|
278
|
+
node scripts/log-stats.js --json > logs/stats.json
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Grep/Awk Integration
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
# Find all 500 errors
|
|
285
|
+
node scripts/log-viewer.js --type=http | grep "500"
|
|
286
|
+
|
|
287
|
+
# Count errors by type
|
|
288
|
+
node scripts/log-viewer.js --errors --raw | jq -r '.type' | sort | uniq -c
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Watch Specific Symbol
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
# Terminal 1: Watch logs
|
|
295
|
+
node scripts/log-viewer.js --symbol=BTC-INR --watch
|
|
296
|
+
|
|
297
|
+
# Terminal 2: Place orders
|
|
298
|
+
# ... your trading operations ...
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## 🚨 Troubleshooting
|
|
304
|
+
|
|
305
|
+
### No logs appearing?
|
|
306
|
+
|
|
307
|
+
1. **Check if log file exists:**
|
|
308
|
+
```bash
|
|
309
|
+
ls -lh logs/mcp-server.log
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
2. **Make sure server is running with logging enabled:**
|
|
313
|
+
```bash
|
|
314
|
+
npm run start:log-append
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
3. **Check log path in code:**
|
|
318
|
+
The log path is set in `src/index.ts` where `fileLogger.initialize()` is called.
|
|
319
|
+
|
|
320
|
+
### Logs too large?
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
# Archive and clear
|
|
324
|
+
npm run logs:clear
|
|
325
|
+
|
|
326
|
+
# View only recent entries
|
|
327
|
+
node scripts/log-viewer.js --last=100
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Can't find specific request?
|
|
331
|
+
|
|
332
|
+
Use correlation ID to track requests across the system:
|
|
333
|
+
```bash
|
|
334
|
+
# 1. Find the correlation ID in any log entry
|
|
335
|
+
# 2. Track it through the entire flow:
|
|
336
|
+
node scripts/log-viewer.js --correlation=YOUR_CORRELATION_ID
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## 📖 Additional Resources
|
|
342
|
+
|
|
343
|
+
- **Main README**: `../README.md`
|
|
344
|
+
- **Log Source Code**:
|
|
345
|
+
- HTTP Client: `src/http/httpClient.ts`
|
|
346
|
+
- MCP Logging: `src/mcp/logging.ts`
|
|
347
|
+
- File Logger: `src/utils/fileLogger.ts`
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## 🎯 Best Practices
|
|
352
|
+
|
|
353
|
+
1. **Always use `--watch` during development** - See issues in real-time
|
|
354
|
+
2. **Use correlation IDs** - Track requests end-to-end
|
|
355
|
+
3. **Archive logs regularly** - Prevent log files from growing too large
|
|
356
|
+
4. **Filter by symbol** - Focus on specific trading pairs
|
|
357
|
+
5. **Check stats dashboard** - Get quick overview of system health
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## 📞 Need Help?
|
|
362
|
+
|
|
363
|
+
If you're still having trouble tracking requests/responses:
|
|
364
|
+
|
|
365
|
+
1. Check the log viewer help: `node scripts/log-viewer.js --help`
|
|
366
|
+
2. Verify logs are being written: `tail -f logs/mcp-server.log`
|
|
367
|
+
3. Check for file permissions issues
|
|
368
|
+
4. Make sure the `logs/` directory exists
|
|
369
|
+
|
|
370
|
+
Happy tracking! 🎉
|
|
371
|
+
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mcpServers": {
|
|
3
|
+
"zebpay": {
|
|
4
|
+
"command": "node",
|
|
5
|
+
"args": ["dist/index.js"],
|
|
6
|
+
"cwd": "/path/to/ai-agents",
|
|
7
|
+
"env": {
|
|
8
|
+
"ZEBPAY_API_KEY": "YOUR_API_KEY_HERE",
|
|
9
|
+
"ZEBPAY_API_SECRET": "YOUR_API_SECRET_HERE",
|
|
10
|
+
"ZEBPAY_SPOT_BASE_URL": "https://www.zebapi.com/api/v2",
|
|
11
|
+
"ZEBPAY_FUTURES_BASE_URL": "https://futures-api.zebpay.com/api/v1",
|
|
12
|
+
"ZEBPAY_MARKET_BASE_URL": "https://www.zebapi.com/api/v1/market",
|
|
13
|
+
"MCP_TRANSPORTS": "stdio",
|
|
14
|
+
"LOG_LEVEL": "info",
|
|
15
|
+
"HTTP_TIMEOUT_MS": "15000",
|
|
16
|
+
"HTTP_RETRY_COUNT": "2"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|