@nirvana-labs/nirvana-mcp 1.20.2 → 1.21.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 +21 -1
- package/code-tool-worker.d.mts.map +1 -1
- package/code-tool-worker.d.ts.map +1 -1
- package/code-tool-worker.js +211 -7
- package/code-tool-worker.js.map +1 -1
- package/code-tool-worker.mjs +211 -7
- package/code-tool-worker.mjs.map +1 -1
- package/code-tool.d.mts +1 -1
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts +1 -1
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +11 -13
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +11 -13
- package/code-tool.mjs.map +1 -1
- package/dynamic-tools.d.mts +1 -1
- package/dynamic-tools.d.ts +1 -1
- package/dynamic-tools.js +1 -1
- package/dynamic-tools.mjs +1 -1
- package/options.d.mts.map +1 -1
- package/options.d.ts.map +1 -1
- package/options.js +6 -3
- package/options.js.map +1 -1
- package/options.mjs +6 -3
- package/options.mjs.map +1 -1
- package/package.json +4 -2
- package/server.js +1 -1
- package/server.mjs +1 -1
- package/src/code-tool-worker.ts +256 -7
- package/src/code-tool.ts +14 -13
- package/src/dynamic-tools.ts +1 -1
- package/src/options.ts +10 -3
- package/src/server.ts +1 -1
- package/src/tools/api-keys/list-api-keys.ts +12 -3
- package/src/tools/compute/vms/list-compute-vms.ts +12 -3
- package/src/tools/compute/vms/volumes/list-vms-compute-volumes.ts +11 -2
- package/src/tools/compute/volumes/list-compute-volumes.ts +12 -3
- package/src/tools/networking/connect/connections/list-connect-networking-connections.ts +12 -5
- package/src/tools/networking/connect/routes/list-connect-networking-routes.ts +12 -3
- package/src/tools/networking/firewall-rules/list-networking-firewall-rules.ts +11 -4
- package/src/tools/networking/vpcs/list-networking-vpcs.ts +12 -3
- package/src/tools/operations/list-operations.ts +12 -3
- package/src/tools/rpc-nodes/dedicated/blockchains/list-dedicated-rpc-nodes-blockchains.ts +13 -6
- package/src/tools/rpc-nodes/dedicated/list-rpc-nodes-dedicated.ts +12 -3
- package/src/tools/rpc-nodes/flex/blockchains/list-flex-rpc-nodes-blockchains.ts +13 -4
- package/src/tools/rpc-nodes/flex/list-rpc-nodes-flex.ts +12 -3
- package/tools/api-keys/list-api-keys.d.mts.map +1 -1
- package/tools/api-keys/list-api-keys.d.ts.map +1 -1
- package/tools/api-keys/list-api-keys.js +12 -3
- package/tools/api-keys/list-api-keys.js.map +1 -1
- package/tools/api-keys/list-api-keys.mjs +12 -3
- package/tools/api-keys/list-api-keys.mjs.map +1 -1
- package/tools/compute/vms/list-compute-vms.d.mts.map +1 -1
- package/tools/compute/vms/list-compute-vms.d.ts.map +1 -1
- package/tools/compute/vms/list-compute-vms.js +12 -3
- package/tools/compute/vms/list-compute-vms.js.map +1 -1
- package/tools/compute/vms/list-compute-vms.mjs +12 -3
- package/tools/compute/vms/list-compute-vms.mjs.map +1 -1
- package/tools/compute/vms/volumes/list-vms-compute-volumes.d.mts.map +1 -1
- package/tools/compute/vms/volumes/list-vms-compute-volumes.d.ts.map +1 -1
- package/tools/compute/vms/volumes/list-vms-compute-volumes.js +11 -2
- package/tools/compute/vms/volumes/list-vms-compute-volumes.js.map +1 -1
- package/tools/compute/vms/volumes/list-vms-compute-volumes.mjs +11 -2
- package/tools/compute/vms/volumes/list-vms-compute-volumes.mjs.map +1 -1
- package/tools/compute/volumes/list-compute-volumes.d.mts.map +1 -1
- package/tools/compute/volumes/list-compute-volumes.d.ts.map +1 -1
- package/tools/compute/volumes/list-compute-volumes.js +12 -3
- package/tools/compute/volumes/list-compute-volumes.js.map +1 -1
- package/tools/compute/volumes/list-compute-volumes.mjs +12 -3
- package/tools/compute/volumes/list-compute-volumes.mjs.map +1 -1
- package/tools/networking/connect/connections/list-connect-networking-connections.d.mts.map +1 -1
- package/tools/networking/connect/connections/list-connect-networking-connections.d.ts.map +1 -1
- package/tools/networking/connect/connections/list-connect-networking-connections.js +12 -3
- package/tools/networking/connect/connections/list-connect-networking-connections.js.map +1 -1
- package/tools/networking/connect/connections/list-connect-networking-connections.mjs +12 -3
- package/tools/networking/connect/connections/list-connect-networking-connections.mjs.map +1 -1
- package/tools/networking/connect/routes/list-connect-networking-routes.d.mts.map +1 -1
- package/tools/networking/connect/routes/list-connect-networking-routes.d.ts.map +1 -1
- package/tools/networking/connect/routes/list-connect-networking-routes.js +12 -3
- package/tools/networking/connect/routes/list-connect-networking-routes.js.map +1 -1
- package/tools/networking/connect/routes/list-connect-networking-routes.mjs +12 -3
- package/tools/networking/connect/routes/list-connect-networking-routes.mjs.map +1 -1
- package/tools/networking/firewall-rules/list-networking-firewall-rules.d.mts.map +1 -1
- package/tools/networking/firewall-rules/list-networking-firewall-rules.d.ts.map +1 -1
- package/tools/networking/firewall-rules/list-networking-firewall-rules.js +11 -2
- package/tools/networking/firewall-rules/list-networking-firewall-rules.js.map +1 -1
- package/tools/networking/firewall-rules/list-networking-firewall-rules.mjs +11 -2
- package/tools/networking/firewall-rules/list-networking-firewall-rules.mjs.map +1 -1
- package/tools/networking/vpcs/list-networking-vpcs.d.mts.map +1 -1
- package/tools/networking/vpcs/list-networking-vpcs.d.ts.map +1 -1
- package/tools/networking/vpcs/list-networking-vpcs.js +12 -3
- package/tools/networking/vpcs/list-networking-vpcs.js.map +1 -1
- package/tools/networking/vpcs/list-networking-vpcs.mjs +12 -3
- package/tools/networking/vpcs/list-networking-vpcs.mjs.map +1 -1
- package/tools/operations/list-operations.d.mts.map +1 -1
- package/tools/operations/list-operations.d.ts.map +1 -1
- package/tools/operations/list-operations.js +12 -3
- package/tools/operations/list-operations.js.map +1 -1
- package/tools/operations/list-operations.mjs +12 -3
- package/tools/operations/list-operations.mjs.map +1 -1
- package/tools/rpc-nodes/dedicated/blockchains/list-dedicated-rpc-nodes-blockchains.d.mts.map +1 -1
- package/tools/rpc-nodes/dedicated/blockchains/list-dedicated-rpc-nodes-blockchains.d.ts.map +1 -1
- package/tools/rpc-nodes/dedicated/blockchains/list-dedicated-rpc-nodes-blockchains.js +13 -4
- package/tools/rpc-nodes/dedicated/blockchains/list-dedicated-rpc-nodes-blockchains.js.map +1 -1
- package/tools/rpc-nodes/dedicated/blockchains/list-dedicated-rpc-nodes-blockchains.mjs +13 -4
- package/tools/rpc-nodes/dedicated/blockchains/list-dedicated-rpc-nodes-blockchains.mjs.map +1 -1
- package/tools/rpc-nodes/dedicated/list-rpc-nodes-dedicated.d.mts.map +1 -1
- package/tools/rpc-nodes/dedicated/list-rpc-nodes-dedicated.d.ts.map +1 -1
- package/tools/rpc-nodes/dedicated/list-rpc-nodes-dedicated.js +12 -3
- package/tools/rpc-nodes/dedicated/list-rpc-nodes-dedicated.js.map +1 -1
- package/tools/rpc-nodes/dedicated/list-rpc-nodes-dedicated.mjs +12 -3
- package/tools/rpc-nodes/dedicated/list-rpc-nodes-dedicated.mjs.map +1 -1
- package/tools/rpc-nodes/flex/blockchains/list-flex-rpc-nodes-blockchains.d.mts.map +1 -1
- package/tools/rpc-nodes/flex/blockchains/list-flex-rpc-nodes-blockchains.d.ts.map +1 -1
- package/tools/rpc-nodes/flex/blockchains/list-flex-rpc-nodes-blockchains.js +13 -4
- package/tools/rpc-nodes/flex/blockchains/list-flex-rpc-nodes-blockchains.js.map +1 -1
- package/tools/rpc-nodes/flex/blockchains/list-flex-rpc-nodes-blockchains.mjs +13 -4
- package/tools/rpc-nodes/flex/blockchains/list-flex-rpc-nodes-blockchains.mjs.map +1 -1
- package/tools/rpc-nodes/flex/list-rpc-nodes-flex.d.mts.map +1 -1
- package/tools/rpc-nodes/flex/list-rpc-nodes-flex.d.ts.map +1 -1
- package/tools/rpc-nodes/flex/list-rpc-nodes-flex.js +12 -3
- package/tools/rpc-nodes/flex/list-rpc-nodes-flex.js.map +1 -1
- package/tools/rpc-nodes/flex/list-rpc-nodes-flex.mjs +12 -3
- package/tools/rpc-nodes/flex/list-rpc-nodes-flex.mjs.map +1 -1
package/src/code-tool-worker.ts
CHANGED
|
@@ -1,11 +1,264 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import util from 'node:util';
|
|
4
|
+
|
|
5
|
+
import Fuse from 'fuse.js';
|
|
6
|
+
import ts from 'typescript';
|
|
7
|
+
|
|
4
8
|
import { WorkerInput, WorkerSuccess, WorkerError } from './code-tool-types';
|
|
5
9
|
import { NirvanaLabs } from '@nirvana-labs/nirvana';
|
|
6
10
|
|
|
11
|
+
function getRunFunctionNode(
|
|
12
|
+
code: string,
|
|
13
|
+
): ts.FunctionDeclaration | ts.FunctionExpression | ts.ArrowFunction | null {
|
|
14
|
+
const sourceFile = ts.createSourceFile('code.ts', code, ts.ScriptTarget.Latest, true);
|
|
15
|
+
|
|
16
|
+
for (const statement of sourceFile.statements) {
|
|
17
|
+
// Check for top-level function declarations
|
|
18
|
+
if (ts.isFunctionDeclaration(statement)) {
|
|
19
|
+
if (statement.name?.text === 'run') {
|
|
20
|
+
return statement;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Check for variable declarations: const run = () => {} or const run = function() {}
|
|
25
|
+
if (ts.isVariableStatement(statement)) {
|
|
26
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
27
|
+
if (ts.isIdentifier(declaration.name) && declaration.name.text === 'run') {
|
|
28
|
+
// Check if it's initialized with a function
|
|
29
|
+
if (
|
|
30
|
+
declaration.initializer &&
|
|
31
|
+
(ts.isFunctionExpression(declaration.initializer) || ts.isArrowFunction(declaration.initializer))
|
|
32
|
+
) {
|
|
33
|
+
return declaration.initializer;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const fuse = new Fuse(
|
|
44
|
+
[
|
|
45
|
+
'client.user.get',
|
|
46
|
+
'client.apiKeys.create',
|
|
47
|
+
'client.apiKeys.delete',
|
|
48
|
+
'client.apiKeys.get',
|
|
49
|
+
'client.apiKeys.list',
|
|
50
|
+
'client.apiKeys.update',
|
|
51
|
+
'client.operations.get',
|
|
52
|
+
'client.operations.list',
|
|
53
|
+
'client.compute.vms.create',
|
|
54
|
+
'client.compute.vms.delete',
|
|
55
|
+
'client.compute.vms.get',
|
|
56
|
+
'client.compute.vms.list',
|
|
57
|
+
'client.compute.vms.restart',
|
|
58
|
+
'client.compute.vms.update',
|
|
59
|
+
'client.compute.vms.availability.create',
|
|
60
|
+
'client.compute.vms.availability.update',
|
|
61
|
+
'client.compute.vms.volumes.list',
|
|
62
|
+
'client.compute.vms.osImages.list',
|
|
63
|
+
'client.compute.volumes.create',
|
|
64
|
+
'client.compute.volumes.delete',
|
|
65
|
+
'client.compute.volumes.get',
|
|
66
|
+
'client.compute.volumes.list',
|
|
67
|
+
'client.compute.volumes.update',
|
|
68
|
+
'client.compute.volumes.availability.create',
|
|
69
|
+
'client.compute.volumes.availability.update',
|
|
70
|
+
'client.networking.vpcs.create',
|
|
71
|
+
'client.networking.vpcs.delete',
|
|
72
|
+
'client.networking.vpcs.get',
|
|
73
|
+
'client.networking.vpcs.list',
|
|
74
|
+
'client.networking.vpcs.update',
|
|
75
|
+
'client.networking.vpcs.availability.create',
|
|
76
|
+
'client.networking.vpcs.availability.update',
|
|
77
|
+
'client.networking.firewallRules.create',
|
|
78
|
+
'client.networking.firewallRules.delete',
|
|
79
|
+
'client.networking.firewallRules.get',
|
|
80
|
+
'client.networking.firewallRules.list',
|
|
81
|
+
'client.networking.firewallRules.update',
|
|
82
|
+
'client.networking.connect.connections.create',
|
|
83
|
+
'client.networking.connect.connections.delete',
|
|
84
|
+
'client.networking.connect.connections.get',
|
|
85
|
+
'client.networking.connect.connections.list',
|
|
86
|
+
'client.networking.connect.connections.update',
|
|
87
|
+
'client.networking.connect.routes.list',
|
|
88
|
+
'client.rpcNodes.flex.create',
|
|
89
|
+
'client.rpcNodes.flex.delete',
|
|
90
|
+
'client.rpcNodes.flex.get',
|
|
91
|
+
'client.rpcNodes.flex.list',
|
|
92
|
+
'client.rpcNodes.flex.update',
|
|
93
|
+
'client.rpcNodes.flex.blockchains.list',
|
|
94
|
+
'client.rpcNodes.dedicated.get',
|
|
95
|
+
'client.rpcNodes.dedicated.list',
|
|
96
|
+
'client.rpcNodes.dedicated.blockchains.list',
|
|
97
|
+
'client.vektor.registry.assets.list',
|
|
98
|
+
'client.vektor.registry.blockchains.list',
|
|
99
|
+
'client.vektor.registry.venues.list',
|
|
100
|
+
'client.vektor.registry.errors.list',
|
|
101
|
+
'client.vektor.registry.lendMarkets.list',
|
|
102
|
+
'client.vektor.registry.borrowMarkets.list',
|
|
103
|
+
'client.vektor.registry.lpPools.list',
|
|
104
|
+
'client.vektor.balances.list',
|
|
105
|
+
'client.vektor.balances.listHistorical',
|
|
106
|
+
'client.vektor.prices.list',
|
|
107
|
+
'client.vektor.prices.listHistorical',
|
|
108
|
+
'client.vektor.lend.markets.list',
|
|
109
|
+
'client.vektor.lend.markets.listHistorical',
|
|
110
|
+
'client.vektor.lend.positions.list',
|
|
111
|
+
'client.vektor.lend.positions.listHistorical',
|
|
112
|
+
'client.vektor.lend.lend.create',
|
|
113
|
+
'client.vektor.lend.withdraw.create',
|
|
114
|
+
'client.vektor.lend.setCollateral.create',
|
|
115
|
+
'client.vektor.borrow.markets.list',
|
|
116
|
+
'client.vektor.borrow.markets.listHistorical',
|
|
117
|
+
'client.vektor.borrow.positions.list',
|
|
118
|
+
'client.vektor.borrow.positions.listHistorical',
|
|
119
|
+
'client.vektor.borrow.accounts.list',
|
|
120
|
+
'client.vektor.borrow.accounts.listHistorical',
|
|
121
|
+
'client.vektor.borrow.borrow.create',
|
|
122
|
+
'client.vektor.borrow.repay.create',
|
|
123
|
+
'client.vektor.lp.pools.list',
|
|
124
|
+
'client.vektor.lp.pools.listHistorical',
|
|
125
|
+
'client.vektor.lp.positions.list',
|
|
126
|
+
'client.vektor.lp.positions.listHistorical',
|
|
127
|
+
'client.vektor.lp.depositQuote.create',
|
|
128
|
+
'client.vektor.lp.withdrawQuote.create',
|
|
129
|
+
'client.vektor.buy.quotes.list',
|
|
130
|
+
'client.vektor.buy.buy.create',
|
|
131
|
+
'client.vektor.sell.quotes.list',
|
|
132
|
+
'client.vektor.sell.sell.create',
|
|
133
|
+
'client.vektor.move.create',
|
|
134
|
+
'client.vektor.wrap.wrap.create',
|
|
135
|
+
'client.vektor.wrap.unwrap.create',
|
|
136
|
+
'client.vektor.bridge.quotes.list',
|
|
137
|
+
'client.vektor.lock.markets.list',
|
|
138
|
+
'client.vektor.lock.positions.list',
|
|
139
|
+
'client.vektor.vote.markets.list',
|
|
140
|
+
'client.vektor.vote.rewards.list',
|
|
141
|
+
'client.vektor.incentivize.list',
|
|
142
|
+
'client.vektor.executions.get',
|
|
143
|
+
'client.vektor.executions.list',
|
|
144
|
+
'client.vektor.executions.steps.get',
|
|
145
|
+
'client.vektor.executions.steps.sign',
|
|
146
|
+
],
|
|
147
|
+
{ threshold: 1, shouldSort: true },
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
function getMethodSuggestions(fullyQualifiedMethodName: string): string[] {
|
|
151
|
+
return fuse
|
|
152
|
+
.search(fullyQualifiedMethodName)
|
|
153
|
+
.map(({ item }) => item)
|
|
154
|
+
.slice(0, 5);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const proxyToObj = new WeakMap<any, any>();
|
|
158
|
+
const objToProxy = new WeakMap<any, any>();
|
|
159
|
+
|
|
160
|
+
type ClientProxyConfig = {
|
|
161
|
+
path: string[];
|
|
162
|
+
isBelievedBad?: boolean;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
function makeSdkProxy<T extends object>(obj: T, { path, isBelievedBad = false }: ClientProxyConfig): T {
|
|
166
|
+
let proxy: T = objToProxy.get(obj);
|
|
167
|
+
|
|
168
|
+
if (!proxy) {
|
|
169
|
+
proxy = new Proxy(obj, {
|
|
170
|
+
get(target, prop, receiver) {
|
|
171
|
+
const propPath = [...path, String(prop)];
|
|
172
|
+
const value = Reflect.get(target, prop, receiver);
|
|
173
|
+
|
|
174
|
+
if (isBelievedBad || (!(prop in target) && value === undefined)) {
|
|
175
|
+
// If we're accessing a path that doesn't exist, it will probably eventually error.
|
|
176
|
+
// Let's proxy it and mark it bad so that we can control the error message.
|
|
177
|
+
// We proxy an empty class so that an invocation or construction attempt is possible.
|
|
178
|
+
return makeSdkProxy(class {}, { path: propPath, isBelievedBad: true });
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (value !== null && (typeof value === 'object' || typeof value === 'function')) {
|
|
182
|
+
return makeSdkProxy(value, { path: propPath, isBelievedBad });
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return value;
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
apply(target, thisArg, args) {
|
|
189
|
+
if (isBelievedBad || typeof target !== 'function') {
|
|
190
|
+
const fullyQualifiedMethodName = path.join('.');
|
|
191
|
+
const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
|
|
192
|
+
throw new Error(
|
|
193
|
+
`${fullyQualifiedMethodName} is not a function. Did you mean: ${suggestions.join(', ')}`,
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return Reflect.apply(target, proxyToObj.get(thisArg) ?? thisArg, args);
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
construct(target, args, newTarget) {
|
|
201
|
+
if (isBelievedBad || typeof target !== 'function') {
|
|
202
|
+
const fullyQualifiedMethodName = path.join('.');
|
|
203
|
+
const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
|
|
204
|
+
throw new Error(
|
|
205
|
+
`${fullyQualifiedMethodName} is not a constructor. Did you mean: ${suggestions.join(', ')}`,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return Reflect.construct(target, args, newTarget);
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
objToProxy.set(obj, proxy);
|
|
214
|
+
proxyToObj.set(proxy, obj);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return proxy;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function parseError(code: string, error: unknown): string | undefined {
|
|
221
|
+
if (!(error instanceof Error)) return;
|
|
222
|
+
const message = error.name ? `${error.name}: ${error.message}` : error.message;
|
|
223
|
+
try {
|
|
224
|
+
// Deno uses V8; the first "<anonymous>:LINE:COLUMN" is the top of stack.
|
|
225
|
+
const lineNumber = error.stack?.match(/<anonymous>:([0-9]+):[0-9]+/)?.[1];
|
|
226
|
+
// -1 for the zero-based indexing
|
|
227
|
+
const line =
|
|
228
|
+
lineNumber &&
|
|
229
|
+
code
|
|
230
|
+
.split('\n')
|
|
231
|
+
.at(parseInt(lineNumber, 10) - 1)
|
|
232
|
+
?.trim();
|
|
233
|
+
return line ? `${message}\n at line ${lineNumber}\n ${line}` : message;
|
|
234
|
+
} catch {
|
|
235
|
+
return message;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
7
239
|
const fetch = async (req: Request): Promise<Response> => {
|
|
8
240
|
const { opts, code } = (await req.json()) as WorkerInput;
|
|
241
|
+
if (code == null) {
|
|
242
|
+
return Response.json(
|
|
243
|
+
{
|
|
244
|
+
message:
|
|
245
|
+
'The code param is missing. Provide one containing a top-level `run` function. Write code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```',
|
|
246
|
+
} satisfies WorkerError,
|
|
247
|
+
{ status: 400, statusText: 'Code execution error' },
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const runFunctionNode = getRunFunctionNode(code);
|
|
252
|
+
if (!runFunctionNode) {
|
|
253
|
+
return Response.json(
|
|
254
|
+
{
|
|
255
|
+
message:
|
|
256
|
+
'The code is missing a top-level `run` function. Write code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```',
|
|
257
|
+
} satisfies WorkerError,
|
|
258
|
+
{ status: 400, statusText: 'Code execution error' },
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
9
262
|
const client = new NirvanaLabs({
|
|
10
263
|
...opts,
|
|
11
264
|
});
|
|
@@ -22,21 +275,17 @@ const fetch = async (req: Request): Promise<Response> => {
|
|
|
22
275
|
};
|
|
23
276
|
try {
|
|
24
277
|
let run_ = async (client: any) => {};
|
|
25
|
-
eval(
|
|
26
|
-
|
|
27
|
-
run_ = run;
|
|
28
|
-
`);
|
|
29
|
-
const result = await run_(client);
|
|
278
|
+
eval(`${code}\nrun_ = run;`);
|
|
279
|
+
const result = await run_(makeSdkProxy(client, { path: ['client'] }));
|
|
30
280
|
return Response.json({
|
|
31
281
|
result,
|
|
32
282
|
logLines,
|
|
33
283
|
errLines,
|
|
34
284
|
} satisfies WorkerSuccess);
|
|
35
285
|
} catch (e) {
|
|
36
|
-
const message = e instanceof Error ? e.message : undefined;
|
|
37
286
|
return Response.json(
|
|
38
287
|
{
|
|
39
|
-
message,
|
|
288
|
+
message: parseError(code, e),
|
|
40
289
|
} satisfies WorkerError,
|
|
41
290
|
{ status: 400, statusText: 'Code execution error' },
|
|
42
291
|
);
|
package/src/code-tool.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { dirname } from 'node:path';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
5
|
import NirvanaLabs, { ClientOptions } from '@nirvana-labs/nirvana';
|
|
6
|
-
import {
|
|
6
|
+
import { ContentBlock, Endpoint, Metadata, ToolCallResult } from './tools/types';
|
|
7
7
|
|
|
8
8
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
9
9
|
|
|
@@ -12,7 +12,7 @@ import { WorkerInput, WorkerError, WorkerSuccess } from './code-tool-types';
|
|
|
12
12
|
/**
|
|
13
13
|
* A tool that runs code against a copy of the SDK.
|
|
14
14
|
*
|
|
15
|
-
* Instead of exposing every endpoint as
|
|
15
|
+
* Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
|
|
16
16
|
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
17
17
|
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
18
18
|
*
|
|
@@ -23,7 +23,7 @@ export async function codeTool(): Promise<Endpoint> {
|
|
|
23
23
|
const tool: Tool = {
|
|
24
24
|
name: 'execute',
|
|
25
25
|
description:
|
|
26
|
-
'Runs
|
|
26
|
+
'Runs TypeScript code to interact with the API.\n\nYou are a skilled programmer writing code to interface with the service.\nDefine an async function named "run" that takes a single parameter of an initialized client named "client", and it will be run.\nWrite code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```\n\nYou will be returned anything that your function returns, plus the results of any console.log statements.\nIf any code triggers an error, the tool will return an error response, so you do not need to add error handling unless you want to output something more helpful than the raw error.\nIt is not necessary to add comments to code, unless by adding those comments you believe that you can generate better code.\nThis code will run in a container, and you will not be able to use fetch or otherwise interact with the network calls other than through the client you are given.\nAny variables you define won\'t live between successive uses of this call, so make sure to return or log any data you might need later.',
|
|
27
27
|
inputSchema: { type: 'object', properties: { code: { type: 'string' } } },
|
|
28
28
|
};
|
|
29
29
|
|
|
@@ -31,7 +31,7 @@ export async function codeTool(): Promise<Endpoint> {
|
|
|
31
31
|
const { newDenoHTTPWorker } = await import('@valtown/deno-http-worker');
|
|
32
32
|
const { workerPath } = await import('./code-tool-paths.cjs');
|
|
33
33
|
|
|
34
|
-
const handler = async (client: NirvanaLabs, args: unknown) => {
|
|
34
|
+
const handler = async (client: NirvanaLabs, args: unknown): Promise<ToolCallResult> => {
|
|
35
35
|
const baseURLHostname = new URL(client.baseURL).hostname;
|
|
36
36
|
const { code } = args as { code: string };
|
|
37
37
|
|
|
@@ -97,7 +97,7 @@ export async function codeTool(): Promise<Endpoint> {
|
|
|
97
97
|
} satisfies WorkerInput);
|
|
98
98
|
|
|
99
99
|
req.write(body, (err) => {
|
|
100
|
-
if (err
|
|
100
|
+
if (err != null) {
|
|
101
101
|
reject(err);
|
|
102
102
|
}
|
|
103
103
|
});
|
|
@@ -108,12 +108,12 @@ export async function codeTool(): Promise<Endpoint> {
|
|
|
108
108
|
if (resp.status === 200) {
|
|
109
109
|
const { result, logLines, errLines } = (await resp.json()) as WorkerSuccess;
|
|
110
110
|
const returnOutput: ContentBlock | null =
|
|
111
|
-
result
|
|
112
|
-
|
|
113
|
-
: {
|
|
111
|
+
result == null ? null : (
|
|
112
|
+
{
|
|
114
113
|
type: 'text',
|
|
115
|
-
text: typeof result === 'string' ?
|
|
116
|
-
}
|
|
114
|
+
text: typeof result === 'string' ? result : JSON.stringify(result),
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
117
|
const logOutput: ContentBlock | null =
|
|
118
118
|
logLines.length === 0 ?
|
|
119
119
|
null
|
|
@@ -133,10 +133,11 @@ export async function codeTool(): Promise<Endpoint> {
|
|
|
133
133
|
};
|
|
134
134
|
} else {
|
|
135
135
|
const { message } = (await resp.json()) as WorkerError;
|
|
136
|
-
|
|
136
|
+
return {
|
|
137
|
+
content: message == null ? [] : [{ type: 'text', text: message }],
|
|
138
|
+
isError: true,
|
|
139
|
+
};
|
|
137
140
|
}
|
|
138
|
-
} catch (e) {
|
|
139
|
-
throw e;
|
|
140
141
|
} finally {
|
|
141
142
|
worker.terminate();
|
|
142
143
|
}
|
package/src/dynamic-tools.ts
CHANGED
|
@@ -14,7 +14,7 @@ function zodToInputSchema(schema: z.ZodSchema) {
|
|
|
14
14
|
/**
|
|
15
15
|
* A list of tools that expose all the endpoints in the API dynamically.
|
|
16
16
|
*
|
|
17
|
-
* Instead of exposing every endpoint as
|
|
17
|
+
* Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
|
|
18
18
|
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
19
19
|
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
20
20
|
*
|
package/src/options.ts
CHANGED
|
@@ -284,8 +284,10 @@ const coerceArray = <T extends z.ZodTypeAny>(zodType: T) =>
|
|
|
284
284
|
);
|
|
285
285
|
|
|
286
286
|
const QueryOptions = z.object({
|
|
287
|
-
tools: coerceArray(z.enum(['dynamic', 'all', 'docs'])).describe('
|
|
288
|
-
no_tools: coerceArray(z.enum(['dynamic', 'all', 'docs'])).describe(
|
|
287
|
+
tools: coerceArray(z.enum(['dynamic', 'all', 'code', 'docs'])).describe('Specify which MCP tools to use'),
|
|
288
|
+
no_tools: coerceArray(z.enum(['dynamic', 'all', 'code', 'docs'])).describe(
|
|
289
|
+
'Specify which MCP tools to not use.',
|
|
290
|
+
),
|
|
289
291
|
tool: coerceArray(z.string()).describe('Include tools matching the specified names'),
|
|
290
292
|
resource: coerceArray(z.string()).describe('Include tools matching the specified resources'),
|
|
291
293
|
operation: coerceArray(z.enum(['read', 'write'])).describe(
|
|
@@ -385,11 +387,16 @@ export function parseQueryOptions(defaultOptions: McpOptions, query: unknown): M
|
|
|
385
387
|
: queryOptions.tools?.includes('docs') ? true
|
|
386
388
|
: defaultOptions.includeDocsTools;
|
|
387
389
|
|
|
390
|
+
let codeTools: boolean | undefined =
|
|
391
|
+
queryOptions.no_tools && queryOptions.no_tools?.includes('code') ? false
|
|
392
|
+
: queryOptions.tools?.includes('code') && defaultOptions.includeCodeTools ? true
|
|
393
|
+
: defaultOptions.includeCodeTools;
|
|
394
|
+
|
|
388
395
|
return {
|
|
389
396
|
client: queryOptions.client ?? defaultOptions.client,
|
|
390
397
|
includeDynamicTools: dynamicTools,
|
|
391
398
|
includeAllTools: allTools,
|
|
392
|
-
includeCodeTools:
|
|
399
|
+
includeCodeTools: codeTools,
|
|
393
400
|
includeDocsTools: docsTools,
|
|
394
401
|
filters,
|
|
395
402
|
capabilities: clientCapabilities,
|
package/src/server.ts
CHANGED
|
@@ -18,10 +18,18 @@ export const metadata: Metadata = {
|
|
|
18
18
|
export const tool: Tool = {
|
|
19
19
|
name: 'list_api_keys',
|
|
20
20
|
description:
|
|
21
|
-
"When using this tool, always use the `jq_filter` parameter to reduce the response size and improve performance.\n\nOnly omit if you're sure you don't need the data.\n\nList all API keys for the authenticated user\n\n# Response Schema\n```json\n{\n $ref: '#/$defs/api_key_list',\n $defs: {\n api_key_list: {\n type: 'object',\n properties: {\n items: {\n type: 'array',\n items: {\n $ref: '#/$defs/api_key'\n }\n }\n },\n required: [ 'items'\n ]\n },\n api_key: {\n type: 'object',\n description: 'API Key response.',\n properties: {\n id: {\n type: 'string',\n description: 'API Key ID.'\n },\n created_at: {\n type: 'string',\n description: 'When the API Key was created.',\n format: 'date-time'\n },\n expires_at: {\n type: 'string',\n description: 'When the API Key expires and is no longer valid.',\n format: 'date-time'\n },\n name: {\n type: 'string',\n description: 'API Key name.'\n },\n status: {\n type: 'string',\n description: 'Status of the API Key.',\n enum: [ 'active',\n 'inactive',\n 'expired'\n ]\n },\n tags: {\n type: 'array',\n description: 'Tags to attach to the API Key.',\n items: {\n type: 'string'\n }\n },\n updated_at: {\n type: 'string',\n description: 'When the API Key was updated.',\n format: 'date-time'\n },\n key: {\n type: 'string',\n description: 'API Key. Only returned on creation.'\n },\n starts_at: {\n type: 'string',\n description: 'When the API Key starts to be valid.',\n format: 'date-time'\n }\n },\n required: [ 'id',\n 'created_at',\n 'expires_at',\n 'name',\n 'status',\n 'tags',\n 'updated_at'\n ]\n }\n }\n}\n```",
|
|
21
|
+
"When using this tool, always use the `jq_filter` parameter to reduce the response size and improve performance.\n\nOnly omit if you're sure you don't need the data.\n\nList all API keys for the authenticated user\n\n# Response Schema\n```json\n{\n $ref: '#/$defs/api_key_list',\n $defs: {\n api_key_list: {\n type: 'object',\n properties: {\n items: {\n type: 'array',\n items: {\n $ref: '#/$defs/api_key'\n }\n },\n pagination: {\n $ref: '#/$defs/pagination'\n }\n },\n required: [ 'items',\n 'pagination'\n ]\n },\n api_key: {\n type: 'object',\n description: 'API Key response.',\n properties: {\n id: {\n type: 'string',\n description: 'API Key ID.'\n },\n created_at: {\n type: 'string',\n description: 'When the API Key was created.',\n format: 'date-time'\n },\n expires_at: {\n type: 'string',\n description: 'When the API Key expires and is no longer valid.',\n format: 'date-time'\n },\n name: {\n type: 'string',\n description: 'API Key name.'\n },\n status: {\n type: 'string',\n description: 'Status of the API Key.',\n enum: [ 'active',\n 'inactive',\n 'expired'\n ]\n },\n tags: {\n type: 'array',\n description: 'Tags to attach to the API Key.',\n items: {\n type: 'string'\n }\n },\n updated_at: {\n type: 'string',\n description: 'When the API Key was updated.',\n format: 'date-time'\n },\n key: {\n type: 'string',\n description: 'API Key. Only returned on creation.'\n },\n starts_at: {\n type: 'string',\n description: 'When the API Key starts to be valid.',\n format: 'date-time'\n }\n },\n required: [ 'id',\n 'created_at',\n 'expires_at',\n 'name',\n 'status',\n 'tags',\n 'updated_at'\n ]\n },\n pagination: {\n type: 'object',\n description: 'Pagination response details.',\n properties: {\n next_cursor: {\n type: 'string'\n },\n previous_cursor: {\n type: 'string'\n },\n total_count: {\n type: 'integer'\n }\n },\n required: [ 'next_cursor',\n 'previous_cursor',\n 'total_count'\n ]\n }\n }\n}\n```",
|
|
22
22
|
inputSchema: {
|
|
23
23
|
type: 'object',
|
|
24
24
|
properties: {
|
|
25
|
+
cursor: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'Pagination cursor returned by a previous request',
|
|
28
|
+
},
|
|
29
|
+
limit: {
|
|
30
|
+
type: 'integer',
|
|
31
|
+
description: 'Maximum number of items to return',
|
|
32
|
+
},
|
|
25
33
|
jq_filter: {
|
|
26
34
|
type: 'string',
|
|
27
35
|
title: 'jq Filter',
|
|
@@ -37,8 +45,9 @@ export const tool: Tool = {
|
|
|
37
45
|
};
|
|
38
46
|
|
|
39
47
|
export const handler = async (client: NirvanaLabs, args: Record<string, unknown> | undefined) => {
|
|
40
|
-
const { jq_filter } = args as any;
|
|
41
|
-
|
|
48
|
+
const { jq_filter, ...body } = args as any;
|
|
49
|
+
const response = await client.apiKeys.list(body).asResponse();
|
|
50
|
+
return asTextContentResult(await maybeFilter(jq_filter, await response.json()));
|
|
42
51
|
};
|
|
43
52
|
|
|
44
53
|
export default { metadata, tool, handler };
|
|
@@ -18,10 +18,18 @@ export const metadata: Metadata = {
|
|
|
18
18
|
export const tool: Tool = {
|
|
19
19
|
name: 'list_compute_vms',
|
|
20
20
|
description:
|
|
21
|
-
"When using this tool, always use the `jq_filter` parameter to reduce the response size and improve performance.\n\nOnly omit if you're sure you don't need the data.\n\nList all VMs\n\n# Response Schema\n```json\n{\n $ref: '#/$defs/vm_list',\n $defs: {\n vm_list: {\n type: 'object',\n properties: {\n items: {\n type: 'array',\n items: {\n $ref: '#/$defs/vm'\n }\n }\n },\n required: [ 'items'\n ]\n },\n vm: {\n type: 'object',\n description: 'VM details.',\n properties: {\n id: {\n type: 'string',\n description: 'Unique identifier for the VM.'\n },\n boot_volume_id: {\n type: 'string',\n description: 'ID of the boot volume attached to the VM.'\n },\n cpu_config: {\n $ref: '#/$defs/cpu_config'\n },\n created_at: {\n type: 'string',\n description: 'When the VM was created.',\n format: 'date-time'\n },\n data_volume_ids: {\n type: 'array',\n description: 'IDs of the data volumes attached to the VM.',\n items: {\n type: 'string'\n }\n },\n memory_config: {\n $ref: '#/$defs/memory_config'\n },\n name: {\n type: 'string',\n description: 'Name of the VM.'\n },\n private_ip: {\n type: 'string',\n description: 'Private IP of the VM.'\n },\n public_ip: {\n type: 'string',\n description: 'Public IP of the VM.'\n },\n public_ip_enabled: {\n type: 'boolean',\n description: 'Whether the public IP is enabled for the VM.'\n },\n region: {\n $ref: '#/$defs/region_name'\n },\n status: {\n $ref: '#/$defs/resource_status'\n },\n subnet_id: {\n type: 'string',\n description: 'ID of the subnet the VM is in.'\n },\n tags: {\n type: 'array',\n description: 'Tags to attach to the VM.',\n items: {\n type: 'string'\n }\n },\n updated_at: {\n type: 'string',\n description: 'When the VM was updated.',\n format: 'date-time'\n },\n vpc_id: {\n type: 'string',\n description: 'ID of the VPC the VM is in.'\n },\n vpc_name: {\n type: 'string',\n description: 'Name of the VPC the VM is in.'\n }\n },\n required: [ 'id',\n 'boot_volume_id',\n 'cpu_config',\n 'created_at',\n 'data_volume_ids',\n 'memory_config',\n 'name',\n 'private_ip',\n 'public_ip',\n 'public_ip_enabled',\n 'region',\n 'status',\n 'subnet_id',\n 'tags',\n 'updated_at',\n 'vpc_id',\n 'vpc_name'\n ]\n },\n cpu_config: {\n type: 'object',\n description: 'CPU configuration for the VM.',\n properties: {\n vcpu: {\n type: 'integer',\n description: 'Number of virtual CPUs.'\n }\n },\n required: [ 'vcpu'\n ]\n },\n memory_config: {\n type: 'object',\n description: 'Memory configuration for the VM.',\n properties: {\n size: {\n type: 'integer',\n description: 'Size of the memory in GB.'\n }\n },\n required: [ 'size'\n ]\n },\n region_name: {\n type: 'string',\n description: 'Region the resource is in.',\n enum: [ 'us-sea-1',\n 'us-sva-1',\n 'us-chi-1',\n 'us-wdc-1',\n 'eu-frk-1',\n 'ap-sin-1',\n 'ap-seo-1',\n 'ap-tyo-1'\n ]\n },\n resource_status: {\n type: 'string',\n description: 'Status of the resource.',\n enum: [ 'pending',\n 'creating',\n 'updating',\n 'ready',\n 'deleting',\n 'deleted',\n 'error'\n ]\n }\n }\n}\n```",
|
|
21
|
+
"When using this tool, always use the `jq_filter` parameter to reduce the response size and improve performance.\n\nOnly omit if you're sure you don't need the data.\n\nList all VMs\n\n# Response Schema\n```json\n{\n $ref: '#/$defs/vm_list',\n $defs: {\n vm_list: {\n type: 'object',\n properties: {\n items: {\n type: 'array',\n items: {\n $ref: '#/$defs/vm'\n }\n },\n pagination: {\n $ref: '#/$defs/pagination'\n }\n },\n required: [ 'items',\n 'pagination'\n ]\n },\n vm: {\n type: 'object',\n description: 'VM details.',\n properties: {\n id: {\n type: 'string',\n description: 'Unique identifier for the VM.'\n },\n boot_volume_id: {\n type: 'string',\n description: 'ID of the boot volume attached to the VM.'\n },\n cpu_config: {\n $ref: '#/$defs/cpu_config'\n },\n created_at: {\n type: 'string',\n description: 'When the VM was created.',\n format: 'date-time'\n },\n data_volume_ids: {\n type: 'array',\n description: 'IDs of the data volumes attached to the VM.',\n items: {\n type: 'string'\n }\n },\n memory_config: {\n $ref: '#/$defs/memory_config'\n },\n name: {\n type: 'string',\n description: 'Name of the VM.'\n },\n private_ip: {\n type: 'string',\n description: 'Private IP of the VM.'\n },\n public_ip: {\n type: 'string',\n description: 'Public IP of the VM.'\n },\n public_ip_enabled: {\n type: 'boolean',\n description: 'Whether the public IP is enabled for the VM.'\n },\n region: {\n $ref: '#/$defs/region_name'\n },\n status: {\n $ref: '#/$defs/resource_status'\n },\n subnet_id: {\n type: 'string',\n description: 'ID of the subnet the VM is in.'\n },\n tags: {\n type: 'array',\n description: 'Tags to attach to the VM.',\n items: {\n type: 'string'\n }\n },\n updated_at: {\n type: 'string',\n description: 'When the VM was updated.',\n format: 'date-time'\n },\n vpc_id: {\n type: 'string',\n description: 'ID of the VPC the VM is in.'\n },\n vpc_name: {\n type: 'string',\n description: 'Name of the VPC the VM is in.'\n }\n },\n required: [ 'id',\n 'boot_volume_id',\n 'cpu_config',\n 'created_at',\n 'data_volume_ids',\n 'memory_config',\n 'name',\n 'private_ip',\n 'public_ip',\n 'public_ip_enabled',\n 'region',\n 'status',\n 'subnet_id',\n 'tags',\n 'updated_at',\n 'vpc_id',\n 'vpc_name'\n ]\n },\n cpu_config: {\n type: 'object',\n description: 'CPU configuration for the VM.',\n properties: {\n vcpu: {\n type: 'integer',\n description: 'Number of virtual CPUs.'\n }\n },\n required: [ 'vcpu'\n ]\n },\n memory_config: {\n type: 'object',\n description: 'Memory configuration for the VM.',\n properties: {\n size: {\n type: 'integer',\n description: 'Size of the memory in GB.'\n }\n },\n required: [ 'size'\n ]\n },\n region_name: {\n type: 'string',\n description: 'Region the resource is in.',\n enum: [ 'us-sea-1',\n 'us-sva-1',\n 'us-chi-1',\n 'us-wdc-1',\n 'eu-frk-1',\n 'ap-sin-1',\n 'ap-seo-1',\n 'ap-tyo-1'\n ]\n },\n resource_status: {\n type: 'string',\n description: 'Status of the resource.',\n enum: [ 'pending',\n 'creating',\n 'updating',\n 'ready',\n 'deleting',\n 'deleted',\n 'error'\n ]\n },\n pagination: {\n type: 'object',\n description: 'Pagination response details.',\n properties: {\n next_cursor: {\n type: 'string'\n },\n previous_cursor: {\n type: 'string'\n },\n total_count: {\n type: 'integer'\n }\n },\n required: [ 'next_cursor',\n 'previous_cursor',\n 'total_count'\n ]\n }\n }\n}\n```",
|
|
22
22
|
inputSchema: {
|
|
23
23
|
type: 'object',
|
|
24
24
|
properties: {
|
|
25
|
+
cursor: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'Pagination cursor returned by a previous request',
|
|
28
|
+
},
|
|
29
|
+
limit: {
|
|
30
|
+
type: 'integer',
|
|
31
|
+
description: 'Maximum number of items to return',
|
|
32
|
+
},
|
|
25
33
|
jq_filter: {
|
|
26
34
|
type: 'string',
|
|
27
35
|
title: 'jq Filter',
|
|
@@ -37,8 +45,9 @@ export const tool: Tool = {
|
|
|
37
45
|
};
|
|
38
46
|
|
|
39
47
|
export const handler = async (client: NirvanaLabs, args: Record<string, unknown> | undefined) => {
|
|
40
|
-
const { jq_filter } = args as any;
|
|
41
|
-
|
|
48
|
+
const { jq_filter, ...body } = args as any;
|
|
49
|
+
const response = await client.compute.vms.list(body).asResponse();
|
|
50
|
+
return asTextContentResult(await maybeFilter(jq_filter, await response.json()));
|
|
42
51
|
};
|
|
43
52
|
|
|
44
53
|
export default { metadata, tool, handler };
|
|
@@ -18,13 +18,21 @@ export const metadata: Metadata = {
|
|
|
18
18
|
export const tool: Tool = {
|
|
19
19
|
name: 'list_vms_compute_volumes',
|
|
20
20
|
description:
|
|
21
|
-
"When using this tool, always use the `jq_filter` parameter to reduce the response size and improve performance.\n\nOnly omit if you're sure you don't need the data.\n\nList VM's Volumes\n\n# Response Schema\n```json\n{\n $ref: '#/$defs/volume_list',\n $defs: {\n volume_list: {\n type: 'object',\n properties: {\n items: {\n type: 'array',\n items: {\n $ref: '#/$defs/volume'\n }\n }\n },\n required: [ 'items'\n ]\n },\n volume: {\n type: 'object',\n description: 'Volume details.',\n properties: {\n id: {\n type: 'string',\n description: 'Unique identifier for the Volume.'\n },\n created_at: {\n type: 'string',\n description: 'When the Volume was created.',\n format: 'date-time'\n },\n kind: {\n $ref: '#/$defs/volume_kind'\n },\n name: {\n type: 'string',\n description: 'Name of the Volume.'\n },\n size: {\n type: 'integer',\n description: 'Size of the Volume in GB.'\n },\n status: {\n $ref: '#/$defs/resource_status'\n },\n tags: {\n type: 'array',\n description: 'Tags to attach to the Volume.',\n items: {\n type: 'string'\n }\n },\n type: {\n $ref: '#/$defs/storage_type'\n },\n updated_at: {\n type: 'string',\n description: 'When the Volume was updated.',\n format: 'date-time'\n },\n vm_id: {\n type: 'string',\n description: 'ID of the VM the Volume is attached to.'\n },\n vm_name: {\n type: 'string',\n description: 'Name of the VM the Volume is attached to.'\n }\n },\n required: [ 'id',\n 'created_at',\n 'kind',\n 'name',\n 'size',\n 'status',\n 'tags',\n 'type',\n 'updated_at',\n 'vm_id',\n 'vm_name'\n ]\n },\n volume_kind: {\n type: 'string',\n description: 'Volume kind.',\n enum: [ 'boot',\n 'data'\n ]\n },\n resource_status: {\n type: 'string',\n description: 'Status of the resource.',\n enum: [ 'pending',\n 'creating',\n 'updating',\n 'ready',\n 'deleting',\n 'deleted',\n 'error'\n ]\n },\n storage_type: {\n type: 'string',\n description: 'Storage type the Volume is using.',\n enum: [ 'nvme'\n ]\n }\n }\n}\n```",
|
|
21
|
+
"When using this tool, always use the `jq_filter` parameter to reduce the response size and improve performance.\n\nOnly omit if you're sure you don't need the data.\n\nList VM's Volumes\n\n# Response Schema\n```json\n{\n $ref: '#/$defs/volume_list',\n $defs: {\n volume_list: {\n type: 'object',\n properties: {\n items: {\n type: 'array',\n items: {\n $ref: '#/$defs/volume'\n }\n },\n pagination: {\n $ref: '#/$defs/pagination'\n }\n },\n required: [ 'items',\n 'pagination'\n ]\n },\n volume: {\n type: 'object',\n description: 'Volume details.',\n properties: {\n id: {\n type: 'string',\n description: 'Unique identifier for the Volume.'\n },\n created_at: {\n type: 'string',\n description: 'When the Volume was created.',\n format: 'date-time'\n },\n kind: {\n $ref: '#/$defs/volume_kind'\n },\n name: {\n type: 'string',\n description: 'Name of the Volume.'\n },\n size: {\n type: 'integer',\n description: 'Size of the Volume in GB.'\n },\n status: {\n $ref: '#/$defs/resource_status'\n },\n tags: {\n type: 'array',\n description: 'Tags to attach to the Volume.',\n items: {\n type: 'string'\n }\n },\n type: {\n $ref: '#/$defs/storage_type'\n },\n updated_at: {\n type: 'string',\n description: 'When the Volume was updated.',\n format: 'date-time'\n },\n vm_id: {\n type: 'string',\n description: 'ID of the VM the Volume is attached to.'\n },\n vm_name: {\n type: 'string',\n description: 'Name of the VM the Volume is attached to.'\n }\n },\n required: [ 'id',\n 'created_at',\n 'kind',\n 'name',\n 'size',\n 'status',\n 'tags',\n 'type',\n 'updated_at',\n 'vm_id',\n 'vm_name'\n ]\n },\n volume_kind: {\n type: 'string',\n description: 'Volume kind.',\n enum: [ 'boot',\n 'data'\n ]\n },\n resource_status: {\n type: 'string',\n description: 'Status of the resource.',\n enum: [ 'pending',\n 'creating',\n 'updating',\n 'ready',\n 'deleting',\n 'deleted',\n 'error'\n ]\n },\n storage_type: {\n type: 'string',\n description: 'Storage type the Volume is using.',\n enum: [ 'nvme'\n ]\n },\n pagination: {\n type: 'object',\n description: 'Pagination response details.',\n properties: {\n next_cursor: {\n type: 'string'\n },\n previous_cursor: {\n type: 'string'\n },\n total_count: {\n type: 'integer'\n }\n },\n required: [ 'next_cursor',\n 'previous_cursor',\n 'total_count'\n ]\n }\n }\n}\n```",
|
|
22
22
|
inputSchema: {
|
|
23
23
|
type: 'object',
|
|
24
24
|
properties: {
|
|
25
25
|
vm_id: {
|
|
26
26
|
type: 'string',
|
|
27
27
|
},
|
|
28
|
+
cursor: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
description: 'Pagination cursor returned by a previous request',
|
|
31
|
+
},
|
|
32
|
+
limit: {
|
|
33
|
+
type: 'integer',
|
|
34
|
+
description: 'Maximum number of items to return',
|
|
35
|
+
},
|
|
28
36
|
jq_filter: {
|
|
29
37
|
type: 'string',
|
|
30
38
|
title: 'jq Filter',
|
|
@@ -41,7 +49,8 @@ export const tool: Tool = {
|
|
|
41
49
|
|
|
42
50
|
export const handler = async (client: NirvanaLabs, args: Record<string, unknown> | undefined) => {
|
|
43
51
|
const { vm_id, jq_filter, ...body } = args as any;
|
|
44
|
-
|
|
52
|
+
const response = await client.compute.vms.volumes.list(vm_id, body).asResponse();
|
|
53
|
+
return asTextContentResult(await maybeFilter(jq_filter, await response.json()));
|
|
45
54
|
};
|
|
46
55
|
|
|
47
56
|
export default { metadata, tool, handler };
|
|
@@ -18,10 +18,18 @@ export const metadata: Metadata = {
|
|
|
18
18
|
export const tool: Tool = {
|
|
19
19
|
name: 'list_compute_volumes',
|
|
20
20
|
description:
|
|
21
|
-
"When using this tool, always use the `jq_filter` parameter to reduce the response size and improve performance.\n\nOnly omit if you're sure you don't need the data.\n\nList all volumes\n\n# Response Schema\n```json\n{\n $ref: '#/$defs/volume_list',\n $defs: {\n volume_list: {\n type: 'object',\n properties: {\n items: {\n type: 'array',\n items: {\n $ref: '#/$defs/volume'\n }\n }\n },\n required: [ 'items'\n ]\n },\n volume: {\n type: 'object',\n description: 'Volume details.',\n properties: {\n id: {\n type: 'string',\n description: 'Unique identifier for the Volume.'\n },\n created_at: {\n type: 'string',\n description: 'When the Volume was created.',\n format: 'date-time'\n },\n kind: {\n $ref: '#/$defs/volume_kind'\n },\n name: {\n type: 'string',\n description: 'Name of the Volume.'\n },\n size: {\n type: 'integer',\n description: 'Size of the Volume in GB.'\n },\n status: {\n $ref: '#/$defs/resource_status'\n },\n tags: {\n type: 'array',\n description: 'Tags to attach to the Volume.',\n items: {\n type: 'string'\n }\n },\n type: {\n $ref: '#/$defs/storage_type'\n },\n updated_at: {\n type: 'string',\n description: 'When the Volume was updated.',\n format: 'date-time'\n },\n vm_id: {\n type: 'string',\n description: 'ID of the VM the Volume is attached to.'\n },\n vm_name: {\n type: 'string',\n description: 'Name of the VM the Volume is attached to.'\n }\n },\n required: [ 'id',\n 'created_at',\n 'kind',\n 'name',\n 'size',\n 'status',\n 'tags',\n 'type',\n 'updated_at',\n 'vm_id',\n 'vm_name'\n ]\n },\n volume_kind: {\n type: 'string',\n description: 'Volume kind.',\n enum: [ 'boot',\n 'data'\n ]\n },\n resource_status: {\n type: 'string',\n description: 'Status of the resource.',\n enum: [ 'pending',\n 'creating',\n 'updating',\n 'ready',\n 'deleting',\n 'deleted',\n 'error'\n ]\n },\n storage_type: {\n type: 'string',\n description: 'Storage type the Volume is using.',\n enum: [ 'nvme'\n ]\n }\n }\n}\n```",
|
|
21
|
+
"When using this tool, always use the `jq_filter` parameter to reduce the response size and improve performance.\n\nOnly omit if you're sure you don't need the data.\n\nList all volumes\n\n# Response Schema\n```json\n{\n $ref: '#/$defs/volume_list',\n $defs: {\n volume_list: {\n type: 'object',\n properties: {\n items: {\n type: 'array',\n items: {\n $ref: '#/$defs/volume'\n }\n },\n pagination: {\n $ref: '#/$defs/pagination'\n }\n },\n required: [ 'items',\n 'pagination'\n ]\n },\n volume: {\n type: 'object',\n description: 'Volume details.',\n properties: {\n id: {\n type: 'string',\n description: 'Unique identifier for the Volume.'\n },\n created_at: {\n type: 'string',\n description: 'When the Volume was created.',\n format: 'date-time'\n },\n kind: {\n $ref: '#/$defs/volume_kind'\n },\n name: {\n type: 'string',\n description: 'Name of the Volume.'\n },\n size: {\n type: 'integer',\n description: 'Size of the Volume in GB.'\n },\n status: {\n $ref: '#/$defs/resource_status'\n },\n tags: {\n type: 'array',\n description: 'Tags to attach to the Volume.',\n items: {\n type: 'string'\n }\n },\n type: {\n $ref: '#/$defs/storage_type'\n },\n updated_at: {\n type: 'string',\n description: 'When the Volume was updated.',\n format: 'date-time'\n },\n vm_id: {\n type: 'string',\n description: 'ID of the VM the Volume is attached to.'\n },\n vm_name: {\n type: 'string',\n description: 'Name of the VM the Volume is attached to.'\n }\n },\n required: [ 'id',\n 'created_at',\n 'kind',\n 'name',\n 'size',\n 'status',\n 'tags',\n 'type',\n 'updated_at',\n 'vm_id',\n 'vm_name'\n ]\n },\n volume_kind: {\n type: 'string',\n description: 'Volume kind.',\n enum: [ 'boot',\n 'data'\n ]\n },\n resource_status: {\n type: 'string',\n description: 'Status of the resource.',\n enum: [ 'pending',\n 'creating',\n 'updating',\n 'ready',\n 'deleting',\n 'deleted',\n 'error'\n ]\n },\n storage_type: {\n type: 'string',\n description: 'Storage type the Volume is using.',\n enum: [ 'nvme'\n ]\n },\n pagination: {\n type: 'object',\n description: 'Pagination response details.',\n properties: {\n next_cursor: {\n type: 'string'\n },\n previous_cursor: {\n type: 'string'\n },\n total_count: {\n type: 'integer'\n }\n },\n required: [ 'next_cursor',\n 'previous_cursor',\n 'total_count'\n ]\n }\n }\n}\n```",
|
|
22
22
|
inputSchema: {
|
|
23
23
|
type: 'object',
|
|
24
24
|
properties: {
|
|
25
|
+
cursor: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'Pagination cursor returned by a previous request',
|
|
28
|
+
},
|
|
29
|
+
limit: {
|
|
30
|
+
type: 'integer',
|
|
31
|
+
description: 'Maximum number of items to return',
|
|
32
|
+
},
|
|
25
33
|
jq_filter: {
|
|
26
34
|
type: 'string',
|
|
27
35
|
title: 'jq Filter',
|
|
@@ -37,8 +45,9 @@ export const tool: Tool = {
|
|
|
37
45
|
};
|
|
38
46
|
|
|
39
47
|
export const handler = async (client: NirvanaLabs, args: Record<string, unknown> | undefined) => {
|
|
40
|
-
const { jq_filter } = args as any;
|
|
41
|
-
|
|
48
|
+
const { jq_filter, ...body } = args as any;
|
|
49
|
+
const response = await client.compute.volumes.list(body).asResponse();
|
|
50
|
+
return asTextContentResult(await maybeFilter(jq_filter, await response.json()));
|
|
42
51
|
};
|
|
43
52
|
|
|
44
53
|
export default { metadata, tool, handler };
|