@lagoon-protocol/lagoon-mcp 0.2.24 → 0.3.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/dist/graphql/queries/index.d.ts +1 -1
- package/dist/graphql/queries/index.d.ts.map +1 -1
- package/dist/graphql/queries/index.js +1 -1
- package/dist/graphql/queries/index.js.map +1 -1
- package/dist/graphql/queries/vault.queries.d.ts +34 -0
- package/dist/graphql/queries/vault.queries.d.ts.map +1 -1
- package/dist/graphql/queries/vault.queries.js +37 -0
- package/dist/graphql/queries/vault.queries.js.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/services/analytics/risk.service.d.ts +72 -0
- package/dist/services/analytics/risk.service.d.ts.map +1 -1
- package/dist/services/analytics/risk.service.js +128 -0
- package/dist/services/analytics/risk.service.js.map +1 -1
- package/dist/tools/analyze-risk.d.ts.map +1 -1
- package/dist/tools/analyze-risk.js +46 -40
- package/dist/tools/analyze-risk.js.map +1 -1
- package/dist/tools/compare-vaults.d.ts.map +1 -1
- package/dist/tools/compare-vaults.js +41 -32
- package/dist/tools/compare-vaults.js.map +1 -1
- package/dist/tools/optimize-portfolio.d.ts +3 -2
- package/dist/tools/optimize-portfolio.d.ts.map +1 -1
- package/dist/tools/optimize-portfolio.js +9 -6
- package/dist/tools/optimize-portfolio.js.map +1 -1
- package/dist/tools/user-portfolio.d.ts.map +1 -1
- package/dist/tools/user-portfolio.js +6 -5
- package/dist/tools/user-portfolio.js.map +1 -1
- package/dist/utils/rate-limiter.d.ts +78 -0
- package/dist/utils/rate-limiter.d.ts.map +1 -0
- package/dist/utils/rate-limiter.js +79 -0
- package/dist/utils/rate-limiter.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate Limiter Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides controlled concurrency for GraphQL requests to prevent 429 rate limit errors.
|
|
5
|
+
* Uses p-limit for efficient promise-based concurrency limiting.
|
|
6
|
+
*
|
|
7
|
+
* Background:
|
|
8
|
+
* The GraphQL API (proxied via Cloudflare) has strict rate limits (~5-10 req/10s).
|
|
9
|
+
* Tools like compare_vaults make multiple parallel requests that can trigger 429 errors.
|
|
10
|
+
* These utilities limit concurrent requests to stay within rate limits.
|
|
11
|
+
*/
|
|
12
|
+
import pLimit from 'p-limit';
|
|
13
|
+
/**
|
|
14
|
+
* Default concurrency limit for GraphQL requests.
|
|
15
|
+
* Conservative value to respect ~5-10 req/10s rate limit.
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_CONCURRENCY = 2;
|
|
18
|
+
/**
|
|
19
|
+
* Type for the p-limit limiter function.
|
|
20
|
+
*/
|
|
21
|
+
export type Limiter = ReturnType<typeof pLimit>;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a rate limiter instance with the specified concurrency.
|
|
24
|
+
*
|
|
25
|
+
* @param concurrency - Maximum number of concurrent operations (default: 2)
|
|
26
|
+
* @returns A p-limit limiter function
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const limiter = createRateLimiter(2);
|
|
31
|
+
* const results = await Promise.all(
|
|
32
|
+
* items.map(item => limiter(() => fetchData(item)))
|
|
33
|
+
* );
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function createRateLimiter(concurrency?: number): Limiter;
|
|
37
|
+
/**
|
|
38
|
+
* Maps over an array with rate-limited concurrency.
|
|
39
|
+
*
|
|
40
|
+
* This is the primary utility for converting unbounded Promise.all patterns
|
|
41
|
+
* to rate-limited parallel execution. Maintains order of results.
|
|
42
|
+
*
|
|
43
|
+
* @param items - Array of items to process
|
|
44
|
+
* @param fn - Async function to apply to each item
|
|
45
|
+
* @param concurrency - Maximum concurrent operations (default: 2)
|
|
46
|
+
* @returns Promise resolving to array of results in same order as input
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Before: Unbounded parallel (causes 429 errors)
|
|
51
|
+
* const results = await Promise.all(
|
|
52
|
+
* vaults.map(v => fetchComposition(v.address))
|
|
53
|
+
* );
|
|
54
|
+
*
|
|
55
|
+
* // After: Rate-limited parallel (max 2 concurrent)
|
|
56
|
+
* const results = await rateLimitedMap(
|
|
57
|
+
* vaults,
|
|
58
|
+
* v => fetchComposition(v.address),
|
|
59
|
+
* 2
|
|
60
|
+
* );
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function rateLimitedMap<T, R>(items: T[], fn: (item: T, index: number) => Promise<R>, concurrency?: number): Promise<R[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Shared rate limiter for GraphQL composition queries.
|
|
66
|
+
* Used across tools that query the Octav API (vault composition).
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* import { compositionLimiter } from '../utils/rate-limiter.js';
|
|
71
|
+
*
|
|
72
|
+
* const results = await Promise.all(
|
|
73
|
+
* vaults.map(v => compositionLimiter(() => fetchComposition(v.address)))
|
|
74
|
+
* );
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare const compositionLimiter: import("p-limit").LimitFunction;
|
|
78
|
+
//# sourceMappingURL=rate-limiter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limiter.d.ts","sourceRoot":"","sources":["../../src/utils/rate-limiter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,MAAM,MAAM,SAAS,CAAC;AAE7B;;;GAGG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC;AAEhD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,GAAE,MAA4B,GAAG,OAAO,CAEpF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,CAAC,EACvC,KAAK,EAAE,CAAC,EAAE,EACV,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EAC1C,WAAW,GAAE,MAA4B,GACxC,OAAO,CAAC,CAAC,EAAE,CAAC,CAGd;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kBAAkB,iCAAyC,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate Limiter Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides controlled concurrency for GraphQL requests to prevent 429 rate limit errors.
|
|
5
|
+
* Uses p-limit for efficient promise-based concurrency limiting.
|
|
6
|
+
*
|
|
7
|
+
* Background:
|
|
8
|
+
* The GraphQL API (proxied via Cloudflare) has strict rate limits (~5-10 req/10s).
|
|
9
|
+
* Tools like compare_vaults make multiple parallel requests that can trigger 429 errors.
|
|
10
|
+
* These utilities limit concurrent requests to stay within rate limits.
|
|
11
|
+
*/
|
|
12
|
+
import pLimit from 'p-limit';
|
|
13
|
+
/**
|
|
14
|
+
* Default concurrency limit for GraphQL requests.
|
|
15
|
+
* Conservative value to respect ~5-10 req/10s rate limit.
|
|
16
|
+
*/
|
|
17
|
+
export const DEFAULT_CONCURRENCY = 2;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a rate limiter instance with the specified concurrency.
|
|
20
|
+
*
|
|
21
|
+
* @param concurrency - Maximum number of concurrent operations (default: 2)
|
|
22
|
+
* @returns A p-limit limiter function
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const limiter = createRateLimiter(2);
|
|
27
|
+
* const results = await Promise.all(
|
|
28
|
+
* items.map(item => limiter(() => fetchData(item)))
|
|
29
|
+
* );
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function createRateLimiter(concurrency = DEFAULT_CONCURRENCY) {
|
|
33
|
+
return pLimit(concurrency);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Maps over an array with rate-limited concurrency.
|
|
37
|
+
*
|
|
38
|
+
* This is the primary utility for converting unbounded Promise.all patterns
|
|
39
|
+
* to rate-limited parallel execution. Maintains order of results.
|
|
40
|
+
*
|
|
41
|
+
* @param items - Array of items to process
|
|
42
|
+
* @param fn - Async function to apply to each item
|
|
43
|
+
* @param concurrency - Maximum concurrent operations (default: 2)
|
|
44
|
+
* @returns Promise resolving to array of results in same order as input
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Before: Unbounded parallel (causes 429 errors)
|
|
49
|
+
* const results = await Promise.all(
|
|
50
|
+
* vaults.map(v => fetchComposition(v.address))
|
|
51
|
+
* );
|
|
52
|
+
*
|
|
53
|
+
* // After: Rate-limited parallel (max 2 concurrent)
|
|
54
|
+
* const results = await rateLimitedMap(
|
|
55
|
+
* vaults,
|
|
56
|
+
* v => fetchComposition(v.address),
|
|
57
|
+
* 2
|
|
58
|
+
* );
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export async function rateLimitedMap(items, fn, concurrency = DEFAULT_CONCURRENCY) {
|
|
62
|
+
const limiter = pLimit(concurrency);
|
|
63
|
+
return Promise.all(items.map((item, index) => limiter(() => fn(item, index))));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Shared rate limiter for GraphQL composition queries.
|
|
67
|
+
* Used across tools that query the Octav API (vault composition).
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import { compositionLimiter } from '../utils/rate-limiter.js';
|
|
72
|
+
*
|
|
73
|
+
* const results = await Promise.all(
|
|
74
|
+
* vaults.map(v => compositionLimiter(() => fetchComposition(v.address)))
|
|
75
|
+
* );
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export const compositionLimiter = createRateLimiter(DEFAULT_CONCURRENCY);
|
|
79
|
+
//# sourceMappingURL=rate-limiter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../../src/utils/rate-limiter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,MAAM,MAAM,SAAS,CAAC;AAE7B;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAOrC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,iBAAiB,CAAC,cAAsB,mBAAmB;IACzE,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,KAAU,EACV,EAA0C,EAC1C,cAAsB,mBAAmB;IAEzC,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IACpC,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACjF,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,mBAAmB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lagoon-protocol/lagoon-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "MCP server for Lagoon DeFi vault analytics - FOR INFORMATIONAL USE ONLY, NOT FINANCIAL ADVICE. Natural language access to vault data, portfolios, and performance metrics",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -86,6 +86,7 @@
|
|
|
86
86
|
"graphql": "^16.8.1",
|
|
87
87
|
"graphql-request": "^6.1.0",
|
|
88
88
|
"node-cache": "^5.1.2",
|
|
89
|
+
"p-limit": "^6.1.0",
|
|
89
90
|
"zod": "^3.22.4"
|
|
90
91
|
},
|
|
91
92
|
"devDependencies": {
|