@almyty/mcp-server 1.2.0 → 1.5.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 +104 -19
- package/dist/catalog.d.ts +90 -0
- package/dist/catalog.js +154 -0
- package/dist/exit-codes.d.ts +40 -0
- package/dist/exit-codes.js +53 -0
- package/dist/index.d.ts +16 -24
- package/dist/index.js +306 -295
- package/dist/proxy.d.ts +8 -0
- package/dist/proxy.js +18 -2
- package/dist/schema.d.ts +36 -0
- package/dist/schema.js +52 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +22 -0
- package/package.json +12 -3
package/dist/proxy.d.ts
CHANGED
|
@@ -49,6 +49,14 @@ export declare class AlmytyProxy {
|
|
|
49
49
|
* Execute a tool call via the almyty backend.
|
|
50
50
|
*/
|
|
51
51
|
callTool(toolName: string, args: Record<string, unknown>): Promise<unknown>;
|
|
52
|
+
/**
|
|
53
|
+
* The REST leg, for the management tools. Same timeout discipline as the
|
|
54
|
+
* JSON-RPC leg: a hung backend must not hold a tool call open forever, and
|
|
55
|
+
* an abort is reported as a timeout rather than as a bare AbortError.
|
|
56
|
+
*
|
|
57
|
+
* almyty answers an error as `{ success: false, message }`, so that is what
|
|
58
|
+
* is read first; the nested `error.message` shape is the fallback.
|
|
59
|
+
*/
|
|
52
60
|
private rest;
|
|
53
61
|
listApis(): Promise<any>;
|
|
54
62
|
createApi(data: object): Promise<any>;
|
package/dist/proxy.js
CHANGED
|
@@ -156,6 +156,14 @@ export class AlmytyProxy {
|
|
|
156
156
|
// ── Management API ──────────────────────────────────────────────
|
|
157
157
|
// These let LLMs control the almyty platform itself — create APIs,
|
|
158
158
|
// tools, gateways, agents — not just call existing tools.
|
|
159
|
+
/**
|
|
160
|
+
* The REST leg, for the management tools. Same timeout discipline as the
|
|
161
|
+
* JSON-RPC leg: a hung backend must not hold a tool call open forever, and
|
|
162
|
+
* an abort is reported as a timeout rather than as a bare AbortError.
|
|
163
|
+
*
|
|
164
|
+
* almyty answers an error as `{ success: false, message }`, so that is what
|
|
165
|
+
* is read first; the nested `error.message` shape is the fallback.
|
|
166
|
+
*/
|
|
159
167
|
async rest(method, path, body) {
|
|
160
168
|
const controller = new AbortController();
|
|
161
169
|
const timer = setTimeout(() => controller.abort(), this.toolTimeoutMs);
|
|
@@ -170,10 +178,18 @@ export class AlmytyProxy {
|
|
|
170
178
|
signal: controller.signal,
|
|
171
179
|
});
|
|
172
180
|
const data = await resp.json().catch(() => ({}));
|
|
173
|
-
if (!resp.ok)
|
|
174
|
-
|
|
181
|
+
if (!resp.ok) {
|
|
182
|
+
const detail = data?.message || data?.error?.message || data?.error || '';
|
|
183
|
+
throw new Error(`${method} ${path} failed (${resp.status})${detail ? `: ${typeof detail === 'string' ? detail : JSON.stringify(detail)}` : ''}`);
|
|
184
|
+
}
|
|
175
185
|
return data;
|
|
176
186
|
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
if (err?.name === 'AbortError') {
|
|
189
|
+
throw new Error(`almyty ${method} ${path} timed out after ${Math.round(this.toolTimeoutMs / 1000)}s`);
|
|
190
|
+
}
|
|
191
|
+
throw err;
|
|
192
|
+
}
|
|
177
193
|
finally {
|
|
178
194
|
clearTimeout(timer);
|
|
179
195
|
}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A gateway tool arrives with a JSON Schema; the MCP SDK's `tool()` wants a
|
|
3
|
+
* Zod raw shape, one Zod type per top-level property. Handing it the JSON
|
|
4
|
+
* Schema object itself meant its values were a string and a nested object
|
|
5
|
+
* rather than Zod types, so full mode registered tools whose parameters the
|
|
6
|
+
* SDK could not describe.
|
|
7
|
+
*
|
|
8
|
+
* The Zod namespace is a parameter rather than an import so the mapping can
|
|
9
|
+
* be checked on its own.
|
|
10
|
+
*/
|
|
11
|
+
export interface ZodLike {
|
|
12
|
+
string(): any;
|
|
13
|
+
number(): any;
|
|
14
|
+
boolean(): any;
|
|
15
|
+
array(inner: any): any;
|
|
16
|
+
record(inner: any): any;
|
|
17
|
+
unknown(): any;
|
|
18
|
+
enum(values: [string, ...string[]]): any;
|
|
19
|
+
}
|
|
20
|
+
interface JsonSchemaNode {
|
|
21
|
+
type?: string | string[];
|
|
22
|
+
description?: string;
|
|
23
|
+
enum?: unknown[];
|
|
24
|
+
items?: JsonSchemaNode;
|
|
25
|
+
properties?: Record<string, JsonSchemaNode>;
|
|
26
|
+
required?: string[];
|
|
27
|
+
}
|
|
28
|
+
/** One JSON Schema node to one Zod type. Anything unrecognised stays unknown. */
|
|
29
|
+
export declare function zodTypeFor(node: JsonSchemaNode | undefined, z: ZodLike): any;
|
|
30
|
+
/**
|
|
31
|
+
* The top level of a tool's JSON Schema as a Zod raw shape. Properties not
|
|
32
|
+
* listed in `required` are optional, and a schema with no properties is an
|
|
33
|
+
* empty shape, which is how the SDK spells "this tool takes no arguments".
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildZodShape(schema: unknown, z: ZodLike): Record<string, any>;
|
|
36
|
+
export {};
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A gateway tool arrives with a JSON Schema; the MCP SDK's `tool()` wants a
|
|
3
|
+
* Zod raw shape, one Zod type per top-level property. Handing it the JSON
|
|
4
|
+
* Schema object itself meant its values were a string and a nested object
|
|
5
|
+
* rather than Zod types, so full mode registered tools whose parameters the
|
|
6
|
+
* SDK could not describe.
|
|
7
|
+
*
|
|
8
|
+
* The Zod namespace is a parameter rather than an import so the mapping can
|
|
9
|
+
* be checked on its own.
|
|
10
|
+
*/
|
|
11
|
+
/** One JSON Schema node to one Zod type. Anything unrecognised stays unknown. */
|
|
12
|
+
export function zodTypeFor(node, z) {
|
|
13
|
+
if (!node)
|
|
14
|
+
return z.unknown();
|
|
15
|
+
// A string enum is the one case worth narrowing: it is how a tool says
|
|
16
|
+
// "one of these", and the model behaves better when told.
|
|
17
|
+
if (Array.isArray(node.enum) && node.enum.length > 0 && node.enum.every((v) => typeof v === 'string')) {
|
|
18
|
+
return z.enum(node.enum);
|
|
19
|
+
}
|
|
20
|
+
// A union type (["string","null"]) is taken by its first concrete member;
|
|
21
|
+
// optionality is carried separately, by `required`.
|
|
22
|
+
const type = Array.isArray(node.type) ? node.type.find((t) => t !== 'null') : node.type;
|
|
23
|
+
switch (type) {
|
|
24
|
+
case 'string': return z.string();
|
|
25
|
+
case 'number': return z.number();
|
|
26
|
+
case 'integer': return z.number();
|
|
27
|
+
case 'boolean': return z.boolean();
|
|
28
|
+
case 'array': return z.array(zodTypeFor(node.items, z));
|
|
29
|
+
case 'object': return z.record(z.unknown());
|
|
30
|
+
default: return z.unknown();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The top level of a tool's JSON Schema as a Zod raw shape. Properties not
|
|
35
|
+
* listed in `required` are optional, and a schema with no properties is an
|
|
36
|
+
* empty shape, which is how the SDK spells "this tool takes no arguments".
|
|
37
|
+
*/
|
|
38
|
+
export function buildZodShape(schema, z) {
|
|
39
|
+
const node = (schema ?? {});
|
|
40
|
+
const properties = node.properties ?? {};
|
|
41
|
+
const required = new Set(node.required ?? []);
|
|
42
|
+
const shape = {};
|
|
43
|
+
for (const [key, definition] of Object.entries(properties)) {
|
|
44
|
+
let field = zodTypeFor(definition, z);
|
|
45
|
+
if (definition?.description && typeof field?.describe === 'function')
|
|
46
|
+
field = field.describe(definition.description);
|
|
47
|
+
if (!required.has(key) && typeof field?.optional === 'function')
|
|
48
|
+
field = field.optional();
|
|
49
|
+
shape[key] = field;
|
|
50
|
+
}
|
|
51
|
+
return shape;
|
|
52
|
+
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI's own version, read from its package.json at startup.
|
|
3
|
+
*
|
|
4
|
+
* It used to be a hardcoded string, which drifted: `--version` answered
|
|
5
|
+
* 0.1.0 while the published package was 1.2.0, so a bug report never
|
|
6
|
+
* identified the build it came from. Both `dist/index.js` and `src/index.ts`
|
|
7
|
+
* sit one directory below the package root, so the same relative path
|
|
8
|
+
* resolves for the built bin and for `tsx src/index.ts`.
|
|
9
|
+
*/
|
|
10
|
+
import { readFileSync } from 'node:fs';
|
|
11
|
+
export function readVersion(fallback = '0.0.0') {
|
|
12
|
+
try {
|
|
13
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
|
14
|
+
return typeof pkg.version === 'string' && pkg.version.length > 0
|
|
15
|
+
? pkg.version
|
|
16
|
+
: fallback;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return fallback;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export const VERSION = readVersion();
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@almyty/mcp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"description": "Serve any almyty gateway to Claude Code or any MCP client
|
|
7
|
+
"description": "Serve any almyty gateway to Claude Code or any MCP client — turn your APIs into MCP tools with a single command.",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"bin": {
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsc && chmod +x dist/index.js",
|
|
18
18
|
"dev": "tsx src/index.ts",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"test:watch": "vitest",
|
|
19
21
|
"prepublishOnly": "npm run build"
|
|
20
22
|
},
|
|
21
23
|
"keywords": [
|
|
@@ -41,7 +43,14 @@
|
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@types/node": "^25.5.0",
|
|
43
45
|
"tsx": "^4.7.0",
|
|
44
|
-
"typescript": "^5.9.3"
|
|
46
|
+
"typescript": "^5.9.3",
|
|
47
|
+
"vitest": "^4.1.0"
|
|
48
|
+
},
|
|
49
|
+
"overrides": {
|
|
50
|
+
"@hono/node-server": "^2.0.5",
|
|
51
|
+
"esbuild": "^0.28.1",
|
|
52
|
+
"fast-uri": "^3.1.5",
|
|
53
|
+
"ip-address": "^10.4.0"
|
|
45
54
|
},
|
|
46
55
|
"homepage": "https://almyty.com",
|
|
47
56
|
"repository": {
|