elevenlabs-voice-agent-mcp 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.claude/settings.local.json +23 -0
  2. package/.env.example +3 -0
  3. package/AGENTS.md +37 -0
  4. package/CLAUDE.md +233 -0
  5. package/README.md +9 -30
  6. package/call-exact-format.ts +66 -0
  7. package/call-wait-null.ts +71 -0
  8. package/create-agent-simple.ts +84 -0
  9. package/create-new-agent.ts +98 -0
  10. package/demo-agent-system-prompt.xml +166 -0
  11. package/dist/index.js +0 -0
  12. package/elevenlabs-voice-agent-mcp-1.0.0.tgz +0 -0
  13. package/em_positive_leads.csv +25 -0
  14. package/list-resources.ts +93 -0
  15. package/make-call-now.ts +66 -0
  16. package/make-test-call.ts +80 -0
  17. package/openapi.json +3238 -0
  18. package/package.json +3 -33
  19. package/src/constants.ts +62 -0
  20. package/src/index.ts +143 -0
  21. package/src/schemas/agent-schemas.ts +193 -0
  22. package/src/schemas/batch-calling-schemas.ts +96 -0
  23. package/src/schemas/common-schemas.ts +83 -0
  24. package/src/schemas/conversation-schemas.ts +44 -0
  25. package/src/schemas/outbound-schemas.ts +70 -0
  26. package/src/schemas/phone-number-schemas.ts +140 -0
  27. package/src/schemas/tool-schemas.ts +161 -0
  28. package/src/services/elevenlabs-api.ts +113 -0
  29. package/src/services/formatters.ts +623 -0
  30. package/src/tools/agent-tools.ts +425 -0
  31. package/src/tools/batch-calling-tools.ts +237 -0
  32. package/src/tools/conversation-tools.ts +167 -0
  33. package/src/tools/knowledge-tools.ts +73 -0
  34. package/src/tools/outbound-tools.ts +95 -0
  35. package/src/tools/phone-number-tools.ts +346 -0
  36. package/src/tools/tool-tools.ts +195 -0
  37. package/src/tools/utility-tools.ts +147 -0
  38. package/src/types.ts +327 -0
  39. package/src/utils/error-handlers.ts +98 -0
  40. package/src/utils/truncation.ts +97 -0
  41. package/test-call-wait-for-hello.ts +76 -0
  42. package/test-call.json +5 -0
  43. package/tsconfig.json +21 -0
  44. package/LICENSE +0 -21
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Error handling utilities for ElevenLabs API requests
3
+ *
4
+ * Provides consistent error handling and user-friendly error messages
5
+ * for various API error scenarios.
6
+ */
7
+
8
+ import axios from "axios";
9
+
10
+ /**
11
+ * Handles errors from ElevenLabs API requests
12
+ *
13
+ * @param error - The error object from axios or other sources
14
+ * @param context - Additional context about the operation (e.g., "creating agent")
15
+ * @returns User-friendly error message with actionable guidance
16
+ */
17
+ export function handleElevenLabsError(error: unknown, context?: string): string {
18
+ const prefix = context ? `Error ${context}: ` : "Error: ";
19
+
20
+ if (axios.isAxiosError(error)) {
21
+ if (error.response) {
22
+ // Server responded with error status
23
+ const status = error.response.status;
24
+ const data = error.response.data as { detail?: string; message?: string };
25
+ const detail = data?.detail || data?.message;
26
+
27
+ switch (status) {
28
+ case 400:
29
+ return `${prefix}Invalid request - ${detail || "Check your parameters"}`;
30
+ case 401:
31
+ return `${prefix}Invalid API key. Please check your ELEVENLABS_API_KEY environment variable.`;
32
+ case 403:
33
+ return `${prefix}Access forbidden. Your API key may not have permission for this operation.`;
34
+ case 404:
35
+ return `${prefix}Resource not found. Please verify the ID is correct.`;
36
+ case 409:
37
+ return `${prefix}Conflict - ${detail || "Resource already exists or is in use"}`;
38
+ case 422:
39
+ return `${prefix}Validation error - ${detail || "Invalid data format"}`;
40
+ case 429:
41
+ return `${prefix}Rate limit exceeded. Please wait 60 seconds before retrying.`;
42
+ case 500:
43
+ return `${prefix}ElevenLabs server error. Please try again in a few moments.`;
44
+ case 503:
45
+ return `${prefix}Service temporarily unavailable. Please try again later.`;
46
+ default:
47
+ return `${prefix}API request failed with status ${status}${detail ? `: ${detail}` : ""}`;
48
+ }
49
+ } else if (error.code === "ECONNABORTED") {
50
+ return `${prefix}Request timed out. Please try again or check your network connection.`;
51
+ } else if (error.code === "ENOTFOUND" || error.code === "ECONNREFUSED") {
52
+ return `${prefix}Cannot connect to ElevenLabs API. Please check your internet connection.`;
53
+ } else if (error.message) {
54
+ return `${prefix}Network error - ${error.message}`;
55
+ }
56
+ }
57
+
58
+ // Generic error handling
59
+ if (error instanceof Error) {
60
+ return `${prefix}${error.message}`;
61
+ }
62
+
63
+ return `${prefix}Unexpected error occurred: ${String(error)}`;
64
+ }
65
+
66
+ /**
67
+ * Validates that the API key is present in environment
68
+ *
69
+ * @throws Error if ELEVENLABS_API_KEY is not set
70
+ */
71
+ export function validateApiKey(): void {
72
+ if (!process.env.ELEVENLABS_API_KEY) {
73
+ throw new Error(
74
+ "ELEVENLABS_API_KEY environment variable is not set. " +
75
+ "Please set it to your ElevenLabs API key."
76
+ );
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Wraps an async function with error handling
82
+ *
83
+ * @param fn - The async function to wrap
84
+ * @param context - Context for error messages
85
+ * @returns Wrapped function that handles errors consistently
86
+ */
87
+ export function withErrorHandling<T extends unknown[], R>(
88
+ fn: (...args: T) => Promise<R>,
89
+ context?: string
90
+ ): (...args: T) => Promise<R> {
91
+ return async (...args: T): Promise<R> => {
92
+ try {
93
+ return await fn(...args);
94
+ } catch (error) {
95
+ throw new Error(handleElevenLabsError(error, context));
96
+ }
97
+ };
98
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Response truncation utilities
3
+ *
4
+ * Handles truncation of large responses to stay within MCP character limits
5
+ * while providing clear guidance to users.
6
+ */
7
+
8
+ import { CHARACTER_LIMIT } from "../constants.js";
9
+
10
+ /**
11
+ * Truncates content if it exceeds the character limit
12
+ *
13
+ * @param content - The content to potentially truncate
14
+ * @param context - Additional context or guidance for the user
15
+ * @returns Original or truncated content with indicator
16
+ */
17
+ export function truncateIfNeeded(content: string, context?: string): string {
18
+ if (content.length <= CHARACTER_LIMIT) {
19
+ return content;
20
+ }
21
+
22
+ const truncated = content.substring(0, CHARACTER_LIMIT);
23
+ const guidance = context || "Consider using filters or pagination to see more results";
24
+
25
+ return `${truncated}\n\n[TRUNCATED: Response exceeded ${CHARACTER_LIMIT} characters. ${guidance}]`;
26
+ }
27
+
28
+ /**
29
+ * Truncates an array of items and provides pagination guidance
30
+ *
31
+ * @param items - Array of items that might need truncation
32
+ * @param formatter - Function to format each item as a string
33
+ * @param currentOffset - Current pagination offset
34
+ * @param context - Additional context for users
35
+ * @returns Formatted and potentially truncated string
36
+ */
37
+ export function truncateArray<T>(
38
+ items: T[],
39
+ formatter: (item: T, index: number) => string,
40
+ currentOffset: number = 0,
41
+ context?: string
42
+ ): string {
43
+ let result = "";
44
+ let count = 0;
45
+
46
+ for (let i = 0; i < items.length; i++) {
47
+ const formatted = formatter(items[i], i);
48
+
49
+ if (result.length + formatted.length > CHARACTER_LIMIT) {
50
+ const nextOffset = currentOffset + count;
51
+ const guidance = context || `Use offset=${nextOffset} to continue from where truncation occurred`;
52
+ result += `\n\n[TRUNCATED: Response exceeded ${CHARACTER_LIMIT} characters. ${guidance}]`;
53
+ break;
54
+ }
55
+
56
+ result += formatted;
57
+ count++;
58
+ }
59
+
60
+ return result;
61
+ }
62
+
63
+ /**
64
+ * Safely truncates a string in the middle, preserving start and end
65
+ *
66
+ * @param content - Content to truncate
67
+ * @param maxLength - Maximum length
68
+ * @returns Truncated string with "..." indicator
69
+ */
70
+ export function truncateMiddle(content: string, maxLength: number): string {
71
+ if (content.length <= maxLength) {
72
+ return content;
73
+ }
74
+
75
+ const halfLength = Math.floor((maxLength - 3) / 2);
76
+ const start = content.substring(0, halfLength);
77
+ const end = content.substring(content.length - halfLength);
78
+
79
+ return `${start}...${end}`;
80
+ }
81
+
82
+ /**
83
+ * Formats a large JSON object with optional truncation
84
+ *
85
+ * @param obj - Object to format
86
+ * @param indent - Indentation spaces (default: 2)
87
+ * @returns JSON string, potentially truncated
88
+ */
89
+ export function formatJSON(obj: unknown, indent: number = 2): string {
90
+ const json = JSON.stringify(obj, null, indent);
91
+
92
+ if (json.length > CHARACTER_LIMIT) {
93
+ return truncateIfNeeded(json, "Response is very large. Consider using filters or requesting specific fields");
94
+ }
95
+
96
+ return json;
97
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Test call using Demo Agent with first_message override
3
+ * This makes the agent wait for the human to say hello first
4
+ */
5
+
6
+ import axios from 'axios';
7
+
8
+ const apiKey = process.env.ELEVENLABS_API_KEY;
9
+
10
+ if (!apiKey) {
11
+ console.error('❌ Error: ELEVENLABS_API_KEY environment variable not set');
12
+ process.exit(1);
13
+ }
14
+
15
+ async function makeTestCall() {
16
+ try {
17
+ console.log('🔄 Initiating test call to Connor...');
18
+ console.log('📱 Using: Demo Agent with first_message override');
19
+ console.log('⏳ Agent will WAIT for human to speak first\n');
20
+
21
+ const response = await axios.post(
22
+ 'https://api.elevenlabs.io/v1/convai/twilio/outbound-call',
23
+ {
24
+ agent_id: 'agent_2601kahgbheaftnr7150xp0x8jbf', // Demo Agent
25
+ agent_phone_number_id: 'phnum_4501kayyj6xtfak80g09czq6yzxm', // Atlas St Louis
26
+ to_number: '+16184072273', // Connor
27
+ conversation_initiation_client_data: {
28
+ dynamic_variables: {
29
+ lead_name: 'Connor',
30
+ rep_name: 'Connor',
31
+ lead_email: 'connor@atlasdigitalusa.com',
32
+ their_timezone: 'Central Time'
33
+ },
34
+ // Override the agent's first message to empty string
35
+ // This makes it wait for the human to speak first
36
+ conversation_config_override: {
37
+ agent: {
38
+ first_message: '' // Empty string = wait for human
39
+ }
40
+ }
41
+ }
42
+ },
43
+ {
44
+ headers: {
45
+ 'xi-api-key': apiKey,
46
+ 'Content-Type': 'application/json'
47
+ }
48
+ }
49
+ );
50
+
51
+ console.log('✅ Call initiated successfully!\n');
52
+ console.log('📞 Call Details:');
53
+ console.log('─────────────────────────────────────');
54
+ console.log(`Conversation ID: ${response.data.conversation_id}`);
55
+ console.log(`Twilio Call SID: ${response.data.callSid}`);
56
+ console.log('─────────────────────────────────────\n');
57
+ console.log('⚠️ CRITICAL: Agent configured to WAIT for human to speak first!');
58
+ console.log(' Connor should say "hello" first, THEN agent will respond.\n');
59
+ console.log('Full Response:');
60
+ console.log(JSON.stringify(response.data, null, 2));
61
+
62
+ } catch (error) {
63
+ if (axios.isAxiosError(error)) {
64
+ console.error('❌ API Error:', error.response?.status);
65
+ console.error('Message:', error.response?.data?.detail || error.message);
66
+ if (error.response?.data) {
67
+ console.error('Full error:', JSON.stringify(error.response.data, null, 2));
68
+ }
69
+ } else {
70
+ console.error('❌ Unexpected error:', error);
71
+ }
72
+ process.exit(1);
73
+ }
74
+ }
75
+
76
+ makeTestCall();
package/test-call.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "agent_id": "agent_2601kahgbheaftnr7150xp0x8jbf",
3
+ "agent_phone_number_id": "phnum_7801kay1k5qjekb9eqakq1x6a8h0",
4
+ "to_number": "+19788066657"
5
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "Node16",
5
+ "moduleResolution": "Node16",
6
+ "lib": ["ES2022"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true,
16
+ "allowSyntheticDefaultImports": true,
17
+ "resolveJsonModule": true
18
+ },
19
+ "include": ["src/**/*"],
20
+ "exclude": ["node_modules", "dist"]
21
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Griffin Long
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.