@omnidim-ai/mcp-server 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +77 -0
- package/build/helpers.d.ts +11 -0
- package/build/helpers.js +74 -0
- package/build/helpers.js.map +1 -0
- package/build/index.d.ts +21 -0
- package/build/index.js +1053 -0
- package/build/index.js.map +1 -0
- package/package.json +69 -0
- package/src/helpers.ts +75 -0
- package/src/index.ts +1143 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,1143 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* OmniDimension MCP server.
|
|
4
|
+
*/
|
|
5
|
+
import { trimLargeResponse } from "./helpers.js";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
9
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
10
|
+
import {
|
|
11
|
+
CallToolRequestSchema,
|
|
12
|
+
ListToolsRequestSchema,
|
|
13
|
+
type Tool,
|
|
14
|
+
type CallToolResult,
|
|
15
|
+
type CallToolRequest
|
|
16
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
17
|
+
|
|
18
|
+
import { z, ZodError } from 'zod';
|
|
19
|
+
import { jsonSchemaToZod } from 'json-schema-to-zod';
|
|
20
|
+
import axios, { type AxiosRequestConfig, type AxiosError } from 'axios';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Type definition for JSON objects
|
|
24
|
+
*/
|
|
25
|
+
type JsonObject = Record<string, any>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Interface for MCP Tool Definition
|
|
29
|
+
*/
|
|
30
|
+
interface McpToolDefinition {
|
|
31
|
+
name: string;
|
|
32
|
+
description: string;
|
|
33
|
+
inputSchema: any;
|
|
34
|
+
method: string;
|
|
35
|
+
pathTemplate: string;
|
|
36
|
+
executionParameters: { name: string, in: string }[];
|
|
37
|
+
requestBodyContentType?: string;
|
|
38
|
+
securityRequirements: any[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Server configuration
|
|
43
|
+
*/
|
|
44
|
+
export const SERVER_NAME = "OmniDimension";
|
|
45
|
+
export const SERVER_VERSION = "0.1.0";
|
|
46
|
+
// Base URL for the API, can be set via environment variable or determined from OpenAPI spec
|
|
47
|
+
export const API_BASE_URL = process.env.API_BASE_URL || "https://backend.omnidim.io/api/v1";
|
|
48
|
+
if (process.env.API_BASE_URL) {
|
|
49
|
+
console.error(`API_BASE_URL override: ${API_BASE_URL}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* MCP Server instance
|
|
54
|
+
*/
|
|
55
|
+
const server = new Server(
|
|
56
|
+
{ name: SERVER_NAME, version: SERVER_VERSION },
|
|
57
|
+
{ capabilities: { tools: {} } }
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Map of tool definitions by name
|
|
62
|
+
*/
|
|
63
|
+
const toolDefinitionMap: Map<string, McpToolDefinition> = new Map([
|
|
64
|
+
|
|
65
|
+
["listAgents", {
|
|
66
|
+
name: "listAgents",
|
|
67
|
+
description: `Retrieve all agents for the authenticated user with pagination support.`,
|
|
68
|
+
inputSchema: {"type":"object","properties":{"pageno":{"type":"integer","minimum":1,"default":1,"description":"Page number for pagination."},"pagesize":{"type":"integer","minimum":1,"default":30,"maximum":150,"description":"Number of items per page (max 150)."},"name":{"type":"string","description":"Filter agents whose name matches this substring (case-insensitive)."}}},
|
|
69
|
+
method: "get",
|
|
70
|
+
pathTemplate: "/agents",
|
|
71
|
+
executionParameters: [{"name":"pageno","in":"query"},{"name":"pagesize","in":"query"},{"name":"name","in":"query"}],
|
|
72
|
+
requestBodyContentType: undefined,
|
|
73
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
74
|
+
}],
|
|
75
|
+
["createAgent", {
|
|
76
|
+
name: "createAgent",
|
|
77
|
+
description: `Create a new agent with the provided configuration. The full
|
|
78
|
+
config supports transcriber, model, voice, web search, transfer,
|
|
79
|
+
end-call conditions, post-call actions (email + webhook),
|
|
80
|
+
ambient background track, initial ringing sound, and multilingual support.
|
|
81
|
+
`,
|
|
82
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"allOf":[{"type":"object","description":"Agent configuration.","properties":{"name":{"type":"string","description":"Name for the agent.","example":"Customer Support Agent"},"welcome_message":{"type":"string","description":"Initial message the agent will say when answering a call.","example":"Hello! How can I help you today?"},"is_welcome_message_interruption":{"type":"boolean","description":"Allow the caller to interrupt the welcome message. When false, the agent finishes speaking the welcome before listening."},"is_interruption_allowed":{"type":"boolean","description":"Global toggle for whether the caller can interrupt the agent mid-sentence at any point in the call."},"dynamic_variables":{"type":"object","description":"Key/value map used to substitute placeholders in the agent's\nprompt and welcome message at call time. Reference a variable\nin your prompt with `{{variable_name}}`. Useful for\npersonalising the same agent across many calls.\n","additionalProperties":{"type":"string"},"example":{"customer_name":"Jane Doe","order_id":"ORD-12345"}},"context_breakdown":{"type":"array","description":"List of context breakdowns, each containing `title`, `body`, and optional `is_enabled`.","items":{"type":"object","required":["title","body"],"properties":{"title":{"type":"string","description":"Title of the breakdown.","example":"Purpose"},"body":{"type":"string","description":"Body of the breakdown — the detailed prompt content.","example":"This agent helps customers with product inquiries and support issues."},"is_enabled":{"type":"boolean","default":true,"description":"Whether this section is included in the prompt."}}}},"call_type":{"type":"string","enum":["Incoming","Outgoing"],"description":"Call type of the assistant."},"transcriber":{"type":"object","description":"Configuration for the speech-to-text transcriber.","properties":{"provider":{"type":"string","enum":["deepgram_stream","cartesia","sarvam","azure_stream","soniox"],"description":"The speech-to-text provider to use.","example":"deepgram_stream"},"model":{"type":"string","enum":["nova-3","nova-2"],"description":"The model to use for transcription (required when provider is `deepgram_stream`).","example":"nova-3"},"language":{"type":"string","description":"Language code for the transcriber. Format and supported\nvalues depend on the provider (e.g. `en-US` for Deepgram,\n`hi-IN` for Sarvam). Applies regardless of which\n`provider` is selected.\n","example":"en-US"},"silence_timeout_ms":{"type":"integer","description":"Silence timeout in milliseconds.","example":400},"should_apply_noise_reduction":{"type":"boolean","description":"Reduce background noise on the inbound audio stream before transcription."},"interruption_min_words":{"type":"integer","minimum":1,"description":"Minimum number of words the caller must say before their speech is treated as an interruption.","example":2},"max_call_duration_in_sec":{"type":"integer","minimum":1,"description":"Hard upper bound on call length in seconds. The agent will end the call once this is reached.","example":600},"first_ideal_message":{"type":"string","description":"First nudge spoken when the caller goes silent past the\nidle threshold. Set `is_first_ideal_message_dynamic` to\n`true` to have the LLM regenerate this each time.\n"},"is_first_ideal_message_dynamic":{"type":"boolean","description":"When true, `first_ideal_message` is treated as a prompt and the LLM generates a fresh nudge each call."},"second_ideal_message":{"type":"string","description":"Second nudge spoken if silence continues after the first."},"is_second_ideal_message_dynamic":{"type":"boolean","description":"When true, `second_ideal_message` is treated as a prompt and the LLM generates a fresh nudge each call."},"numerals":{"type":"boolean","description":"Convert numbers from words to digits."},"punctuate":{"type":"boolean","description":"Add punctuation to the transcript."},"smart_format":{"type":"boolean","description":"Apply smart formatting to the transcript."},"diarize":{"type":"boolean","description":"Identify different speakers in the transcript."}}},"model":{"type":"object","description":"Configuration for the language model.","properties":{"model":{"type":"string","enum":["azure-gpt-4.1-mini","azure-gpt-4.1-nano","azure-gpt-4o","azure-gpt-4o-mini","claude-3-5-haiku-latest","claude-3-5-sonnet-latest","claude-3-7-sonnet-latest","claude-3-opus-latest","claude-opus-4-0","claude-sonnet-4-0","gemini-1.5-pro","gemini-2.0-flash","gemini-2.5-flash","gemini-2.5-flash-lite","gemini-2.5-pro","gemini-3-flash-preview","gemini-3-pro-preview","gemma2-9b-it","gpt-3.5-turbo","gpt-4o","gpt-4o-mini","gpt-5.4","llama-3.3-70b-versatile","llama3-70b-8192","llama3-8b-8192"],"description":"The language model to use.","example":"gpt-4o-mini"},"temperature":{"type":"number","minimum":0,"maximum":1,"description":"Controls randomness in the model's output (0.0 to 1.0).","example":0.7}}},"voice":{"type":"object","description":"Configuration for the text-to-speech voice.","properties":{"provider":{"type":"string","enum":["eleven_labs","deepgram","google","cartesia","rime"],"description":"The voice provider to use.","example":"eleven_labs"},"voice_id":{"type":"string","description":"The specific external voice identifier from the provider.","example":"JBFqnCBsd6RMkjVDRZzb"},"model":{"type":"string","description":"TTS model identifier. Only consumed when `provider` is\n`cartesia` (e.g. `sonic-3.5`). For ElevenLabs and other\nproviders the model is implied by `voice_id` and this\nfield is ignored.\n","example":"sonic-3.5"},"speech_speed":{"type":"number","minimum":0.5,"maximum":2,"default":1,"description":"Playback speed multiplier for the agent's voice. 1.0 is normal speed."}}},"web_search":{"type":"object","description":"Configuration for web search capabilities.","properties":{"enabled":{"type":"boolean","description":"Enable or disable web search functionality."},"provider":{"type":"string","enum":["DuckDuckGo"],"description":"The search provider to use.","example":"DuckDuckGo"}}},"post_call_actions":{"type":"object","description":"Side effects that fire once the call ends. Configure email, webhook, or both.","properties":{"email":{"type":"object","properties":{"enabled":{"type":"boolean"},"recipients":{"type":"array","description":"Email addresses that should receive the notification.","items":{"type":"string","format":"email"},"example":["support@example.com"]},"include":{"type":"array","description":"Which sections to include in the email body.","items":{"type":"string","enum":["summary","extracted_variables","fullConversation","sentiment"]}},"extracted_variables":{"type":"array","description":"Variables the model should pull out of the conversation for the email.","items":{"type":"object","required":["key","prompt"],"properties":{"key":{"type":"string","description":"Unique identifier for the variable in the post-call payload.","example":"customer_issue"},"prompt":{"type":"string","description":"Instruction for the model on what to pull out of the conversation.","example":"Identify the main issue the customer is experiencing."}}}},"trigger_call_statuses":{"type":"array","description":"Call outcomes that should fire this action. Omit to\nuse the default (`completed`, `voicemail_detected`).\nPass an explicit list to also include failed calls,\nno-answers, busy signals, etc.\n","items":{"type":"string","enum":["completed","voicemail_detected","failed","no_answer","busy","cancelled"]},"example":["completed","voicemail_detected"]}}},"webhook":{"type":"object","properties":{"enabled":{"type":"boolean"},"url":{"type":"string","format":"uri","description":"Endpoint that receives a POST with the call payload.","example":"https://your-webhook-endpoint.com/omnidim-callback"},"include":{"type":"array","description":"Which sections to include in the webhook body.","items":{"type":"string","enum":["summary","extracted_variables","fullConversation","sentiment"]}},"extracted_variables":{"type":"array","description":"Variables the model should pull out of the conversation for the webhook.","items":{"type":"object","required":["key","prompt"],"properties":{"key":{"type":"string","description":"Unique identifier for the variable in the post-call payload.","example":"customer_issue"},"prompt":{"type":"string","description":"Instruction for the model on what to pull out of the conversation.","example":"Identify the main issue the customer is experiencing."}}}},"trigger_call_statuses":{"type":"array","description":"Call outcomes that should fire this webhook. Omit to\nuse the default (`completed`, `voicemail_detected`).\n","items":{"type":"string","enum":["completed","voicemail_detected","failed","no_answer","busy","cancelled"]},"example":["completed","failed"]}}}}},"transfer":{"type":"object","description":"Conditional call transfer to a human agent or another number.","properties":{"enabled":{"type":"boolean"},"transfer_options":{"type":"array","description":"Where to transfer the call and under what condition. The first matching condition wins.","items":{"type":"object","required":["number","transfer_condition","transfer_message"],"properties":{"number":{"type":"string","description":"Primary phone number to transfer to. Include country code with leading `+`.","example":"+15551234567"},"type":{"type":"string","enum":["static","dynamic"],"default":"static","description":"`static` transfers to `number`. `dynamic` lets the agent\npick a number at runtime based on the conversation.\n"},"backup_numbers":{"type":"array","description":"Fallback numbers tried if the primary is unreachable.","items":{"type":"string"}},"transfer_condition":{"type":"string","description":"Natural-language condition that triggers this transfer option.","example":"Transfer if the customer asks to speak with a human."},"transfer_message":{"type":"string","description":"Message the agent says to the caller before executing the transfer.","example":"Please hold while I connect you to one of our agents."}}}}}},"end_call":{"type":"object","description":"Hang up automatically when a condition is met.","properties":{"enabled":{"type":"boolean"},"condition":{"type":"string","description":"Natural-language condition that triggers ending the call. Only evaluated when `enabled` is true.","example":"End the call once the customer's issue is resolved."},"message":{"type":"string","description":"What the agent says before hanging up.","example":"Thank you for contacting us. Have a great day!"},"message_type":{"type":"string","enum":["static","prompt"],"description":"`static` speaks `message` verbatim. `prompt` treats\n`message_prompt` as an LLM instruction and generates a\nfresh closing line each call (useful for matching the\ncaller's language and tone).\n"},"message_prompt":{"type":"string","description":"LLM prompt used to generate the closing line when `message_type` is `prompt`.","example":"End the call politely in the same language the user is speaking."}}},"background_track":{"type":"object","description":"Ambient background noise that plays under the agent's voice.","properties":{"enabled":{"type":"boolean","description":"Whether to mix the ambient track under the agent's audio."},"name":{"type":"string","enum":["call_center","filler","office","office_1","restaurant"],"description":"Ambient track to mix under the agent."},"volume":{"type":"number","minimum":0,"maximum":1,"default":0.2,"description":"Volume level on a 0–1 scale. Default 0.2."},"tts_volume_reduction":{"type":"number","minimum":0,"maximum":1,"description":"Amount to drop the agent's TTS volume while the ambient track plays, on a 0–1 scale. Helps the voice cut through without raising the overall mix."}}},"initial_ringing_sound_enabled":{"type":"boolean","description":"Plays a ringing tone after the call is picked up, until the agent starts speaking."},"voicemail":{"type":"object","description":"Voicemail / answering-machine handling for outbound calls.","properties":{"enabled":{"type":"boolean","description":"Detect voicemail and react instead of speaking to a machine."},"message":{"type":"string","description":"Message to leave when voicemail is detected."}}},"languages":{"type":"array","description":"Languages the agent should support. Pass each language as a display-name string.","items":{"type":"string","enum":["English","English (India)","English (US)","Hindi","Bengali","Spanish","Tamil","Marathi","Telugu","Gujarati","French"]},"example":["English","Hindi"]}}},{"type":"object","required":["name","welcome_message","context_breakdown"]}],"description":"The JSON request body."}},"required":["requestBody"]},
|
|
83
|
+
method: "post",
|
|
84
|
+
pathTemplate: "/agents/create",
|
|
85
|
+
executionParameters: [],
|
|
86
|
+
requestBodyContentType: "application/json",
|
|
87
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
88
|
+
}],
|
|
89
|
+
["getAgent", {
|
|
90
|
+
name: "getAgent",
|
|
91
|
+
description: `Get details of a specific agent by ID.`,
|
|
92
|
+
inputSchema: {"type":"object","properties":{"agent_id":{"type":"number","description":"The ID of the agent."}},"required":["agent_id"]},
|
|
93
|
+
method: "get",
|
|
94
|
+
pathTemplate: "/agents/{agent_id}",
|
|
95
|
+
executionParameters: [{"name":"agent_id","in":"path"}],
|
|
96
|
+
requestBodyContentType: undefined,
|
|
97
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
98
|
+
}],
|
|
99
|
+
["updateAgent", {
|
|
100
|
+
name: "updateAgent",
|
|
101
|
+
description: `Update an existing agent. Send only the fields you want to change.`,
|
|
102
|
+
inputSchema: {"type":"object","properties":{"agent_id":{"type":"number","description":"The ID of the agent."},"requestBody":{"type":"object","description":"Agent configuration.","properties":{"name":{"type":"string","description":"Name for the agent."},"welcome_message":{"type":"string","description":"Initial message the agent will say when answering a call."},"is_welcome_message_interruption":{"type":"boolean","description":"Allow the caller to interrupt the welcome message. When false, the agent finishes speaking the welcome before listening."},"is_interruption_allowed":{"type":"boolean","description":"Global toggle for whether the caller can interrupt the agent mid-sentence at any point in the call."},"dynamic_variables":{"type":"object","description":"Key/value map used to substitute placeholders in the agent's\nprompt and welcome message at call time. Reference a variable\nin your prompt with `{{variable_name}}`. Useful for\npersonalising the same agent across many calls.\n","additionalProperties":{"type":"string"}},"context_breakdown":{"type":"array","description":"List of context breakdowns, each containing `title`, `body`, and optional `is_enabled`.","items":{"type":"object","required":["title","body"],"properties":{"title":{"type":"string","description":"Title of the breakdown."},"body":{"type":"string","description":"Body of the breakdown — the detailed prompt content."},"is_enabled":{"type":"boolean","default":true,"description":"Whether this section is included in the prompt."}}}},"call_type":{"type":"string","enum":["Incoming","Outgoing"],"description":"Call type of the assistant."},"transcriber":{"type":"object","description":"Configuration for the speech-to-text transcriber.","properties":{"provider":{"type":"string","enum":["deepgram_stream","cartesia","sarvam","azure_stream","soniox"],"description":"The speech-to-text provider to use."},"model":{"type":"string","enum":["nova-3","nova-2"],"description":"The model to use for transcription (required when provider is `deepgram_stream`)."},"language":{"type":"string","description":"Language code for the transcriber. Format and supported\nvalues depend on the provider (e.g. `en-US` for Deepgram,\n`hi-IN` for Sarvam). Applies regardless of which\n`provider` is selected.\n"},"silence_timeout_ms":{"type":"number","description":"Silence timeout in milliseconds."},"should_apply_noise_reduction":{"type":"boolean","description":"Reduce background noise on the inbound audio stream before transcription."},"interruption_min_words":{"type":"number","minimum":1,"description":"Minimum number of words the caller must say before their speech is treated as an interruption."},"max_call_duration_in_sec":{"type":"number","minimum":1,"description":"Hard upper bound on call length in seconds. The agent will end the call once this is reached."},"first_ideal_message":{"type":"string","description":"First nudge spoken when the caller goes silent past the\nidle threshold. Set `is_first_ideal_message_dynamic` to\n`true` to have the LLM regenerate this each time.\n"},"is_first_ideal_message_dynamic":{"type":"boolean","description":"When true, `first_ideal_message` is treated as a prompt and the LLM generates a fresh nudge each call."},"second_ideal_message":{"type":"string","description":"Second nudge spoken if silence continues after the first."},"is_second_ideal_message_dynamic":{"type":"boolean","description":"When true, `second_ideal_message` is treated as a prompt and the LLM generates a fresh nudge each call."},"numerals":{"type":"boolean","description":"Convert numbers from words to digits."},"punctuate":{"type":"boolean","description":"Add punctuation to the transcript."},"smart_format":{"type":"boolean","description":"Apply smart formatting to the transcript."},"diarize":{"type":"boolean","description":"Identify different speakers in the transcript."}}},"model":{"type":"object","description":"Configuration for the language model.","properties":{"model":{"type":"string","enum":["azure-gpt-4.1-mini","azure-gpt-4.1-nano","azure-gpt-4o","azure-gpt-4o-mini","claude-3-5-haiku-latest","claude-3-5-sonnet-latest","claude-3-7-sonnet-latest","claude-3-opus-latest","claude-opus-4-0","claude-sonnet-4-0","gemini-1.5-pro","gemini-2.0-flash","gemini-2.5-flash","gemini-2.5-flash-lite","gemini-2.5-pro","gemini-3-flash-preview","gemini-3-pro-preview","gemma2-9b-it","gpt-3.5-turbo","gpt-4o","gpt-4o-mini","gpt-5.4","llama-3.3-70b-versatile","llama3-70b-8192","llama3-8b-8192"],"description":"The language model to use."},"temperature":{"type":"number","minimum":0,"maximum":1,"description":"Controls randomness in the model's output (0.0 to 1.0)."}}},"voice":{"type":"object","description":"Configuration for the text-to-speech voice.","properties":{"provider":{"type":"string","enum":["eleven_labs","deepgram","google","cartesia","rime"],"description":"The voice provider to use."},"voice_id":{"type":"string","description":"The specific external voice identifier from the provider."},"model":{"type":"string","description":"TTS model identifier. Only consumed when `provider` is\n`cartesia` (e.g. `sonic-3.5`). For ElevenLabs and other\nproviders the model is implied by `voice_id` and this\nfield is ignored.\n"},"speech_speed":{"type":"number","minimum":0.5,"maximum":2,"default":1,"description":"Playback speed multiplier for the agent's voice. 1.0 is normal speed."}}},"web_search":{"type":"object","description":"Configuration for web search capabilities.","properties":{"enabled":{"type":"boolean","description":"Enable or disable web search functionality."},"provider":{"type":"string","enum":["DuckDuckGo"],"description":"The search provider to use."}}},"post_call_actions":{"type":"object","description":"Side effects that fire once the call ends. Configure email, webhook, or both.","properties":{"email":{"type":"object","properties":{"enabled":{"type":"boolean"},"recipients":{"type":"array","description":"Email addresses that should receive the notification.","items":{"type":"string","format":"email"}},"include":{"type":"array","description":"Which sections to include in the email body.","items":{"type":"string","enum":["summary","extracted_variables","fullConversation","sentiment"]}},"extracted_variables":{"type":"array","description":"Variables the model should pull out of the conversation for the email.","items":{"type":"object","required":["key","prompt"],"properties":{"key":{"type":"string","description":"Unique identifier for the variable in the post-call payload."},"prompt":{"type":"string","description":"Instruction for the model on what to pull out of the conversation."}}}},"trigger_call_statuses":{"type":"array","description":"Call outcomes that should fire this action. Omit to\nuse the default (`completed`, `voicemail_detected`).\nPass an explicit list to also include failed calls,\nno-answers, busy signals, etc.\n","items":{"type":"string","enum":["completed","voicemail_detected","failed","no_answer","busy","cancelled"]}}}},"webhook":{"type":"object","properties":{"enabled":{"type":"boolean"},"url":{"type":"string","format":"uri","description":"Endpoint that receives a POST with the call payload."},"include":{"type":"array","description":"Which sections to include in the webhook body.","items":{"type":"string","enum":["summary","extracted_variables","fullConversation","sentiment"]}},"extracted_variables":{"type":"array","description":"Variables the model should pull out of the conversation for the webhook.","items":{"type":"object","required":["key","prompt"],"properties":{"key":{"type":"string","description":"Unique identifier for the variable in the post-call payload."},"prompt":{"type":"string","description":"Instruction for the model on what to pull out of the conversation."}}}},"trigger_call_statuses":{"type":"array","description":"Call outcomes that should fire this webhook. Omit to\nuse the default (`completed`, `voicemail_detected`).\n","items":{"type":"string","enum":["completed","voicemail_detected","failed","no_answer","busy","cancelled"]}}}}}},"transfer":{"type":"object","description":"Conditional call transfer to a human agent or another number.","properties":{"enabled":{"type":"boolean"},"transfer_options":{"type":"array","description":"Where to transfer the call and under what condition. The first matching condition wins.","items":{"type":"object","required":["number","transfer_condition","transfer_message"],"properties":{"number":{"type":"string","description":"Primary phone number to transfer to. Include country code with leading `+`."},"type":{"type":"string","enum":["static","dynamic"],"default":"static","description":"`static` transfers to `number`. `dynamic` lets the agent\npick a number at runtime based on the conversation.\n"},"backup_numbers":{"type":"array","description":"Fallback numbers tried if the primary is unreachable.","items":{"type":"string"}},"transfer_condition":{"type":"string","description":"Natural-language condition that triggers this transfer option."},"transfer_message":{"type":"string","description":"Message the agent says to the caller before executing the transfer."}}}}}},"end_call":{"type":"object","description":"Hang up automatically when a condition is met.","properties":{"enabled":{"type":"boolean"},"condition":{"type":"string","description":"Natural-language condition that triggers ending the call. Only evaluated when `enabled` is true."},"message":{"type":"string","description":"What the agent says before hanging up."},"message_type":{"type":"string","enum":["static","prompt"],"description":"`static` speaks `message` verbatim. `prompt` treats\n`message_prompt` as an LLM instruction and generates a\nfresh closing line each call (useful for matching the\ncaller's language and tone).\n"},"message_prompt":{"type":"string","description":"LLM prompt used to generate the closing line when `message_type` is `prompt`."}}},"background_track":{"type":"object","description":"Ambient background noise that plays under the agent's voice.","properties":{"enabled":{"type":"boolean","description":"Whether to mix the ambient track under the agent's audio."},"name":{"type":"string","enum":["call_center","filler","office","office_1","restaurant"],"description":"Ambient track to mix under the agent."},"volume":{"type":"number","minimum":0,"maximum":1,"default":0.2,"description":"Volume level on a 0–1 scale. Default 0.2."},"tts_volume_reduction":{"type":"number","minimum":0,"maximum":1,"description":"Amount to drop the agent's TTS volume while the ambient track plays, on a 0–1 scale. Helps the voice cut through without raising the overall mix."}}},"initial_ringing_sound_enabled":{"type":"boolean","description":"Plays a ringing tone after the call is picked up, until the agent starts speaking."},"voicemail":{"type":"object","description":"Voicemail / answering-machine handling for outbound calls.","properties":{"enabled":{"type":"boolean","description":"Detect voicemail and react instead of speaking to a machine."},"message":{"type":"string","description":"Message to leave when voicemail is detected."}}},"languages":{"type":"array","description":"Languages the agent should support. Pass each language as a display-name string.","items":{"type":"string","enum":["English","English (India)","English (US)","Hindi","Bengali","Spanish","Tamil","Marathi","Telugu","Gujarati","French"]}}}}},"required":["agent_id","requestBody"]},
|
|
103
|
+
method: "put",
|
|
104
|
+
pathTemplate: "/agents/{agent_id}",
|
|
105
|
+
executionParameters: [{"name":"agent_id","in":"path"}],
|
|
106
|
+
requestBodyContentType: "application/json",
|
|
107
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
108
|
+
}],
|
|
109
|
+
["deleteAgent", {
|
|
110
|
+
name: "deleteAgent",
|
|
111
|
+
description: `Permanently delete an agent.`,
|
|
112
|
+
inputSchema: {"type":"object","properties":{"agent_id":{"type":"number","description":"The ID of the agent."}},"required":["agent_id"]},
|
|
113
|
+
method: "delete",
|
|
114
|
+
pathTemplate: "/agents/{agent_id}",
|
|
115
|
+
executionParameters: [{"name":"agent_id","in":"path"}],
|
|
116
|
+
requestBodyContentType: undefined,
|
|
117
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
118
|
+
}],
|
|
119
|
+
["dispatchCall", {
|
|
120
|
+
name: "dispatchCall",
|
|
121
|
+
description: `Initiate a call to a phone number using a specified agent. The
|
|
122
|
+
phone number must include a country code with a leading plus.
|
|
123
|
+
`,
|
|
124
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["agent_id","to_number"],"properties":{"agent_id":{"type":"number","description":"The ID of the agent that will handle the call."},"to_number":{"type":"string","description":"The phone number to call. Must include country code (e.g., +15551234567)."},"from_number_id":{"type":"number","description":"The imported phone number id to call."},"call_context":{"type":"object","description":"Optional context information as key-value pairs to be passed to the agent during the call. Can contain any custom fields relevant to your use case.","additionalProperties":true}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
125
|
+
method: "post",
|
|
126
|
+
pathTemplate: "/calls/dispatch",
|
|
127
|
+
executionParameters: [],
|
|
128
|
+
requestBodyContentType: "application/json",
|
|
129
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
130
|
+
}],
|
|
131
|
+
["listCallLogs", {
|
|
132
|
+
name: "listCallLogs",
|
|
133
|
+
description: `Retrieve call logs with pagination and optional filtering.`,
|
|
134
|
+
inputSchema: {"type":"object","properties":{"pageno":{"type":"integer","minimum":1,"default":1,"description":"Page number for pagination."},"pagesize":{"type":"integer","minimum":1,"default":30,"maximum":150,"description":"Number of items per page."},"agentid":{"type":"number","description":"Filter by agent ID."},"call_status":{"type":"string","enum":["completed","busy","failed","no-answer"]},"bulk_call_id":{"type":"number","description":"Filter by bulk-call campaign ID."}}},
|
|
135
|
+
method: "get",
|
|
136
|
+
pathTemplate: "/calls/logs",
|
|
137
|
+
executionParameters: [{"name":"pageno","in":"query"},{"name":"pagesize","in":"query"},{"name":"agentid","in":"query"},{"name":"call_status","in":"query"},{"name":"bulk_call_id","in":"query"}],
|
|
138
|
+
requestBodyContentType: undefined,
|
|
139
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
140
|
+
}],
|
|
141
|
+
["getCallLog", {
|
|
142
|
+
name: "getCallLog",
|
|
143
|
+
description: `Detailed information about a specific call (duration, status, transcript, sentiment, extracted variables).`,
|
|
144
|
+
inputSchema: {"type":"object","properties":{"call_log_id":{"type":"number"}},"required":["call_log_id"]},
|
|
145
|
+
method: "get",
|
|
146
|
+
pathTemplate: "/calls/logs/{call_log_id}",
|
|
147
|
+
executionParameters: [{"name":"call_log_id","in":"path"}],
|
|
148
|
+
requestBodyContentType: undefined,
|
|
149
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
150
|
+
}],
|
|
151
|
+
["fetchBulkCalls", {
|
|
152
|
+
name: "fetchBulkCalls",
|
|
153
|
+
description: `List bulk-call campaigns with pagination and optional status filter.`,
|
|
154
|
+
inputSchema: {"type":"object","properties":{"pageno":{"type":"integer","minimum":1,"default":1},"pagesize":{"type":"integer","minimum":1,"default":10,"maximum":150,"description":"Items per page (max 150 — sending more returns 500)."},"status":{"type":"string","description":"Filter by status (e.g. completed)."}}},
|
|
155
|
+
method: "get",
|
|
156
|
+
pathTemplate: "/calls/bulk_call",
|
|
157
|
+
executionParameters: [{"name":"pageno","in":"query"},{"name":"pagesize","in":"query"},{"name":"status","in":"query"}],
|
|
158
|
+
requestBodyContentType: undefined,
|
|
159
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
160
|
+
}],
|
|
161
|
+
["createBulkCall", {
|
|
162
|
+
name: "createBulkCall",
|
|
163
|
+
description: `Create a new bulk-call campaign. Supports immediate, scheduled, and auto-retry modes.`,
|
|
164
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["name","contact_list","phone_number_id"],"properties":{"name":{"type":"string","description":"Name of the bulk call campaign."},"phone_number_id":{"type":"string","description":"Your phone number id to use for making calls."},"contact_list":{"type":"array","minItems":1,"description":"Array of contact objects. Each row needs `phone_number`.\nAny other key you add on the row (e.g. `customer_name`,\n`account_id`, `priority`) is passed to the agent as a\ncontext variable for that specific call, so the agent\ncan reference it during the conversation.\n","items":{"type":"object","required":["phone_number"],"properties":{"phone_number":{"type":"string","description":"Phone number in international format (e.g., +15551234567)."}},"additionalProperties":true}},"is_scheduled":{"type":"boolean","default":false,"description":"Whether the campaign should be scheduled for future execution."},"scheduled_datetime":{"type":"string","description":"Scheduled execution time in format `YYYY-MM-DD HH:MM:SS` (required if `is_scheduled` is true)."},"timezone":{"type":"string","default":"UTC","description":"Timezone for scheduled execution."},"concurrent_call_limit":{"type":"number","default":1,"minimum":1,"description":"Maximum number of concurrent calls allowed."},"enabled_reschedule_call":{"type":"boolean","default":false,"description":"Enable automatic call rescheduling. When enabled the system can reschedule unreachable calls."},"retry_config":{"type":"object","description":"Auto-retry configuration object containing retry settings.","properties":{"auto_retry":{"type":"boolean","default":false},"auto_retry_schedule":{"type":"string","enum":["immediately","next_day","scheduled_time"],"description":"When to retry failed calls."},"retry_schedule_days":{"type":"number","default":0,"minimum":0,"description":"Days to wait before a scheduled retry."},"retry_schedule_hours":{"type":"number","default":0,"minimum":0,"description":"Hours to wait before a scheduled retry."},"retry_limit":{"type":"number","default":0,"minimum":0,"maximum":5,"description":"Maximum number of retry attempts (0–5)."}}}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
165
|
+
method: "post",
|
|
166
|
+
pathTemplate: "/calls/bulk_call/create",
|
|
167
|
+
executionParameters: [],
|
|
168
|
+
requestBodyContentType: "application/json",
|
|
169
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
170
|
+
}],
|
|
171
|
+
["getBulkCall", {
|
|
172
|
+
name: "getBulkCall",
|
|
173
|
+
description: `Get detailed information about a bulk-call campaign.`,
|
|
174
|
+
inputSchema: {"type":"object","properties":{"bulk_call_id":{"type":"number"}},"required":["bulk_call_id"]},
|
|
175
|
+
method: "get",
|
|
176
|
+
pathTemplate: "/calls/bulk_call/{bulk_call_id}",
|
|
177
|
+
executionParameters: [{"name":"bulk_call_id","in":"path"}],
|
|
178
|
+
requestBodyContentType: undefined,
|
|
179
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
180
|
+
}],
|
|
181
|
+
["bulkCallActions", {
|
|
182
|
+
name: "bulkCallActions",
|
|
183
|
+
description: `Pause, resume, or reschedule a running campaign.`,
|
|
184
|
+
inputSchema: {"type":"object","properties":{"bulk_call_id":{"type":"number"},"requestBody":{"type":"object","required":["action"],"properties":{"action":{"type":"string","enum":["pause","resume","reschedule"],"description":"What to do with the campaign."},"new_scheduled_datetime":{"type":"string","description":"New start time for `reschedule`. Format `YYYY-MM-DD HH:MM:SS`."},"new_timezone":{"type":"string","description":"IANA timezone for `reschedule`."}},"description":"The JSON request body."}},"required":["bulk_call_id","requestBody"]},
|
|
185
|
+
method: "put",
|
|
186
|
+
pathTemplate: "/calls/bulk_call/{bulk_call_id}",
|
|
187
|
+
executionParameters: [{"name":"bulk_call_id","in":"path"}],
|
|
188
|
+
requestBodyContentType: "application/json",
|
|
189
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
190
|
+
}],
|
|
191
|
+
["cancelBulkCall", {
|
|
192
|
+
name: "cancelBulkCall",
|
|
193
|
+
description: `Cancel a bulk-call campaign.`,
|
|
194
|
+
inputSchema: {"type":"object","properties":{"bulk_call_id":{"type":"number"}},"required":["bulk_call_id"]},
|
|
195
|
+
method: "delete",
|
|
196
|
+
pathTemplate: "/calls/bulk_call/{bulk_call_id}",
|
|
197
|
+
executionParameters: [{"name":"bulk_call_id","in":"path"}],
|
|
198
|
+
requestBodyContentType: undefined,
|
|
199
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
200
|
+
}],
|
|
201
|
+
["getBulkCallLiveStatus", {
|
|
202
|
+
name: "getBulkCallLiveStatus",
|
|
203
|
+
description: `Real-time status of a running bulk-call campaign.`,
|
|
204
|
+
inputSchema: {"type":"object","properties":{"bulk_call_id":{"type":"number"}},"required":["bulk_call_id"]},
|
|
205
|
+
method: "get",
|
|
206
|
+
pathTemplate: "/bulk-call/{bulk_call_id}/live-status",
|
|
207
|
+
executionParameters: [{"name":"bulk_call_id","in":"path"}],
|
|
208
|
+
requestBodyContentType: undefined,
|
|
209
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
210
|
+
}],
|
|
211
|
+
["listKnowledgeBaseFiles", {
|
|
212
|
+
name: "listKnowledgeBaseFiles",
|
|
213
|
+
description: `List all knowledge-base files for the authenticated user.`,
|
|
214
|
+
inputSchema: {"type":"object","properties":{}},
|
|
215
|
+
method: "get",
|
|
216
|
+
pathTemplate: "/knowledge_base/list",
|
|
217
|
+
executionParameters: [],
|
|
218
|
+
requestBodyContentType: undefined,
|
|
219
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
220
|
+
}],
|
|
221
|
+
["canUploadFile", {
|
|
222
|
+
name: "canUploadFile",
|
|
223
|
+
description: `Check whether a file can be uploaded based on size and type.`,
|
|
224
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["file_size","file_type"],"properties":{"file_size":{"type":"number","minimum":1,"description":"Size in bytes."},"file_type":{"type":"string","description":"File extension. Only `pdf` is accepted."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
225
|
+
method: "post",
|
|
226
|
+
pathTemplate: "/knowledge_base/can_upload",
|
|
227
|
+
executionParameters: [],
|
|
228
|
+
requestBodyContentType: "application/json",
|
|
229
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
230
|
+
}],
|
|
231
|
+
["uploadKnowledgeBaseFile", {
|
|
232
|
+
name: "uploadKnowledgeBaseFile",
|
|
233
|
+
description: `Upload a PDF file. The file content must be Base64 encoded.`,
|
|
234
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["file","filename"],"properties":{"file":{"type":"string","description":"Base64-encoded file content."},"filename":{"type":"string","description":"Filename including the `.pdf` extension."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
235
|
+
method: "post",
|
|
236
|
+
pathTemplate: "/knowledge_base/create",
|
|
237
|
+
executionParameters: [],
|
|
238
|
+
requestBodyContentType: "application/json",
|
|
239
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
240
|
+
}],
|
|
241
|
+
["attachKnowledgeBaseFiles", {
|
|
242
|
+
name: "attachKnowledgeBaseFiles",
|
|
243
|
+
description: `Attach multiple knowledge-base files to an agent.`,
|
|
244
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["file_ids","agent_id"],"properties":{"file_ids":{"type":"array","minItems":1,"items":{"type":"number"},"description":"List of knowledge-base file IDs to attach."},"agent_id":{"type":"number","description":"ID of the agent to attach files to."},"when_to_use":{"type":"string","description":"Instruction to the agent on when to consult these files."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
245
|
+
method: "post",
|
|
246
|
+
pathTemplate: "/knowledge_base/attach",
|
|
247
|
+
executionParameters: [],
|
|
248
|
+
requestBodyContentType: "application/json",
|
|
249
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
250
|
+
}],
|
|
251
|
+
["detachKnowledgeBaseFiles", {
|
|
252
|
+
name: "detachKnowledgeBaseFiles",
|
|
253
|
+
description: `Detach multiple knowledge-base files from an agent.`,
|
|
254
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["file_ids","agent_id"],"properties":{"file_ids":{"type":"array","minItems":1,"items":{"type":"number"},"description":"List of knowledge-base file IDs to detach."},"agent_id":{"type":"number","description":"ID of the agent to detach files from."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
255
|
+
method: "post",
|
|
256
|
+
pathTemplate: "/knowledge_base/detach",
|
|
257
|
+
executionParameters: [],
|
|
258
|
+
requestBodyContentType: "application/json",
|
|
259
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
260
|
+
}],
|
|
261
|
+
["deleteKnowledgeBaseFile", {
|
|
262
|
+
name: "deleteKnowledgeBaseFile",
|
|
263
|
+
description: `Permanently delete a file. Removes it from any attached agents. Cannot be undone.`,
|
|
264
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["file_id"],"properties":{"file_id":{"type":"number","description":"ID of the file to delete."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
265
|
+
method: "post",
|
|
266
|
+
pathTemplate: "/knowledge_base/delete",
|
|
267
|
+
executionParameters: [],
|
|
268
|
+
requestBodyContentType: "application/json",
|
|
269
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
270
|
+
}],
|
|
271
|
+
["listPhoneNumbers", {
|
|
272
|
+
name: "listPhoneNumbers",
|
|
273
|
+
description: `Retrieve all phone numbers associated with your account.`,
|
|
274
|
+
inputSchema: {"type":"object","properties":{"pageno":{"type":"integer","minimum":1,"default":1},"pagesize":{"type":"integer","minimum":1,"default":30,"maximum":150}}},
|
|
275
|
+
method: "get",
|
|
276
|
+
pathTemplate: "/phone_number/list",
|
|
277
|
+
executionParameters: [{"name":"pageno","in":"query"},{"name":"pagesize","in":"query"}],
|
|
278
|
+
requestBodyContentType: undefined,
|
|
279
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
280
|
+
}],
|
|
281
|
+
["attachPhoneNumber", {
|
|
282
|
+
name: "attachPhoneNumber",
|
|
283
|
+
description: `Attach an account-owned phone number to an existing agent.`,
|
|
284
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["phone_number_id","agent_id"],"properties":{"phone_number_id":{"type":"number","description":"ID of the phone number to attach."},"agent_id":{"type":"number","description":"ID of the agent to attach the phone number to."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
285
|
+
method: "post",
|
|
286
|
+
pathTemplate: "/phone_number/attach",
|
|
287
|
+
executionParameters: [],
|
|
288
|
+
requestBodyContentType: "application/json",
|
|
289
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
290
|
+
}],
|
|
291
|
+
["detachPhoneNumber", {
|
|
292
|
+
name: "detachPhoneNumber",
|
|
293
|
+
description: `Detach a phone number from its associated agent.`,
|
|
294
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["phone_number_id"],"properties":{"phone_number_id":{"type":"number","description":"ID of the phone number to detach."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
295
|
+
method: "post",
|
|
296
|
+
pathTemplate: "/phone_number/detach",
|
|
297
|
+
executionParameters: [],
|
|
298
|
+
requestBodyContentType: "application/json",
|
|
299
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
300
|
+
}],
|
|
301
|
+
["importTwilioNumber", {
|
|
302
|
+
name: "importTwilioNumber",
|
|
303
|
+
description: `Import an existing Twilio number by providing your Twilio credentials.`,
|
|
304
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["phone_number","account_sid","account_token"],"properties":{"phone_number":{"type":"string","description":"Phone number in E.164 format (starting with `+`)."},"account_sid":{"type":"string","description":"Your Twilio account SID."},"account_token":{"type":"string","description":"Your Twilio auth token."},"name":{"type":"string","description":"Optional friendly name for the imported number."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
305
|
+
method: "post",
|
|
306
|
+
pathTemplate: "/phone_number/import/twilio",
|
|
307
|
+
executionParameters: [],
|
|
308
|
+
requestBodyContentType: "application/json",
|
|
309
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
310
|
+
}],
|
|
311
|
+
["importExotelNumber", {
|
|
312
|
+
name: "importExotelNumber",
|
|
313
|
+
description: `Import an Exotel number by providing your Exotel credentials.`,
|
|
314
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["exotel_phone_number","exotel_api_key","exotel_api_token","exotel_subdomain","exotel_account_sid","exotel_app_id"],"properties":{"exotel_phone_number":{"type":"string","description":"Exotel phone number in E.164 format."},"exotel_api_key":{"type":"string","description":"Your Exotel API key."},"exotel_api_token":{"type":"string","description":"Your Exotel API token."},"exotel_subdomain":{"type":"string","description":"Your Exotel subdomain (e.g. `your-account.in.exotel.com`)."},"exotel_account_sid":{"type":"string","description":"Your Exotel account SID."},"exotel_app_id":{"type":"string","description":"The Exotel App ID configured for the bot."},"name":{"type":"string","description":"Optional friendly name for the imported number."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
315
|
+
method: "post",
|
|
316
|
+
pathTemplate: "/phone_number/import/exotel",
|
|
317
|
+
executionParameters: [],
|
|
318
|
+
requestBodyContentType: "application/json",
|
|
319
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
320
|
+
}],
|
|
321
|
+
["importSipTrunk", {
|
|
322
|
+
name: "importSipTrunk",
|
|
323
|
+
description: `Import a phone number associated with a SIP trunk.`,
|
|
324
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["phone_number","sip_host","sip_trunk_name"],"properties":{"phone_number":{"type":"string","description":"Phone number in E.164 format (starting with `+`)."},"sip_host":{"type":"string","description":"SIP server hostname or IP."},"sip_trunk_name":{"type":"string","description":"Name for this SIP trunk (must be unique within your account)."},"name":{"type":"string","description":"Optional friendly name for the imported number."},"sip_port":{"type":"number","default":5060,"description":"SIP server port."},"sip_username":{"type":"string","description":"SIP authentication username."},"sip_password":{"type":"string","format":"password","description":"SIP authentication password."},"sip_dial_prefix":{"type":"string","description":"Optional prefix to prepend before the destination number when dialing (e.g. to strip the country code)."},"sip_strip_plus":{"type":"boolean","description":"When true, strips the leading `+` from the dialed number."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
325
|
+
method: "post",
|
|
326
|
+
pathTemplate: "/phone_number/import/sip",
|
|
327
|
+
executionParameters: [],
|
|
328
|
+
requestBodyContentType: "application/json",
|
|
329
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
330
|
+
}],
|
|
331
|
+
["listLLMProviders", {
|
|
332
|
+
name: "listLLMProviders",
|
|
333
|
+
description: `Retrieve all available Large Language Model providers.`,
|
|
334
|
+
inputSchema: {"type":"object","properties":{}},
|
|
335
|
+
method: "get",
|
|
336
|
+
pathTemplate: "/providers/llms",
|
|
337
|
+
executionParameters: [],
|
|
338
|
+
requestBodyContentType: undefined,
|
|
339
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
340
|
+
}],
|
|
341
|
+
["listVoices", {
|
|
342
|
+
name: "listVoices",
|
|
343
|
+
description: `Retrieve voices with filtering and pagination support. ElevenLabs
|
|
344
|
+
supports advanced filtering by name, language, accent, and gender.
|
|
345
|
+
Other providers support basic pagination only.
|
|
346
|
+
`,
|
|
347
|
+
inputSchema: {"type":"object","properties":{"provider":{"type":"string","enum":["eleven_labs","google","deepgram","cartesia","sarvam"],"description":"TTS provider to list voices from. Omit to list across all providers."},"search":{"type":"string","description":"Substring match against voice name or description. ElevenLabs only."},"language":{"type":"string","description":"ISO language code (e.g. `en`, `hi`, `es`). ElevenLabs only."},"accent":{"type":"string","description":"Accent label (e.g. `american`, `british`). ElevenLabs only."},"gender":{"type":"string","enum":["male","female"],"description":"Filter voices by gender. ElevenLabs only."},"page":{"type":"integer","minimum":1,"default":1,"description":"1-indexed page number."},"page_size":{"type":"integer","minimum":1,"default":30,"maximum":100,"description":"Voices per page. Capped at 100."}}},
|
|
348
|
+
method: "get",
|
|
349
|
+
pathTemplate: "/providers/voices",
|
|
350
|
+
executionParameters: [{"name":"provider","in":"query"},{"name":"search","in":"query"},{"name":"language","in":"query"},{"name":"accent","in":"query"},{"name":"gender","in":"query"},{"name":"page","in":"query"},{"name":"page_size","in":"query"}],
|
|
351
|
+
requestBodyContentType: undefined,
|
|
352
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
353
|
+
}],
|
|
354
|
+
["listSTTProviders", {
|
|
355
|
+
name: "listSTTProviders",
|
|
356
|
+
description: `Retrieve all Speech-to-Text providers.`,
|
|
357
|
+
inputSchema: {"type":"object","properties":{}},
|
|
358
|
+
method: "get",
|
|
359
|
+
pathTemplate: "/providers/stt",
|
|
360
|
+
executionParameters: [],
|
|
361
|
+
requestBodyContentType: undefined,
|
|
362
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
363
|
+
}],
|
|
364
|
+
["listTTSProviders", {
|
|
365
|
+
name: "listTTSProviders",
|
|
366
|
+
description: `Retrieve all Text-to-Speech providers.`,
|
|
367
|
+
inputSchema: {"type":"object","properties":{}},
|
|
368
|
+
method: "get",
|
|
369
|
+
pathTemplate: "/providers/tts",
|
|
370
|
+
executionParameters: [],
|
|
371
|
+
requestBodyContentType: undefined,
|
|
372
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
373
|
+
}],
|
|
374
|
+
["listAllProviders", {
|
|
375
|
+
name: "listAllProviders",
|
|
376
|
+
description: `Comprehensive response with services and voices in one payload.`,
|
|
377
|
+
inputSchema: {"type":"object","properties":{}},
|
|
378
|
+
method: "get",
|
|
379
|
+
pathTemplate: "/providers/all",
|
|
380
|
+
executionParameters: [],
|
|
381
|
+
requestBodyContentType: undefined,
|
|
382
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
383
|
+
}],
|
|
384
|
+
["getVoice", {
|
|
385
|
+
name: "getVoice",
|
|
386
|
+
description: `Detailed metadata for a specific voice.`,
|
|
387
|
+
inputSchema: {"type":"object","properties":{"voice_id":{"type":"number"}},"required":["voice_id"]},
|
|
388
|
+
method: "get",
|
|
389
|
+
pathTemplate: "/providers/voice/{voice_id}",
|
|
390
|
+
executionParameters: [{"name":"voice_id","in":"path"}],
|
|
391
|
+
requestBodyContentType: undefined,
|
|
392
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
393
|
+
}],
|
|
394
|
+
["listSimulations", {
|
|
395
|
+
name: "listSimulations",
|
|
396
|
+
description: `Retrieve simulations with pagination.`,
|
|
397
|
+
inputSchema: {"type":"object","properties":{"pageno":{"type":"integer","minimum":1,"default":1},"pagesize":{"type":"integer","minimum":1,"default":10,"maximum":150}}},
|
|
398
|
+
method: "get",
|
|
399
|
+
pathTemplate: "/simulations",
|
|
400
|
+
executionParameters: [{"name":"pageno","in":"query"},{"name":"pagesize","in":"query"}],
|
|
401
|
+
requestBodyContentType: undefined,
|
|
402
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
403
|
+
}],
|
|
404
|
+
["createSimulation", {
|
|
405
|
+
name: "createSimulation",
|
|
406
|
+
description: `Create a new test simulation with scenarios.`,
|
|
407
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["name","agent_id"],"properties":{"name":{"type":"string","description":"Name of the simulation."},"agent_id":{"type":"number","description":"ID of the agent to test."},"number_of_call_to_make":{"type":"number","default":1,"minimum":1,"maximum":3,"description":"Number of calls to make per scenario (default 1, max 3)."},"concurrent_call_count":{"type":"number","default":3,"minimum":1,"maximum":3,"description":"Number of concurrent calls to run (default 3, max 3)."},"max_call_duration_in_minutes":{"type":"number","default":3,"minimum":1,"maximum":10,"description":"Maximum duration for each call in minutes (default 3, max 10)."},"scenarios":{"type":"array","description":"List of test scenarios to execute.","items":{"type":"object","required":["name","description","expected_result"],"properties":{"name":{"type":"string","description":"Name of the test scenario."},"description":{"type":"string","description":"Detailed instructions for the test scenario."},"expected_result":{"type":"string","description":"Expected outcome or behavior from the agent."},"selected_voices":{"type":"array","description":"Voice configurations for the test calls. If multiple voices are selected, the agent randomly picks one per call per scenario.","items":{"type":"object","required":["id","provider"],"properties":{"id":{"type":"string","description":"Voice ID from the provider."},"provider":{"type":"string","enum":["eleven_labs","play_ht","deepgram","cartesia","rime"]}}}}}}}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
408
|
+
method: "post",
|
|
409
|
+
pathTemplate: "/simulations",
|
|
410
|
+
executionParameters: [],
|
|
411
|
+
requestBodyContentType: "application/json",
|
|
412
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
413
|
+
}],
|
|
414
|
+
["getSimulation", {
|
|
415
|
+
name: "getSimulation",
|
|
416
|
+
description: `Detailed simulation information.`,
|
|
417
|
+
inputSchema: {"type":"object","properties":{"simulation_id":{"type":"number"}},"required":["simulation_id"]},
|
|
418
|
+
method: "get",
|
|
419
|
+
pathTemplate: "/simulations/{simulation_id}",
|
|
420
|
+
executionParameters: [{"name":"simulation_id","in":"path"}],
|
|
421
|
+
requestBodyContentType: undefined,
|
|
422
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
423
|
+
}],
|
|
424
|
+
["updateSimulation", {
|
|
425
|
+
name: "updateSimulation",
|
|
426
|
+
description: `Update an existing simulation. Pass the full \`scenarios\` array (existing entries you want to keep plus any changes).`,
|
|
427
|
+
inputSchema: {"type":"object","properties":{"simulation_id":{"type":"number"},"requestBody":{"type":"object","properties":{"name":{"type":"string","description":"Name of the simulation for identification."},"agent_id":{"type":"number","description":"ID of the agent to test."},"number_of_call_to_make":{"type":"number","minimum":1,"maximum":3,"description":"Number of calls to make per scenario (default 1, max 3)."},"concurrent_call_count":{"type":"number","minimum":1,"maximum":3,"description":"Number of concurrent calls to run (default 3, max 3)."},"max_call_duration_in_minutes":{"type":"number","minimum":1,"maximum":10,"description":"Maximum duration for each call in minutes (default 3, max 10)."},"scenarios":{"type":"array","description":"Full scenario list. Include existing scenarios you want to keep, plus any new or updated ones.","items":{"type":"object","required":["name","description","expected_result"],"properties":{"id":{"type":"number","description":"Include this to update an existing scenario; omit it to add a new one."},"name":{"type":"string","description":"Name of the test scenario."},"description":{"type":"string","description":"Updated instructions for the test scenario."},"expected_result":{"type":"string","description":"Updated expected outcome from the agent."},"selected_voices":{"type":"array","description":"Updated voice configurations for the test calls.","items":{"type":"object","required":["id","provider"],"properties":{"id":{"type":"string","description":"Voice ID from the provider."},"provider":{"type":"string","enum":["eleven_labs","play_ht","deepgram","cartesia","rime"]}}}}}}}},"description":"The JSON request body."}},"required":["simulation_id","requestBody"]},
|
|
428
|
+
method: "put",
|
|
429
|
+
pathTemplate: "/simulations/{simulation_id}",
|
|
430
|
+
executionParameters: [{"name":"simulation_id","in":"path"}],
|
|
431
|
+
requestBodyContentType: "application/json",
|
|
432
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
433
|
+
}],
|
|
434
|
+
["deleteSimulation", {
|
|
435
|
+
name: "deleteSimulation",
|
|
436
|
+
description: `Permanently delete a simulation.`,
|
|
437
|
+
inputSchema: {"type":"object","properties":{"simulation_id":{"type":"number"}},"required":["simulation_id"]},
|
|
438
|
+
method: "delete",
|
|
439
|
+
pathTemplate: "/simulations/{simulation_id}",
|
|
440
|
+
executionParameters: [{"name":"simulation_id","in":"path"}],
|
|
441
|
+
requestBodyContentType: undefined,
|
|
442
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
443
|
+
}],
|
|
444
|
+
["startSimulation", {
|
|
445
|
+
name: "startSimulation",
|
|
446
|
+
description: `Begin running a simulation. Optionally update scenarios at start time (same shape as Update simulation).`,
|
|
447
|
+
inputSchema: {"type":"object","properties":{"simulation_id":{"type":"number"},"requestBody":{"type":"object","properties":{"scenarios":{"type":"array","description":"Optional array of scenarios to update before starting.","items":{"type":"object","required":["name","description","expected_result"],"properties":{"id":{"type":"number","description":"Include this to update an existing scenario; omit it to add a new one."},"name":{"type":"string"},"description":{"type":"string","description":"Updated instructions for the test scenario."},"expected_result":{"type":"string","description":"Updated expected outcome from the agent."},"selected_voices":{"type":"array","description":"Updated voice configurations for the test calls.","items":{"type":"object","required":["id","provider"],"properties":{"id":{"type":"string","description":"Voice ID from the provider."},"provider":{"type":"string","enum":["eleven_labs","play_ht","deepgram","cartesia","rime"]}}}}}}}},"description":"The JSON request body."}},"required":["simulation_id"]},
|
|
448
|
+
method: "post",
|
|
449
|
+
pathTemplate: "/simulations/{simulation_id}/start",
|
|
450
|
+
executionParameters: [{"name":"simulation_id","in":"path"}],
|
|
451
|
+
requestBodyContentType: "application/json",
|
|
452
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
453
|
+
}],
|
|
454
|
+
["stopSimulation", {
|
|
455
|
+
name: "stopSimulation",
|
|
456
|
+
description: `Stop a running simulation.`,
|
|
457
|
+
inputSchema: {"type":"object","properties":{"simulation_id":{"type":"number"}},"required":["simulation_id"]},
|
|
458
|
+
method: "post",
|
|
459
|
+
pathTemplate: "/simulations/{simulation_id}/stop",
|
|
460
|
+
executionParameters: [{"name":"simulation_id","in":"path"}],
|
|
461
|
+
requestBodyContentType: undefined,
|
|
462
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
463
|
+
}],
|
|
464
|
+
["enhancePrompt", {
|
|
465
|
+
name: "enhancePrompt",
|
|
466
|
+
description: `Generate prompt-improvement suggestions for a completed simulation.`,
|
|
467
|
+
inputSchema: {"type":"object","properties":{"simulation_id":{"type":"number"}},"required":["simulation_id"]},
|
|
468
|
+
method: "post",
|
|
469
|
+
pathTemplate: "/simulations/{simulation_id}/enhance-prompt",
|
|
470
|
+
executionParameters: [{"name":"simulation_id","in":"path"}],
|
|
471
|
+
requestBodyContentType: undefined,
|
|
472
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
473
|
+
}],
|
|
474
|
+
["listChildOrganizations", {
|
|
475
|
+
name: "listChildOrganizations",
|
|
476
|
+
description: `List all child organizations and their users under the reseller
|
|
477
|
+
account. Returns each organization's balance, cost-per-minute
|
|
478
|
+
rate, and concurrency limit, plus the dashboard menu access
|
|
479
|
+
flags scoped to your reseller's permissions for every user.
|
|
480
|
+
`,
|
|
481
|
+
inputSchema: {"type":"object","properties":{}},
|
|
482
|
+
method: "get",
|
|
483
|
+
pathTemplate: "/reseller/organizations",
|
|
484
|
+
executionParameters: [],
|
|
485
|
+
requestBodyContentType: undefined,
|
|
486
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
487
|
+
}],
|
|
488
|
+
["addUser", {
|
|
489
|
+
name: "addUser",
|
|
490
|
+
description: `Create a new child user and organization under the reseller.
|
|
491
|
+
The new organization is linked to your reseller account
|
|
492
|
+
automatically.
|
|
493
|
+
`,
|
|
494
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["name","email","phone","password"],"properties":{"name":{"type":"string","description":"Full name of the new user."},"email":{"type":"string","format":"email","description":"Email address. Also used as the login."},"phone":{"type":"string","description":"Phone number including country code (e.g. `+15551234567`)."},"password":{"type":"string","format":"password","description":"Account password for the new user."},"welcome_minutes_to_credit":{"type":"number","description":"Minutes to credit to the new account on signup."},"cost_per_min":{"type":"number","description":"Cost per minute charged to this user (e.g. `0.20`). Must be at least the reseller's premium model rate."},"concurrent_call_limit":{"type":"number","description":"Maximum number of concurrent calls allowed for this account."},"expiry_date":{"type":"string","format":"date","description":"Account expiry date in `YYYY-MM-DD` format (e.g. `2026-12-31`)."},"user_currency":{"type":"string","description":"ISO 4217 currency code for the account (e.g. `USD`, `INR`). Defaults to the reseller's currency."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
495
|
+
method: "post",
|
|
496
|
+
pathTemplate: "/reseller/users/add",
|
|
497
|
+
executionParameters: [],
|
|
498
|
+
requestBodyContentType: "application/json",
|
|
499
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
500
|
+
}],
|
|
501
|
+
["setUserAccessControl", {
|
|
502
|
+
name: "setUserAccessControl",
|
|
503
|
+
description: `Enable or disable dashboard menu access flags for a child user.
|
|
504
|
+
Only the flags you pass are changed. Flags outside your
|
|
505
|
+
reseller's permissions are silently ignored.
|
|
506
|
+
`,
|
|
507
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["user_id","dashboard_menu_access"],"properties":{"user_id":{"type":"number","description":"ID of the child user to update."},"dashboard_menu_access":{"allOf":[{"type":"object","description":"Reseller-managed dashboard menu access flags. Each property is\na boolean toggle for a feature area in the child user's\ndashboard. On read endpoints, only flags the reseller\nthemselves has enabled are returned (so a child cannot have a\nflag the reseller doesn't have).\n","properties":{"is_bots_menu_access":{"type":"boolean"},"is_leads_access":{"type":"boolean"},"is_voice_cloning_access":{"type":"boolean"},"is_workflow_access":{"type":"boolean"},"is_asr_evaluation_menu_access":{"type":"boolean"},"is_train_with_call_recording_menu_access":{"type":"boolean"},"is_call_logs_menu_access":{"type":"boolean"},"is_call_simulation_menu_access":{"type":"boolean"},"is_omni_crm_access":{"type":"boolean"},"access_to_monitor_live_call":{"type":"boolean"},"is_whatsapp_flow_enabled":{"type":"boolean"},"is_billing_menu_access":{"type":"boolean"},"is_knowledge_base_access":{"type":"boolean"},"is_integration_access":{"type":"boolean"},"is_phone_number_access":{"type":"boolean"},"is_bulk_call_access":{"type":"boolean"},"is_analytics_access":{"type":"boolean"}}}],"description":"Flags to update. Only pass the flags you want to\nchange. Others are left untouched. Flags outside\nyour reseller's permissions are silently dropped.\n"}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
508
|
+
method: "post",
|
|
509
|
+
pathTemplate: "/reseller/users/access-control",
|
|
510
|
+
executionParameters: [],
|
|
511
|
+
requestBodyContentType: "application/json",
|
|
512
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
513
|
+
}],
|
|
514
|
+
["setUserExpiry", {
|
|
515
|
+
name: "setUserExpiry",
|
|
516
|
+
description: `Set or remove the expiry date on a child user. The user must
|
|
517
|
+
belong to a child organization of your reseller.
|
|
518
|
+
`,
|
|
519
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["user_id"],"properties":{"user_id":{"type":"number","description":"ID of the child user to update."},"expiry_date":{"type":["string","null"],"format":"date","description":"Expiry date in `YYYY-MM-DD` format. Omit or pass `null` to remove the expiry."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
520
|
+
method: "post",
|
|
521
|
+
pathTemplate: "/reseller/users/expiry",
|
|
522
|
+
executionParameters: [],
|
|
523
|
+
requestBodyContentType: "application/json",
|
|
524
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
525
|
+
}],
|
|
526
|
+
["setChildConcurrency", {
|
|
527
|
+
name: "setChildConcurrency",
|
|
528
|
+
description: `Set the maximum number of simultaneous calls a child
|
|
529
|
+
organization can run. Slots come from the reseller's shared
|
|
530
|
+
pool. Increasing the limit deducts the delta from your pool
|
|
531
|
+
and fails if you don't have enough slots. Decreasing the
|
|
532
|
+
limit returns the delta to your pool immediately.
|
|
533
|
+
`,
|
|
534
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["child_organization_id","new_limit"],"properties":{"child_organization_id":{"type":"number","description":"ID of the child organization to update."},"new_limit":{"type":"number","description":"The desired absolute concurrent call limit (must be `>= 0`)."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
535
|
+
method: "post",
|
|
536
|
+
pathTemplate: "/reseller/concurrency",
|
|
537
|
+
executionParameters: [],
|
|
538
|
+
requestBodyContentType: "application/json",
|
|
539
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
540
|
+
}],
|
|
541
|
+
["calculateCreditOperation", {
|
|
542
|
+
name: "calculateCreditOperation",
|
|
543
|
+
description: `Preview the cost of a transfer or revert without moving any
|
|
544
|
+
credits. Use this to confirm amounts before calling the
|
|
545
|
+
transfer or revert endpoints. The response shape differs
|
|
546
|
+
between forward transfers and reverts. See the examples.
|
|
547
|
+
`,
|
|
548
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["minutes"],"properties":{"minutes":{"type":"number","description":"Number of minutes to calculate for."},"cost_per_min":{"type":"number","description":"Rate per minute for a forward transfer (e.g. `0.20`). Not required when `is_revert` is `true`."},"is_revert":{"type":"boolean","description":"Set to `true` to calculate a revert instead of a forward transfer.","default":false},"child_organization_id":{"type":"number","description":"ID of the child organization to revert credits from. Required when `is_revert` is `true`."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
549
|
+
method: "post",
|
|
550
|
+
pathTemplate: "/reseller/credits/calculate",
|
|
551
|
+
executionParameters: [],
|
|
552
|
+
requestBodyContentType: "application/json",
|
|
553
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
554
|
+
}],
|
|
555
|
+
["transferCreditsToChild", {
|
|
556
|
+
name: "transferCreditsToChild",
|
|
557
|
+
description: `Transfer minutes from the reseller balance to a child
|
|
558
|
+
organization. Credits are deducted from your balance
|
|
559
|
+
immediately on success. The target organization must be a
|
|
560
|
+
direct child of your reseller. Use the calculate endpoint
|
|
561
|
+
first to preview the cost.
|
|
562
|
+
`,
|
|
563
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["to_organization_id","minutes","cost_per_min"],"properties":{"to_organization_id":{"type":"number","description":"ID of the child organization to transfer credits to."},"minutes":{"type":"number","description":"Number of minutes to transfer."},"cost_per_min":{"type":"number","description":"Rate per minute to charge the child organization (e.g. `0.20`)."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
564
|
+
method: "post",
|
|
565
|
+
pathTemplate: "/reseller/credits/transfer",
|
|
566
|
+
executionParameters: [],
|
|
567
|
+
requestBodyContentType: "application/json",
|
|
568
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
569
|
+
}],
|
|
570
|
+
["revertCreditsFromChild", {
|
|
571
|
+
name: "revertCreditsFromChild",
|
|
572
|
+
description: `Take back unused minutes from a child organization to the
|
|
573
|
+
reseller balance. The refund is calculated at the child's
|
|
574
|
+
current rate, so you don't pass one. This matches exactly
|
|
575
|
+
what was originally charged. Use the calculate endpoint
|
|
576
|
+
first to preview the refund.
|
|
577
|
+
`,
|
|
578
|
+
inputSchema: {"type":"object","properties":{"requestBody":{"type":"object","required":["from_organization_id","minutes"],"properties":{"from_organization_id":{"type":"number","description":"ID of the child organization to revert credits from."},"minutes":{"type":"number","description":"Number of minutes to revert."}},"description":"The JSON request body."}},"required":["requestBody"]},
|
|
579
|
+
method: "post",
|
|
580
|
+
pathTemplate: "/reseller/credits/revert",
|
|
581
|
+
executionParameters: [],
|
|
582
|
+
requestBodyContentType: "application/json",
|
|
583
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
584
|
+
}],
|
|
585
|
+
["getResellerCreditLogs", {
|
|
586
|
+
name: "getResellerCreditLogs",
|
|
587
|
+
description: `Paginated history of all credit transfers and reverts for the
|
|
588
|
+
reseller account. Returns reverse-chronological order by
|
|
589
|
+
default. Date filters are inclusive.
|
|
590
|
+
`,
|
|
591
|
+
inputSchema: {"type":"object","properties":{"page":{"type":"integer","minimum":1,"default":1,"description":"Page number for pagination."},"page_size":{"type":"number","default":20,"description":"Number of records per page (max 100)."},"date_from":{"type":"string","format":"date","description":"Filter logs from this date in `YYYY-MM-DD` format (e.g. `2026-01-01`)."},"date_to":{"type":"string","format":"date","description":"Filter logs up to and including this date in `YYYY-MM-DD` format (e.g. `2026-03-31`)."}}},
|
|
592
|
+
method: "get",
|
|
593
|
+
pathTemplate: "/reseller/credits/logs",
|
|
594
|
+
executionParameters: [{"name":"page","in":"query"},{"name":"page_size","in":"query"},{"name":"date_from","in":"query"},{"name":"date_to","in":"query"}],
|
|
595
|
+
requestBodyContentType: undefined,
|
|
596
|
+
securityRequirements: [{"BearerAuth":[]}]
|
|
597
|
+
}],
|
|
598
|
+
]);
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Security schemes from the OpenAPI spec
|
|
602
|
+
*/
|
|
603
|
+
const securitySchemes = {
|
|
604
|
+
"BearerAuth": {
|
|
605
|
+
"type": "http",
|
|
606
|
+
"scheme": "bearer",
|
|
607
|
+
"description": "Bearer token authentication. Obtain your API key from the\nOmniDimension dashboard.\n"
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
613
|
+
const toolsForClient: Tool[] = Array.from(toolDefinitionMap.values()).map(def => ({
|
|
614
|
+
name: def.name,
|
|
615
|
+
description: def.description,
|
|
616
|
+
inputSchema: def.inputSchema
|
|
617
|
+
}));
|
|
618
|
+
return { tools: toolsForClient };
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest): Promise<CallToolResult> => {
|
|
623
|
+
const { name: toolName, arguments: toolArgs } = request.params;
|
|
624
|
+
const toolDefinition = toolDefinitionMap.get(toolName);
|
|
625
|
+
if (!toolDefinition) {
|
|
626
|
+
console.error(`Error: Unknown tool requested: ${toolName}`);
|
|
627
|
+
return { content: [{ type: "text", text: `Error: Unknown tool requested: ${toolName}` }] };
|
|
628
|
+
}
|
|
629
|
+
return await executeApiTool(toolName, toolDefinition, toolArgs ?? {}, securitySchemes);
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Type definition for cached OAuth tokens
|
|
636
|
+
*/
|
|
637
|
+
interface TokenCacheEntry {
|
|
638
|
+
token: string;
|
|
639
|
+
expiresAt: number;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Declare global __oauthTokenCache property for TypeScript
|
|
644
|
+
*/
|
|
645
|
+
declare global {
|
|
646
|
+
var __oauthTokenCache: Record<string, TokenCacheEntry> | undefined;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Acquires an OAuth2 token using client credentials flow
|
|
651
|
+
*
|
|
652
|
+
* @param schemeName Name of the security scheme
|
|
653
|
+
* @param scheme OAuth2 security scheme
|
|
654
|
+
* @returns Acquired token or null if unable to acquire
|
|
655
|
+
*/
|
|
656
|
+
async function acquireOAuth2Token(schemeName: string, scheme: any): Promise<string | null | undefined> {
|
|
657
|
+
try {
|
|
658
|
+
// Check if we have the necessary credentials
|
|
659
|
+
const clientId = process.env[`OAUTH_CLIENT_ID_SCHEMENAME`];
|
|
660
|
+
const clientSecret = process.env[`OAUTH_CLIENT_SECRET_SCHEMENAME`];
|
|
661
|
+
const scopes = process.env[`OAUTH_SCOPES_SCHEMENAME`];
|
|
662
|
+
|
|
663
|
+
if (!clientId || !clientSecret) {
|
|
664
|
+
console.error(`Missing client credentials for OAuth2 scheme '${schemeName}'`);
|
|
665
|
+
return null;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// Initialize token cache if needed
|
|
669
|
+
if (typeof global.__oauthTokenCache === 'undefined') {
|
|
670
|
+
global.__oauthTokenCache = {};
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// Check if we have a cached token
|
|
674
|
+
const cacheKey = `${schemeName}_${clientId}`;
|
|
675
|
+
const cachedToken = global.__oauthTokenCache[cacheKey];
|
|
676
|
+
const now = Date.now();
|
|
677
|
+
|
|
678
|
+
if (cachedToken && cachedToken.expiresAt > now) {
|
|
679
|
+
console.error(`Using cached OAuth2 token for '${schemeName}' (expires in ${Math.floor((cachedToken.expiresAt - now) / 1000)} seconds)`);
|
|
680
|
+
return cachedToken.token;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// Determine token URL based on flow type
|
|
684
|
+
let tokenUrl = '';
|
|
685
|
+
if (scheme.flows?.clientCredentials?.tokenUrl) {
|
|
686
|
+
tokenUrl = scheme.flows.clientCredentials.tokenUrl;
|
|
687
|
+
console.error(`Using client credentials flow for '${schemeName}'`);
|
|
688
|
+
} else if (scheme.flows?.password?.tokenUrl) {
|
|
689
|
+
tokenUrl = scheme.flows.password.tokenUrl;
|
|
690
|
+
console.error(`Using password flow for '${schemeName}'`);
|
|
691
|
+
} else {
|
|
692
|
+
console.error(`No supported OAuth2 flow found for '${schemeName}'`);
|
|
693
|
+
return null;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// Prepare the token request
|
|
697
|
+
let formData = new URLSearchParams();
|
|
698
|
+
formData.append('grant_type', 'client_credentials');
|
|
699
|
+
|
|
700
|
+
// Add scopes if specified
|
|
701
|
+
if (scopes) {
|
|
702
|
+
formData.append('scope', scopes);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
console.error(`Requesting OAuth2 token from ${tokenUrl}`);
|
|
706
|
+
|
|
707
|
+
// Make the token request
|
|
708
|
+
const response = await axios({
|
|
709
|
+
method: 'POST',
|
|
710
|
+
url: tokenUrl,
|
|
711
|
+
headers: {
|
|
712
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
713
|
+
'Authorization': `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
|
|
714
|
+
},
|
|
715
|
+
data: formData.toString()
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
// Process the response
|
|
719
|
+
if (response.data?.access_token) {
|
|
720
|
+
const token = response.data.access_token;
|
|
721
|
+
const expiresIn = response.data.expires_in || 3600; // Default to 1 hour
|
|
722
|
+
|
|
723
|
+
// Cache the token
|
|
724
|
+
global.__oauthTokenCache[cacheKey] = {
|
|
725
|
+
token,
|
|
726
|
+
expiresAt: now + (expiresIn * 1000) - 60000 // Expire 1 minute early
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
console.error(`Successfully acquired OAuth2 token for '${schemeName}' (expires in ${expiresIn} seconds)`);
|
|
730
|
+
return token;
|
|
731
|
+
} else {
|
|
732
|
+
console.error(`Failed to acquire OAuth2 token for '${schemeName}': No access_token in response`);
|
|
733
|
+
return null;
|
|
734
|
+
}
|
|
735
|
+
} catch (error: unknown) {
|
|
736
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
737
|
+
console.error(`Error acquiring OAuth2 token for '${schemeName}':`, errorMessage);
|
|
738
|
+
return null;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Executes an API tool with the provided arguments
|
|
745
|
+
*
|
|
746
|
+
* @param toolName Name of the tool to execute
|
|
747
|
+
* @param definition Tool definition
|
|
748
|
+
* @param toolArgs Arguments provided by the user
|
|
749
|
+
* @param allSecuritySchemes Security schemes from the OpenAPI spec
|
|
750
|
+
* @returns Call tool result
|
|
751
|
+
*/
|
|
752
|
+
async function executeApiTool(
|
|
753
|
+
toolName: string,
|
|
754
|
+
definition: McpToolDefinition,
|
|
755
|
+
toolArgs: JsonObject,
|
|
756
|
+
allSecuritySchemes: Record<string, any>
|
|
757
|
+
): Promise<CallToolResult> {
|
|
758
|
+
try {
|
|
759
|
+
// Validate arguments against the input schema
|
|
760
|
+
let validatedArgs: JsonObject;
|
|
761
|
+
try {
|
|
762
|
+
const zodSchema = getZodSchemaFromJsonSchema(definition.inputSchema, toolName);
|
|
763
|
+
const argsToParse = (typeof toolArgs === 'object' && toolArgs !== null) ? toolArgs : {};
|
|
764
|
+
validatedArgs = zodSchema.parse(argsToParse);
|
|
765
|
+
} catch (error: unknown) {
|
|
766
|
+
if (error instanceof ZodError) {
|
|
767
|
+
const validationErrorMessage = `Invalid arguments for tool '${toolName}': ${error.errors.map(e => `${e.path.join('.')} (${e.code}): ${e.message}`).join(', ')}`;
|
|
768
|
+
return { content: [{ type: 'text', text: validationErrorMessage }] };
|
|
769
|
+
} else {
|
|
770
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
771
|
+
return { content: [{ type: 'text', text: `Internal error during validation setup: ${errorMessage}` }] };
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// Prepare URL, query parameters, headers, and request body
|
|
776
|
+
let urlPath = definition.pathTemplate;
|
|
777
|
+
const queryParams: Record<string, any> = {};
|
|
778
|
+
const headers: Record<string, string> = { 'Accept': 'application/json' };
|
|
779
|
+
let requestBodyData: any = undefined;
|
|
780
|
+
|
|
781
|
+
// Apply parameters to the URL path, query, or headers
|
|
782
|
+
definition.executionParameters.forEach((param) => {
|
|
783
|
+
const value = validatedArgs[param.name];
|
|
784
|
+
if (typeof value !== 'undefined' && value !== null) {
|
|
785
|
+
if (param.in === 'path') {
|
|
786
|
+
urlPath = urlPath.replace(`{${param.name}}`, encodeURIComponent(String(value)));
|
|
787
|
+
}
|
|
788
|
+
else if (param.in === 'query') {
|
|
789
|
+
queryParams[param.name] = value;
|
|
790
|
+
}
|
|
791
|
+
else if (param.in === 'header') {
|
|
792
|
+
headers[param.name.toLowerCase()] = String(value);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
// Ensure all path parameters are resolved
|
|
798
|
+
if (urlPath.includes('{')) {
|
|
799
|
+
throw new Error(`Failed to resolve path parameters: ${urlPath}`);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// Construct the full URL
|
|
803
|
+
const requestUrl = API_BASE_URL ? `${API_BASE_URL}${urlPath}` : urlPath;
|
|
804
|
+
|
|
805
|
+
// Handle request body if needed
|
|
806
|
+
if (definition.requestBodyContentType && typeof validatedArgs['requestBody'] !== 'undefined') {
|
|
807
|
+
requestBodyData = validatedArgs['requestBody'];
|
|
808
|
+
headers['content-type'] = definition.requestBodyContentType;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
// Apply security requirements if available
|
|
813
|
+
// Security requirements use OR between array items and AND within each object
|
|
814
|
+
const appliedSecurity = definition.securityRequirements?.find(req => {
|
|
815
|
+
// Try each security requirement (combined with OR)
|
|
816
|
+
return Object.entries(req).every(([schemeName, scopesArray]) => {
|
|
817
|
+
const scheme = allSecuritySchemes[schemeName];
|
|
818
|
+
if (!scheme) return false;
|
|
819
|
+
|
|
820
|
+
// API Key security (header, query, cookie)
|
|
821
|
+
if (scheme.type === 'apiKey') {
|
|
822
|
+
return !!process.env[`API_KEY_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`];
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// HTTP security (basic, bearer)
|
|
826
|
+
if (scheme.type === 'http') {
|
|
827
|
+
if (scheme.scheme?.toLowerCase() === 'bearer') {
|
|
828
|
+
return !!(process.env.OMNIDIM_API_KEY || process.env[`BEARER_TOKEN_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`]);
|
|
829
|
+
}
|
|
830
|
+
else if (scheme.scheme?.toLowerCase() === 'basic') {
|
|
831
|
+
return !!process.env[`BASIC_USERNAME_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`] &&
|
|
832
|
+
!!process.env[`BASIC_PASSWORD_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`];
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
// OAuth2 security
|
|
837
|
+
if (scheme.type === 'oauth2') {
|
|
838
|
+
// Check for pre-existing token
|
|
839
|
+
if (process.env[`OAUTH_TOKEN_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`]) {
|
|
840
|
+
return true;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
// Check for client credentials for auto-acquisition
|
|
844
|
+
if (process.env[`OAUTH_CLIENT_ID_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`] &&
|
|
845
|
+
process.env[`OAUTH_CLIENT_SECRET_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`]) {
|
|
846
|
+
// Verify we have a supported flow
|
|
847
|
+
if (scheme.flows?.clientCredentials || scheme.flows?.password) {
|
|
848
|
+
return true;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// OpenID Connect
|
|
856
|
+
if (scheme.type === 'openIdConnect') {
|
|
857
|
+
return !!process.env[`OPENID_TOKEN_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`];
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
return false;
|
|
861
|
+
});
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
// If we found matching security scheme(s), apply them
|
|
865
|
+
if (appliedSecurity) {
|
|
866
|
+
// Apply each security scheme from this requirement (combined with AND)
|
|
867
|
+
for (const [schemeName, scopesArray] of Object.entries(appliedSecurity)) {
|
|
868
|
+
const scheme = allSecuritySchemes[schemeName];
|
|
869
|
+
|
|
870
|
+
// API Key security
|
|
871
|
+
if (scheme?.type === 'apiKey') {
|
|
872
|
+
const apiKey = process.env[`API_KEY_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`];
|
|
873
|
+
if (apiKey) {
|
|
874
|
+
if (scheme.in === 'header') {
|
|
875
|
+
headers[scheme.name.toLowerCase()] = apiKey;
|
|
876
|
+
if (process.env.OMNIDIM_DEBUG) console.error(`Applied API key '${schemeName}' in header '${scheme.name}'`);
|
|
877
|
+
}
|
|
878
|
+
else if (scheme.in === 'query') {
|
|
879
|
+
queryParams[scheme.name] = apiKey;
|
|
880
|
+
if (process.env.OMNIDIM_DEBUG) console.error(`Applied API key '${schemeName}' in query parameter '${scheme.name}'`);
|
|
881
|
+
}
|
|
882
|
+
else if (scheme.in === 'cookie') {
|
|
883
|
+
// Add the cookie, preserving other cookies if they exist
|
|
884
|
+
headers['cookie'] = `${scheme.name}=${apiKey}${headers['cookie'] ? `; ${headers['cookie']}` : ''}`;
|
|
885
|
+
if (process.env.OMNIDIM_DEBUG) console.error(`Applied API key '${schemeName}' in cookie '${scheme.name}'`);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
// HTTP security (Bearer or Basic)
|
|
890
|
+
else if (scheme?.type === 'http') {
|
|
891
|
+
if (scheme.scheme?.toLowerCase() === 'bearer') {
|
|
892
|
+
const token = process.env.OMNIDIM_API_KEY || process.env[`BEARER_TOKEN_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`];
|
|
893
|
+
if (token) {
|
|
894
|
+
headers['authorization'] = `Bearer ${token}`;
|
|
895
|
+
if (process.env.OMNIDIM_DEBUG) console.error(`Applied Bearer token for '${schemeName}'`);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
else if (scheme.scheme?.toLowerCase() === 'basic') {
|
|
899
|
+
const username = process.env[`BASIC_USERNAME_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`];
|
|
900
|
+
const password = process.env[`BASIC_PASSWORD_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`];
|
|
901
|
+
if (username && password) {
|
|
902
|
+
headers['authorization'] = `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`;
|
|
903
|
+
if (process.env.OMNIDIM_DEBUG) console.error(`Applied Basic authentication for '${schemeName}'`);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
// OAuth2 security
|
|
908
|
+
else if (scheme?.type === 'oauth2') {
|
|
909
|
+
// First try to use a pre-provided token
|
|
910
|
+
let token = process.env[`OAUTH_TOKEN_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`];
|
|
911
|
+
|
|
912
|
+
// If no token but we have client credentials, try to acquire a token
|
|
913
|
+
if (!token && (scheme.flows?.clientCredentials || scheme.flows?.password)) {
|
|
914
|
+
console.error(`Attempting to acquire OAuth token for '${schemeName}'`);
|
|
915
|
+
token = (await acquireOAuth2Token(schemeName, scheme)) ?? '';
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
// Apply token if available
|
|
919
|
+
if (token) {
|
|
920
|
+
headers['authorization'] = `Bearer ${token}`;
|
|
921
|
+
if (process.env.OMNIDIM_DEBUG) console.error(`Applied OAuth2 token for '${schemeName}'`);
|
|
922
|
+
|
|
923
|
+
// List the scopes that were requested, if any
|
|
924
|
+
const scopes = scopesArray as string[];
|
|
925
|
+
if (scopes && scopes.length > 0) {
|
|
926
|
+
console.error(`Requested scopes: ${scopes.join(', ')}`);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
// OpenID Connect
|
|
931
|
+
else if (scheme?.type === 'openIdConnect') {
|
|
932
|
+
const token = process.env[`OPENID_TOKEN_${schemeName.replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`];
|
|
933
|
+
if (token) {
|
|
934
|
+
headers['authorization'] = `Bearer ${token}`;
|
|
935
|
+
if (process.env.OMNIDIM_DEBUG) console.error(`Applied OpenID Connect token for '${schemeName}'`);
|
|
936
|
+
|
|
937
|
+
// List the scopes that were requested, if any
|
|
938
|
+
const scopes = scopesArray as string[];
|
|
939
|
+
if (scopes && scopes.length > 0) {
|
|
940
|
+
console.error(`Requested scopes: ${scopes.join(', ')}`);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
else if (definition.securityRequirements?.length > 0) {
|
|
947
|
+
return {
|
|
948
|
+
content: [{
|
|
949
|
+
type: 'text',
|
|
950
|
+
text: `OMNIDIM_API_KEY is not set. Configure it in your MCP client's "env" block, then restart the client. Get a key at https://omnidim.io/api-management.`,
|
|
951
|
+
}],
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
// Prepare the axios request configuration
|
|
957
|
+
headers['user-agent'] = `${SERVER_NAME}-mcp-server/${SERVER_VERSION}`;
|
|
958
|
+
const config: AxiosRequestConfig = {
|
|
959
|
+
method: definition.method.toUpperCase(),
|
|
960
|
+
url: requestUrl,
|
|
961
|
+
params: queryParams,
|
|
962
|
+
headers: headers,
|
|
963
|
+
timeout: 60_000,
|
|
964
|
+
...(requestBodyData !== undefined && { data: requestBodyData }),
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
if (process.env.OMNIDIM_DEBUG) {
|
|
968
|
+
console.error(`Executing tool "${toolName}": ${config.method} ${config.url}`);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
// Execute the request
|
|
972
|
+
const response = await axios(config);
|
|
973
|
+
|
|
974
|
+
// Process and format the response
|
|
975
|
+
let responseText = '';
|
|
976
|
+
const contentType = String(response.headers['content-type'] ?? '').toLowerCase();
|
|
977
|
+
|
|
978
|
+
// Handle JSON responses
|
|
979
|
+
if (contentType.includes('application/json') && typeof response.data === 'object' && response.data !== null) {
|
|
980
|
+
try {
|
|
981
|
+
const trimmed = trimLargeResponse(response.data);
|
|
982
|
+
responseText = trimmed.text;
|
|
983
|
+
if (trimmed.note) responseText += `\n\n${trimmed.note}`;
|
|
984
|
+
} catch (e) {
|
|
985
|
+
responseText = "[Stringify Error]";
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
// The backend returns an HTML 404 page (not JSON) when a path
|
|
989
|
+
// converter rejects an input (e.g. GET /agents/abc).
|
|
990
|
+
else if (contentType.includes('text/html')) {
|
|
991
|
+
const title = typeof response.data === 'string'
|
|
992
|
+
? (response.data.match(/<title>([^<]*)<\/title>/i)?.[1]?.trim() ?? 'HTML response')
|
|
993
|
+
: 'HTML response';
|
|
994
|
+
responseText = `Upstream returned HTML instead of JSON (HTTP ${response.status}: "${title}"). The path or method is likely wrong.`;
|
|
995
|
+
}
|
|
996
|
+
else if (typeof response.data === 'string') {
|
|
997
|
+
responseText = response.data;
|
|
998
|
+
}
|
|
999
|
+
// Handle other response types
|
|
1000
|
+
else if (response.data !== undefined && response.data !== null) {
|
|
1001
|
+
responseText = String(response.data);
|
|
1002
|
+
}
|
|
1003
|
+
// Handle empty responses
|
|
1004
|
+
else {
|
|
1005
|
+
responseText = `(Status: ${response.status} - No body content)`;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// Return formatted response
|
|
1009
|
+
return {
|
|
1010
|
+
content: [
|
|
1011
|
+
{
|
|
1012
|
+
type: "text",
|
|
1013
|
+
text: `API Response (Status: ${response.status}):\n${responseText}`
|
|
1014
|
+
}
|
|
1015
|
+
],
|
|
1016
|
+
};
|
|
1017
|
+
|
|
1018
|
+
} catch (error: unknown) {
|
|
1019
|
+
// Handle errors during execution
|
|
1020
|
+
let errorMessage: string;
|
|
1021
|
+
|
|
1022
|
+
// Format Axios errors specially
|
|
1023
|
+
if (axios.isAxiosError(error)) {
|
|
1024
|
+
errorMessage = formatApiError(error);
|
|
1025
|
+
}
|
|
1026
|
+
// Handle standard errors
|
|
1027
|
+
else if (error instanceof Error) {
|
|
1028
|
+
errorMessage = error.message;
|
|
1029
|
+
}
|
|
1030
|
+
// Handle unexpected error types
|
|
1031
|
+
else {
|
|
1032
|
+
errorMessage = 'Unexpected error: ' + String(error);
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
// Log error to stderr
|
|
1036
|
+
console.error(`Error during execution of tool '${toolName}':`, errorMessage);
|
|
1037
|
+
|
|
1038
|
+
// Return error message to client
|
|
1039
|
+
return { content: [{ type: "text", text: errorMessage }] };
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* Main function to start the server
|
|
1046
|
+
*/
|
|
1047
|
+
async function main() {
|
|
1048
|
+
// Set up stdio transport
|
|
1049
|
+
try {
|
|
1050
|
+
const transport = new StdioServerTransport();
|
|
1051
|
+
await server.connect(transport);
|
|
1052
|
+
console.error(`${SERVER_NAME} MCP Server (v${SERVER_VERSION}) running on stdio${API_BASE_URL ? `, proxying API at ${API_BASE_URL}` : ''}`);
|
|
1053
|
+
} catch (error) {
|
|
1054
|
+
console.error("Error during server startup:", error);
|
|
1055
|
+
process.exit(1);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* Cleanup function for graceful shutdown
|
|
1061
|
+
*/
|
|
1062
|
+
async function cleanup() {
|
|
1063
|
+
console.error("Shutting down MCP server...");
|
|
1064
|
+
process.exit(0);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// Register signal handlers
|
|
1068
|
+
process.on('SIGINT', cleanup);
|
|
1069
|
+
process.on('SIGTERM', cleanup);
|
|
1070
|
+
|
|
1071
|
+
// Start the server
|
|
1072
|
+
main().catch((error) => {
|
|
1073
|
+
console.error("Fatal error in main execution:", error);
|
|
1074
|
+
process.exit(1);
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* Formats API errors for better readability
|
|
1079
|
+
*
|
|
1080
|
+
* @param error Axios error
|
|
1081
|
+
* @returns Formatted error message
|
|
1082
|
+
*/
|
|
1083
|
+
function formatApiError(error: AxiosError): string {
|
|
1084
|
+
let message = 'API request failed.';
|
|
1085
|
+
if (error.response) {
|
|
1086
|
+
message = `API Error: Status ${error.response.status} (${error.response.statusText || 'Status text not available'}). `;
|
|
1087
|
+
const responseData = error.response.data;
|
|
1088
|
+
const MAX_LEN = 200;
|
|
1089
|
+
if (typeof responseData === 'string') {
|
|
1090
|
+
message += `Response: ${responseData.substring(0, MAX_LEN)}${responseData.length > MAX_LEN ? '...' : ''}`;
|
|
1091
|
+
}
|
|
1092
|
+
else if (responseData) {
|
|
1093
|
+
try {
|
|
1094
|
+
const jsonString = JSON.stringify(responseData);
|
|
1095
|
+
message += `Response: ${jsonString.substring(0, MAX_LEN)}${jsonString.length > MAX_LEN ? '...' : ''}`;
|
|
1096
|
+
} catch {
|
|
1097
|
+
message += 'Response: [Could not serialize data]';
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
else {
|
|
1101
|
+
message += 'No response body received.';
|
|
1102
|
+
}
|
|
1103
|
+
} else if (error.request) {
|
|
1104
|
+
message = 'API Network Error: No response received from server.';
|
|
1105
|
+
if (error.code) message += ` (Code: ${error.code})`;
|
|
1106
|
+
} else {
|
|
1107
|
+
message += `API Request Setup Error: ${error.message}`;
|
|
1108
|
+
}
|
|
1109
|
+
return message;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
/**
|
|
1113
|
+
* Converts a JSON Schema to a Zod schema for runtime validation
|
|
1114
|
+
*
|
|
1115
|
+
* @param jsonSchema JSON Schema
|
|
1116
|
+
* @param toolName Tool name for error reporting
|
|
1117
|
+
* @returns Zod schema
|
|
1118
|
+
*/
|
|
1119
|
+
const zodSchemaCache: Map<string, z.ZodTypeAny> = new Map();
|
|
1120
|
+
function getZodSchemaFromJsonSchema(jsonSchema: any, toolName: string): z.ZodTypeAny {
|
|
1121
|
+
const cached = zodSchemaCache.get(toolName);
|
|
1122
|
+
if (cached) return cached;
|
|
1123
|
+
if (typeof jsonSchema !== 'object' || jsonSchema === null) {
|
|
1124
|
+
const fallback = z.object({}).passthrough();
|
|
1125
|
+
zodSchemaCache.set(toolName, fallback);
|
|
1126
|
+
return fallback;
|
|
1127
|
+
}
|
|
1128
|
+
try {
|
|
1129
|
+
const body = jsonSchemaToZod(jsonSchema);
|
|
1130
|
+
const factory = new Function('z', `return (${body});`) as (z: any) => z.ZodTypeAny;
|
|
1131
|
+
const schema = factory(z);
|
|
1132
|
+
if (typeof (schema as any)?.parse !== 'function') {
|
|
1133
|
+
throw new Error('Schema factory did not produce a valid Zod schema.');
|
|
1134
|
+
}
|
|
1135
|
+
zodSchemaCache.set(toolName, schema);
|
|
1136
|
+
return schema;
|
|
1137
|
+
} catch (err: any) {
|
|
1138
|
+
console.error(`Failed to generate Zod schema for '${toolName}':`, err);
|
|
1139
|
+
const fallback = z.object({}).passthrough();
|
|
1140
|
+
zodSchemaCache.set(toolName, fallback);
|
|
1141
|
+
return fallback;
|
|
1142
|
+
}
|
|
1143
|
+
}
|