@almyty/mcp-server 1.0.2 → 1.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.
- package/README.md +29 -38
- package/dist/auth.d.ts +18 -20
- package/dist/auth.js +25 -74
- package/dist/index.js +133 -31
- package/dist/proxy.d.ts +40 -4
- package/dist/proxy.js +129 -51
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
# @almyty/mcp-server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
MCP server that connects AI coding agents to almyty tools and skills.
|
|
4
4
|
|
|
5
|
-
## Quick
|
|
5
|
+
## Quick start
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npx @almyty/
|
|
8
|
+
$ npx @almyty/auth login
|
|
9
|
+
$ npx @almyty/mcp-server
|
|
9
10
|
```
|
|
10
11
|
|
|
11
|
-
##
|
|
12
|
+
## Agent configuration
|
|
12
13
|
|
|
13
14
|
### Claude Code
|
|
14
15
|
|
|
15
16
|
```bash
|
|
16
|
-
claude mcp add almyty -- npx -y @almyty/mcp-server
|
|
17
|
+
$ claude mcp add almyty -- npx -y @almyty/mcp-server
|
|
17
18
|
```
|
|
18
19
|
|
|
19
|
-
### Cursor / Windsurf (`.cursor/mcp.json`)
|
|
20
|
+
### Cursor / Windsurf (`.cursor/mcp.json` or `.windsurf/mcp.json`)
|
|
20
21
|
|
|
21
22
|
```json
|
|
22
23
|
{
|
|
@@ -42,6 +43,14 @@ claude mcp add almyty -- npx -y @almyty/mcp-server
|
|
|
42
43
|
}
|
|
43
44
|
```
|
|
44
45
|
|
|
46
|
+
### OpenAI Codex CLI (`~/.codex/config.toml`)
|
|
47
|
+
|
|
48
|
+
```toml
|
|
49
|
+
[mcp_servers.almyty]
|
|
50
|
+
command = "npx"
|
|
51
|
+
args = ["-y", "@almyty/mcp-server"]
|
|
52
|
+
```
|
|
53
|
+
|
|
45
54
|
### Google Gemini CLI (`~/.gemini/settings.json`)
|
|
46
55
|
|
|
47
56
|
```json
|
|
@@ -55,45 +64,27 @@ claude mcp add almyty -- npx -y @almyty/mcp-server
|
|
|
55
64
|
}
|
|
56
65
|
```
|
|
57
66
|
|
|
58
|
-
|
|
67
|
+
## Modes
|
|
59
68
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
command = "npx"
|
|
63
|
-
args = ["-y", "@almyty/mcp-server"]
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## How It Works
|
|
69
|
+
- **Skill-first** (default): Exposes 2 tools (`almyty_execute` + `almyty_search`) and loads skills on demand. Keeps context small.
|
|
70
|
+
- **Full**: Exposes all tools individually. Set `ALMYTY_MODE=full` to enable.
|
|
67
71
|
|
|
68
|
-
|
|
72
|
+
## Environment variables
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
Skill-first: 2 tools + on-demand skills = ~300 tokens base
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Environment Variables
|
|
80
|
-
|
|
81
|
-
| Variable | Default | Description |
|
|
82
|
-
|----------|---------|-------------|
|
|
83
|
-
| `ALMYTY_URL` | `https://api.almyty.com` | almyty API URL |
|
|
84
|
-
| `ALMYTY_TOKEN` | — | Auth token (or use `npx @almyty/mcp-server login`) |
|
|
85
|
-
| `ALMYTY_GATEWAY_ID` | — | Scope to a specific gateway |
|
|
74
|
+
| Variable | Description |
|
|
75
|
+
|----------|-------------|
|
|
76
|
+
| `ALMYTY_URL` | API URL (default: `https://api.almyty.com`) |
|
|
77
|
+
| `ALMYTY_TOKEN` | Auth token |
|
|
78
|
+
| `ALMYTY_GATEWAY_ID` | Scope to a specific gateway |
|
|
79
|
+
| `ALMYTY_MODE` | `skill` (default) or `full` |
|
|
86
80
|
|
|
87
81
|
## Authentication
|
|
88
82
|
|
|
89
|
-
|
|
90
|
-
# Interactive login (opens browser)
|
|
91
|
-
npx @almyty/mcp-server login
|
|
83
|
+
Requires `npx @almyty/auth login` first. Reads credentials from `~/.almyty/credentials.json`.
|
|
92
84
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
```
|
|
85
|
+
## Docs
|
|
86
|
+
|
|
87
|
+
https://almyty.com/docs
|
|
97
88
|
|
|
98
89
|
## License
|
|
99
90
|
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Credential resolver for @almyty/mcp-server.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Authentication itself lives in the dedicated @almyty/auth package
|
|
5
|
+
* (`npx @almyty/auth login`). This module just READS the shared
|
|
6
|
+
* credentials store and surfaces them to the MCP server runtime.
|
|
7
|
+
*
|
|
8
|
+
* Lookup order:
|
|
9
|
+
* 1. ALMYTY_TOKEN environment variable (CI / scripts / config files)
|
|
10
|
+
* 2. ~/.almyty/credentials.json (interactive use, written
|
|
11
|
+
* by `npx @almyty/auth login`)
|
|
8
12
|
*/
|
|
9
13
|
interface StoredCredentials {
|
|
10
14
|
url: string;
|
|
11
15
|
token: string;
|
|
12
16
|
email?: string;
|
|
13
|
-
|
|
17
|
+
frontendUrl?: string;
|
|
14
18
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Load stored credentials from ~/.almyty/credentials.json
|
|
17
|
-
*/
|
|
18
19
|
export declare function loadCredentials(): StoredCredentials | null;
|
|
19
20
|
/**
|
|
20
|
-
*
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* Remove stored credentials
|
|
21
|
+
* Resolve token: env var > stored credentials. Returns null when no
|
|
22
|
+
* credentials are available — the MCP server caller decides whether
|
|
23
|
+
* that's fatal (it usually is, but read-only diagnostics may not need
|
|
24
|
+
* a token).
|
|
25
25
|
*/
|
|
26
|
-
export declare function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*/
|
|
31
|
-
export declare function login(baseUrl: string): Promise<void>;
|
|
26
|
+
export declare function resolveCredentials(): {
|
|
27
|
+
url: string;
|
|
28
|
+
token: string;
|
|
29
|
+
} | null;
|
|
32
30
|
export {};
|
package/dist/auth.js
CHANGED
|
@@ -1,93 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Credential resolver for @almyty/mcp-server.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Authentication itself lives in the dedicated @almyty/auth package
|
|
5
|
+
* (`npx @almyty/auth login`). This module just READS the shared
|
|
6
|
+
* credentials store and surfaces them to the MCP server runtime.
|
|
7
|
+
*
|
|
8
|
+
* Lookup order:
|
|
9
|
+
* 1. ALMYTY_TOKEN environment variable (CI / scripts / config files)
|
|
10
|
+
* 2. ~/.almyty/credentials.json (interactive use, written
|
|
11
|
+
* by `npx @almyty/auth login`)
|
|
8
12
|
*/
|
|
9
|
-
import { readFileSync,
|
|
13
|
+
import { readFileSync, existsSync } from 'fs';
|
|
10
14
|
import { homedir } from 'os';
|
|
11
15
|
import { join } from 'path';
|
|
12
|
-
|
|
13
|
-
const CREDENTIALS_DIR = join(homedir(), '.almyty');
|
|
14
|
-
const CREDENTIALS_FILE = join(CREDENTIALS_DIR, 'credentials.json');
|
|
15
|
-
/**
|
|
16
|
-
* Load stored credentials from ~/.almyty/credentials.json
|
|
17
|
-
*/
|
|
16
|
+
const CREDENTIALS_FILE = join(homedir(), '.almyty', 'credentials.json');
|
|
18
17
|
export function loadCredentials() {
|
|
19
18
|
try {
|
|
20
19
|
if (!existsSync(CREDENTIALS_FILE))
|
|
21
20
|
return null;
|
|
22
|
-
|
|
23
|
-
return JSON.parse(data);
|
|
21
|
+
return JSON.parse(readFileSync(CREDENTIALS_FILE, 'utf-8'));
|
|
24
22
|
}
|
|
25
23
|
catch {
|
|
26
24
|
return null;
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
27
|
/**
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
writeFileSync(CREDENTIALS_FILE, JSON.stringify(creds, null, 2), { mode: 0o600 });
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Remove stored credentials
|
|
38
|
-
*/
|
|
39
|
-
export function logout() {
|
|
40
|
-
try {
|
|
41
|
-
if (existsSync(CREDENTIALS_FILE)) {
|
|
42
|
-
unlinkSync(CREDENTIALS_FILE);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
// Ignore errors
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Interactive login: prompts for email/password, authenticates against
|
|
51
|
-
* the almyty backend, and stores the JWT token.
|
|
28
|
+
* Resolve token: env var > stored credentials. Returns null when no
|
|
29
|
+
* credentials are available — the MCP server caller decides whether
|
|
30
|
+
* that's fatal (it usually is, but read-only diagnostics may not need
|
|
31
|
+
* a token).
|
|
52
32
|
*/
|
|
53
|
-
export
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const ask = (question) => new Promise((resolve) => rl.question(question, resolve));
|
|
59
|
-
try {
|
|
60
|
-
console.error(`Logging in to ${baseUrl}...\n`);
|
|
61
|
-
const email = await ask('Email: ');
|
|
62
|
-
const password = await ask('Password: ');
|
|
63
|
-
console.error('\nAuthenticating...');
|
|
64
|
-
const response = await fetch(`${baseUrl}/api/auth/login`, {
|
|
65
|
-
method: 'POST',
|
|
66
|
-
headers: { 'Content-Type': 'application/json' },
|
|
67
|
-
body: JSON.stringify({ email, password }),
|
|
68
|
-
});
|
|
69
|
-
if (!response.ok) {
|
|
70
|
-
const error = await response.json().catch(() => ({ message: 'Authentication failed' }));
|
|
71
|
-
console.error(`Error: ${error.message || 'Authentication failed'}`);
|
|
72
|
-
process.exit(1);
|
|
73
|
-
}
|
|
74
|
-
const data = await response.json();
|
|
75
|
-
const token = data.accessToken || data.token;
|
|
76
|
-
if (!token) {
|
|
77
|
-
console.error('Error: No token received from server');
|
|
78
|
-
process.exit(1);
|
|
79
|
-
}
|
|
80
|
-
saveCredentials({
|
|
81
|
-
url: baseUrl,
|
|
82
|
-
token,
|
|
83
|
-
email,
|
|
84
|
-
});
|
|
85
|
-
console.error(`\nLogged in successfully as ${email}`);
|
|
86
|
-
console.error(`Credentials saved to ${CREDENTIALS_FILE}`);
|
|
87
|
-
console.error('\nYou can now use the MCP server without ALMYTY_TOKEN:');
|
|
88
|
-
console.error(' npx @almyty/mcp-server');
|
|
33
|
+
export function resolveCredentials() {
|
|
34
|
+
const envToken = process.env.ALMYTY_TOKEN;
|
|
35
|
+
const envUrl = process.env.ALMYTY_URL || 'https://api.almyty.com';
|
|
36
|
+
if (envToken) {
|
|
37
|
+
return { url: envUrl, token: envToken };
|
|
89
38
|
}
|
|
90
|
-
|
|
91
|
-
|
|
39
|
+
const creds = loadCredentials();
|
|
40
|
+
if (creds?.token) {
|
|
41
|
+
return { url: creds.url, token: creds.token };
|
|
92
42
|
}
|
|
43
|
+
return null;
|
|
93
44
|
}
|
package/dist/index.js
CHANGED
|
@@ -33,24 +33,35 @@
|
|
|
33
33
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
34
34
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
35
35
|
import { z } from 'zod';
|
|
36
|
-
import {
|
|
36
|
+
import { resolveCredentials } from './auth.js';
|
|
37
37
|
import { AlmytyProxy } from './proxy.js';
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
// Accept gateway as positional arg or env var:
|
|
39
|
+
// npx @almyty/mcp-server acme/petstore
|
|
40
|
+
// ALMYTY_GATEWAY_ID=acme/petstore npx @almyty/mcp-server
|
|
41
|
+
const ALMYTY_GATEWAY_ID = process.argv[2] || process.env.ALMYTY_GATEWAY_ID;
|
|
40
42
|
const ALMYTY_MODE = (process.env.ALMYTY_MODE || 'skill-first');
|
|
43
|
+
/**
|
|
44
|
+
* Sanitize a skill name into a valid MCP prompt identifier.
|
|
45
|
+
* MCP prompt names should be safe identifiers — replace anything outside
|
|
46
|
+
* [a-zA-Z0-9_-] (e.g. slashes from `petstore/pets`) with underscores so
|
|
47
|
+
* the registration doesn't blow up on real-world skill names.
|
|
48
|
+
*/
|
|
49
|
+
function sanitizePromptName(name) {
|
|
50
|
+
return name
|
|
51
|
+
.replace(/[^a-zA-Z0-9_-]/g, '_')
|
|
52
|
+
.replace(/_{2,}/g, '_')
|
|
53
|
+
.replace(/^_+|_+$/g, '') || 'skill';
|
|
54
|
+
}
|
|
41
55
|
async function main() {
|
|
42
|
-
// Resolve token: env var >
|
|
43
|
-
|
|
44
|
-
if (!
|
|
45
|
-
const creds = loadCredentials();
|
|
46
|
-
token = creds?.token;
|
|
47
|
-
}
|
|
48
|
-
if (!token) {
|
|
56
|
+
// Resolve token: env var > ~/.almyty/credentials.json
|
|
57
|
+
const creds = resolveCredentials();
|
|
58
|
+
if (!creds) {
|
|
49
59
|
console.error('Error: No authentication token found.\n' +
|
|
50
|
-
'Set ALMYTY_TOKEN environment variable or run: npx @almyty/
|
|
60
|
+
'Set ALMYTY_TOKEN environment variable or run: npx @almyty/auth login');
|
|
51
61
|
process.exit(1);
|
|
52
62
|
}
|
|
53
|
-
const
|
|
63
|
+
const ALMYTY_URL = creds.url;
|
|
64
|
+
const proxy = new AlmytyProxy(ALMYTY_URL, creds.token, ALMYTY_GATEWAY_ID);
|
|
54
65
|
// Fetch tools + skills from backend
|
|
55
66
|
const [tools, skills] = await Promise.all([
|
|
56
67
|
proxy.fetchTools(),
|
|
@@ -159,8 +170,20 @@ async function main() {
|
|
|
159
170
|
// skill it needs via prompts/get, instead of having all
|
|
160
171
|
// N tool schemas (~200 tokens each) always in context.
|
|
161
172
|
// =====================================================
|
|
173
|
+
// Track sanitized prompt names to avoid collisions when two skills
|
|
174
|
+
// sanitize to the same identifier (e.g. `petstore/pets` and
|
|
175
|
+
// `petstore-pets` both become `petstore_pets`).
|
|
176
|
+
const usedPromptNames = new Set();
|
|
162
177
|
for (const skill of skills) {
|
|
163
|
-
|
|
178
|
+
let promptName = `skill-${sanitizePromptName(skill.name)}`;
|
|
179
|
+
if (usedPromptNames.has(promptName)) {
|
|
180
|
+
let suffix = 2;
|
|
181
|
+
while (usedPromptNames.has(`${promptName}-${suffix}`))
|
|
182
|
+
suffix++;
|
|
183
|
+
promptName = `${promptName}-${suffix}`;
|
|
184
|
+
}
|
|
185
|
+
usedPromptNames.add(promptName);
|
|
186
|
+
server.prompt(promptName, `How to use: ${skill.name} (${skill.toolCount} tools)`, async () => ({
|
|
164
187
|
messages: [{
|
|
165
188
|
role: 'user',
|
|
166
189
|
content: {
|
|
@@ -210,20 +233,94 @@ async function main() {
|
|
|
210
233
|
}, null, 2),
|
|
211
234
|
}],
|
|
212
235
|
}));
|
|
236
|
+
// =====================================================
|
|
237
|
+
// MANAGEMENT TOOLS — control the almyty platform itself
|
|
238
|
+
// =====================================================
|
|
239
|
+
// These tools let LLMs manage almyty: create APIs, import
|
|
240
|
+
// schemas, generate tools, set up gateways, build agents.
|
|
241
|
+
// Available in both modes (skill-first and full).
|
|
242
|
+
server.tool('almyty_list_apis', 'List all connected APIs in your organization.', {}, async () => {
|
|
243
|
+
const result = await proxy.listApis();
|
|
244
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
245
|
+
});
|
|
246
|
+
server.tool('almyty_create_api', 'Connect a new API. Provide a name, type (openapi/graphql/soap/protobuf/sdk), and base URL.', {
|
|
247
|
+
name: z.string().describe('Human-readable API name'),
|
|
248
|
+
type: z.enum(['openapi', 'graphql', 'soap', 'protobuf', 'sdk']).describe('Schema type'),
|
|
249
|
+
baseUrl: z.string().optional().describe('API base URL (not needed for SDK type)'),
|
|
250
|
+
}, async (args) => {
|
|
251
|
+
const result = await proxy.createApi(args);
|
|
252
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
253
|
+
});
|
|
254
|
+
server.tool('almyty_import_schema', 'Import an API schema and auto-generate tools. Provide the API ID and a schema URL.', {
|
|
255
|
+
apiId: z.string().describe('ID of the API to import into'),
|
|
256
|
+
schemaUrl: z.string().describe('URL of the schema (e.g. OpenAPI JSON endpoint)'),
|
|
257
|
+
generateTools: z.boolean().default(true).describe('Auto-generate tools from operations'),
|
|
258
|
+
}, async (args) => {
|
|
259
|
+
const result = await proxy.importSchema(args.apiId, { schemaUrl: args.schemaUrl, generateTools: args.generateTools });
|
|
260
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
261
|
+
});
|
|
262
|
+
server.tool('almyty_list_gateways', 'List all gateways in your organization.', {}, async () => {
|
|
263
|
+
const result = await proxy.listGateways();
|
|
264
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
265
|
+
});
|
|
266
|
+
server.tool('almyty_create_gateway', 'Create a gateway to expose tools OR an agent via a protocol (MCP, A2A, UTCP, Skills). Use kind="tool" for a tool gateway or kind="agent" for an agent gateway.', {
|
|
267
|
+
name: z.string().describe('Gateway name'),
|
|
268
|
+
type: z.enum(['mcp', 'a2a', 'utcp', 'skills']).describe('Protocol type'),
|
|
269
|
+
endpoint: z.string().describe('URL slug for the gateway endpoint'),
|
|
270
|
+
kind: z.enum(['tool', 'agent']).default('tool').describe('What the gateway exposes: tools or a single agent'),
|
|
271
|
+
agentId: z.string().optional().describe('Agent ID (required when kind is "agent")'),
|
|
272
|
+
}, async (args) => {
|
|
273
|
+
const result = await proxy.createGateway({ ...args, configuration: {} });
|
|
274
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
275
|
+
});
|
|
276
|
+
server.tool('almyty_assign_tool', 'Assign a tool to a tool-kind gateway.', {
|
|
277
|
+
gatewayId: z.string().describe('Gateway ID'),
|
|
278
|
+
toolId: z.string().describe('Tool ID to assign'),
|
|
279
|
+
}, async (args) => {
|
|
280
|
+
const result = await proxy.assignToolToGateway(args.gatewayId, args.toolId);
|
|
281
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
282
|
+
});
|
|
283
|
+
server.tool('almyty_list_agents', 'List all agents in your organization.', {}, async () => {
|
|
284
|
+
const result = await proxy.listAgents();
|
|
285
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
286
|
+
});
|
|
287
|
+
server.tool('almyty_create_agent', 'Create a new agent. Workflow agents use a visual DAG pipeline. Autonomous agents use instructions + tool access.', {
|
|
288
|
+
name: z.string().describe('Agent name'),
|
|
289
|
+
description: z.string().optional().describe('What the agent does'),
|
|
290
|
+
mode: z.enum(['workflow', 'autonomous']).default('autonomous').describe('workflow = visual pipeline, autonomous = instruction-driven'),
|
|
291
|
+
instructions: z.string().optional().describe('Instructions for autonomous agents'),
|
|
292
|
+
}, async (args) => {
|
|
293
|
+
const result = await proxy.createAgent(args);
|
|
294
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
295
|
+
});
|
|
296
|
+
server.tool('almyty_invoke_agent', 'Invoke an agent with input. Returns the agent execution result.', {
|
|
297
|
+
agentId: z.string().describe('Agent ID'),
|
|
298
|
+
input: z.record(z.unknown()).describe('Input data for the agent'),
|
|
299
|
+
}, async (args) => {
|
|
300
|
+
const result = await proxy.invokeAgent(args.agentId, args.input);
|
|
301
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
302
|
+
});
|
|
303
|
+
server.tool('almyty_add_provider', 'Add an LLM provider (OpenAI, Anthropic, etc.).', {
|
|
304
|
+
name: z.string().describe('Display name'),
|
|
305
|
+
type: z.string().describe('Provider type (openai, anthropic, gemini, azure, bedrock, etc.)'),
|
|
306
|
+
apiKey: z.string().describe('API key for the provider'),
|
|
307
|
+
}, async (args) => {
|
|
308
|
+
const result = await proxy.addProvider({ name: args.name, type: args.type, configuration: { apiKey: args.apiKey } });
|
|
309
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
310
|
+
});
|
|
311
|
+
process.stderr.write(`almyty: ${tools.length} gateway tools, ${skills.length} skills, 10 management tools (mode: ${ALMYTY_MODE})\n`);
|
|
213
312
|
// Connect via stdio
|
|
214
313
|
const transport = new StdioServerTransport();
|
|
215
314
|
await server.connect(transport);
|
|
216
315
|
}
|
|
217
|
-
// Handle subcommands
|
|
316
|
+
// Handle subcommands (check before main() uses argv[2] as gateway ID)
|
|
218
317
|
const subcommand = process.argv[2];
|
|
219
|
-
if (subcommand === 'login') {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
logout();
|
|
226
|
-
console.log('Logged out successfully.');
|
|
318
|
+
if (subcommand === 'login' || subcommand === 'logout' || subcommand === 'whoami') {
|
|
319
|
+
// Auth lives in @almyty/auth. Redirect rather than silently doing
|
|
320
|
+
// nothing — users typing the old commands should see the new entry point.
|
|
321
|
+
console.error(`Authentication moved to @almyty/auth.`);
|
|
322
|
+
console.error(` npx @almyty/auth ${subcommand}`);
|
|
323
|
+
process.exit(1);
|
|
227
324
|
}
|
|
228
325
|
else if (subcommand === '--help' || subcommand === '-h') {
|
|
229
326
|
console.log(`
|
|
@@ -238,15 +335,21 @@ Token overhead comparison:
|
|
|
238
335
|
Skill-first: 2 tools = ~300 tokens/turn (skills loaded on demand)
|
|
239
336
|
|
|
240
337
|
Usage:
|
|
241
|
-
npx @almyty/mcp-server
|
|
242
|
-
npx @almyty/mcp-server
|
|
243
|
-
|
|
338
|
+
npx @almyty/mcp-server <org/gateway> Start server for a specific gateway
|
|
339
|
+
npx @almyty/mcp-server Start server (all gateways)
|
|
340
|
+
|
|
341
|
+
Examples:
|
|
342
|
+
npx @almyty/mcp-server acme/petstore
|
|
343
|
+
claude mcp add petstore -- npx -y @almyty/mcp-server acme/petstore
|
|
344
|
+
|
|
345
|
+
Authentication:
|
|
346
|
+
npx @almyty/auth login Browser-based login (one-time setup)
|
|
244
347
|
|
|
245
348
|
Environment:
|
|
246
349
|
ALMYTY_URL Base URL (default: https://api.almyty.com)
|
|
247
|
-
ALMYTY_TOKEN
|
|
248
|
-
ALMYTY_GATEWAY_ID
|
|
249
|
-
ALMYTY_MODE "skill-first" (default) | "full"
|
|
350
|
+
ALMYTY_TOKEN API key (auto-read from ~/.almyty/credentials.json)
|
|
351
|
+
ALMYTY_GATEWAY_ID Gateway (alternative to positional arg)
|
|
352
|
+
ALMYTY_MODE "skill-first" (default) | "full"
|
|
250
353
|
|
|
251
354
|
Modes:
|
|
252
355
|
skill-first 2 tools (almyty_execute + almyty_search) + skills as prompts
|
|
@@ -256,9 +359,8 @@ Modes:
|
|
|
256
359
|
|
|
257
360
|
Configuration:
|
|
258
361
|
|
|
259
|
-
Claude Code: claude mcp add
|
|
260
|
-
Cursor: .cursor/mcp.json → { "mcpServers": { "
|
|
261
|
-
Codex: ~/.codex/config.toml → [mcp_servers.almyty] command="npx" args=["-y","@almyty/mcp-server"]
|
|
362
|
+
Claude Code: claude mcp add petstore -- npx -y @almyty/mcp-server acme/petstore
|
|
363
|
+
Cursor: .cursor/mcp.json → { "mcpServers": { "petstore": { "command": "npx", "args": ["-y", "@almyty/mcp-server", "acme/petstore"] } } }
|
|
262
364
|
Copilot: .vscode/mcp.json → { "servers": { "almyty": { "command": "npx", "args": ["-y", "@almyty/mcp-server"] } } }
|
|
263
365
|
Gemini: ~/.gemini/settings.json → { "mcpServers": { "almyty": { ... } } }
|
|
264
366
|
`);
|
package/dist/proxy.d.ts
CHANGED
|
@@ -7,17 +7,38 @@ export interface McpToolDefinition {
|
|
|
7
7
|
description?: string;
|
|
8
8
|
inputSchema: Record<string, unknown>;
|
|
9
9
|
}
|
|
10
|
+
interface ProxyOptions {
|
|
11
|
+
/** Override for fetch timeouts. */
|
|
12
|
+
discoveryTimeoutMs?: number;
|
|
13
|
+
toolTimeoutMs?: number;
|
|
14
|
+
/** Optional logger for non-fatal warnings (e.g. skills/list failure). */
|
|
15
|
+
warn?: (msg: string) => void;
|
|
16
|
+
}
|
|
10
17
|
export declare class AlmytyProxy {
|
|
11
|
-
private baseUrl;
|
|
12
|
-
private token;
|
|
13
|
-
private gatewayId?;
|
|
14
|
-
|
|
18
|
+
private readonly baseUrl;
|
|
19
|
+
private readonly token;
|
|
20
|
+
private readonly gatewayId?;
|
|
21
|
+
private readonly discoveryTimeoutMs;
|
|
22
|
+
private readonly toolTimeoutMs;
|
|
23
|
+
private readonly warn;
|
|
24
|
+
private requestSeq;
|
|
25
|
+
constructor(baseUrl: string, token: string, gatewayId?: string, options?: ProxyOptions);
|
|
26
|
+
private endpoint;
|
|
27
|
+
private nextId;
|
|
28
|
+
/**
|
|
29
|
+
* Wrap a fetch with an AbortSignal-based timeout. Without this, a hung
|
|
30
|
+
* backend (e.g., a load-balancer black-hole) would hang the MCP server
|
|
31
|
+
* indefinitely with no signal to the LLM client.
|
|
32
|
+
*/
|
|
33
|
+
private fetchWithTimeout;
|
|
15
34
|
/**
|
|
16
35
|
* Fetch available tools from the almyty backend.
|
|
17
36
|
*/
|
|
18
37
|
fetchTools(): Promise<McpToolDefinition[]>;
|
|
19
38
|
/**
|
|
20
39
|
* Fetch skills from the almyty backend and return as resource content.
|
|
40
|
+
* Failures are logged but non-fatal — the server can still operate
|
|
41
|
+
* without skills (the user just won't have prompt-based guidance).
|
|
21
42
|
*/
|
|
22
43
|
fetchSkills(): Promise<Array<{
|
|
23
44
|
name: string;
|
|
@@ -28,4 +49,19 @@ export declare class AlmytyProxy {
|
|
|
28
49
|
* Execute a tool call via the almyty backend.
|
|
29
50
|
*/
|
|
30
51
|
callTool(toolName: string, args: Record<string, unknown>): Promise<unknown>;
|
|
52
|
+
private rest;
|
|
53
|
+
listApis(): Promise<any>;
|
|
54
|
+
createApi(data: object): Promise<any>;
|
|
55
|
+
importSchema(apiId: string, data: object): Promise<any>;
|
|
56
|
+
generateTools(apiId: string): Promise<any>;
|
|
57
|
+
listTools(): Promise<any>;
|
|
58
|
+
listGateways(): Promise<any>;
|
|
59
|
+
createGateway(data: object): Promise<any>;
|
|
60
|
+
assignToolToGateway(gatewayId: string, toolId: string): Promise<any>;
|
|
61
|
+
listAgents(): Promise<any>;
|
|
62
|
+
createAgent(data: object): Promise<any>;
|
|
63
|
+
invokeAgent(agentId: string, input: object): Promise<any>;
|
|
64
|
+
listProviders(): Promise<any>;
|
|
65
|
+
addProvider(data: object): Promise<any>;
|
|
31
66
|
}
|
|
67
|
+
export {};
|
package/dist/proxy.js
CHANGED
|
@@ -2,37 +2,79 @@
|
|
|
2
2
|
* HTTP proxy to the almyty backend.
|
|
3
3
|
* Fetches tools and executes tool calls via the MCP JSON-RPC API.
|
|
4
4
|
*/
|
|
5
|
+
/** Default timeout for backend calls (ms). Tool execution is intentionally
|
|
6
|
+
* longer than discovery because the LLM may be invoking a long-running tool. */
|
|
7
|
+
const DEFAULT_DISCOVERY_TIMEOUT_MS = 15_000;
|
|
8
|
+
const DEFAULT_TOOL_TIMEOUT_MS = 120_000;
|
|
5
9
|
export class AlmytyProxy {
|
|
6
10
|
baseUrl;
|
|
7
11
|
token;
|
|
8
12
|
gatewayId;
|
|
9
|
-
|
|
13
|
+
discoveryTimeoutMs;
|
|
14
|
+
toolTimeoutMs;
|
|
15
|
+
warn;
|
|
16
|
+
requestSeq = 0;
|
|
17
|
+
constructor(baseUrl, token, gatewayId, options = {}) {
|
|
10
18
|
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
11
19
|
this.token = token;
|
|
12
20
|
this.gatewayId = gatewayId;
|
|
21
|
+
this.discoveryTimeoutMs = options.discoveryTimeoutMs ?? DEFAULT_DISCOVERY_TIMEOUT_MS;
|
|
22
|
+
this.toolTimeoutMs = options.toolTimeoutMs ?? DEFAULT_TOOL_TIMEOUT_MS;
|
|
23
|
+
// Default warning sink: stderr (stdout is reserved for the MCP protocol).
|
|
24
|
+
this.warn = options.warn ?? ((m) => process.stderr.write(`[almyty mcp-server] ${m}\n`));
|
|
25
|
+
}
|
|
26
|
+
endpoint() {
|
|
27
|
+
// Per-gateway scoping uses the slug-based MCP route (/mcp/:orgSlug/:gatewaySlug),
|
|
28
|
+
// which the caller must encode into ALMYTY_GATEWAY_ID as "orgSlug/gatewaySlug".
|
|
29
|
+
// The unscoped route is the universal /mcp JSON-RPC endpoint.
|
|
30
|
+
return this.gatewayId
|
|
31
|
+
? `${this.baseUrl}/mcp/${this.gatewayId}`
|
|
32
|
+
: `${this.baseUrl}/mcp`;
|
|
33
|
+
}
|
|
34
|
+
nextId() {
|
|
35
|
+
return ++this.requestSeq;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Wrap a fetch with an AbortSignal-based timeout. Without this, a hung
|
|
39
|
+
* backend (e.g., a load-balancer black-hole) would hang the MCP server
|
|
40
|
+
* indefinitely with no signal to the LLM client.
|
|
41
|
+
*/
|
|
42
|
+
async fetchWithTimeout(method, body, timeoutMs) {
|
|
43
|
+
const controller = new AbortController();
|
|
44
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
45
|
+
try {
|
|
46
|
+
return await fetch(this.endpoint(), {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: {
|
|
49
|
+
'Content-Type': 'application/json',
|
|
50
|
+
'Authorization': `Bearer ${this.token}`,
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify(body),
|
|
53
|
+
signal: controller.signal,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
if (err?.name === 'AbortError') {
|
|
58
|
+
throw new Error(`almyty backend ${method} timed out after ${Math.round(timeoutMs / 1000)}s`);
|
|
59
|
+
}
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
}
|
|
13
65
|
}
|
|
14
66
|
/**
|
|
15
67
|
* Fetch available tools from the almyty backend.
|
|
16
68
|
*/
|
|
17
69
|
async fetchTools() {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
'Content-Type': 'application/json',
|
|
25
|
-
'Authorization': `Bearer ${this.token}`,
|
|
26
|
-
},
|
|
27
|
-
body: JSON.stringify({
|
|
28
|
-
jsonrpc: '2.0',
|
|
29
|
-
id: 1,
|
|
30
|
-
method: 'tools/list',
|
|
31
|
-
params: {},
|
|
32
|
-
}),
|
|
33
|
-
});
|
|
70
|
+
const response = await this.fetchWithTimeout('tools/list', {
|
|
71
|
+
jsonrpc: '2.0',
|
|
72
|
+
id: this.nextId(),
|
|
73
|
+
method: 'tools/list',
|
|
74
|
+
params: {},
|
|
75
|
+
}, this.discoveryTimeoutMs);
|
|
34
76
|
if (!response.ok) {
|
|
35
|
-
const text = await response.text();
|
|
77
|
+
const text = await response.text().catch(() => '');
|
|
36
78
|
throw new Error(`Failed to fetch tools (${response.status}): ${text}`);
|
|
37
79
|
}
|
|
38
80
|
const data = await response.json();
|
|
@@ -43,55 +85,53 @@ export class AlmytyProxy {
|
|
|
43
85
|
}
|
|
44
86
|
/**
|
|
45
87
|
* Fetch skills from the almyty backend and return as resource content.
|
|
88
|
+
* Failures are logged but non-fatal — the server can still operate
|
|
89
|
+
* without skills (the user just won't have prompt-based guidance).
|
|
46
90
|
*/
|
|
47
91
|
async fetchSkills() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const response = await fetch(endpoint, {
|
|
52
|
-
method: 'POST',
|
|
53
|
-
headers: {
|
|
54
|
-
'Content-Type': 'application/json',
|
|
55
|
-
'Authorization': `Bearer ${this.token}`,
|
|
56
|
-
},
|
|
57
|
-
body: JSON.stringify({
|
|
92
|
+
let response;
|
|
93
|
+
try {
|
|
94
|
+
response = await this.fetchWithTimeout('skills/list', {
|
|
58
95
|
jsonrpc: '2.0',
|
|
59
|
-
id:
|
|
96
|
+
id: this.nextId(),
|
|
60
97
|
method: 'skills/list',
|
|
61
98
|
params: { limit: 100 },
|
|
62
|
-
})
|
|
63
|
-
}
|
|
99
|
+
}, this.discoveryTimeoutMs);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
// Previously this swallowed the error and returned []. Surface it
|
|
103
|
+
// to stderr so users can tell the difference between "no skills
|
|
104
|
+
// configured" and "skills endpoint is broken".
|
|
105
|
+
this.warn(`skills/list failed: ${err?.message ?? err}`);
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
64
108
|
if (!response.ok) {
|
|
109
|
+
const text = await response.text().catch(() => '');
|
|
110
|
+
this.warn(`skills/list returned HTTP ${response.status}: ${text.slice(0, 200)}`);
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
const data = await response.json().catch(() => ({}));
|
|
114
|
+
if (data.error) {
|
|
115
|
+
this.warn(`skills/list MCP error: ${data.error.message}`);
|
|
65
116
|
return [];
|
|
66
117
|
}
|
|
67
|
-
const data = await response.json();
|
|
68
118
|
return data.result?.skills || [];
|
|
69
119
|
}
|
|
70
120
|
/**
|
|
71
121
|
* Execute a tool call via the almyty backend.
|
|
72
122
|
*/
|
|
73
123
|
async callTool(toolName, args) {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
'Authorization': `Bearer ${this.token}`,
|
|
124
|
+
const response = await this.fetchWithTimeout(`tools/call ${toolName}`, {
|
|
125
|
+
jsonrpc: '2.0',
|
|
126
|
+
id: this.nextId(),
|
|
127
|
+
method: 'tools/call',
|
|
128
|
+
params: {
|
|
129
|
+
name: toolName,
|
|
130
|
+
arguments: args,
|
|
82
131
|
},
|
|
83
|
-
|
|
84
|
-
jsonrpc: '2.0',
|
|
85
|
-
id: Date.now(),
|
|
86
|
-
method: 'tools/call',
|
|
87
|
-
params: {
|
|
88
|
-
name: toolName,
|
|
89
|
-
arguments: args,
|
|
90
|
-
},
|
|
91
|
-
}),
|
|
92
|
-
});
|
|
132
|
+
}, this.toolTimeoutMs);
|
|
93
133
|
if (!response.ok) {
|
|
94
|
-
const text = await response.text();
|
|
134
|
+
const text = await response.text().catch(() => '');
|
|
95
135
|
throw new Error(`Tool execution failed (${response.status}): ${text}`);
|
|
96
136
|
}
|
|
97
137
|
const data = await response.json();
|
|
@@ -113,4 +153,42 @@ export class AlmytyProxy {
|
|
|
113
153
|
}
|
|
114
154
|
return data.result;
|
|
115
155
|
}
|
|
156
|
+
// ── Management API ──────────────────────────────────────────────
|
|
157
|
+
// These let LLMs control the almyty platform itself — create APIs,
|
|
158
|
+
// tools, gateways, agents — not just call existing tools.
|
|
159
|
+
async rest(method, path, body) {
|
|
160
|
+
const controller = new AbortController();
|
|
161
|
+
const timer = setTimeout(() => controller.abort(), this.toolTimeoutMs);
|
|
162
|
+
try {
|
|
163
|
+
const resp = await fetch(`${this.baseUrl}${path}`, {
|
|
164
|
+
method,
|
|
165
|
+
headers: {
|
|
166
|
+
'Content-Type': 'application/json',
|
|
167
|
+
'Authorization': `Bearer ${this.token}`,
|
|
168
|
+
},
|
|
169
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
170
|
+
signal: controller.signal,
|
|
171
|
+
});
|
|
172
|
+
const data = await resp.json().catch(() => ({}));
|
|
173
|
+
if (!resp.ok)
|
|
174
|
+
throw new Error(data?.error?.message || `${resp.status}`);
|
|
175
|
+
return data;
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
clearTimeout(timer);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async listApis() { return this.rest('GET', '/apis'); }
|
|
182
|
+
async createApi(data) { return this.rest('POST', '/apis', data); }
|
|
183
|
+
async importSchema(apiId, data) { return this.rest('POST', `/apis/${apiId}/import-schema`, data); }
|
|
184
|
+
async generateTools(apiId) { return this.rest('POST', `/apis/${apiId}/generate-tools`); }
|
|
185
|
+
async listTools() { return this.rest('GET', '/tools'); }
|
|
186
|
+
async listGateways() { return this.rest('GET', '/gateways'); }
|
|
187
|
+
async createGateway(data) { return this.rest('POST', '/gateways', data); }
|
|
188
|
+
async assignToolToGateway(gatewayId, toolId) { return this.rest('POST', `/gateways/${gatewayId}/tools`, { toolId }); }
|
|
189
|
+
async listAgents() { return this.rest('GET', '/agents'); }
|
|
190
|
+
async createAgent(data) { return this.rest('POST', '/agents', data); }
|
|
191
|
+
async invokeAgent(agentId, input) { return this.rest('POST', `/agents/${agentId}/invoke`, input); }
|
|
192
|
+
async listProviders() { return this.rest('GET', '/llm-providers'); }
|
|
193
|
+
async addProvider(data) { return this.rest('POST', '/llm-providers', data); }
|
|
116
194
|
}
|
package/package.json
CHANGED