nixflex-mcp 0.5.0 → 0.5.2
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/{KIT-EXAMPLES-K7.md → CALL-EXAMPLES.md} +2 -2
- package/CALL-REQUESTS.md +3 -5
- package/CHANGELOG.md +31 -27
- package/{B57-DELETES.md → DELETING-CONTENT.md} +2 -4
- package/LICENSE +9 -9
- package/METHODS.md +8 -8
- package/{KIT-EXAMPLES-K6.md → NUMBER-EXAMPLES.md} +118 -118
- package/NUMBER-FEATURES.md +3 -5
- package/ORGANISATIONS.md +3 -3
- package/README.md +15 -29
- package/agent-reads.js +26 -26
- package/agent-schema.js +24 -24
- package/booking-schemas.js +1 -0
- package/c6-output.js +32 -32
- package/c6-tools.js +35 -35
- package/call-reads.js +43 -43
- package/call-tools.js +22 -22
- package/campaign-schema.js +38 -38
- package/core-tools.js +36 -36
- package/foundation/connection.mjs +48 -48
- package/foundation/launch.mjs +39 -39
- package/foundation/origin-fence.mjs +21 -21
- package/foundation/origins.mjs +15 -15
- package/index.js +165 -165
- package/k6-private.js +36 -36
- package/k6-schemas.js +27 -27
- package/k6-tools.js +42 -42
- package/k7-call.js +34 -34
- package/k7-errors.js +16 -16
- package/k7-schemas.js +34 -34
- package/k7-tools.js +20 -20
- package/k9-deletes.js +90 -90
- package/kit-request.js +24 -24
- package/knowledge-request.js +24 -24
- package/number-reads.js +23 -23
- package/number-schema.js +26 -26
- package/number-usage.js +13 -13
- package/organisation-tools.js +26 -26
- package/package.json +6 -4
- package/safe-tools.js +36 -36
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
// Shared installer/runtime policy. Keep byte-identical in MCP and CLI.
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
|
-
import { join, isAbsolute } from 'node:path';
|
|
5
|
-
import { APPROVED_ORIGINS, approvedOrigin } from './origins.mjs';
|
|
6
|
-
export { APPROVED_ORIGINS, approvedOrigin } from './origins.mjs';
|
|
7
|
-
export function readLegacy(file, read = readFileSync) {
|
|
8
|
-
let raw;
|
|
9
|
-
try { raw = read(file, 'utf8'); }
|
|
10
|
-
catch (error) {
|
|
11
|
-
if (error.code === 'ENOENT') throw new Error('No MCP credentials. Use a full key and explicit API URL in the client environment, or an existing nixflex login file.');
|
|
12
|
-
throw new Error('Cannot read the Nixflex credential file; no fallback was used.');
|
|
13
|
-
}
|
|
14
|
-
let cfg;
|
|
15
|
-
try { cfg = JSON.parse(raw); } catch { throw new Error('Malformed Nixflex credential file; no fallback was used.'); }
|
|
16
|
-
if (!cfg || typeof cfg !== 'object' || Array.isArray(cfg))
|
|
17
|
-
throw new Error('Invalid Nixflex credential file.');
|
|
18
|
-
return cfg;
|
|
19
|
-
}
|
|
20
|
-
export function resolveConnection({ env = process.env, home = homedir(), read = readFileSync } = {}) {
|
|
21
|
-
const source = env.NIXFLEX_CREDENTIAL_SOURCE || (env.NIXFLEX_API_KEY ? 'environment' : 'legacy');
|
|
22
|
-
if (!['environment', 'legacy'].includes(source)) throw new Error('Invalid MCP credential source.');
|
|
23
|
-
let key, baseUrl, configFile;
|
|
24
|
-
if (source === 'environment') {
|
|
25
|
-
if (env.NIXFLEX_PROFILE) throw new Error('Choose an environment pair or a legacy profile, not both.');
|
|
26
|
-
if (!env.NIXFLEX_BASE_URL) throw new Error('NIXFLEX_BASE_URL is required with an environment key; no production default was used.');
|
|
27
|
-
key = env.NIXFLEX_API_KEY;
|
|
28
|
-
baseUrl = approvedOrigin(env.NIXFLEX_BASE_URL);
|
|
29
|
-
} else {
|
|
30
|
-
configFile = env.NIXFLEX_CONFIG_FILE || join(home, '.nixflex', 'config.json');
|
|
31
|
-
if (!isAbsolute(configFile)) throw new Error('NIXFLEX_CONFIG_FILE must be an absolute path.');
|
|
32
|
-
let cfg = readLegacy(configFile, read);
|
|
33
|
-
if (env.NIXFLEX_PROFILE) {
|
|
34
|
-
const name = env.NIXFLEX_PROFILE;
|
|
35
|
-
if (!/^[a-zA-Z0-9_-]{1,64}$/.test(name) || !cfg.profiles ||
|
|
36
|
-
!Object.hasOwn(cfg.profiles, name) || !cfg.profiles[name]?.base_url)
|
|
37
|
-
throw new Error('Legacy MCP profile missing or has no explicit API URL; no fallback was used.');
|
|
38
|
-
cfg = cfg.profiles[name];
|
|
39
|
-
}
|
|
40
|
-
key = cfg.api_key;
|
|
41
|
-
baseUrl = approvedOrigin(cfg.base_url === undefined ? APPROVED_ORIGINS[0] : cfg.base_url);
|
|
42
|
-
if (env.NIXFLEX_BASE_URL && approvedOrigin(env.NIXFLEX_BASE_URL) !== baseUrl)
|
|
43
|
-
throw new Error('MCP credential file destination changed or conflicts with this installation; refusing to retarget the key.');
|
|
44
|
-
}
|
|
45
|
-
if (typeof key !== 'string' || !/^nxf_[a-z0-9]+:nxfs_[a-z0-9]+$/i.test(key))
|
|
46
|
-
throw new Error('Missing or invalid full MCP API key. No request was sent.');
|
|
47
|
-
return { key, baseUrl, source, configFile, profile: env.NIXFLEX_PROFILE };
|
|
48
|
-
}
|
|
1
|
+
// Shared installer/runtime policy. Keep byte-identical in MCP and CLI.
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join, isAbsolute } from 'node:path';
|
|
5
|
+
import { APPROVED_ORIGINS, approvedOrigin } from './origins.mjs';
|
|
6
|
+
export { APPROVED_ORIGINS, approvedOrigin } from './origins.mjs';
|
|
7
|
+
export function readLegacy(file, read = readFileSync) {
|
|
8
|
+
let raw;
|
|
9
|
+
try { raw = read(file, 'utf8'); }
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error.code === 'ENOENT') throw new Error('No MCP credentials. Use a full key and explicit API URL in the client environment, or an existing nixflex login file.');
|
|
12
|
+
throw new Error('Cannot read the Nixflex credential file; no fallback was used.');
|
|
13
|
+
}
|
|
14
|
+
let cfg;
|
|
15
|
+
try { cfg = JSON.parse(raw); } catch { throw new Error('Malformed Nixflex credential file; no fallback was used.'); }
|
|
16
|
+
if (!cfg || typeof cfg !== 'object' || Array.isArray(cfg))
|
|
17
|
+
throw new Error('Invalid Nixflex credential file.');
|
|
18
|
+
return cfg;
|
|
19
|
+
}
|
|
20
|
+
export function resolveConnection({ env = process.env, home = homedir(), read = readFileSync } = {}) {
|
|
21
|
+
const source = env.NIXFLEX_CREDENTIAL_SOURCE || (env.NIXFLEX_API_KEY ? 'environment' : 'legacy');
|
|
22
|
+
if (!['environment', 'legacy'].includes(source)) throw new Error('Invalid MCP credential source.');
|
|
23
|
+
let key, baseUrl, configFile;
|
|
24
|
+
if (source === 'environment') {
|
|
25
|
+
if (env.NIXFLEX_PROFILE) throw new Error('Choose an environment pair or a legacy profile, not both.');
|
|
26
|
+
if (!env.NIXFLEX_BASE_URL) throw new Error('NIXFLEX_BASE_URL is required with an environment key; no production default was used.');
|
|
27
|
+
key = env.NIXFLEX_API_KEY;
|
|
28
|
+
baseUrl = approvedOrigin(env.NIXFLEX_BASE_URL);
|
|
29
|
+
} else {
|
|
30
|
+
configFile = env.NIXFLEX_CONFIG_FILE || join(home, '.nixflex', 'config.json');
|
|
31
|
+
if (!isAbsolute(configFile)) throw new Error('NIXFLEX_CONFIG_FILE must be an absolute path.');
|
|
32
|
+
let cfg = readLegacy(configFile, read);
|
|
33
|
+
if (env.NIXFLEX_PROFILE) {
|
|
34
|
+
const name = env.NIXFLEX_PROFILE;
|
|
35
|
+
if (!/^[a-zA-Z0-9_-]{1,64}$/.test(name) || !cfg.profiles ||
|
|
36
|
+
!Object.hasOwn(cfg.profiles, name) || !cfg.profiles[name]?.base_url)
|
|
37
|
+
throw new Error('Legacy MCP profile missing or has no explicit API URL; no fallback was used.');
|
|
38
|
+
cfg = cfg.profiles[name];
|
|
39
|
+
}
|
|
40
|
+
key = cfg.api_key;
|
|
41
|
+
baseUrl = approvedOrigin(cfg.base_url === undefined ? APPROVED_ORIGINS[0] : cfg.base_url);
|
|
42
|
+
if (env.NIXFLEX_BASE_URL && approvedOrigin(env.NIXFLEX_BASE_URL) !== baseUrl)
|
|
43
|
+
throw new Error('MCP credential file destination changed or conflicts with this installation; refusing to retarget the key.');
|
|
44
|
+
}
|
|
45
|
+
if (typeof key !== 'string' || !/^nxf_[a-z0-9]+:nxfs_[a-z0-9]+$/i.test(key))
|
|
46
|
+
throw new Error('Missing or invalid full MCP API key. No request was sent.');
|
|
47
|
+
return { key, baseUrl, source, configFile, profile: env.NIXFLEX_PROFILE };
|
|
48
|
+
}
|
package/foundation/launch.mjs
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
// Shared, secret-free builders. Keep byte-identical in MCP and CLI.
|
|
2
|
-
import { approvedOrigin } from './origins.mjs';
|
|
3
|
-
export const SUPPORTED_CLIENTS = Object.freeze(['claude', 'claude-code', 'codex', 'cursor']);
|
|
4
|
-
export function buildServerConfig({ client, platform, version, baseUrl, source = 'environment', configFile, profile }) {
|
|
5
|
-
if (!SUPPORTED_CLIENTS.includes(client)) throw new Error('Supported tools: Claude Desktop, Claude Code, Codex and Cursor. VS Code setup is retired.');
|
|
6
|
-
if (!['win32', 'darwin', 'linux'].includes(platform) || (client === 'claude' && platform === 'linux'))
|
|
7
|
-
throw new Error('This client/platform combination is not supported.');
|
|
8
|
-
if (typeof version !== 'string' || version !== version.trim() || !/^\d+\.\d+\.\d+$/.test(version)) throw new Error('MCP launch requires a fixed release version.');
|
|
9
|
-
if (!['environment', 'legacy'].includes(source)) throw new Error('Invalid credential source.');
|
|
10
|
-
const origin = approvedOrigin(baseUrl);
|
|
11
|
-
const env = { NIXFLEX_CREDENTIAL_SOURCE: source, NIXFLEX_BASE_URL: origin };
|
|
12
|
-
if (source === 'legacy') {
|
|
13
|
-
if (typeof configFile !== 'string' || !configFile || /[\r\n]/.test(configFile)) throw new Error('Missing credential file path.');
|
|
14
|
-
env.NIXFLEX_CONFIG_FILE = configFile;
|
|
15
|
-
if (profile) {
|
|
16
|
-
if (!/^[a-zA-Z0-9_-]{1,64}$/.test(profile)) throw new Error('Invalid profile name.');
|
|
17
|
-
env.NIXFLEX_PROFILE = profile;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
const entry = platform === 'win32'
|
|
21
|
-
? { command: 'cmd.exe', args: ['/d', '/s', '/c', 'npx -y nixflex-mcp@' + version], env }
|
|
22
|
-
: { command: 'npx', args: ['-y', 'nixflex-mcp@' + version], env };
|
|
23
|
-
if (source === 'environment' && client === 'cursor') env.NIXFLEX_API_KEY = '${env:NIXFLEX_API_KEY}';
|
|
24
|
-
if (source === 'environment' && client === 'codex') entry.env_vars = ['NIXFLEX_API_KEY'];
|
|
25
|
-
return entry;
|
|
26
|
-
}
|
|
27
|
-
export function serverName(baseUrl) {
|
|
28
|
-
return approvedOrigin(baseUrl) === 'https://api.nixflex.com' ? 'nixflex' : 'nixflex-staging';
|
|
29
|
-
}
|
|
30
|
-
export function configSnippet(options) {
|
|
31
|
-
const entry = buildServerConfig(options), name = serverName(options.baseUrl);
|
|
32
|
-
if (options.client !== 'codex') return JSON.stringify({ mcpServers: { [name]: entry } }, null, 2) + '\n';
|
|
33
|
-
const lines = ['[mcp_servers.' + name + ']', 'command = ' + JSON.stringify(entry.command),
|
|
34
|
-
'args = ' + JSON.stringify(entry.args), 'startup_timeout_sec = 30'];
|
|
35
|
-
if (entry.env_vars) lines.push('env_vars = ' + JSON.stringify(entry.env_vars));
|
|
36
|
-
lines.push('', '[mcp_servers.' + name + '.env]');
|
|
37
|
-
for (const [key, value] of Object.entries(entry.env)) lines.push(key + ' = ' + JSON.stringify(value));
|
|
38
|
-
return lines.join('\n') + '\n';
|
|
39
|
-
}
|
|
1
|
+
// Shared, secret-free builders. Keep byte-identical in MCP and CLI.
|
|
2
|
+
import { approvedOrigin } from './origins.mjs';
|
|
3
|
+
export const SUPPORTED_CLIENTS = Object.freeze(['claude', 'claude-code', 'codex', 'cursor']);
|
|
4
|
+
export function buildServerConfig({ client, platform, version, baseUrl, source = 'environment', configFile, profile }) {
|
|
5
|
+
if (!SUPPORTED_CLIENTS.includes(client)) throw new Error('Supported tools: Claude Desktop, Claude Code, Codex and Cursor. VS Code setup is retired.');
|
|
6
|
+
if (!['win32', 'darwin', 'linux'].includes(platform) || (client === 'claude' && platform === 'linux'))
|
|
7
|
+
throw new Error('This client/platform combination is not supported.');
|
|
8
|
+
if (typeof version !== 'string' || version !== version.trim() || !/^\d+\.\d+\.\d+$/.test(version)) throw new Error('MCP launch requires a fixed release version.');
|
|
9
|
+
if (!['environment', 'legacy'].includes(source)) throw new Error('Invalid credential source.');
|
|
10
|
+
const origin = approvedOrigin(baseUrl);
|
|
11
|
+
const env = { NIXFLEX_CREDENTIAL_SOURCE: source, NIXFLEX_BASE_URL: origin };
|
|
12
|
+
if (source === 'legacy') {
|
|
13
|
+
if (typeof configFile !== 'string' || !configFile || /[\r\n]/.test(configFile)) throw new Error('Missing credential file path.');
|
|
14
|
+
env.NIXFLEX_CONFIG_FILE = configFile;
|
|
15
|
+
if (profile) {
|
|
16
|
+
if (!/^[a-zA-Z0-9_-]{1,64}$/.test(profile)) throw new Error('Invalid profile name.');
|
|
17
|
+
env.NIXFLEX_PROFILE = profile;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const entry = platform === 'win32'
|
|
21
|
+
? { command: 'cmd.exe', args: ['/d', '/s', '/c', 'npx -y nixflex-mcp@' + version], env }
|
|
22
|
+
: { command: 'npx', args: ['-y', 'nixflex-mcp@' + version], env };
|
|
23
|
+
if (source === 'environment' && client === 'cursor') env.NIXFLEX_API_KEY = '${env:NIXFLEX_API_KEY}';
|
|
24
|
+
if (source === 'environment' && client === 'codex') entry.env_vars = ['NIXFLEX_API_KEY'];
|
|
25
|
+
return entry;
|
|
26
|
+
}
|
|
27
|
+
export function serverName(baseUrl) {
|
|
28
|
+
return approvedOrigin(baseUrl) === 'https://api.nixflex.com' ? 'nixflex' : 'nixflex-staging';
|
|
29
|
+
}
|
|
30
|
+
export function configSnippet(options) {
|
|
31
|
+
const entry = buildServerConfig(options), name = serverName(options.baseUrl);
|
|
32
|
+
if (options.client !== 'codex') return JSON.stringify({ mcpServers: { [name]: entry } }, null, 2) + '\n';
|
|
33
|
+
const lines = ['[mcp_servers.' + name + ']', 'command = ' + JSON.stringify(entry.command),
|
|
34
|
+
'args = ' + JSON.stringify(entry.args), 'startup_timeout_sec = 30'];
|
|
35
|
+
if (entry.env_vars) lines.push('env_vars = ' + JSON.stringify(entry.env_vars));
|
|
36
|
+
lines.push('', '[mcp_servers.' + name + '.env]');
|
|
37
|
+
for (const [key, value] of Object.entries(entry.env)) lines.push(key + ' = ' + JSON.stringify(value));
|
|
38
|
+
return lines.join('\n') + '\n';
|
|
39
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
// Isolated MCP process only: even the installed SDK must never follow redirects.
|
|
2
|
-
export function installOriginFence(baseUrl, version) {
|
|
3
|
-
const original = globalThis.fetch;
|
|
4
|
-
globalThis.fetch = (input, options = {}) => {
|
|
5
|
-
const target = new URL(typeof input === 'string' || input instanceof URL ? input : input.url);
|
|
6
|
-
if (target.origin !== baseUrl || !target.pathname.startsWith('/v1/'))
|
|
7
|
-
throw new Error('MCP request destination refused.');
|
|
8
|
-
const headers = new Headers(options.headers);
|
|
9
|
-
if (version) headers.set('User-Agent', 'nixflex-mcp/' + version);
|
|
10
|
-
const signal = AbortSignal.any([AbortSignal.timeout(30000), ...(options.signal ? [options.signal] : [])]);
|
|
11
|
-
return (async () => {
|
|
12
|
-
const response = await original(input, { ...options, headers, signal, redirect: 'error' });
|
|
13
|
-
// Also bound old SDK response-body reads, and bridge its legacy request-ID header.
|
|
14
|
-
const bytes = response.status === 204 ? null : await response.arrayBuffer();
|
|
15
|
-
const resultHeaders = new Headers(response.headers);
|
|
16
|
-
if (resultHeaders.has('x-request-id')) resultHeaders.set('x-railway-request-id', resultHeaders.get('x-request-id'));
|
|
17
|
-
return new Response(bytes, { status: response.status, statusText: response.statusText, headers: resultHeaders });
|
|
18
|
-
})();
|
|
19
|
-
};
|
|
20
|
-
return () => { globalThis.fetch = original; };
|
|
21
|
-
}
|
|
1
|
+
// Isolated MCP process only: even the installed SDK must never follow redirects.
|
|
2
|
+
export function installOriginFence(baseUrl, version) {
|
|
3
|
+
const original = globalThis.fetch;
|
|
4
|
+
globalThis.fetch = (input, options = {}) => {
|
|
5
|
+
const target = new URL(typeof input === 'string' || input instanceof URL ? input : input.url);
|
|
6
|
+
if (target.origin !== baseUrl || !target.pathname.startsWith('/v1/'))
|
|
7
|
+
throw new Error('MCP request destination refused.');
|
|
8
|
+
const headers = new Headers(options.headers);
|
|
9
|
+
if (version) headers.set('User-Agent', 'nixflex-mcp/' + version);
|
|
10
|
+
const signal = AbortSignal.any([AbortSignal.timeout(30000), ...(options.signal ? [options.signal] : [])]);
|
|
11
|
+
return (async () => {
|
|
12
|
+
const response = await original(input, { ...options, headers, signal, redirect: 'error' });
|
|
13
|
+
// Also bound old SDK response-body reads, and bridge its legacy request-ID header.
|
|
14
|
+
const bytes = response.status === 204 ? null : await response.arrayBuffer();
|
|
15
|
+
const resultHeaders = new Headers(response.headers);
|
|
16
|
+
if (resultHeaders.has('x-request-id')) resultHeaders.set('x-railway-request-id', resultHeaders.get('x-request-id'));
|
|
17
|
+
return new Response(bytes, { status: response.status, statusText: response.statusText, headers: resultHeaders });
|
|
18
|
+
})();
|
|
19
|
+
};
|
|
20
|
+
return () => { globalThis.fetch = original; };
|
|
21
|
+
}
|
package/foundation/origins.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
// Pure policy: safe to reuse in dashboard snippet generation (no Node imports).
|
|
2
|
-
export const APPROVED_ORIGINS = Object.freeze([
|
|
3
|
-
'https://api.nixflex.com',
|
|
4
|
-
'https://nixflex-voice-engine-staging.up.railway.app',
|
|
5
|
-
]);
|
|
6
|
-
export function approvedOrigin(value) {
|
|
7
|
-
if (typeof value !== 'string' || value !== value.trim() || /[\\\s]/.test(value))
|
|
8
|
-
throw new Error('MCP API destination must be an approved HTTPS Nixflex origin.');
|
|
9
|
-
let url;
|
|
10
|
-
try { url = new URL(value); } catch { throw new Error('Invalid MCP API destination.'); }
|
|
11
|
-
if (url.username || url.password || url.search || url.hash || url.pathname !== '/' ||
|
|
12
|
-
!APPROVED_ORIGINS.includes(url.origin))
|
|
13
|
-
throw new Error('MCP API destination must be an approved HTTPS Nixflex origin.');
|
|
14
|
-
return url.origin;
|
|
15
|
-
}
|
|
1
|
+
// Pure policy: safe to reuse in dashboard snippet generation (no Node imports).
|
|
2
|
+
export const APPROVED_ORIGINS = Object.freeze([
|
|
3
|
+
'https://api.nixflex.com',
|
|
4
|
+
'https://nixflex-voice-engine-staging.up.railway.app',
|
|
5
|
+
]);
|
|
6
|
+
export function approvedOrigin(value) {
|
|
7
|
+
if (typeof value !== 'string' || value !== value.trim() || /[\\\s]/.test(value))
|
|
8
|
+
throw new Error('MCP API destination must be an approved HTTPS Nixflex origin.');
|
|
9
|
+
let url;
|
|
10
|
+
try { url = new URL(value); } catch { throw new Error('Invalid MCP API destination.'); }
|
|
11
|
+
if (url.username || url.password || url.search || url.hash || url.pathname !== '/' ||
|
|
12
|
+
!APPROVED_ORIGINS.includes(url.origin))
|
|
13
|
+
throw new Error('MCP API destination must be an approved HTTPS Nixflex origin.');
|
|
14
|
+
return url.origin;
|
|
15
|
+
}
|
package/index.js
CHANGED
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// ============================================
|
|
3
|
-
// nixflex-mcp - the Nixflex MCP server (stdio).
|
|
4
|
-
//
|
|
5
|
-
// Supported clients: Claude Desktop, Claude Code, Codex and Cursor.
|
|
6
|
-
// See README.md for OS-specific, pinned setup; never put a key in a snippet.
|
|
7
|
-
//
|
|
8
|
-
// Mutation tools use the official SDK. Group2 number reads have a GET-only adapter
|
|
9
|
-
// for installed SDK 0.8.0 until the new SDK is published. The same code the CLI
|
|
10
|
-
// and the docs use, so a tool can never do something the API does not. Coverage mirrors
|
|
11
|
-
// the CLI 1:1; tests/tools.test.mjs pins the tool count.
|
|
12
|
-
// STDIO RULE: never write to stdout. stdout IS the protocol. All logging goes to stderr.
|
|
13
|
-
// SAFETY: delete/rotate tools require confirm: true and return a preview otherwise.
|
|
14
|
-
// All mutations have destructive hints; hints alone do not add a confirmation gate.
|
|
15
|
-
// There is no delete-all tool. Spending tools (create_call, create_campaign, send_sms,
|
|
16
|
-
// create_sms_campaign) say so in their description and need every field spelled out.
|
|
17
|
-
// GENERIC FIELDS: update/create tools take a `fields` object passed straight to the API,
|
|
18
|
-
// so a new API field needs no server update (same rule as the CLI's --set).
|
|
19
|
-
// LISTS ARE SUMMARIES: list_calls strips transcripts and analysis - use get_call for one
|
|
20
|
-
// call in full. Full transcripts in a list blew the context in the first live audit.
|
|
21
|
-
// ============================================
|
|
22
|
-
import { McpServer } from '@modelcontextprotocol/server';
|
|
23
|
-
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
24
|
-
import * as z from 'zod/v4';
|
|
25
|
-
import Nixflex from 'nixflex';
|
|
26
|
-
import { registerOrganisationTools, organisationRequest } from './organisation-tools.js';
|
|
27
|
-
import { registerCoreTools } from './core-tools.js';
|
|
28
|
-
import { registerC6Tools } from './c6-tools.js';
|
|
29
|
-
import { registerKnowledgeTools } from './knowledge-tools.js';
|
|
30
|
-
import { registerK6Tools } from './k6-tools.js';
|
|
31
|
-
import { registerK7Tools } from './k7-tools.js';
|
|
32
|
-
import { registerK7CreateCall } from './k7-call.js';
|
|
33
|
-
import { registerK9Deletes, contentDeleteRequest } from './k9-deletes.js';
|
|
34
|
-
import { knowledgeRequest } from './knowledge-request.js';
|
|
35
|
-
import { privateWebhookRead } from './c6-output.js';
|
|
36
|
-
import { registerC5Tools } from './c5-tools.js';
|
|
37
|
-
import { kitRequest } from './kit-request.js';
|
|
38
|
-
import { contactLocation, voiceCampaignSchema, smsCampaignSchema, campaignBody, smsListSchema, smsDetailSchema } from './campaign-schema.js';
|
|
39
|
-
import { executeTool, errorBody } from './safe-tools.js';
|
|
40
|
-
import { numberReads } from './number-reads.js';
|
|
41
|
-
import { numberReadSchema, numberFields } from './number-schema.js';
|
|
42
|
-
import { agentCreateFields, agentUpdateFields } from './agent-schema.js';
|
|
43
|
-
import { agentReads, agentListSchema } from './agent-reads.js';
|
|
44
|
-
import { createCallBody, summariseCall as callSummary } from './call-tools.js';
|
|
45
|
-
import { callReads, callListSchema, callGetSchema } from './call-reads.js';
|
|
46
|
-
import { readFileSync } from 'node:fs';
|
|
47
|
-
import { resolveConnection } from './foundation/connection.mjs';
|
|
48
|
-
import { installOriginFence } from './foundation/origin-fence.mjs';
|
|
49
|
-
import { toolMetadata } from './foundation/tool-metadata.mjs';
|
|
50
|
-
|
|
51
|
-
const VERSION = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version;
|
|
52
|
-
const log = (...a) => process.stderr.write('[nixflex-mcp] ' + a.join(' ') + '\n');
|
|
53
|
-
|
|
54
|
-
let connection;
|
|
55
|
-
try { connection = resolveConnection(); }
|
|
56
|
-
catch (error) {
|
|
57
|
-
await new Promise(resolve => process.stderr.write('[nixflex-mcp] ' + error.message + '\n', resolve));
|
|
58
|
-
process.exit(2);
|
|
59
|
-
}
|
|
60
|
-
const { key, baseUrl, source } = connection;
|
|
61
|
-
installOriginFence(baseUrl, VERSION);
|
|
62
|
-
const request = kitRequest(key, baseUrl);
|
|
63
|
-
const client = new Nixflex({ apiKey: key, baseUrl, maxRetries: 0 });
|
|
64
|
-
const readNumbers = numberReads(key, baseUrl);
|
|
65
|
-
const readAgents = agentReads(key, baseUrl);
|
|
66
|
-
const readCalls = callReads(key, baseUrl);
|
|
67
|
-
|
|
68
|
-
// ---- helpers ----
|
|
69
|
-
const text = (data) => ({ content: [{ type: 'text', text: typeof data === 'string' ? data : JSON.stringify(data, null, 2) }] });
|
|
70
|
-
const fail = (e) => {
|
|
71
|
-
const body = errorBody(e);
|
|
72
|
-
return { content: [{ type: 'text', text: JSON.stringify(body, null, 2) }], isError: true };
|
|
73
|
-
};
|
|
74
|
-
const run = (name, fn) => async (args) => { try { return text(await executeTool(name, fn, args)); } catch (e) { return fail(e); } };
|
|
75
|
-
const E164 = z.string().regex(/^\+[1-9]\d{6,14}$/, 'E.164 number, e.g. +447700900123');
|
|
76
|
-
const fields = z.record(z.string(), z.unknown()).describe('Any fields the API accepts, passed as-is. Unknown names are rejected by the API, never dropped silently.');
|
|
77
|
-
const confirmArg = z.boolean().optional().describe('Required true to actually do it. Without it the tool returns a preview and changes nothing.');
|
|
78
|
-
const preview = async (what, fetch) => { let current = null; try { current = await fetch(); } catch { /* preview */ } return { would_delete: what, current, hint: 'Call again with confirm: true.' }; };
|
|
79
|
-
const summariseCall = callSummary;
|
|
80
|
-
|
|
81
|
-
const server = new McpServer({ name: 'nixflex', version: VERSION });
|
|
82
|
-
// Client hints, never authorization or a guarantee that the client asks permission.
|
|
83
|
-
const T = (name, description, schema, fn) => server.registerTool(name, { ...toolMetadata(name, description), inputSchema: schema }, run(name, fn));
|
|
84
|
-
|
|
85
|
-
// ============ account ============
|
|
86
|
-
T('get_usage', 'Usage and balance for this account.', z.object({}), () => client.usage.get());
|
|
87
|
-
T('rotate_api_key', 'Replace the API secret. The current secret stops working immediately - every integration must be updated. Requires confirm: true.',
|
|
88
|
-
z.object({ confirm: confirmArg }), async ({ confirm }) => confirm ? client.keys.rotate() : { would_rotate: key.split(':')[0], warning: 'The current secret stops working the moment this runs.', hint: 'Call again with confirm: true.' });
|
|
89
|
-
|
|
90
|
-
// ============ agents ============
|
|
91
|
-
T('list_agents', 'List the agents on this account. Phone numbers, webhooks and integrations are attached per NUMBER, not per agent - use list_phone_numbers to see them.',
|
|
92
|
-
agentListSchema, readAgents);
|
|
93
|
-
T('get_agent', 'One agent with its prompt and settings.', z.object({ agent_id: z.string() }), ({ agent_id }) => client.agents.get(agent_id));
|
|
94
|
-
T('create_agent', 'Create an agent. All fields are optional. New defaults: maximum call 300 seconds, silence hang-up 10 seconds, dynamic greeting on; any other agent field (voice_id, language, incall_sms_enabled, silence_hangup_seconds, record_call, recording_source = provider or nixflex, ...) goes in fields.',
|
|
95
|
-
z.object({ name: z.string().optional(), system_prompt: z.string().optional(), fields: agentCreateFields.optional() }), ({ name, system_prompt, fields: f }) => client.agents.create({ name, system_prompt, ...(f || {}) }));
|
|
96
|
-
T('update_agent', 'Update an agent. Empty/unknown-only updates fail; mixed unknown keys return warnings. Only passed fields change. Pass null only to clear nullable fields.',
|
|
97
|
-
z.object({ agent_id: z.string(), fields: agentUpdateFields }), ({ agent_id, fields: f }) => client.agents.update(agent_id, f));
|
|
98
|
-
T('delete_agent', 'Soft disable an agent, not permanent deletion. Does not detach numbers or erase history. Requires confirm: true; otherwise returns a preview.',
|
|
99
|
-
z.object({ agent_id: z.string(), confirm: confirmArg }), async ({ agent_id, confirm }) => confirm ? client.agents.delete(agent_id) : preview('agent ' + agent_id, () => client.agents.get(agent_id)));
|
|
100
|
-
|
|
101
|
-
// ============ calls ============
|
|
102
|
-
registerK7CreateCall(server, {client, request, metadata:toolMetadata, E164, contactLocation});
|
|
103
|
-
T('list_calls', 'Call summaries without transcript. history:true adds dashboard filters, totals and next_cursor; continue with cursor + limit only. period defaults month; today uses UTC, or pass exact since/until from dashboard.',
|
|
104
|
-
callListSchema, args => readCalls.list(args, summariseCall));
|
|
105
|
-
T('get_call', 'One call. Optional view: detail (nullable retained data), recording (status + link with expires_at; never fetch customer storage). No view preserves the legacy read.', callGetSchema, readCalls.one);
|
|
106
|
-
|
|
107
|
-
// ============ campaigns (voice batch) ============
|
|
108
|
-
T('create_campaign', 'Create an outbound voice campaign - many calls, one prompt. SPENDS credit when launched. Each recipient: { phone, variables?, prompt_override? }. Scheduling fields go in fields.',
|
|
109
|
-
voiceCampaignSchema, args => client.campaigns.create(campaignBody(args)));
|
|
110
|
-
T('launch_campaign', 'Launch a created campaign (starts dialling).', z.object({ campaign_id: z.string() }), ({ campaign_id }) => client.campaigns.launch(campaign_id));
|
|
111
|
-
|
|
112
|
-
// ============ phone numbers ============
|
|
113
|
-
T('list_phone_numbers', 'Read public numbers with optional agent/provider filters and cursor pagination, or phone_number for safe settings. Add usage:true with phone_number for call/SMS/web usage; optional period and time_zone (default all/UTC). Retained history, not a billing ledger; unused means no calls and no SMS. Webhooks, calendar and custom functions are configured per number.',
|
|
114
|
-
numberReadSchema, readNumbers);
|
|
115
|
-
T('import_phone_number', 'Attach a number you own at Twilio or Telnyx to an agent. Needs carrier credentials in fields (twilio_sid + twilio_token, or telnyx_api_key + telnyx_connection_id).',
|
|
116
|
-
z.object({ phone_number: E164, agent_id: z.string(), fields }), ({ fields: f, ...rest }) => client.phoneNumbers.import({ ...rest, ...f }));
|
|
117
|
-
T('update_phone_number', 'Update saved settings and seven boolean switches, or send fields:{agent_id:ID} ALONE to move to an active agent of this account. Busy calls/replies/campaigns/number operations refuse a move. The number keeps its own settings/functions/history; shared agent settings change. Website voice needs Web agent enabled; monitoring eligibility alone does not start listening. Only passed fields change; null clears only nullable overrides.',
|
|
118
|
-
z.object({ phone_number: E164, fields: numberFields }), ({ phone_number, fields: f }) => client.phoneNumbers.update(phone_number, f));
|
|
119
|
-
T('delete_phone_number', 'Disconnect a number from Nixflex (the carrier keeps it and keeps billing it). Requires confirm: true.',
|
|
120
|
-
z.object({ phone_number: E164, confirm: confirmArg }), async ({ phone_number, confirm }) => confirm ? client.phoneNumbers.delete(phone_number) : { would_delete: 'number ' + phone_number + ' from Nixflex', hint: 'Call again with confirm: true.' });
|
|
121
|
-
T('set_number_web_calls', 'Turn browser (web) calls on or off for a number.',
|
|
122
|
-
z.object({ phone_number: E164, enabled: z.boolean() }), ({ phone_number, enabled }) => client.phoneNumbers.setWebCalls(phone_number, enabled));
|
|
123
|
-
|
|
124
|
-
// ============ caller context ============
|
|
125
|
-
T('get_caller_context', 'What the agent knows about a caller on one of your numbers. phone_number is YOUR number; caller_number is the customer.',
|
|
126
|
-
z.object({ phone_number: E164, caller_number: E164 }), ({ phone_number, caller_number }) => client.callers.get(phone_number, caller_number));
|
|
127
|
-
T('set_caller_context', 'Set what the agent should know about a caller: name (full), email, phone, location, reference_id, preference. Omitted fields are kept; null removes one. last_call and open_item are engine-only.',
|
|
128
|
-
z.object({ phone_number: E164, caller_number: E164, name: z.string().nullable().optional(), email: z.string().nullable().optional(), phone: z.string().nullable().optional(), location: z.string().nullable().optional(), reference_id: z.string().nullable().optional(), preference: z.string().nullable().optional() }),
|
|
129
|
-
({ phone_number, caller_number, ...f }) => client.callers.set(phone_number, caller_number, f));
|
|
130
|
-
T('import_caller_context', 'Load up to 1,000 caller records onto one of your numbers in one go. Every row is validated before any is written.',
|
|
131
|
-
z.object({ phone_number: E164, callers: z.array(z.object({ caller_number: E164, name: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), location: z.string().optional(), reference_id: z.string().optional(), preference: z.string().optional() })).min(1).max(1000) }),
|
|
132
|
-
({ phone_number, callers }) => client.callers.import(phone_number, callers));
|
|
133
|
-
T('delete_caller_context', 'Erase everything known about a caller on one of your numbers. Requires confirm: true.',
|
|
134
|
-
z.object({ phone_number: E164, caller_number: E164, confirm: confirmArg }), async ({ phone_number, caller_number, confirm }) => confirm ? client.callers.delete(phone_number, caller_number) : preview('caller ' + caller_number + ' on ' + phone_number, async () => (await client.callers.get(phone_number, caller_number)).caller));
|
|
135
|
-
|
|
136
|
-
// ============ sms ============
|
|
137
|
-
T('send_sms', 'Send one text from one of your numbers. SPENDS carrier credit.',
|
|
138
|
-
z.object({ agent_id: z.string(), from_number: E164, to: E164, message: z.string(), context: z.object({reply_context:z.string().optional()}).optional(), ...contactLocation }), (a) => client.sms.send(a));
|
|
139
|
-
T('create_sms_campaign', 'Create a bulk SMS campaign. SPENDS carrier credit when launched. Each recipient: { phone, variables? } - variables fill {{placeholders}} in the message.',
|
|
140
|
-
smsCampaignSchema, args => request('POST', '/sms/campaigns', campaignBody(args)));
|
|
141
|
-
T('launch_sms_campaign', 'Launch a created SMS campaign.', z.object({ campaign_id: z.string() }), ({ campaign_id }) => client.sms.campaigns.launch(campaign_id));
|
|
142
|
-
T('list_sms_campaigns', 'SMS campaigns, newest first; use next_cursor as before for the next page.', smsListSchema, args => request('GET','/sms/campaigns',undefined,args));
|
|
143
|
-
T('get_sms_campaign', 'Campaign, recipients, messages and independent pagination cursors. Sent is distinct from delivered and failed.', smsDetailSchema, ({campaign_id,...query}) => request('GET','/sms/campaigns/'+encodeURIComponent(campaign_id),undefined,query));
|
|
144
|
-
|
|
145
|
-
// ============ webhooks (per number) ============
|
|
146
|
-
T('set_webhook', 'Set the post-call webhook URL on a number (slot 1 or 2). Payloads use the organisation signing secret, independent of API-key rotation.',
|
|
147
|
-
z.object({ phone_number: E164, url: z.string().url(), slot: z.union([z.literal(1), z.literal(2)]).optional() }), ({ phone_number, url, slot }) => client.webhooks.set(phone_number, url, slot || 1));
|
|
148
|
-
T('get_webhook', 'The webhook URL configured on a number.', z.object({ phone_number: E164, slot: z.union([z.literal(1), z.literal(2)]).optional() }), ({ phone_number, slot }) => privateWebhookRead(() => client.webhooks.get(phone_number, slot || 1)));
|
|
149
|
-
T('delete_webhook', 'Remove the webhook URL from a number. Requires confirm: true.',
|
|
150
|
-
z.object({ phone_number: E164, slot: z.union([z.literal(1), z.literal(2)]).optional(), confirm: confirmArg }), async ({ phone_number, slot, confirm }) => confirm ? client.webhooks.delete(phone_number, slot || 1) : preview('webhook slot ' + (slot || 1) + ' on ' + phone_number, () => privateWebhookRead(() => client.webhooks.get(phone_number, slot || 1))));
|
|
151
|
-
|
|
152
|
-
// Organisation tools are part of this one main install.
|
|
153
|
-
registerOrganisationTools(server, organisationRequest(key, baseUrl));
|
|
154
|
-
registerCoreTools(server, request);
|
|
155
|
-
registerC5Tools(server, request);
|
|
156
|
-
registerC6Tools(server, request);
|
|
157
|
-
registerKnowledgeTools(server, knowledgeRequest(key, baseUrl));
|
|
158
|
-
registerK6Tools(server, request);
|
|
159
|
-
registerK7Tools(server, request);
|
|
160
|
-
registerK9Deletes(server, contentDeleteRequest(key, baseUrl));
|
|
161
|
-
|
|
162
|
-
// ---- start ----
|
|
163
|
-
const transport = new StdioServerTransport();
|
|
164
|
-
await server.connect(transport);
|
|
165
|
-
log('ready v' + VERSION + ' source=' + source + ' api=' + baseUrl);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// ============================================
|
|
3
|
+
// nixflex-mcp - the Nixflex MCP server (stdio).
|
|
4
|
+
//
|
|
5
|
+
// Supported clients: Claude Desktop, Claude Code, Codex and Cursor.
|
|
6
|
+
// See README.md for OS-specific, pinned setup; never put a key in a snippet.
|
|
7
|
+
//
|
|
8
|
+
// Mutation tools use the official SDK. Group2 number reads have a GET-only adapter
|
|
9
|
+
// for installed SDK 0.8.0 until the new SDK is published. The same code the CLI
|
|
10
|
+
// and the docs use, so a tool can never do something the API does not. Coverage mirrors
|
|
11
|
+
// the CLI 1:1; tests/tools.test.mjs pins the tool count.
|
|
12
|
+
// STDIO RULE: never write to stdout. stdout IS the protocol. All logging goes to stderr.
|
|
13
|
+
// SAFETY: delete/rotate tools require confirm: true and return a preview otherwise.
|
|
14
|
+
// All mutations have destructive hints; hints alone do not add a confirmation gate.
|
|
15
|
+
// There is no delete-all tool. Spending tools (create_call, create_campaign, send_sms,
|
|
16
|
+
// create_sms_campaign) say so in their description and need every field spelled out.
|
|
17
|
+
// GENERIC FIELDS: update/create tools take a `fields` object passed straight to the API,
|
|
18
|
+
// so a new API field needs no server update (same rule as the CLI's --set).
|
|
19
|
+
// LISTS ARE SUMMARIES: list_calls strips transcripts and analysis - use get_call for one
|
|
20
|
+
// call in full. Full transcripts in a list blew the context in the first live audit.
|
|
21
|
+
// ============================================
|
|
22
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
23
|
+
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
24
|
+
import * as z from 'zod/v4';
|
|
25
|
+
import Nixflex from 'nixflex';
|
|
26
|
+
import { registerOrganisationTools, organisationRequest } from './organisation-tools.js';
|
|
27
|
+
import { registerCoreTools } from './core-tools.js';
|
|
28
|
+
import { registerC6Tools } from './c6-tools.js';
|
|
29
|
+
import { registerKnowledgeTools } from './knowledge-tools.js';
|
|
30
|
+
import { registerK6Tools } from './k6-tools.js';
|
|
31
|
+
import { registerK7Tools } from './k7-tools.js';
|
|
32
|
+
import { registerK7CreateCall } from './k7-call.js';
|
|
33
|
+
import { registerK9Deletes, contentDeleteRequest } from './k9-deletes.js';
|
|
34
|
+
import { knowledgeRequest } from './knowledge-request.js';
|
|
35
|
+
import { privateWebhookRead } from './c6-output.js';
|
|
36
|
+
import { registerC5Tools } from './c5-tools.js';
|
|
37
|
+
import { kitRequest } from './kit-request.js';
|
|
38
|
+
import { contactLocation, voiceCampaignSchema, smsCampaignSchema, campaignBody, smsListSchema, smsDetailSchema } from './campaign-schema.js';
|
|
39
|
+
import { executeTool, errorBody } from './safe-tools.js';
|
|
40
|
+
import { numberReads } from './number-reads.js';
|
|
41
|
+
import { numberReadSchema, numberFields } from './number-schema.js';
|
|
42
|
+
import { agentCreateFields, agentUpdateFields } from './agent-schema.js';
|
|
43
|
+
import { agentReads, agentListSchema } from './agent-reads.js';
|
|
44
|
+
import { createCallBody, summariseCall as callSummary } from './call-tools.js';
|
|
45
|
+
import { callReads, callListSchema, callGetSchema } from './call-reads.js';
|
|
46
|
+
import { readFileSync } from 'node:fs';
|
|
47
|
+
import { resolveConnection } from './foundation/connection.mjs';
|
|
48
|
+
import { installOriginFence } from './foundation/origin-fence.mjs';
|
|
49
|
+
import { toolMetadata } from './foundation/tool-metadata.mjs';
|
|
50
|
+
|
|
51
|
+
const VERSION = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version;
|
|
52
|
+
const log = (...a) => process.stderr.write('[nixflex-mcp] ' + a.join(' ') + '\n');
|
|
53
|
+
|
|
54
|
+
let connection;
|
|
55
|
+
try { connection = resolveConnection(); }
|
|
56
|
+
catch (error) {
|
|
57
|
+
await new Promise(resolve => process.stderr.write('[nixflex-mcp] ' + error.message + '\n', resolve));
|
|
58
|
+
process.exit(2);
|
|
59
|
+
}
|
|
60
|
+
const { key, baseUrl, source } = connection;
|
|
61
|
+
installOriginFence(baseUrl, VERSION);
|
|
62
|
+
const request = kitRequest(key, baseUrl);
|
|
63
|
+
const client = new Nixflex({ apiKey: key, baseUrl, maxRetries: 0 });
|
|
64
|
+
const readNumbers = numberReads(key, baseUrl);
|
|
65
|
+
const readAgents = agentReads(key, baseUrl);
|
|
66
|
+
const readCalls = callReads(key, baseUrl);
|
|
67
|
+
|
|
68
|
+
// ---- helpers ----
|
|
69
|
+
const text = (data) => ({ content: [{ type: 'text', text: typeof data === 'string' ? data : JSON.stringify(data, null, 2) }] });
|
|
70
|
+
const fail = (e) => {
|
|
71
|
+
const body = errorBody(e);
|
|
72
|
+
return { content: [{ type: 'text', text: JSON.stringify(body, null, 2) }], isError: true };
|
|
73
|
+
};
|
|
74
|
+
const run = (name, fn) => async (args) => { try { return text(await executeTool(name, fn, args)); } catch (e) { return fail(e); } };
|
|
75
|
+
const E164 = z.string().regex(/^\+[1-9]\d{6,14}$/, 'E.164 number, e.g. +447700900123');
|
|
76
|
+
const fields = z.record(z.string(), z.unknown()).describe('Any fields the API accepts, passed as-is. Unknown names are rejected by the API, never dropped silently.');
|
|
77
|
+
const confirmArg = z.boolean().optional().describe('Required true to actually do it. Without it the tool returns a preview and changes nothing.');
|
|
78
|
+
const preview = async (what, fetch) => { let current = null; try { current = await fetch(); } catch { /* preview */ } return { would_delete: what, current, hint: 'Call again with confirm: true.' }; };
|
|
79
|
+
const summariseCall = callSummary;
|
|
80
|
+
|
|
81
|
+
const server = new McpServer({ name: 'nixflex', version: VERSION });
|
|
82
|
+
// Client hints, never authorization or a guarantee that the client asks permission.
|
|
83
|
+
const T = (name, description, schema, fn) => server.registerTool(name, { ...toolMetadata(name, description), inputSchema: schema }, run(name, fn));
|
|
84
|
+
|
|
85
|
+
// ============ account ============
|
|
86
|
+
T('get_usage', 'Usage and balance for this account.', z.object({}), () => client.usage.get());
|
|
87
|
+
T('rotate_api_key', 'Replace the API secret. The current secret stops working immediately - every integration must be updated. Requires confirm: true.',
|
|
88
|
+
z.object({ confirm: confirmArg }), async ({ confirm }) => confirm ? client.keys.rotate() : { would_rotate: key.split(':')[0], warning: 'The current secret stops working the moment this runs.', hint: 'Call again with confirm: true.' });
|
|
89
|
+
|
|
90
|
+
// ============ agents ============
|
|
91
|
+
T('list_agents', 'List the agents on this account. Phone numbers, webhooks and integrations are attached per NUMBER, not per agent - use list_phone_numbers to see them.',
|
|
92
|
+
agentListSchema, readAgents);
|
|
93
|
+
T('get_agent', 'One agent with its prompt and settings.', z.object({ agent_id: z.string() }), ({ agent_id }) => client.agents.get(agent_id));
|
|
94
|
+
T('create_agent', 'Create an agent. All fields are optional. New defaults: maximum call 300 seconds, silence hang-up 10 seconds, dynamic greeting on; any other agent field (voice_id, language, incall_sms_enabled, silence_hangup_seconds, record_call, recording_source = provider or nixflex, ...) goes in fields.',
|
|
95
|
+
z.object({ name: z.string().optional(), system_prompt: z.string().optional(), fields: agentCreateFields.optional() }), ({ name, system_prompt, fields: f }) => client.agents.create({ name, system_prompt, ...(f || {}) }));
|
|
96
|
+
T('update_agent', 'Update an agent. Empty/unknown-only updates fail; mixed unknown keys return warnings. Only passed fields change. Pass null only to clear nullable fields.',
|
|
97
|
+
z.object({ agent_id: z.string(), fields: agentUpdateFields }), ({ agent_id, fields: f }) => client.agents.update(agent_id, f));
|
|
98
|
+
T('delete_agent', 'Soft disable an agent, not permanent deletion. Does not detach numbers or erase history. Requires confirm: true; otherwise returns a preview.',
|
|
99
|
+
z.object({ agent_id: z.string(), confirm: confirmArg }), async ({ agent_id, confirm }) => confirm ? client.agents.delete(agent_id) : preview('agent ' + agent_id, () => client.agents.get(agent_id)));
|
|
100
|
+
|
|
101
|
+
// ============ calls ============
|
|
102
|
+
registerK7CreateCall(server, {client, request, metadata:toolMetadata, E164, contactLocation});
|
|
103
|
+
T('list_calls', 'Call summaries without transcript. history:true adds dashboard filters, totals and next_cursor; continue with cursor + limit only. period defaults month; today uses UTC, or pass exact since/until from dashboard.',
|
|
104
|
+
callListSchema, args => readCalls.list(args, summariseCall));
|
|
105
|
+
T('get_call', 'One call. Optional view: detail (nullable retained data), recording (status + link with expires_at; never fetch customer storage). No view preserves the legacy read.', callGetSchema, readCalls.one);
|
|
106
|
+
|
|
107
|
+
// ============ campaigns (voice batch) ============
|
|
108
|
+
T('create_campaign', 'Create an outbound voice campaign - many calls, one prompt. SPENDS credit when launched. Each recipient: { phone, variables?, prompt_override? }. Scheduling fields go in fields.',
|
|
109
|
+
voiceCampaignSchema, args => client.campaigns.create(campaignBody(args)));
|
|
110
|
+
T('launch_campaign', 'Launch a created campaign (starts dialling).', z.object({ campaign_id: z.string() }), ({ campaign_id }) => client.campaigns.launch(campaign_id));
|
|
111
|
+
|
|
112
|
+
// ============ phone numbers ============
|
|
113
|
+
T('list_phone_numbers', 'Read public numbers with optional agent/provider filters and cursor pagination, or phone_number for safe settings. Add usage:true with phone_number for call/SMS/web usage; optional period and time_zone (default all/UTC). Retained history, not a billing ledger; unused means no calls and no SMS. Webhooks, calendar and custom functions are configured per number.',
|
|
114
|
+
numberReadSchema, readNumbers);
|
|
115
|
+
T('import_phone_number', 'Attach a number you own at Twilio or Telnyx to an agent. Needs carrier credentials in fields (twilio_sid + twilio_token, or telnyx_api_key + telnyx_connection_id).',
|
|
116
|
+
z.object({ phone_number: E164, agent_id: z.string(), fields }), ({ fields: f, ...rest }) => client.phoneNumbers.import({ ...rest, ...f }));
|
|
117
|
+
T('update_phone_number', 'Update saved settings and seven boolean switches, or send fields:{agent_id:ID} ALONE to move to an active agent of this account. Busy calls/replies/campaigns/number operations refuse a move. The number keeps its own settings/functions/history; shared agent settings change. Website voice needs Web agent enabled; monitoring eligibility alone does not start listening. Only passed fields change; null clears only nullable overrides.',
|
|
118
|
+
z.object({ phone_number: E164, fields: numberFields }), ({ phone_number, fields: f }) => client.phoneNumbers.update(phone_number, f));
|
|
119
|
+
T('delete_phone_number', 'Disconnect a number from Nixflex (the carrier keeps it and keeps billing it). Requires confirm: true.',
|
|
120
|
+
z.object({ phone_number: E164, confirm: confirmArg }), async ({ phone_number, confirm }) => confirm ? client.phoneNumbers.delete(phone_number) : { would_delete: 'number ' + phone_number + ' from Nixflex', hint: 'Call again with confirm: true.' });
|
|
121
|
+
T('set_number_web_calls', 'Turn browser (web) calls on or off for a number.',
|
|
122
|
+
z.object({ phone_number: E164, enabled: z.boolean() }), ({ phone_number, enabled }) => client.phoneNumbers.setWebCalls(phone_number, enabled));
|
|
123
|
+
|
|
124
|
+
// ============ caller context ============
|
|
125
|
+
T('get_caller_context', 'What the agent knows about a caller on one of your numbers. phone_number is YOUR number; caller_number is the customer.',
|
|
126
|
+
z.object({ phone_number: E164, caller_number: E164 }), ({ phone_number, caller_number }) => client.callers.get(phone_number, caller_number));
|
|
127
|
+
T('set_caller_context', 'Set what the agent should know about a caller: name (full), email, phone, location, reference_id, preference. Omitted fields are kept; null removes one. last_call and open_item are engine-only.',
|
|
128
|
+
z.object({ phone_number: E164, caller_number: E164, name: z.string().nullable().optional(), email: z.string().nullable().optional(), phone: z.string().nullable().optional(), location: z.string().nullable().optional(), reference_id: z.string().nullable().optional(), preference: z.string().nullable().optional() }),
|
|
129
|
+
({ phone_number, caller_number, ...f }) => client.callers.set(phone_number, caller_number, f));
|
|
130
|
+
T('import_caller_context', 'Load up to 1,000 caller records onto one of your numbers in one go. Every row is validated before any is written.',
|
|
131
|
+
z.object({ phone_number: E164, callers: z.array(z.object({ caller_number: E164, name: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), location: z.string().optional(), reference_id: z.string().optional(), preference: z.string().optional() })).min(1).max(1000) }),
|
|
132
|
+
({ phone_number, callers }) => client.callers.import(phone_number, callers));
|
|
133
|
+
T('delete_caller_context', 'Erase everything known about a caller on one of your numbers. Requires confirm: true.',
|
|
134
|
+
z.object({ phone_number: E164, caller_number: E164, confirm: confirmArg }), async ({ phone_number, caller_number, confirm }) => confirm ? client.callers.delete(phone_number, caller_number) : preview('caller ' + caller_number + ' on ' + phone_number, async () => (await client.callers.get(phone_number, caller_number)).caller));
|
|
135
|
+
|
|
136
|
+
// ============ sms ============
|
|
137
|
+
T('send_sms', 'Send one text from one of your numbers. SPENDS carrier credit.',
|
|
138
|
+
z.object({ agent_id: z.string(), from_number: E164, to: E164, message: z.string(), context: z.object({reply_context:z.string().optional()}).optional(), ...contactLocation }), (a) => client.sms.send(a));
|
|
139
|
+
T('create_sms_campaign', 'Create a bulk SMS campaign. SPENDS carrier credit when launched. Each recipient: { phone, variables? } - variables fill {{placeholders}} in the message.',
|
|
140
|
+
smsCampaignSchema, args => request('POST', '/sms/campaigns', campaignBody(args)));
|
|
141
|
+
T('launch_sms_campaign', 'Launch a created SMS campaign.', z.object({ campaign_id: z.string() }), ({ campaign_id }) => client.sms.campaigns.launch(campaign_id));
|
|
142
|
+
T('list_sms_campaigns', 'SMS campaigns, newest first; use next_cursor as before for the next page.', smsListSchema, args => request('GET','/sms/campaigns',undefined,args));
|
|
143
|
+
T('get_sms_campaign', 'Campaign, recipients, messages and independent pagination cursors. Sent is distinct from delivered and failed.', smsDetailSchema, ({campaign_id,...query}) => request('GET','/sms/campaigns/'+encodeURIComponent(campaign_id),undefined,query));
|
|
144
|
+
|
|
145
|
+
// ============ webhooks (per number) ============
|
|
146
|
+
T('set_webhook', 'Set the post-call webhook URL on a number (slot 1 or 2). Payloads use the organisation signing secret, independent of API-key rotation.',
|
|
147
|
+
z.object({ phone_number: E164, url: z.string().url(), slot: z.union([z.literal(1), z.literal(2)]).optional() }), ({ phone_number, url, slot }) => client.webhooks.set(phone_number, url, slot || 1));
|
|
148
|
+
T('get_webhook', 'The webhook URL configured on a number.', z.object({ phone_number: E164, slot: z.union([z.literal(1), z.literal(2)]).optional() }), ({ phone_number, slot }) => privateWebhookRead(() => client.webhooks.get(phone_number, slot || 1)));
|
|
149
|
+
T('delete_webhook', 'Remove the webhook URL from a number. Requires confirm: true.',
|
|
150
|
+
z.object({ phone_number: E164, slot: z.union([z.literal(1), z.literal(2)]).optional(), confirm: confirmArg }), async ({ phone_number, slot, confirm }) => confirm ? client.webhooks.delete(phone_number, slot || 1) : preview('webhook slot ' + (slot || 1) + ' on ' + phone_number, () => privateWebhookRead(() => client.webhooks.get(phone_number, slot || 1))));
|
|
151
|
+
|
|
152
|
+
// Organisation tools are part of this one main install.
|
|
153
|
+
registerOrganisationTools(server, organisationRequest(key, baseUrl));
|
|
154
|
+
registerCoreTools(server, request);
|
|
155
|
+
registerC5Tools(server, request);
|
|
156
|
+
registerC6Tools(server, request);
|
|
157
|
+
registerKnowledgeTools(server, knowledgeRequest(key, baseUrl));
|
|
158
|
+
registerK6Tools(server, request);
|
|
159
|
+
registerK7Tools(server, request);
|
|
160
|
+
registerK9Deletes(server, contentDeleteRequest(key, baseUrl));
|
|
161
|
+
|
|
162
|
+
// ---- start ----
|
|
163
|
+
const transport = new StdioServerTransport();
|
|
164
|
+
await server.connect(transport);
|
|
165
|
+
log('ready v' + VERSION + ' source=' + source + ' api=' + baseUrl);
|