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/k9-deletes.js CHANGED
@@ -1,90 +1,90 @@
1
- // B57 adapters use the existing one-attempt transport and origin fence, not a future SDK.
2
- import * as z from 'zod/v4';
3
- import { NixflexError } from 'nixflex';
4
- import { errorBody } from './safe-tools.js';
5
- import { kitRequest } from './kit-request.js';
6
-
7
- /** Keep the shared transport untouched; only B57 deletes require a full receipt. */
8
- export function contentDeleteRequest(key, baseUrl, fetcher = fetch) {
9
- return async (method, path) => {
10
- let status = 0, requestId;
11
- const request = kitRequest(key, baseUrl, async (...args) => {
12
- const response = await fetcher(...args);
13
- status = response.status;
14
- requestId = response.headers.get('x-request-id') || response.headers.get('x-railway-request-id') || undefined;
15
- return response;
16
- });
17
- const invalid = () => new NixflexError(status, {error:{type:'connection_error',
18
- code:'invalid_response',message:'Deletion receipt could not be confirmed.'}}, requestId);
19
- let receipt;
20
- try { receipt = await request(method, path); }
21
- catch (error) {
22
- if (error instanceof NixflexError && error.code === 'invalid_response') throw invalid();
23
- throw error;
24
- }
25
- const call = path.startsWith('/calls/') && !path.startsWith('/calls/batch/');
26
- const id = decodeURIComponent(path.slice(path.lastIndexOf('/') + 1));
27
- const valid = receipt?.deleted === true && (call
28
- ? receipt.call_id === id && typeof receipt.recording_deleted === 'boolean' &&
29
- ['carrier_best_effort','queued'].includes(receipt.recording_cleanup)
30
- : receipt.campaign_id === id && typeof receipt.message === 'string');
31
- if (!valid) throw invalid();
32
- return receipt;
33
- };
34
- }
35
-
36
- const confirm = z.boolean().optional().describe('Required true to actually do it. Without it the tool returns a preview and changes nothing.');
37
- export const contentDeletes = [
38
- { name:'delete_call', id:'call_id', prefix:'/calls/', noun:'call',
39
- description:'End a running call and delete its content. recording_cleanup is carrier_best_effort or queued, not proof every copy is erased. 503 hangup_pending with retry_pending:true means queued, not deleted. Requires confirm: true; preview makes zero requests. Never automatically retries.' },
40
- { name:'delete_sms_campaign', id:'campaign_id', prefix:'/sms/campaigns/', noun:'SMS campaign',
41
- description:'Cancel waiting work and hide an SMS campaign. History and used charges remain; no refund or recall of sent messages. Owner/Admin only; missing/foreign is 404. 503 hangup_pending with retry_pending:true means queued, not deleted. Requires confirm: true; preview makes zero requests. Never automatically retries.' },
42
- { name:'delete_campaign', id:'campaign_id', prefix:'/calls/batch/', noun:'voice campaign',
43
- description:'Cancel waiting work, end running calls and hide a voice campaign. History and used charges remain; no refund. Owner/Admin only; missing/foreign is 404. 503 hangup_pending with retry_pending:true means queued, not deleted. Requires confirm: true; preview makes zero requests. Never automatically retries.' },
44
- ];
45
-
46
- function deletionError(error) {
47
- const proof = error?.details;
48
- const queued = error instanceof NixflexError && error.status === 503 &&
49
- error.code === 'hangup_pending' && error.type === 'server_error' && typeof error.message === 'string' &&
50
- proof?.deleted === false && proof.retry_pending === true;
51
- const notSent = proof?.outcome === 'not_sent' && proof.sent === false &&
52
- proof.charged === false && proof.safe_to_retry === true;
53
- if (queued || notSent) return error;
54
- if (error instanceof NixflexError && error.status >= 400 && error.status < 500) return error;
55
- const unknown = new NixflexError(error?.status || 0, {error:{
56
- type:'outcome_unknown', code:'outcome_unknown',
57
- message:'Outcome unknown - check before retrying. The change may already have happened; it was not automatically repeated.',
58
- doc_url:error?.docUrl,
59
- details:{...proof,original_code:error?.code,outcome:'unknown',safe_to_retry:false},
60
- }},error?.requestId);
61
- unknown.outcome='unknown';unknown.safe_to_retry=false;
62
- return unknown;
63
- }
64
-
65
- export function registerK9Deletes(server, request) {
66
- for (const row of contentDeletes) {
67
- const title = row.name === 'delete_call' ? 'Delete one call and recording' :
68
- row.name === 'delete_sms_campaign' ? 'Delete an SMS campaign' : 'Delete a voice campaign';
69
- server.registerTool(row.name, {
70
- title, description:row.description+' Use only for the user\'s explicitly requested change. Check uncertain outcomes before retrying.',
71
- annotations:{title,readOnlyHint:false,destructiveHint:true,idempotentHint:false,openWorldHint:true},
72
- inputSchema:z.object({[row.id]:z.string(),confirm}),
73
- }, async args => {
74
- const reply = data => ({content:[{type:'text',text:JSON.stringify(data,null,2)}]});
75
- if (args.confirm !== true) return reply({
76
- would_delete:row.noun+' '+args[row.id],
77
- warning:row.noun==='call' ? 'The running call will be ended; recording cleanup may remain queued.' :
78
- 'Waiting work will be cancelled and running calls ended. History and used charges remain; no refund.',
79
- hint:'Call again with confirm: true. This preview made no requests.',
80
- });
81
- try {
82
- const id=args[row.id];
83
- if(typeof id!=='string'||!id.length||id.length>200||id==='.'||id==='..'||/[\x00-\x1f\x7f]/.test(id))
84
- throw new NixflexError(400,{error:{type:'invalid_request',code:'invalid_delete',message:'Choose a valid call or campaign identifier. Nothing was sent.',details:{}}});
85
- return reply(await request('DELETE',row.prefix+encodeURIComponent(id)));
86
- }
87
- catch (error) { return {...reply(errorBody(deletionError(error))),isError:true}; }
88
- });
89
- }
90
- }
1
+ // Content deletion adapters use the existing one-attempt transport and origin fence, not a future SDK.
2
+ import * as z from 'zod/v4';
3
+ import { NixflexError } from 'nixflex';
4
+ import { errorBody } from './safe-tools.js';
5
+ import { kitRequest } from './kit-request.js';
6
+
7
+ /** Keep the shared transport untouched; only single-item deletes require a full receipt. */
8
+ export function contentDeleteRequest(key, baseUrl, fetcher = fetch) {
9
+ return async (method, path) => {
10
+ let status = 0, requestId;
11
+ const request = kitRequest(key, baseUrl, async (...args) => {
12
+ const response = await fetcher(...args);
13
+ status = response.status;
14
+ requestId = response.headers.get('x-request-id') || response.headers.get('x-railway-request-id') || undefined;
15
+ return response;
16
+ });
17
+ const invalid = () => new NixflexError(status, {error:{type:'connection_error',
18
+ code:'invalid_response',message:'Deletion receipt could not be confirmed.'}}, requestId);
19
+ let receipt;
20
+ try { receipt = await request(method, path); }
21
+ catch (error) {
22
+ if (error instanceof NixflexError && error.code === 'invalid_response') throw invalid();
23
+ throw error;
24
+ }
25
+ const call = path.startsWith('/calls/') && !path.startsWith('/calls/batch/');
26
+ const id = decodeURIComponent(path.slice(path.lastIndexOf('/') + 1));
27
+ const valid = receipt?.deleted === true && (call
28
+ ? receipt.call_id === id && typeof receipt.recording_deleted === 'boolean' &&
29
+ ['carrier_best_effort','queued'].includes(receipt.recording_cleanup)
30
+ : receipt.campaign_id === id && typeof receipt.message === 'string');
31
+ if (!valid) throw invalid();
32
+ return receipt;
33
+ };
34
+ }
35
+
36
+ const confirm = z.boolean().optional().describe('Required true to actually do it. Without it the tool returns a preview and changes nothing.');
37
+ export const contentDeletes = [
38
+ { name:'delete_call', id:'call_id', prefix:'/calls/', noun:'call',
39
+ description:'End a running call and delete its content. recording_cleanup is carrier_best_effort or queued, not proof every copy is erased. 503 hangup_pending with retry_pending:true means queued, not deleted. Requires confirm: true; preview makes zero requests. Never automatically retries.' },
40
+ { name:'delete_sms_campaign', id:'campaign_id', prefix:'/sms/campaigns/', noun:'SMS campaign',
41
+ description:'Cancel waiting work and hide an SMS campaign. History and used charges remain; no refund or recall of sent messages. Owner/Admin only; missing/foreign is 404. 503 hangup_pending with retry_pending:true means queued, not deleted. Requires confirm: true; preview makes zero requests. Never automatically retries.' },
42
+ { name:'delete_campaign', id:'campaign_id', prefix:'/calls/batch/', noun:'voice campaign',
43
+ description:'Cancel waiting work, end running calls and hide a voice campaign. History and used charges remain; no refund. Owner/Admin only; missing/foreign is 404. 503 hangup_pending with retry_pending:true means queued, not deleted. Requires confirm: true; preview makes zero requests. Never automatically retries.' },
44
+ ];
45
+
46
+ function deletionError(error) {
47
+ const proof = error?.details;
48
+ const queued = error instanceof NixflexError && error.status === 503 &&
49
+ error.code === 'hangup_pending' && error.type === 'server_error' && typeof error.message === 'string' &&
50
+ proof?.deleted === false && proof.retry_pending === true;
51
+ const notSent = proof?.outcome === 'not_sent' && proof.sent === false &&
52
+ proof.charged === false && proof.safe_to_retry === true;
53
+ if (queued || notSent) return error;
54
+ if (error instanceof NixflexError && error.status >= 400 && error.status < 500) return error;
55
+ const unknown = new NixflexError(error?.status || 0, {error:{
56
+ type:'outcome_unknown', code:'outcome_unknown',
57
+ message:'Outcome unknown - check before retrying. The change may already have happened; it was not automatically repeated.',
58
+ doc_url:error?.docUrl,
59
+ details:{...proof,original_code:error?.code,outcome:'unknown',safe_to_retry:false},
60
+ }},error?.requestId);
61
+ unknown.outcome='unknown';unknown.safe_to_retry=false;
62
+ return unknown;
63
+ }
64
+
65
+ export function registerK9Deletes(server, request) {
66
+ for (const row of contentDeletes) {
67
+ const title = row.name === 'delete_call' ? 'Delete one call and recording' :
68
+ row.name === 'delete_sms_campaign' ? 'Delete an SMS campaign' : 'Delete a voice campaign';
69
+ server.registerTool(row.name, {
70
+ title, description:row.description+' Use only for the user\'s explicitly requested change. Check uncertain outcomes before retrying.',
71
+ annotations:{title,readOnlyHint:false,destructiveHint:true,idempotentHint:false,openWorldHint:true},
72
+ inputSchema:z.object({[row.id]:z.string(),confirm}),
73
+ }, async args => {
74
+ const reply = data => ({content:[{type:'text',text:JSON.stringify(data,null,2)}]});
75
+ if (args.confirm !== true) return reply({
76
+ would_delete:row.noun+' '+args[row.id],
77
+ warning:row.noun==='call' ? 'The running call will be ended; recording cleanup may remain queued.' :
78
+ 'Waiting work will be cancelled and running calls ended. History and used charges remain; no refund.',
79
+ hint:'Call again with confirm: true. This preview made no requests.',
80
+ });
81
+ try {
82
+ const id=args[row.id];
83
+ if(typeof id!=='string'||!id.length||id.length>200||id==='.'||id==='..'||/[\x00-\x1f\x7f]/.test(id))
84
+ throw new NixflexError(400,{error:{type:'invalid_request',code:'invalid_delete',message:'Choose a valid call or campaign identifier. Nothing was sent.',details:{}}});
85
+ return reply(await request('DELETE',row.prefix+encodeURIComponent(id)));
86
+ }
87
+ catch (error) { return {...reply(errorBody(deletionError(error))),isError:true}; }
88
+ });
89
+ }
90
+ }
package/kit-request.js CHANGED
@@ -1,24 +1,24 @@
1
- import { NixflexError, NixflexConnectionError, errorFromResponse } from 'nixflex';
2
- import { readFileSync } from 'node:fs';
3
- export const KIT_VERSION = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version;
4
- /** One attempt. executeTool owns the one GET-only retry, including organisation reads. */
5
- export function kitRequest(key, baseUrl, fetcher = fetch) {
6
- return async (method, path, body, query) => {
7
- if (!path.startsWith('/') || path.startsWith('//') || /[?#\\]/.test(path)) throw Error('Invalid API path.');
8
- const url = new URL(baseUrl.replace(/\/+$/, '') + '/v1' + path);
9
- for (const [k,v] of Object.entries(query || {})) if (v !== undefined && v !== null) url.searchParams.set(k, String(v));
10
- let response;
11
- try {
12
- response = await fetcher(url, { method, redirect: 'error', signal: AbortSignal.timeout(30000),
13
- headers: { Authorization: 'Bearer ' + key, 'Content-Type': 'application/json', 'User-Agent': 'nixflex-mcp/' + KIT_VERSION },
14
- body: body === undefined ? undefined : JSON.stringify(body) });
15
- } catch { throw new NixflexConnectionError('API request could not be confirmed.'); }
16
- const requestId = response.headers.get('x-request-id') || response.headers.get('x-railway-request-id') || undefined;
17
- if (response.status === 204) return undefined;
18
- let data;
19
- try { data = await response.json(); }
20
- catch { throw new NixflexError(0, {error:{type:'connection_error',code:'invalid_response',message:'API response could not be confirmed.'}}, requestId); }
21
- if (!response.ok) throw errorFromResponse(response.status, data, requestId, Number(response.headers.get('retry-after')) || 0);
22
- return data;
23
- };
24
- }
1
+ import { NixflexError, NixflexConnectionError, errorFromResponse } from 'nixflex';
2
+ import { readFileSync } from 'node:fs';
3
+ export const KIT_VERSION = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version;
4
+ /** One attempt. executeTool owns the one GET-only retry, including organisation reads. */
5
+ export function kitRequest(key, baseUrl, fetcher = fetch) {
6
+ return async (method, path, body, query) => {
7
+ if (!path.startsWith('/') || path.startsWith('//') || /[?#\\]/.test(path)) throw Error('Invalid API path.');
8
+ const url = new URL(baseUrl.replace(/\/+$/, '') + '/v1' + path);
9
+ for (const [k,v] of Object.entries(query || {})) if (v !== undefined && v !== null) url.searchParams.set(k, String(v));
10
+ let response;
11
+ try {
12
+ response = await fetcher(url, { method, redirect: 'error', signal: AbortSignal.timeout(30000),
13
+ headers: { Authorization: 'Bearer ' + key, 'Content-Type': 'application/json', 'User-Agent': 'nixflex-mcp/' + KIT_VERSION },
14
+ body: body === undefined ? undefined : JSON.stringify(body) });
15
+ } catch { throw new NixflexConnectionError('API request could not be confirmed.'); }
16
+ const requestId = response.headers.get('x-request-id') || response.headers.get('x-railway-request-id') || undefined;
17
+ if (response.status === 204) return undefined;
18
+ let data;
19
+ try { data = await response.json(); }
20
+ catch { throw new NixflexError(0, {error:{type:'connection_error',code:'invalid_response',message:'API response could not be confirmed.'}}, requestId); }
21
+ if (!response.ok) throw errorFromResponse(response.status, data, requestId, Number(response.headers.get('retry-after')) || 0);
22
+ return data;
23
+ };
24
+ }
@@ -1,24 +1,24 @@
1
- import { NixflexError, NixflexConnectionError, errorFromResponse } from 'nixflex';
2
- import { KIT_VERSION } from './kit-request.js';
3
- /** One request. Existing executeTool supplies only GET retries. Content is never logged. */
4
- export function knowledgeRequest(key, baseUrl, fetcher = fetch) {
5
- return async (method, path, body, query, operationKey) => {
6
- if (!path.startsWith('/') || path.startsWith('//') || /[?#\\]/.test(path)) throw new TypeError('Invalid API path.');
7
- if (operationKey !== undefined && (!/^[A-Za-z0-9_.:-]{8,128}$/.test(operationKey) || operationKey.startsWith('prompt:')))
8
- throw new TypeError('Invalid operation key.');
9
- const url = new URL(baseUrl.replace(/\/+$/, '') + '/v1' + path);
10
- for (const [name, value] of Object.entries(query || {})) if (value !== undefined) url.searchParams.set(name, String(value));
11
- let res;
12
- try {
13
- res = await fetcher(url, { method, redirect: 'error', signal: AbortSignal.timeout(30000),
14
- headers: { Authorization: 'Bearer ' + key, 'Content-Type': 'application/json', 'User-Agent': 'nixflex-mcp/' + KIT_VERSION,
15
- ...(operationKey === undefined ? {} : { 'Idempotency-Key': operationKey }) },
16
- body: body === undefined ? undefined : JSON.stringify(body) });
17
- } catch { throw new NixflexConnectionError('Knowledge request could not be confirmed.'); }
18
- let data;
19
- try { data = await res.json(); }
20
- catch { throw new NixflexError(0, { error: { code: 'invalid_response', type: 'connection_error', message: 'Knowledge response could not be confirmed.' } }); }
21
- if (!res.ok) throw errorFromResponse(res.status, data, undefined, Number(res.headers.get('retry-after')) || 0);
22
- return data;
23
- };
24
- }
1
+ import { NixflexError, NixflexConnectionError, errorFromResponse } from 'nixflex';
2
+ import { KIT_VERSION } from './kit-request.js';
3
+ /** One request. Existing executeTool supplies only GET retries. Content is never logged. */
4
+ export function knowledgeRequest(key, baseUrl, fetcher = fetch) {
5
+ return async (method, path, body, query, operationKey) => {
6
+ if (!path.startsWith('/') || path.startsWith('//') || /[?#\\]/.test(path)) throw new TypeError('Invalid API path.');
7
+ if (operationKey !== undefined && (!/^[A-Za-z0-9_.:-]{8,128}$/.test(operationKey) || operationKey.startsWith('prompt:')))
8
+ throw new TypeError('Invalid operation key.');
9
+ const url = new URL(baseUrl.replace(/\/+$/, '') + '/v1' + path);
10
+ for (const [name, value] of Object.entries(query || {})) if (value !== undefined) url.searchParams.set(name, String(value));
11
+ let res;
12
+ try {
13
+ res = await fetcher(url, { method, redirect: 'error', signal: AbortSignal.timeout(30000),
14
+ headers: { Authorization: 'Bearer ' + key, 'Content-Type': 'application/json', 'User-Agent': 'nixflex-mcp/' + KIT_VERSION,
15
+ ...(operationKey === undefined ? {} : { 'Idempotency-Key': operationKey }) },
16
+ body: body === undefined ? undefined : JSON.stringify(body) });
17
+ } catch { throw new NixflexConnectionError('Knowledge request could not be confirmed.'); }
18
+ let data;
19
+ try { data = await res.json(); }
20
+ catch { throw new NixflexError(0, { error: { code: 'invalid_response', type: 'connection_error', message: 'Knowledge response could not be confirmed.' } }); }
21
+ if (!res.ok) throw errorFromResponse(res.status, data, undefined, Number(res.headers.get('retry-after')) || 0);
22
+ return data;
23
+ };
24
+ }
package/number-reads.js CHANGED
@@ -1,23 +1,23 @@
1
- // Read-only compatibility adapter until the updated SDK is published. Installed
2
- // SDK 0.8.0 has no number get and discards new list filters. No mutation uses this.
3
- import { NixflexConnectionError, errorFromResponse } from 'nixflex';
4
- import { numberUsage } from './number-usage.js';
5
- export function numberReads(apiKey, baseUrl = 'https://api.nixflex.com', fetcher = fetch) {
6
- return async function read({ phone_number, agent_id, provider, limit, cursor, usage, period, time_zone } = {}) {
7
- if (usage === true) return numberUsage(apiKey, baseUrl, {phone_number,period,time_zone}, fetcher);
8
- const suffix = phone_number ? '/' + encodeURIComponent(phone_number) : '';
9
- const url = new URL(baseUrl.replace(/\/+$/, '') + '/v1/phone-numbers' + suffix);
10
- if (!phone_number) for (const [k,v] of Object.entries({agent_id,provider,limit,cursor})) if(v !== undefined) url.searchParams.set(k,String(v));
11
- let response;
12
- try {
13
- response = await fetcher(url.toString(), {method:'GET',redirect:'error',signal:AbortSignal.timeout(30000),
14
- headers:{Authorization:'Bearer '+apiKey,Accept:'application/json'}});
15
- } catch { throw new NixflexConnectionError('Could not read phone numbers.'); }
16
- let body;
17
- try { body = await response.json(); }
18
- catch { throw new NixflexConnectionError('Invalid phone number read response.'); }
19
- if (!response.ok) throw errorFromResponse(response.status,body,response.headers.get('x-railway-request-id') || undefined,
20
- Number(response.headers.get('retry-after')) || undefined);
21
- return body;
22
- };
23
- }
1
+ // Read-only compatibility adapter until the updated SDK is published. Installed
2
+ // SDK 0.8.0 has no number get and discards new list filters. No mutation uses this.
3
+ import { NixflexConnectionError, errorFromResponse } from 'nixflex';
4
+ import { numberUsage } from './number-usage.js';
5
+ export function numberReads(apiKey, baseUrl = 'https://api.nixflex.com', fetcher = fetch) {
6
+ return async function read({ phone_number, agent_id, provider, limit, cursor, usage, period, time_zone } = {}) {
7
+ if (usage === true) return numberUsage(apiKey, baseUrl, {phone_number,period,time_zone}, fetcher);
8
+ const suffix = phone_number ? '/' + encodeURIComponent(phone_number) : '';
9
+ const url = new URL(baseUrl.replace(/\/+$/, '') + '/v1/phone-numbers' + suffix);
10
+ if (!phone_number) for (const [k,v] of Object.entries({agent_id,provider,limit,cursor})) if(v !== undefined) url.searchParams.set(k,String(v));
11
+ let response;
12
+ try {
13
+ response = await fetcher(url.toString(), {method:'GET',redirect:'error',signal:AbortSignal.timeout(30000),
14
+ headers:{Authorization:'Bearer '+apiKey,Accept:'application/json'}});
15
+ } catch { throw new NixflexConnectionError('Could not read phone numbers.'); }
16
+ let body;
17
+ try { body = await response.json(); }
18
+ catch { throw new NixflexConnectionError('Invalid phone number read response.'); }
19
+ if (!response.ok) throw errorFromResponse(response.status,body,response.headers.get('x-railway-request-id') || undefined,
20
+ Number(response.headers.get('retry-after')) || undefined);
21
+ return body;
22
+ };
23
+ }
package/number-schema.js CHANGED
@@ -1,26 +1,26 @@
1
- import * as z from 'zod/v4';
2
- const phone = z.string().regex(/^\+[1-9]\d{6,14}$/,'E.164 number');
3
- export const numberReadSchema = z.object({
4
- phone_number:phone.optional().describe('Read one number with all safe settings, key status and effective website voice; omit to list.'),
5
- usage:z.boolean().optional().describe('With phone_number, read retained-history usage instead of settings. Read-only, not a billing ledger.'),
6
- period:z.enum(['today','7','14','30','90','all']).optional().describe('Usage only. Calendar days including today; default all.'),
7
- time_zone:z.string().max(64).optional().describe('Usage only. IANA zone such as Europe/London; default UTC. Match dashboard browser zone.'),
8
- agent_id:z.string().optional(),provider:z.enum(['twilio','telnyx']).optional(),
9
- limit:z.number().int().min(1).max(100).optional().describe('Opt into pagination. count is returned rows, not total.'),
10
- cursor:z.string().optional().describe('Reuse next_cursor with the same filters. With cursor alone limit defaults to 50.')
11
- }).refine(v=>!v.phone_number || [v.agent_id,v.provider,v.limit,v.cursor].every(x=>x===undefined),
12
- 'Use phone_number alone for a single read, or list filters/pagination without phone_number.')
13
- .refine(v=>v.usage===true ? !!v.phone_number : v.period===undefined && v.time_zone===undefined,
14
- 'Usage requires usage:true and phone_number; period/time_zone are only for usage.');
15
- export const numberFields = z.object({
16
- agent_id:z.string().min(1).max(200).optional().describe('Move to an active agent of the same account. Send agent_id ALONE. Busy calls, replies, campaigns and number operations refuse the move. Own number settings/history stay.'),
17
- inbound_enabled:z.boolean().optional().describe('Accept incoming calls.'),
18
- outbound_enabled:z.boolean().optional().describe('Permit outbound calls; false locks outbound.'),
19
- sms_reply_enabled:z.boolean().optional().describe('SMS automatic replies.'),
20
- web_agent_enabled:z.boolean().optional().describe('Website master switch, required for website voice.'),
21
- web_calls_enabled:z.boolean().optional().describe('Saved website voice switch. Effective only with Web agent enabled.'),
22
- web_functions_enabled:z.boolean().optional().describe('All enabled custom functions available to website visitors; enable only if safe for anyone.'),
23
- monitor_enabled:z.boolean().optional().describe('Monitoring eligibility; does not attach a listener.')
24
- }).catchall(z.unknown()).refine(v=>v.agent_id===undefined || Object.keys(v).length===1,
25
- 'Send agent_id alone when moving a number. Change other settings separately.')
26
- .describe('Only passed settings change. Use booleans for the seven switches. null is supported only on documented nullable overrides. Unknown PATCH fields may be ignored; use documented names.');
1
+ import * as z from 'zod/v4';
2
+ const phone = z.string().regex(/^\+[1-9]\d{6,14}$/,'E.164 number');
3
+ export const numberReadSchema = z.object({
4
+ phone_number:phone.optional().describe('Read one number with all safe settings, key status and effective website voice; omit to list.'),
5
+ usage:z.boolean().optional().describe('With phone_number, read retained-history usage instead of settings. Read-only, not a billing ledger.'),
6
+ period:z.enum(['today','7','14','30','90','all']).optional().describe('Usage only. Calendar days including today; default all.'),
7
+ time_zone:z.string().max(64).optional().describe('Usage only. IANA zone such as Europe/London; default UTC. Match dashboard browser zone.'),
8
+ agent_id:z.string().optional(),provider:z.enum(['twilio','telnyx']).optional(),
9
+ limit:z.number().int().min(1).max(100).optional().describe('Opt into pagination. count is returned rows, not total.'),
10
+ cursor:z.string().optional().describe('Reuse next_cursor with the same filters. With cursor alone limit defaults to 50.')
11
+ }).refine(v=>!v.phone_number || [v.agent_id,v.provider,v.limit,v.cursor].every(x=>x===undefined),
12
+ 'Use phone_number alone for a single read, or list filters/pagination without phone_number.')
13
+ .refine(v=>v.usage===true ? !!v.phone_number : v.period===undefined && v.time_zone===undefined,
14
+ 'Usage requires usage:true and phone_number; period/time_zone are only for usage.');
15
+ export const numberFields = z.object({
16
+ agent_id:z.string().min(1).max(200).optional().describe('Move to an active agent of the same account. Send agent_id ALONE. Busy calls, replies, campaigns and number operations refuse the move. Own number settings/history stay.'),
17
+ inbound_enabled:z.boolean().optional().describe('Accept incoming calls.'),
18
+ outbound_enabled:z.boolean().optional().describe('Permit outbound calls; false locks outbound.'),
19
+ sms_reply_enabled:z.boolean().optional().describe('SMS automatic replies.'),
20
+ web_agent_enabled:z.boolean().optional().describe('Website master switch, required for website voice.'),
21
+ web_calls_enabled:z.boolean().optional().describe('Saved website voice switch. Effective only with Web agent enabled.'),
22
+ web_functions_enabled:z.boolean().optional().describe('All enabled custom functions available to website visitors; enable only if safe for anyone.'),
23
+ monitor_enabled:z.boolean().optional().describe('Monitoring eligibility; does not attach a listener.')
24
+ }).catchall(z.unknown()).refine(v=>v.agent_id===undefined || Object.keys(v).length===1,
25
+ 'Send agent_id alone when moving a number. Change other settings separately.')
26
+ .describe('Only passed settings change. Use booleans for the seven switches. null is supported only on documented nullable overrides. Unknown PATCH fields may be ignored; use documented names.');
package/number-usage.js CHANGED
@@ -1,13 +1,13 @@
1
- import { NixflexConnectionError, errorFromResponse } from 'nixflex';
2
- // GET-only compatibility with the installed SDK; no new credential storage or writes.
3
- export async function numberUsage(apiKey, baseUrl, args, fetcher = fetch) {
4
- const url = new URL((baseUrl || 'https://api.nixflex.com').replace(/\/+$/, '') + '/v1/phone-numbers/' + encodeURIComponent(args.phone_number) + '/usage');
5
- for (const k of ['period','time_zone']) if (args[k] !== undefined) url.searchParams.set(k,args[k]);
6
- let response, body;
7
- try { response = await fetcher(url.toString(), {method:'GET',redirect:'error',signal:AbortSignal.timeout(10000),headers:{Authorization:'Bearer '+apiKey,Accept:'application/json'}}); }
8
- catch { throw new NixflexConnectionError('Could not read phone number usage.'); }
9
- try { body = await response.json(); }
10
- catch { throw new NixflexConnectionError('Invalid phone number usage response.'); }
11
- if (!response.ok) throw errorFromResponse(response.status,body,response.headers.get('x-railway-request-id') || undefined,Number(response.headers.get('retry-after')) || undefined);
12
- return body;
13
- }
1
+ import { NixflexConnectionError, errorFromResponse } from 'nixflex';
2
+ // GET-only compatibility with the installed SDK; no new credential storage or writes.
3
+ export async function numberUsage(apiKey, baseUrl, args, fetcher = fetch) {
4
+ const url = new URL((baseUrl || 'https://api.nixflex.com').replace(/\/+$/, '') + '/v1/phone-numbers/' + encodeURIComponent(args.phone_number) + '/usage');
5
+ for (const k of ['period','time_zone']) if (args[k] !== undefined) url.searchParams.set(k,args[k]);
6
+ let response, body;
7
+ try { response = await fetcher(url.toString(), {method:'GET',redirect:'error',signal:AbortSignal.timeout(10000),headers:{Authorization:'Bearer '+apiKey,Accept:'application/json'}}); }
8
+ catch { throw new NixflexConnectionError('Could not read phone number usage.'); }
9
+ try { body = await response.json(); }
10
+ catch { throw new NixflexConnectionError('Invalid phone number usage response.'); }
11
+ if (!response.ok) throw errorFromResponse(response.status,body,response.headers.get('x-railway-request-id') || undefined,Number(response.headers.get('retry-after')) || undefined);
12
+ return body;
13
+ }
@@ -1,26 +1,26 @@
1
- import * as z from 'zod/v4';
2
- import {NixflexConnectionError,errorFromResponse} from 'nixflex';
3
- import {kitRequest} from './kit-request.js';
4
- import {executeTool,errorBody} from './safe-tools.js';
5
- export function organisationRequest(key,baseUrl,fetcher=fetch){
6
- const request=kitRequest(key,baseUrl,fetcher);
7
- return (method,path,body,query)=>request(method,'/organisation'+path,body,query);
8
- }
9
- export function registerOrganisationTools(server,request){
10
- const id=z.string().uuid(),role=z.enum(['admin','member']),email=z.string().email().max(254),confirm=z.boolean().optional();
11
- const add=(name,title,read,schema,fn)=>server.registerTool(name,{title,
12
- description:title+'. '+(read?'Read only; use only when the user requests this account information.':'Use only for the user\'s explicitly requested change. Requires confirm:true; otherwise previews only. A lost response is not retried. Check the result before repeating.')+' Uses the organisation API key shared by its owner. Personal leave, invite acceptance, ownership transfer and account deletion are dashboard-only.',
13
- annotations:{title,readOnlyHint:read,destructiveHint:!read,idempotentHint:read,openWorldHint:true},inputSchema:schema},async args=>{
14
- try{const result=await executeTool(name,async a=>!read&&a.confirm!==true?{would_change:title,target:a.user_id||a.invite_id||a.email||null,hint:'Ask for the user’s explicit approval, then call with confirm:true.'}:fn(a),args);return {content:[{type:'text',text:JSON.stringify(result,null,2)}]}}
15
- catch(e){return {content:[{type:'text',text:JSON.stringify(errorBody(e))}],isError:true}}
16
- });
17
- add('get_organisation','Read this organisation',true,z.object({}),()=>request('GET',''));
18
- add('list_organisation_members','Read members and invitations',true,z.object({}),()=>request('GET','/members'));
19
- add('list_organisation_activity','Read up to 50 activity events',true,z.object({before:z.string().regex(/^\d{1,18}$/).optional(),actor:id.optional()}),a=>request('GET','/activity',undefined,a));
20
- add('invite_organisation_member','Invite a teammate by email',false,z.object({email,role,confirm}),a=>request('POST','/invites',{email:a.email,role:a.role}));
21
- add('resend_organisation_invite','Replace and resend an invitation',false,z.object({invite_id:id,confirm}),a=>request('POST','/invites/'+a.invite_id+'/resend'));
22
- add('revoke_organisation_invite','Revoke an unused invitation',false,z.object({invite_id:id,confirm}),a=>request('DELETE','/invites/'+a.invite_id));
23
- add('remove_organisation_member','Remove a teammate without deleting shared work or rolling the API key',false,z.object({user_id:id,confirm}),a=>request('DELETE','/members/'+a.user_id));
24
- add('update_organisation_member_role','Change a teammate to Admin or Member',false,z.object({user_id:id,role,confirm}),a=>request('PATCH','/members/'+a.user_id,{role:a.role}));
25
- add('claim_organisation_owner','Send a verified-email owner claim for an API-only account',false,z.object({email,confirm}),a=>request('POST','/claim-invite',{email:a.email}));
26
- }
1
+ import * as z from 'zod/v4';
2
+ import {NixflexConnectionError,errorFromResponse} from 'nixflex';
3
+ import {kitRequest} from './kit-request.js';
4
+ import {executeTool,errorBody} from './safe-tools.js';
5
+ export function organisationRequest(key,baseUrl,fetcher=fetch){
6
+ const request=kitRequest(key,baseUrl,fetcher);
7
+ return (method,path,body,query)=>request(method,'/organisation'+path,body,query);
8
+ }
9
+ export function registerOrganisationTools(server,request){
10
+ const id=z.string().uuid(),role=z.enum(['admin','member']),email=z.string().email().max(254),confirm=z.boolean().optional();
11
+ const add=(name,title,read,schema,fn)=>server.registerTool(name,{title,
12
+ description:title+'. '+(read?'Read only; use only when the user requests this account information.':'Use only for the user\'s explicitly requested change. Requires confirm:true; otherwise previews only. A lost response is not retried. Check the result before repeating.')+' Uses the organisation API key shared by its owner. Personal leave, invite acceptance, ownership transfer and account deletion are dashboard-only.',
13
+ annotations:{title,readOnlyHint:read,destructiveHint:!read,idempotentHint:read,openWorldHint:true},inputSchema:schema},async args=>{
14
+ try{const result=await executeTool(name,async a=>!read&&a.confirm!==true?{would_change:title,target:a.user_id||a.invite_id||a.email||null,hint:'Ask for the user’s explicit approval, then call with confirm:true.'}:fn(a),args);return {content:[{type:'text',text:JSON.stringify(result,null,2)}]}}
15
+ catch(e){return {content:[{type:'text',text:JSON.stringify(errorBody(e))}],isError:true}}
16
+ });
17
+ add('get_organisation','Read this organisation',true,z.object({}),()=>request('GET',''));
18
+ add('list_organisation_members','Read members and invitations',true,z.object({}),()=>request('GET','/members'));
19
+ add('list_organisation_activity','Read up to 50 activity events',true,z.object({before:z.string().regex(/^\d{1,18}$/).optional(),actor:id.optional()}),a=>request('GET','/activity',undefined,a));
20
+ add('invite_organisation_member','Invite a teammate by email',false,z.object({email,role,confirm}),a=>request('POST','/invites',{email:a.email,role:a.role}));
21
+ add('resend_organisation_invite','Replace and resend an invitation',false,z.object({invite_id:id,confirm}),a=>request('POST','/invites/'+a.invite_id+'/resend'));
22
+ add('revoke_organisation_invite','Revoke an unused invitation',false,z.object({invite_id:id,confirm}),a=>request('DELETE','/invites/'+a.invite_id));
23
+ add('remove_organisation_member','Remove a teammate without deleting shared work or rolling the API key',false,z.object({user_id:id,confirm}),a=>request('DELETE','/members/'+a.user_id));
24
+ add('update_organisation_member_role','Change a teammate to Admin or Member',false,z.object({user_id:id,role,confirm}),a=>request('PATCH','/members/'+a.user_id,{role:a.role}));
25
+ add('claim_organisation_owner','Send a verified-email owner claim for an API-only account',false,z.object({email,confirm}),a=>request('POST','/claim-invite',{email:a.email}));
26
+ }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "nixflex-mcp",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
+ "author": "Nixflex <dev@nixflex.com>",
4
5
  "description": "MCP server for the Nixflex voice AI platform - manage agents, calls, numbers and caller context from Claude Desktop, Cursor or any MCP client.",
5
6
  "keywords": [
6
7
  "nixflex",
@@ -48,6 +49,7 @@
48
49
  "knowledge-request.js",
49
50
  "k6-tools.js",
50
51
  "k6-schemas.js",
52
+ "booking-schemas.js",
51
53
  "k6-private.js",
52
54
  "k7-call.js",
53
55
  "k7-errors.js",
@@ -55,10 +57,10 @@
55
57
  "k7-tools.js",
56
58
  "k9-deletes.js",
57
59
  "NUMBER-FEATURES.md",
58
- "KIT-EXAMPLES-K6.md",
60
+ "NUMBER-EXAMPLES.md",
59
61
  "CALL-REQUESTS.md",
60
- "KIT-EXAMPLES-K7.md",
61
- "B57-DELETES.md"
62
+ "CALL-EXAMPLES.md",
63
+ "DELETING-CONTENT.md"
62
64
  ],
63
65
  "engines": {
64
66
  "node": ">=22"
package/safe-tools.js CHANGED
@@ -1,36 +1,36 @@
1
- // Works with the installed nixflex 0.8.0, without waiting for an npm publication.
2
- // The SDK instance MUST have maxRetries:0. Only read-only tools may repeat here.
3
- import { NixflexError } from 'nixflex';
4
- const pause = ms => new Promise(resolve => setTimeout(resolve, ms));
5
- export async function executeTool(name, fn, args, wait = pause) {
6
- const read = /^(get_|list_)/.test(name);
7
- for (let attempt = 0; ; attempt++) {
8
- try { return await fn(args || {}); }
9
- catch (e) {
10
- if (read && attempt === 0 && e instanceof NixflexError &&
11
- (e.status === 0 || e.status === 429 || e.status >= 500)) {
12
- await wait(e.status === 429 ? Math.min(30, Math.max(1, e.retryAfterSeconds || 1)) * 1000 : 300);
13
- continue;
14
- }
15
- const p = e?.details;
16
- const notSent = p?.outcome === 'not_sent' && p.sent === false && p.charged === false && p.safe_to_retry === true;
17
- if (!read && !notSent && ((e instanceof NixflexError && (e.status === 0 || e.status >= 500)) ||
18
- e instanceof SyntaxError || e?.name === 'AbortError' || e instanceof TypeError)) {
19
- const error = new NixflexError(e.status || 0, {error:{
20
- code:'outcome_unknown',type:'outcome_unknown',
21
- doc_url:e.docUrl,
22
- message:'Outcome unknown - check before retrying. The change may already have happened; it was not automatically repeated.',
23
- details:{...p,original_code:e.code,outcome:'unknown',safe_to_retry:false},
24
- }},e.requestId);
25
- error.outcome='unknown';error.safe_to_retry=false;throw error;
26
- }
27
- throw e;
28
- }
29
- }
30
- }
31
- export function errorBody(e) {
32
- return {error:{type:e?.type || 'error',code:e?.code || 'unknown_error',status:e?.status || 0,
33
- message:e instanceof NixflexError ? e.message : 'The request could not be completed.',
34
- doc_url:e?.docUrl ?? null,request_id:e?.requestId ?? e?.details?.request_id ?? null,details:e?.details || {},
35
- ...(e?.outcome==='unknown'?{outcome:'unknown',safe_to_retry:false}:{})}};
36
- }
1
+ // Works with the installed nixflex 0.8.0, without waiting for an npm publication.
2
+ // The SDK instance MUST have maxRetries:0. Only read-only tools may repeat here.
3
+ import { NixflexError } from 'nixflex';
4
+ const pause = ms => new Promise(resolve => setTimeout(resolve, ms));
5
+ export async function executeTool(name, fn, args, wait = pause) {
6
+ const read = /^(get_|list_)/.test(name);
7
+ for (let attempt = 0; ; attempt++) {
8
+ try { return await fn(args || {}); }
9
+ catch (e) {
10
+ if (read && attempt === 0 && e instanceof NixflexError &&
11
+ (e.status === 0 || e.status === 429 || e.status >= 500)) {
12
+ await wait(e.status === 429 ? Math.min(30, Math.max(1, e.retryAfterSeconds || 1)) * 1000 : 300);
13
+ continue;
14
+ }
15
+ const p = e?.details;
16
+ const notSent = p?.outcome === 'not_sent' && p.sent === false && p.charged === false && p.safe_to_retry === true;
17
+ if (!read && !notSent && ((e instanceof NixflexError && (e.status === 0 || e.status >= 500)) ||
18
+ e instanceof SyntaxError || e?.name === 'AbortError' || e instanceof TypeError)) {
19
+ const error = new NixflexError(e.status || 0, {error:{
20
+ code:'outcome_unknown',type:'outcome_unknown',
21
+ doc_url:e.docUrl,
22
+ message:'Outcome unknown - check before retrying. The change may already have happened; it was not automatically repeated.',
23
+ details:{...p,original_code:e.code,outcome:'unknown',safe_to_retry:false},
24
+ }},e.requestId);
25
+ error.outcome='unknown';error.safe_to_retry=false;throw error;
26
+ }
27
+ throw e;
28
+ }
29
+ }
30
+ }
31
+ export function errorBody(e) {
32
+ return {error:{type:e?.type || 'error',code:e?.code || 'unknown_error',status:e?.status || 0,
33
+ message:e instanceof NixflexError ? e.message : 'The request could not be completed.',
34
+ doc_url:e?.docUrl ?? null,request_id:e?.requestId ?? e?.details?.request_id ?? null,details:e?.details || {},
35
+ ...(e?.outcome==='unknown'?{outcome:'unknown',safe_to_retry:false}:{})}};
36
+ }