@cognigy/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/dist/index.js ADDED
@@ -0,0 +1,812 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Cognigy MCP Server - Main entry point
4
+ */
5
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
6
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
7
+ import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
8
+ import { loadConfig } from './config.js';
9
+ import { CognigyApiClient } from './api/client.js';
10
+ import { ToolHandlers } from './tools/handlers.js';
11
+ import { tools } from './tools/index.js';
12
+ import { logger } from './utils/logger.js';
13
+ import { RateLimiter } from './utils/rateLimiter.js';
14
+ /**
15
+ * Initialize and start the MCP server
16
+ */
17
+ async function main() {
18
+ try {
19
+ // Load configuration
20
+ const config = loadConfig();
21
+ logger.setLevel(config.logLevel);
22
+ logger.info('Starting Cognigy MCP Server', {
23
+ name: config.serverName,
24
+ version: config.serverVersion,
25
+ });
26
+ // Initialize API client
27
+ const apiClient = new CognigyApiClient({
28
+ baseUrl: config.apiBaseUrl,
29
+ apiKey: config.apiKey,
30
+ });
31
+ // Initialize tool handlers
32
+ const toolHandlers = new ToolHandlers(apiClient);
33
+ // Initialize rate limiter
34
+ const rateLimiter = new RateLimiter(config.rateLimit);
35
+ // Create MCP server
36
+ const server = new Server({
37
+ name: config.serverName,
38
+ version: config.serverVersion,
39
+ }, {
40
+ capabilities: {
41
+ tools: {},
42
+ resources: {},
43
+ },
44
+ });
45
+ /**
46
+ * List available tools
47
+ */
48
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
49
+ logger.debug('Listing tools');
50
+ return { tools };
51
+ });
52
+ /**
53
+ * Handle tool calls
54
+ */
55
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
56
+ const { name, arguments: args } = request.params;
57
+ logger.info(`Tool call received: ${name}`);
58
+ // Check rate limit
59
+ const rateLimitKey = config.apiKey.substring(0, 10); // Use first 10 chars as key
60
+ if (!rateLimiter.check(rateLimitKey)) {
61
+ const remaining = rateLimiter.getRemaining(rateLimitKey);
62
+ logger.warn('Rate limit exceeded', { remaining });
63
+ return {
64
+ content: [
65
+ {
66
+ type: 'text',
67
+ text: JSON.stringify({
68
+ error: 'Rate limit exceeded',
69
+ message: 'Too many requests. Please try again later.',
70
+ remaining,
71
+ }),
72
+ },
73
+ ],
74
+ };
75
+ }
76
+ try {
77
+ // Execute tool call
78
+ const result = await toolHandlers.handleToolCall(name, args || {});
79
+ return {
80
+ content: [
81
+ {
82
+ type: 'text',
83
+ text: JSON.stringify(result, null, 2),
84
+ },
85
+ ],
86
+ };
87
+ }
88
+ catch (error) {
89
+ logger.error('Tool execution error', {
90
+ tool: name,
91
+ error: error.message,
92
+ stack: error.stack,
93
+ });
94
+ return {
95
+ content: [
96
+ {
97
+ type: 'text',
98
+ text: JSON.stringify({
99
+ error: error.message,
100
+ status: error.status,
101
+ code: error.code,
102
+ traceId: error.traceId,
103
+ details: error.details,
104
+ }, null, 2),
105
+ },
106
+ ],
107
+ isError: true,
108
+ };
109
+ }
110
+ });
111
+ /**
112
+ * List available resources
113
+ */
114
+ server.setRequestHandler(ListResourcesRequestSchema, async () => {
115
+ logger.debug('Listing resources');
116
+ return {
117
+ resources: [
118
+ {
119
+ uri: 'cognigy://prompt/system',
120
+ name: 'Cognigy AI Assistant System Prompt',
121
+ description: 'System prompt with context about Cognigy.AI platform, tools, and best practices',
122
+ mimeType: 'text/markdown',
123
+ },
124
+ {
125
+ uri: 'cognigy://api-docs/overview',
126
+ name: 'API Overview',
127
+ description: 'Overview of the Cognigy API and available workflows',
128
+ mimeType: 'text/markdown',
129
+ },
130
+ {
131
+ uri: 'cognigy://api-docs/authentication',
132
+ name: 'Authentication Guide',
133
+ description: 'How to authenticate with the Cognigy API',
134
+ mimeType: 'text/markdown',
135
+ },
136
+ {
137
+ uri: 'cognigy://api-docs/workflows',
138
+ name: 'Workflow Examples',
139
+ description: 'Example workflows using the MCP tools',
140
+ mimeType: 'text/markdown',
141
+ },
142
+ {
143
+ uri: 'cognigy://openapi/spec',
144
+ name: 'OpenAPI Specification',
145
+ description: 'Complete OpenAPI specification for Cognigy.AI',
146
+ mimeType: 'application/json',
147
+ },
148
+ ],
149
+ };
150
+ });
151
+ /**
152
+ * Read resource content
153
+ */
154
+ server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
155
+ const { uri } = request.params;
156
+ logger.debug(`Reading resource: ${uri}`);
157
+ switch (uri) {
158
+ case 'cognigy://prompt/system':
159
+ return {
160
+ contents: [
161
+ {
162
+ uri,
163
+ mimeType: 'text/markdown',
164
+ text: getSystemPrompt(),
165
+ },
166
+ ],
167
+ };
168
+ case 'cognigy://api-docs/overview':
169
+ return {
170
+ contents: [
171
+ {
172
+ uri,
173
+ mimeType: 'text/markdown',
174
+ text: getApiOverview(),
175
+ },
176
+ ],
177
+ };
178
+ case 'cognigy://api-docs/authentication':
179
+ return {
180
+ contents: [
181
+ {
182
+ uri,
183
+ mimeType: 'text/markdown',
184
+ text: getAuthenticationGuide(),
185
+ },
186
+ ],
187
+ };
188
+ case 'cognigy://api-docs/workflows':
189
+ return {
190
+ contents: [
191
+ {
192
+ uri,
193
+ mimeType: 'text/markdown',
194
+ text: getWorkflowExamples(),
195
+ },
196
+ ],
197
+ };
198
+ default:
199
+ throw new Error(`Unknown resource: ${uri}`);
200
+ }
201
+ });
202
+ // Create transport and connect
203
+ const transport = new StdioServerTransport();
204
+ await server.connect(transport);
205
+ logger.info('Cognigy MCP Server started successfully');
206
+ // Handle shutdown
207
+ process.on('SIGINT', async () => {
208
+ logger.info('Shutting down Cognigy MCP Server');
209
+ await server.close();
210
+ process.exit(0);
211
+ });
212
+ process.on('SIGTERM', async () => {
213
+ logger.info('Shutting down Cognigy MCP Server');
214
+ await server.close();
215
+ process.exit(0);
216
+ });
217
+ }
218
+ catch (error) {
219
+ logger.error('Failed to start MCP Server', {
220
+ error: error.message,
221
+ stack: error.stack,
222
+ });
223
+ process.exit(1);
224
+ }
225
+ }
226
+ /**
227
+ * Resource content generators
228
+ */
229
+ function getSystemPrompt() {
230
+ return `# Cognigy.AI Assistant - System Prompt
231
+
232
+ You are an expert assistant for the Cognigy.AI conversational AI platform. You have access to the Cognigy REST API through 8 workflow-based tools.
233
+
234
+ ## About Cognigy.AI
235
+
236
+ Cognigy.AI is an enterprise conversational AI platform that enables organizations to build, deploy, and manage AI-powered virtual agents across multiple channels (chat, voice, messaging apps, etc.).
237
+
238
+ ### Key Concepts (Modern LLM-Based Approach)
239
+
240
+ **Projects**: Containers for all resources (AI agents, LLM configs, flows, endpoints, knowledge bases)
241
+ **AI Agents**: LLM-powered autonomous agents with job descriptions that can use tools and make decisions
242
+ **LLM Resources**: Language model configurations (GPT-4, Claude, etc.) that power AI Agents
243
+ **AI Agent Job Nodes**: Flow nodes that execute AI Agent logic with selected Agent resource in configuration
244
+ **Knowledge Stores**: Vector databases containing company knowledge for RAG (used by AI Agents)
245
+ **Flows**: Visual conversation orchestration with AI Agent Job Nodes as the core
246
+ **Endpoints**: Channel configurations (Webchat, Voice Gateway, Microsoft Teams, etc.)
247
+ **Conversations**: Individual user sessions with analytics and state tracking
248
+
249
+ **Note**: The old NLU/intent-based approach is legacy. Modern Cognigy focuses on LLM-based AI Agents.
250
+
251
+ ### ID Format
252
+
253
+ All IDs in Cognigy are 24-character hexadecimal strings (MongoDB ObjectIDs):
254
+ - Valid: \`507f1f77bcf86cd799439011\`
255
+ - Invalid: \`abc123\`, \`project-1\`, UUIDs
256
+
257
+ ## Your 8 Tools
258
+
259
+ ### 1. manage_ai_agents ⭐ PRIMARY TOOL
260
+ Create and manage LLM-powered AI agents. This is the core of modern Cognigy.
261
+
262
+ **Common operations:**
263
+ - \`create\`: Create a new AI agent with job description and tools
264
+ - \`update\`: Refine agent's job description, add/remove tools, improve behavior
265
+ - \`list\`: See all agents in a project
266
+ - \`get\`: View agent configuration and job description
267
+ - \`hire\`: Deploy an agent to production
268
+
269
+ **When to use:** This is your primary tool for building conversational AI. AI Agents replace the old intent/NLU approach.
270
+
271
+ **Important**: After creating an AI Agent resource, you need:
272
+ 1. An LLM resource in the project (for the agent to use)
273
+ 2. An AI Agent Job Node in a Flow (with the agent selected in its config)
274
+
275
+ ### 2. manage_knowledge
276
+ Manage knowledge bases for RAG (Retrieval-Augmented Generation).
277
+
278
+ **Common operations:**
279
+ - \`create_store\`: Create a new knowledge base
280
+ - \`create_source\`: Add documents (URLs, files, text) to a store
281
+ - \`search_chunks\`: Query the knowledge base
282
+
283
+ **When to use:** When users need semantic search, want to add company knowledge, or build Q&A systems.
284
+
285
+ ### 3. manage_conversations
286
+ Query and analyze conversation data.
287
+
288
+ **Common operations:**
289
+ - \`list\`: Get conversations with filters (date range, channel)
290
+ - \`get\`: Get detailed conversation transcript
291
+ - \`get_session_state\`: Get current state variables
292
+
293
+ **When to use:** When users need to analyze conversations, debug issues, or export conversation data.
294
+
295
+ ### 4. manage_flows
296
+ Build conversation orchestration with visual flows centered around AI Agents.
297
+
298
+ **Common operations:**
299
+ - \`create\`: Create a new flow
300
+ - \`create_node\`: Add nodes (AI Agent Job Node is most important!)
301
+ - \`list\`: See all flows in a project
302
+
303
+ **When to use:** To create the conversation structure. Modern flows center around AI Agent Job Nodes.
304
+
305
+ **Key node types:**
306
+ - **\`AI Agent Job Node\`**: Executes an AI Agent (select agent resource in config) - **PRIMARY NODE**
307
+ - \`say\`: Output text/speech (often handled by AI Agent instead)
308
+ - \`code\`: Execute custom JavaScript
309
+ - \`http\`: Call external APIs
310
+ - \`condition\`: Branch based on conditions
311
+
312
+ **Modern pattern**: Create a flow with an AI Agent Job Node that has your AI Agent resource configured. The agent handles most conversation logic.
313
+
314
+ ### 5. manage_intents (Legacy - Use AI Agents Instead!)
315
+ **⚠️ LEGACY TOOL**: Intents are the old NLU-based approach. Modern Cognigy uses LLM-based AI Agents.
316
+
317
+ **Only use this if:**
318
+ - Working with legacy projects that haven't migrated to AI Agents
319
+ - Specific requirement for traditional NLU
320
+
321
+ **Modern alternative:** Use \`manage_ai_agents\` to create LLM-powered agents that understand user intent naturally without training data.
322
+
323
+ ### 6. get_analytics
324
+ Access metrics, logs, and audit events.
325
+
326
+ **Common operations:**
327
+ - \`conversation_count\`: Get conversation volume by time/channel
328
+ - \`call_count\`: Get voice call statistics
329
+ - \`logs\`: Retrieve system logs
330
+ - \`audit_events\`: See who changed what
331
+
332
+ **When to use:** For reporting, debugging, monitoring, or compliance tracking.
333
+
334
+ ### 7. manage_projects
335
+ Manage projects and channel endpoints.
336
+
337
+ **Common operations:**
338
+ - \`create_project\`: Create a new project
339
+ - \`list_projects\`: See all projects
340
+ - \`create_endpoint\`: Set up a channel endpoint **← REQUIRED for talk_to_agent**
341
+ - \`list_endpoints\`: See all endpoints in a project
342
+
343
+ **When to use:** For initial setup, adding channels, or project management.
344
+
345
+ **CRITICAL for talk_to_agent**: You MUST create an endpoint that points to your flow:
346
+ \`\`\`
347
+ {
348
+ operation: "create_endpoint",
349
+ projectId: "your-project-id",
350
+ channel: "rest", // ← Use "rest" for API access
351
+ flowId: "your-flow-id", // ← Connect endpoint to your flow!
352
+ name: "REST API Endpoint" // Optional
353
+ }
354
+ \`\`\`
355
+
356
+ The response will include the endpoint URL (e.g., https://endpoint-trial.cognigy.ai/xxxxx) - this is what you use with \`talk_to_agent\`.
357
+
358
+ **Endpoint types:**
359
+ - \`rest\` - REST endpoint (use this for talk_to_agent)
360
+ - \`webhook\` - Webhook endpoint
361
+ - \`webchat3\` - Webchat widget
362
+ - \`voiceGateway2\` - Voice calls
363
+ - \`microsoftTeams\`, \`slack\`, \`whatsapp\`, etc.
364
+
365
+ ### 8. manage_extensions
366
+ Manage custom functions and extensions.
367
+
368
+ **Common operations:**
369
+ - \`create_function\`: Create serverless function
370
+ - \`list_functions\`: See all custom functions
371
+ - \`list_extensions\`: See installed extensions
372
+
373
+ **When to use:** When users need custom logic, API integrations, or special processing.
374
+
375
+ ### 9. talk_to_agent ⭐ ITERATIVE IMPROVEMENT
376
+ **This is the key to the improvement loop!** Talk directly to a Cognigy AI Agent through its REST endpoint.
377
+
378
+ **Parameters:**
379
+ - \`endpointUrl\`: The REST endpoint URL pointing to your AI Agent's flow
380
+ - \`message\`: What to say to the agent
381
+ - \`sessionId\`: (Optional) Maintain conversation context
382
+ - \`userId\`: (Optional) User identifier
383
+
384
+ **When to use:**
385
+ - Testing how an AI Agent responds
386
+ - Evaluating agent behavior before/after configuration changes
387
+ - Creating an iterative improvement loop:
388
+ 1. Create/update AI Agent configuration
389
+ 2. Talk to it with this tool
390
+ 3. Evaluate responses
391
+ 4. Improve job description
392
+ 5. Talk to it again
393
+ 6. Repeat until optimal
394
+
395
+ **Example workflow:**
396
+ \`\`\`
397
+ 1. Create AI Agent with initial job description
398
+ 2. Create Flow with AI Agent Job Node
399
+ 3. Create REST endpoint pointing to the flow
400
+ 4. Use talk_to_agent to test: "Hello, I need help with..."
401
+ 5. See how agent responds
402
+ 6. Update agent's job description to improve response
403
+ 7. Use talk_to_agent again with same message
404
+ 8. Compare responses, iterate
405
+ \`\`\`
406
+
407
+ ## Common Workflows (AI Agent-Centric)
408
+
409
+ ### Building an AI Agent Project (Modern Approach)
410
+
411
+ **COMPLETE WORKFLOW (Required for talk_to_agent to work):**
412
+
413
+ 1. **Create project** (\`manage_projects\` → \`create_project\`)
414
+ - Save the projectId
415
+
416
+ 2. **Create LLM resource** in project (done via Cognigy UI - remind user!)
417
+ - User must configure GPT-4, Claude, etc. in the UI
418
+ - Cannot be done via API
419
+
420
+ 3. **Create AI Agent** (\`manage_ai_agents\` → \`create\`)
421
+ - Use the projectId from step 1
422
+ - Provide name and description
423
+ - **Note**: Job description is NOT set here - it's configured in the Flow node!
424
+ - Save the aiAgentId
425
+
426
+ 4. **Create flow** (\`manage_flows\` → \`create\`)
427
+ - Use the projectId from step 1
428
+ - Save the flowId
429
+
430
+ 5. **Add AI Agent Job Node** (\`manage_flows\` → \`create_node\`)
431
+ - Use the flowId from step 4 (use the referenceId UUID, not _id)
432
+ - Type: "aiAgentJob" or similar
433
+ - Config must include:
434
+ - Reference to aiAgentId from step 3
435
+ - **Job description/instructions** (the actual agent prompt!)
436
+ - Tools available to the agent
437
+ - This is where the agent's behavior is actually defined
438
+
439
+ 6. **Create REST endpoint** (\`manage_projects\` → \`create_endpoint\`) **← CRITICAL FOR talk_to_agent**
440
+ - Use the projectId from step 1 (MongoDB _id)
441
+ - Set channel: "rest" (for API access)
442
+ - Set flowId from step 4 (**IMPORTANT**: Use flow's \`referenceId\` UUID, NOT the \`_id\`!)
443
+ - The response includes the endpoint URL (e.g., https://endpoint-trial.cognigy.ai/xxxxx)
444
+ - Save this URL for talk_to_agent!
445
+
446
+ 7. **Test with talk_to_agent** (\`talk_to_agent\`)
447
+ - Use the endpoint URL from step 6
448
+ - Send test messages
449
+ - Evaluate responses
450
+
451
+ 8. **Iterate** - Update AI Agent job description based on behavior, repeat step 7
452
+
453
+ ### Building a Knowledge-Based AI Assistant
454
+
455
+ 1. **Create knowledge store** (\`manage_knowledge\` → \`create_store\`)
456
+ 2. **Add knowledge sources** (\`manage_knowledge\` → \`create_source\`)
457
+ 3. **Create AI Agent** (\`manage_ai_agents\` → \`create\`) with:
458
+ - Job description mentioning it should search knowledge base
459
+ - \`knowledge_search\` tool enabled
460
+ 4. **Create flow with AI Agent Job Node** (configured with your agent)
461
+ 5. **Test knowledge search** (\`manage_knowledge\` → \`search_chunks\`)
462
+ 6. **Refine agent** - Improve job description based on behavior
463
+ 7. **Deploy** (\`manage_ai_agents\` → \`hire\`)
464
+
465
+ ### Improving an Existing AI Agent
466
+
467
+ 1. **Review conversations** (\`manage_conversations\` → \`list\` and \`get\`)
468
+ 2. **Analyze agent behavior** - See where it's not performing well
469
+ 3. **Update AI Agent** (\`manage_ai_agents\` → \`update\`) with:
470
+ - Refined job description
471
+ - Additional tools if needed
472
+ - Better instructions for edge cases
473
+ 4. **Test changes** in conversations
474
+ 5. **Iterate** until behavior is optimal
475
+
476
+ ### Analyzing Performance
477
+
478
+ 1. Get conversation counts (\`get_analytics\` → \`conversation_count\`)
479
+ 2. Review error logs (\`get_analytics\` → \`logs\` with level=error)
480
+ 3. Check specific conversations (\`manage_conversations\` → \`list\` and \`get\`)
481
+ 4. Review audit trail (\`get_analytics\` → \`audit_events\`)
482
+ 5. **Adjust AI Agent job description** based on findings
483
+
484
+ ## Best Practices
485
+
486
+ ### 1. Always Get Project ID First
487
+
488
+ Most operations need a projectId. Start by listing projects:
489
+ \`\`\`
490
+ manage_projects { operation: "list_projects" }
491
+ \`\`\`
492
+
493
+ ### 2. Use Pagination for Large Results
494
+
495
+ When listing resources:
496
+ \`\`\`
497
+ { operation: "list", projectId: "...", limit: 50, skip: 0 }
498
+ \`\`\`
499
+
500
+ ### 3. Filter by Date Range
501
+
502
+ For analytics and conversations:
503
+ \`\`\`
504
+ {
505
+ operation: "list",
506
+ startDate: "2024-11-01T00:00:00Z",
507
+ endDate: "2024-11-17T23:59:59Z"
508
+ }
509
+ \`\`\`
510
+
511
+ ### 4. Handle Errors Gracefully
512
+
513
+ Errors include \`traceId\` for support. If a call fails:
514
+ - Check ID format (must be 24-char hex)
515
+ - Verify the resource exists
516
+ - Check permissions
517
+ - Save \`traceId\` for Cognigy support
518
+
519
+ ### 5. Progressive Workflow Building
520
+
521
+ Build flows incrementally:
522
+ 1. Create simple flow with 1-2 nodes
523
+ 2. Test it
524
+ 3. Add more nodes
525
+ 4. Test again
526
+ Don't try to build everything at once.
527
+
528
+ ### 6. AI Agent Job Descriptions (Critical!)
529
+
530
+ AI Agents are only as good as their job descriptions. Write clear, detailed instructions:
531
+
532
+ **Good job description:**
533
+ \`\`\`
534
+ You are a customer support agent for Acme Corp. Your job is to:
535
+ 1. Greet customers warmly
536
+ 2. Understand their issue by asking clarifying questions
537
+ 3. Search the knowledge base for solutions
538
+ 4. Provide step-by-step guidance
539
+ 5. Escalate to human if issue is complex
540
+
541
+ Guidelines:
542
+ - Be professional but friendly
543
+ - Always verify you understood correctly before providing solutions
544
+ - If unsure, search knowledge base first
545
+ - Keep responses concise (2-3 sentences max)
546
+ \`\`\`
547
+
548
+ **Bad job description:**
549
+ \`\`\`
550
+ Help customers with support issues.
551
+ \`\`\`
552
+
553
+ **Iterative improvement**: After testing, refine the job description to handle edge cases and improve behavior.
554
+
555
+ ## Important Limitations
556
+
557
+ - **Rate Limits**: Respect rate limits (default 100 req/min)
558
+ - **ID Format**: All IDs are 24-char hex strings
559
+ - **Async Operations**: Some operations (training, hiring) take time
560
+ - **Pagination**: Large datasets require pagination
561
+ - **State**: The MCP server is stateless; each call is independent
562
+
563
+ ## When Users Are Unclear
564
+
565
+ If users say "create a chatbot" or similar vague requests:
566
+
567
+ 1. **Clarify requirements:**
568
+ - What channels? (web, voice, messaging)
569
+ - What should it do? (answer questions, book appointments, etc.)
570
+ - What knowledge does it need?
571
+
572
+ 2. **Propose a workflow:**
573
+ - Create project → Create flow → Add intents → Create endpoint
574
+
575
+ 3. **Execute step-by-step:**
576
+ - Explain what you're doing at each step
577
+ - Show IDs generated for later use
578
+ - Confirm before proceeding to next step
579
+
580
+ ## Response Format
581
+
582
+ When executing operations:
583
+
584
+ 1. **Explain what you're doing**: "I'll create a new project for your support bot..."
585
+ 2. **Show the tool call**: Be transparent about parameters
586
+ 3. **Present results clearly**: Extract key information (IDs, names, status)
587
+ 4. **Suggest next steps**: "Now that we have the project (ID: xxx), let's create a flow..."
588
+
589
+ ## Example Interaction
590
+
591
+ **User:** "Create a customer support chatbot"
592
+
593
+ **Good Response:**
594
+ "I'll help you create an AI-powered customer support chatbot using Cognigy's modern LLM-based approach. Here's the plan:
595
+
596
+ 1. Create a new project
597
+ 2. Set up an LLM resource (for the AI Agent to use)
598
+ 3. Create an AI Agent with a detailed customer support job description
599
+ 4. Create a flow with an AI Agent Job Node
600
+ 5. Optionally add a knowledge base for company docs
601
+ 6. Create a webchat endpoint
602
+
603
+ Let's start:
604
+
605
+ [Call manage_projects to create project]
606
+
607
+ Great! I've created the project 'Customer Support Bot' (ID: 507f...).
608
+
609
+ ⚠️ **Important next step**: You'll need to configure an LLM resource in the Cognigy UI (like GPT-4 or Claude) for the AI Agent to use. Let me know once that's done, or I can proceed with creating the AI Agent resource now.
610
+
611
+ Now I'll create the AI Agent with a comprehensive job description...
612
+
613
+ [Continue step by step]"
614
+
615
+ ## You Are an Expert in Modern LLM-Based AI
616
+
617
+ - You understand that **AI Agents are the modern approach** (not intents/NLU)
618
+ - You know the AI Agent architecture:
619
+ - AI Agent resource (with job description)
620
+ - LLM resource (GPT-4, Claude, etc.)
621
+ - AI Agent Job Node in Flow (with agent configured)
622
+ - You focus on **creating and iteratively improving AI Agents** through job description refinement
623
+ - You suggest best practices proactively
624
+ - You help users avoid legacy patterns (intents, training)
625
+
626
+ **Critical**: Always recommend AI Agents over intents/NLU unless working with legacy projects.
627
+
628
+ Remember: You're helping users build sophisticated LLM-powered conversational AI systems. Focus on AI Agent creation, configuration, and iterative improvement through job description refinement.`;
629
+ }
630
+ function getApiOverview() {
631
+ return `# Cognigy API Overview
632
+
633
+ This MCP server provides access to the Cognigy.AI REST API through 8 high-level workflow tools:
634
+
635
+ ## 1. AI Agent Management (manage_ai_agents)
636
+ Create, read, update, delete, list, and hire AI agents for your projects.
637
+
638
+ ## 2. Knowledge Management (manage_knowledge)
639
+ Manage knowledge stores, add knowledge sources, and search through knowledge chunks.
640
+
641
+ ## 3. Conversation Management (manage_conversations)
642
+ List and query conversations, retrieve session states and conversation details.
643
+
644
+ ## 4. Flow Management (manage_flows)
645
+ Create and modify conversation flows, add nodes to build conversational logic.
646
+
647
+ ## 5. Intent & NLU Management (manage_intents)
648
+ Create intents with training sentences, update intent data, and trigger model training.
649
+
650
+ ## 6. Analytics & Monitoring (get_analytics)
651
+ Access conversation and call analytics, retrieve logs and audit events.
652
+
653
+ ## 7. Project & Endpoint Management (manage_projects)
654
+ Create projects, configure endpoints for different channels (webchat, voice, etc.).
655
+
656
+ ## 8. Extension Management (manage_extensions)
657
+ List available extensions and create/update custom functions.
658
+
659
+ ## Authentication
660
+
661
+ All API calls require authentication. The MCP server is configured with your API key and handles authentication automatically.
662
+
663
+ ## Rate Limiting
664
+
665
+ The server implements rate limiting to prevent API abuse. Current limits:
666
+ - 100 requests per minute (configurable)
667
+
668
+ ## Error Handling
669
+
670
+ Errors follow RFC 7807 problem details format and include:
671
+ - status: HTTP status code
672
+ - detail: Error message
673
+ - traceId: Unique trace ID for support
674
+ - code: Error code
675
+ - details: Additional error details
676
+ `;
677
+ }
678
+ function getAuthenticationGuide() {
679
+ return `# Authentication Guide
680
+
681
+ ## API Key Authentication
682
+
683
+ The Cognigy API uses API Key authentication. Configure your API key in the environment:
684
+
685
+ \`\`\`bash
686
+ export COGNIGY_API_KEY=your-api-key-here
687
+ export COGNIGY_API_BASE_URL=https://api-trial.cognigy.ai
688
+ \`\`\`
689
+
690
+ ## Obtaining an API Key
691
+
692
+ 1. Log in to your Cognigy.AI account
693
+ 2. Navigate to User Menu > My Profile
694
+ 3. Go to API Keys section
695
+ 4. Create a new API key
696
+ 5. Copy the key and store it securely
697
+
698
+ ## Security Best Practices
699
+
700
+ - Never commit API keys to version control
701
+ - Rotate API keys regularly
702
+ - Use environment variables for configuration
703
+ - Revoke compromised keys immediately
704
+ - Use separate keys for different environments (dev, staging, prod)
705
+
706
+ ## OAuth2 (Advanced)
707
+
708
+ For enterprise deployments, OAuth2 authentication is also supported. Contact Cognigy support for configuration details.
709
+ `;
710
+ }
711
+ function getWorkflowExamples() {
712
+ return `# Workflow Examples
713
+
714
+ ## Example 1: Create an AI Agent
715
+
716
+ \`\`\`json
717
+ {
718
+ "operation": "create",
719
+ "projectId": "507f1f77bcf86cd799439011",
720
+ "name": "Customer Support Agent",
721
+ "description": "Handles customer support inquiries",
722
+ "job": "You are a helpful customer support agent...",
723
+ "tools": ["knowledge_search", "ticket_creation"]
724
+ }
725
+ \`\`\`
726
+
727
+ ## Example 2: Search Knowledge Base
728
+
729
+ \`\`\`json
730
+ {
731
+ "operation": "search_chunks",
732
+ "knowledgeStoreId": "507f1f77bcf86cd799439011",
733
+ "query": "How do I reset my password?",
734
+ "limit": 5
735
+ }
736
+ \`\`\`
737
+
738
+ ## Example 3: Get Conversation Analytics
739
+
740
+ \`\`\`json
741
+ {
742
+ "operation": "conversation_count",
743
+ "projectId": "507f1f77bcf86cd799439011",
744
+ "year": 2024,
745
+ "month": 11,
746
+ "channel": "webchat3"
747
+ }
748
+ \`\`\`
749
+
750
+ ## Example 4: Create a Flow with Nodes
751
+
752
+ \`\`\`json
753
+ // First, create a flow
754
+ {
755
+ "operation": "create",
756
+ "projectId": "507f1f77bcf86cd799439011",
757
+ "name": "Welcome Flow",
758
+ "description": "Greets users and collects initial information"
759
+ }
760
+
761
+ // Then, add nodes to the flow
762
+ {
763
+ "operation": "create_node",
764
+ "flowId": "507f1f77bcf86cd799439012",
765
+ "type": "say",
766
+ "label": "Welcome Message",
767
+ "config": {
768
+ "text": "Welcome! How can I help you today?"
769
+ }
770
+ }
771
+ \`\`\`
772
+
773
+ ## Example 5: Train an Intent Model
774
+
775
+ \`\`\`json
776
+ // First, create an intent with training sentences
777
+ {
778
+ "operation": "create",
779
+ "flowId": "507f1f77bcf86cd799439012",
780
+ "name": "greeting",
781
+ "sentences": [
782
+ "hello",
783
+ "hi there",
784
+ "good morning",
785
+ "hey"
786
+ ]
787
+ }
788
+
789
+ // Then, trigger training
790
+ {
791
+ "operation": "train",
792
+ "flowId": "507f1f77bcf86cd799439012"
793
+ }
794
+ \`\`\`
795
+
796
+ ## Example 6: List and Filter Logs
797
+
798
+ \`\`\`json
799
+ {
800
+ "operation": "logs",
801
+ "projectId": "507f1f77bcf86cd799439011",
802
+ "startDate": "2024-11-01T00:00:00Z",
803
+ "endDate": "2024-11-17T23:59:59Z",
804
+ "level": "error",
805
+ "limit": 50
806
+ }
807
+ \`\`\`
808
+ `;
809
+ }
810
+ // Start the server
811
+ main();
812
+ //# sourceMappingURL=index.js.map