nixflex-mcp 0.5.0 → 0.5.1

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/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.1",
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",
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
+ }