@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/QUICK_START.md ADDED
@@ -0,0 +1,195 @@
1
+ # Quick Start Guide
2
+
3
+ ## What This Is
4
+
5
+ A **Model Context Protocol (MCP) server** that lets AI assistants (Claude, Cursor) interact with Cognigy.AI through 9 high-level tools, including a **complete self-improvement loop** for AI Agents.
6
+
7
+ ## Key Feature: 100% Automatic AI Agent Setup
8
+
9
+ **One tool call creates everything:**
10
+ - ✅ AI Agent resource
11
+ - ✅ Flow with AI Agent Job Node
12
+ - ✅ REST Endpoint
13
+ - ✅ **Agent is immediately testable!**
14
+
15
+ ## Installation (5 minutes)
16
+
17
+ ### 1. Install Dependencies
18
+
19
+ ```bash
20
+ cd /path/to/cognigy/services/mcp-server
21
+ npm install
22
+ ```
23
+
24
+ ### 2. Build
25
+
26
+ ```bash
27
+ npm run build
28
+ ```
29
+
30
+ ### 3. Configure for Cursor
31
+
32
+ Add to `~/Library/Application Support/Cursor/User/globalStorage/mcp/mcp.json`:
33
+
34
+ ```json
35
+ {
36
+ "mcpServers": {
37
+ "cognigy": {
38
+ "command": "node",
39
+ "args": [
40
+ "/ABSOLUTE/PATH/TO/cognigy/services/mcp-server/dist/index.js"
41
+ ],
42
+ "env": {
43
+ "COGNIGY_API_BASE_URL": "https://api-trial.cognigy.ai",
44
+ "COGNIGY_API_KEY": "your-api-key-here"
45
+ }
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ **Get your API key:**
52
+ 1. Login to Cognigy.AI
53
+ 2. User Menu → My Profile → API Keys
54
+ 3. Create new key, copy it
55
+
56
+ ### 4. Restart Cursor
57
+
58
+ Settings → MCP → Toggle "cognigy" off/on (or restart Cursor completely)
59
+
60
+ ## Usage
61
+
62
+ ### Create an AI Agent (Fully Automatic!)
63
+
64
+ In Cursor chat:
65
+ ```
66
+ @cognigy Create an AI agent called "Support Bot" in project <project-id>
67
+ ```
68
+
69
+ **This ONE command creates:**
70
+ - AI Agent resource
71
+ - Flow
72
+ - AI Agent Job Node (connected to agent)
73
+ - REST Endpoint
74
+ - Returns endpoint URL
75
+
76
+ ### Talk to Your Agent
77
+
78
+ ```
79
+ @cognigy Talk to the agent at <endpoint-url>
80
+ Message: "I need help with something"
81
+ ```
82
+
83
+ **Returns the agent's actual response!**
84
+
85
+ ### Improve Your Agent (The Loop!)
86
+
87
+ ```
88
+ @cognigy Update agent <agent-id> description to be more empathetic and friendly
89
+ ```
90
+
91
+ Then talk to it again and compare responses!
92
+
93
+ ### The Complete Self-Improvement Loop
94
+
95
+ ```
96
+ 1. @cognigy Create AI agent "Password Reset Helper" in project <id>
97
+ → Everything created, endpoint URL returned
98
+
99
+ 2. @cognigy Talk to agent at <url>: "I forgot my password"
100
+ → Agent responds (might be generic)
101
+
102
+ 3. Update agent description in Cognigy UI with better instructions
103
+ (Or use update tool if supported)
104
+
105
+ 4. @cognigy Talk to agent again: "I forgot my password"
106
+ → Compare responses - should be better!
107
+
108
+ 5. Repeat steps 3-4 until perfect!
109
+ ```
110
+
111
+ ## The 9 Tools
112
+
113
+ 1. **`manage_ai_agents`** ⭐ - Create/update AI agents (AUTO-CREATES EVERYTHING!)
114
+ 2. **`manage_knowledge`** - Knowledge stores for RAG
115
+ 3. **`manage_conversations`** - Query conversation history
116
+ 4. **`manage_flows`** - Create/modify flows
117
+ 5. **`manage_intents`** (Legacy) - Old NLU approach
118
+ 6. **`get_analytics`** - Metrics, logs, audit events
119
+ 7. **`manage_projects`** - Projects and endpoints
120
+ 8. **`manage_extensions`** - Custom functions
121
+ 9. **`talk_to_agent`** 🔄 - Talk to your agent, test responses
122
+
123
+ ## Important Notes
124
+
125
+ ### ID Formats (Critical!)
126
+
127
+ Cognigy uses **two different ID formats**:
128
+
129
+ **MongoDB _id** (24-char hex):
130
+ - Format: `691b1c2e36bda2b14170fd73`
131
+ - Used for: `projectId`, `aiAgentId`, most operations
132
+
133
+ **UUID referenceId** (36-char with hyphens):
134
+ - Format: `8184e6a8-e10c-4b03-8a83-538c004c321a`
135
+ - Used for: `flowId` in endpoints
136
+
137
+ When you create resources, you get both IDs. Use the right one for each operation!
138
+
139
+ ### System Prompt
140
+
141
+ The MCP server includes a **comprehensive system prompt** as a resource that Claude/Cursor can read. This gives context about:
142
+ - Cognigy.AI concepts (flows, agents, endpoints)
143
+ - How tools work together
144
+ - Best practices
145
+ - Common workflows
146
+
147
+ The AI assistant automatically becomes a Cognigy expert!
148
+
149
+ ### Modern Approach: AI Agents > Intents
150
+
151
+ Focus on **LLM-based AI Agents** (tool #1), not traditional NLU/intents (tool #5 - legacy).
152
+
153
+ ## Troubleshooting
154
+
155
+ ### "COGNIGY_API_BASE_URL environment variable is required"
156
+ → Check your MCP config has the `env` section with API credentials
157
+
158
+ ### Agent not responding
159
+ → Make sure you have an LLM resource configured in the project (via Cognigy UI)
160
+
161
+ ### Invalid ID format errors
162
+ → Check if you're using the right ID format (MongoDB _id vs UUID referenceId)
163
+
164
+ ## What's Tested and Working
165
+
166
+ ✅ AI Agent creation with automatic flow/endpoint setup
167
+ ✅ REST endpoint creation
168
+ ✅ Talk to agent via endpoint
169
+ ✅ Agent responds properly
170
+ ✅ Update agent and see changes
171
+ ✅ Complete improvement loop
172
+
173
+ ## Next Steps
174
+
175
+ 1. **Get your project ID:**
176
+ ```
177
+ @cognigy List my projects
178
+ ```
179
+
180
+ 2. **Create your first agent:**
181
+ ```
182
+ @cognigy Create AI agent "My First Bot" in project <id>
183
+ ```
184
+
185
+ 3. **Start talking to it:**
186
+ ```
187
+ @cognigy Talk to agent at <endpoint-url>: "Hello!"
188
+ ```
189
+
190
+ 4. **Improve and iterate!** 🔄
191
+
192
+ ---
193
+
194
+ **That's it!** You're ready to build and improve AI agents with the self-improvement loop! 🚀
195
+
package/README.md ADDED
@@ -0,0 +1,298 @@
1
+ # Cognigy MCP Server
2
+
3
+ > **📚 New here?** See **[INDEX.md](INDEX.md)** for quick navigation to the right documentation for your needs!
4
+
5
+ A production-ready Model Context Protocol (MCP) server that provides AI assistants (Claude Desktop, Cursor IDE) with access to the Cognigy.AI REST API.
6
+
7
+ ## 🎯 Key Feature: Self-Improving AI Agents
8
+
9
+ **Create a complete AI Agent setup in ONE tool call**, then iterate and improve through conversation:
10
+
11
+ 1. **Create** → AI Agent + Flow + Job Node + Endpoint (automatic!)
12
+ 2. **Test** → Talk to your agent via REST endpoint
13
+ 3. **Improve** → Update job description based on responses
14
+ 4. **Test Again** → Compare responses and iterate
15
+ 5. **Repeat** → Until your agent is perfect!
16
+
17
+ ## Overview
18
+
19
+ This MCP server exposes the Cognigy.AI API through 9 high-level workflow tools focused on **LLM-based AI Agents** (the modern approach), making it easy for AI assistants to build, test, and improve conversational AI systems.
20
+
21
+ ## Features
22
+
23
+ - **9 High-Level Workflow Tools**: Grouped 359 API endpoints into 9 logical workflows (97.5% reduction!)
24
+ - **100% Automatic AI Agent Setup**: One tool call creates Agent + Flow + Job Node + Endpoint
25
+ - **Self-Improvement Loop**: Talk to agents, test responses, iterate until perfect
26
+ - **System Prompt Included**: AI assistants automatically become Cognigy experts
27
+ - **Authentication**: API Key authentication (configured via MCP)
28
+ - **Rate Limiting**: Built-in protection against API abuse
29
+ - **Error Handling**: RFC 7807 compliant error responses
30
+ - **Type Safety**: Full TypeScript with Zod validation
31
+ - **Production Ready**: Logging, tests, multiple deployment options
32
+
33
+ ## Workflow Tools (AI Agent-Centric)
34
+
35
+ 1. **AI Agent Management** ⭐ - Create, update LLM-powered AI agents (PRIMARY TOOL)
36
+ 2. **Knowledge Management** - Manage knowledge stores for RAG-enabled AI agents
37
+ 3. **Conversation Management** - Query conversations to improve AI agent behavior
38
+ 4. **Flow Management** - Create flows with AI Agent Job Nodes
39
+ 5. **Intent & NLU Management** (Legacy) - Old approach, use AI Agents instead
40
+ 6. **Analytics & Monitoring** - Get metrics, logs, and audit events
41
+ 7. **Project & Endpoint Management** - Manage projects and REST endpoints
42
+ 8. **Extension Management** - Manage custom extensions and functions
43
+ 9. **Talk to AI Agent** 🔄 - **THE IMPROVEMENT LOOP** - Talk directly to your AI Agent via REST endpoint!
44
+
45
+ **Important**: AI Agent job descriptions are configured in the **AI Agent Job Node** within a Flow, not in the Agent resource itself.
46
+
47
+ **Modern Approach**: Focus on AI Agents (LLM-powered) rather than intents/NLU (legacy)
48
+
49
+ ### 🔄 The Self-Improvement Loop
50
+
51
+ The **`talk_to_agent`** tool enables a powerful iterative improvement workflow:
52
+
53
+ ```
54
+ ┌─────────────────────────────────────────────────────┐
55
+ │ 1. Create/Update AI Agent (job description) │
56
+ └────────────────┬────────────────────────────────────┘
57
+
58
+ ┌─────────────────────────────────────────────────────┐
59
+ │ 2. Talk to Agent (via REST endpoint) │
60
+ │ "How do I reset my password?" │
61
+ └────────────────┬────────────────────────────────────┘
62
+
63
+ ┌─────────────────────────────────────────────────────┐
64
+ │ 3. Evaluate Response │
65
+ │ - Is it helpful? │
66
+ │ - Is the tone right? │
67
+ │ - Does it follow guidelines? │
68
+ └────────────────┬────────────────────────────────────┘
69
+
70
+ ┌─────────────────────────────────────────────────────┐
71
+ │ 4. Improve Job Description │
72
+ │ - Add specific instructions │
73
+ │ - Fix issues found │
74
+ │ - Add edge case handling │
75
+ └────────────────┬────────────────────────────────────┘
76
+
77
+ ┌─────────────────────────────────────────────────────┐
78
+ │ 5. Talk to Agent Again (same question) │
79
+ │ Compare responses → Better? → Iterate │
80
+ └─────────────────────────────────────────────────────┘
81
+ ```
82
+
83
+ **Human in the loop**: You provide feedback, suggest improvements, and approve changes!
84
+
85
+ ## Quick Start
86
+
87
+ ### Prerequisites
88
+
89
+ - **Node.js 20+** (check with `node -v`)
90
+ - **A Cognigy API key** — Cognigy.AI → User Menu → My Profile → API Keys → Create New
91
+
92
+ ### Add to your MCP client
93
+
94
+ Add the following to your MCP client's config file. No build step, no cloning — `npx` handles everything automatically.
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "cognigy": {
100
+ "command": "npx",
101
+ "args": ["-y", "@cognigy/mcp-server"],
102
+ "env": {
103
+ "COGNIGY_API_BASE_URL": "https://api-trial.cognigy.ai",
104
+ "COGNIGY_API_KEY": "your-api-key-here"
105
+ }
106
+ }
107
+ }
108
+ }
109
+ ```
110
+
111
+ Restart your MCP client, then try:
112
+ ```
113
+ @cognigy List my Cognigy projects
114
+ ```
115
+
116
+ **See [QUICK_START.md](QUICK_START.md) for detailed usage examples!**
117
+
118
+ ## Setup by MCP Client
119
+
120
+ ### Claude Desktop
121
+
122
+ Edit `~/Library/Application Support/Claude/claude_desktop_config.json` and add the config block above. Restart Claude Desktop.
123
+
124
+ ### Cursor IDE
125
+
126
+ Edit the MCP config file directly, or go to **Cursor > Settings > Cursor Settings > MCP > Add MCP Server**.
127
+
128
+ **Config file location:**
129
+ - macOS: `~/Library/Application Support/Cursor/User/globalStorage/mcp/mcp.json`
130
+ - Windows: `%APPDATA%\Cursor\User\globalStorage\mcp\mcp.json`
131
+ - Linux: `~/.config/Cursor/User/globalStorage/mcp/mcp.json`
132
+
133
+ Add the config block above. Restart Cursor. Open the AI chat and type `@cognigy` to use the tools.
134
+
135
+ ### ChatGPT / Windsurf / Other MCP Clients
136
+
137
+ Any MCP client that supports the **stdio** transport works. Add the same config block to your client's MCP settings.
138
+
139
+ ## Configuration
140
+
141
+ All configuration is passed via the `env` block in the MCP config. No `.env` file needed.
142
+
143
+ | Variable | Required | Default | Description |
144
+ |---|---|---|---|
145
+ | `COGNIGY_API_BASE_URL` | Yes | — | Your Cognigy API URL |
146
+ | `COGNIGY_API_KEY` | Yes | — | Your Cognigy API key |
147
+ | `LOG_LEVEL` | No | `info` | `debug`, `info`, `warn`, `error` |
148
+ | `RATE_LIMIT_MAX_REQUESTS` | No | `100` | Max requests per window |
149
+ | `RATE_LIMIT_WINDOW_MS` | No | `60000` | Rate limit window (ms) |
150
+
151
+ ### Getting Your API Key
152
+
153
+ 1. Log in to Cognigy.AI
154
+ 2. **User Menu → My Profile**
155
+ 3. **API Keys** section
156
+ 4. Click **Create API Key**
157
+ 5. Copy the key
158
+
159
+ <details>
160
+ <summary>Local development setup (for contributors)</summary>
161
+
162
+ If you're developing the MCP server itself:
163
+
164
+ ```bash
165
+ git clone <repo-url>
166
+ cd cognigy-mcp
167
+ npm install
168
+ npm run build
169
+ ```
170
+
171
+ Then point your MCP client to the local build:
172
+
173
+ ```json
174
+ {
175
+ "mcpServers": {
176
+ "cognigy": {
177
+ "command": "node",
178
+ "args": ["/absolute/path/to/cognigy-mcp/dist/index.js"],
179
+ "env": {
180
+ "COGNIGY_API_BASE_URL": "https://api-trial.cognigy.ai",
181
+ "COGNIGY_API_KEY": "your-api-key-here"
182
+ }
183
+ }
184
+ }
185
+ }
186
+ ```
187
+
188
+ Or use the interactive setup: `npm run setup`
189
+
190
+ </details>
191
+
192
+ ### System Prompt (Included!)
193
+
194
+ The MCP server includes a comprehensive **system prompt as an MCP resource** that Claude automatically loads. This transforms Claude into a Cognigy expert that:
195
+
196
+ - ✅ Understands modern **LLM-based AI Agent architecture**
197
+ - ✅ Focuses on **creating and refining AI Agents** (not legacy NLU/intents)
198
+ - ✅ Knows the AI Agent workflow: Agent resource → LLM resource → AI Agent Job Node
199
+ - ✅ Plans multi-step workflows automatically
200
+ - ✅ Suggests best practices for AI Agent job descriptions
201
+ - ✅ Guides users to iterate and improve agent behavior
202
+
203
+ **No additional configuration needed** - it works automatically! See `docs/SYSTEM_PROMPT.md` for details.
204
+
205
+ ## Architecture
206
+
207
+ The MCP server follows a modular architecture:
208
+
209
+ - `src/index.ts` - Main server initialization and MCP protocol handling
210
+ - `src/tools/` - Tool handlers for each workflow category
211
+ - `src/api/` - API client and request handlers
212
+ - `src/schemas/` - Zod schemas for input validation
213
+ - `src/utils/` - Utilities (logging, rate limiting, etc.)
214
+ - `src/resources/` - MCP resources (documentation, examples)
215
+
216
+ ## Security
217
+
218
+ - API keys are never logged or exposed
219
+ - All inputs are validated using Zod schemas
220
+ - Rate limiting prevents API abuse
221
+ - Supports OAuth2 for enterprise deployments
222
+
223
+ ## Project Statistics
224
+
225
+ - **9 Tools**: Instead of 359 endpoint-specific tools (97.5% reduction)
226
+ - **34 Operations**: Covering all major Cognigy workflows + agent testing
227
+ - **~115 API Endpoints**: Accessible through workflow grouping
228
+ - **Full Type Safety**: TypeScript with Zod validation
229
+ - **Production Ready**: Rate limiting, logging, error handling, tests
230
+ - **🔄 100% Automated**: Create AI Agent → Flow → Job Node → Endpoint in one call
231
+ - **✅ Tested & Working**: Complete self-improvement loop validated end-to-end
232
+
233
+ ## What's Working (Verified!)
234
+
235
+ ✅ **Automatic AI Agent Setup** - Creates agent, flow, job node, and endpoint in one tool call
236
+ ✅ **Talk to Agent** - Sends messages and receives responses via REST endpoint
237
+ ✅ **Agent Updates** - Modify agent configuration and see changes immediately
238
+ ✅ **Complete Improvement Loop** - Create → Test → Improve → Test → Iterate
239
+ ✅ **All Infrastructure Tools** - Projects, flows, endpoints, knowledge, analytics
240
+ ✅ **System Prompt** - AI assistants have full Cognigy domain expertise
241
+
242
+ ## Important ID Format Note
243
+
244
+ Cognigy uses two ID formats:
245
+ - **MongoDB _id** (24-char hex): `691b1c2e36bda2b14170fd73` - Used for most operations
246
+ - **UUID referenceId** (36-char): `8184e6a8-e10c-4b03-8a83-538c004c321a` - Used for flowId in endpoints
247
+
248
+ When creating resources, both IDs are returned. The tools handle this automatically.
249
+
250
+ ## Key Design Decision: Why Only 9 Tools?
251
+
252
+ The Cognigy API has ~359 endpoints across 50+ categories. Creating one tool per endpoint would overwhelm AI agents and make the system unusable. Our solution:
253
+
254
+ **Workflow-Based Grouping**: Group related endpoints into high-level workflows that represent what users actually want to accomplish:
255
+
256
+ - ✅ Natural for AI agents to understand
257
+ - ✅ Matches human mental models
258
+ - ✅ Easy to discover and use
259
+ - ✅ Maintainable and extensible
260
+
261
+ Example: Instead of separate tools for `createAgent`, `getAgent`, `updateAgent`, `deleteAgent`, `listAgents`, `hireAgent`, we have one `manage_ai_agents` tool with an `operation` parameter.
262
+
263
+ ## Modern AI Agent-Centric Approach
264
+
265
+ The MCP server focuses on **LLM-based AI Agents** (the modern approach) rather than traditional NLU/intents (legacy).
266
+
267
+ **What Happens When You Create an AI Agent:**
268
+ 1. ✅ AI Agent resource created
269
+ 2. ✅ Flow created automatically
270
+ 3. ✅ AI Agent Job Node added to flow (connected to agent)
271
+ 4. ✅ REST Endpoint created (ready to use!)
272
+ 5. ✅ Endpoint URL returned
273
+
274
+ **Then:** Use `talk_to_agent` tool to test responses and iterate!
275
+
276
+ **Note:** You'll need an LLM resource (GPT-4, Claude, etc.) configured in the project via Cognigy UI for the agent to work.
277
+
278
+ ## Documentation Navigation
279
+
280
+ - **Quick Start**: See [QUICK_START.md](QUICK_START.md) for setup & usage examples
281
+ - **Technical Details**: See [PROJECT_SUMMARY.md](PROJECT_SUMMARY.md) for architecture
282
+ - **For Developers**: See [HANDOFF.md](HANDOFF.md) for implementation details
283
+ - **All Docs**: See [INDEX.md](INDEX.md) for complete documentation index
284
+
285
+ ## Contributing
286
+
287
+ Contributions are welcome! Read [.cursorrules](.cursorrules) for development guidelines and [HANDOFF.md](HANDOFF.md) for technical details.
288
+
289
+ ## Support
290
+
291
+ - **Documentation**: See `docs/` directory
292
+ - **Issues**: GitHub issues
293
+ - **Cognigy API Support**: support@cognigy.com
294
+
295
+ ## License
296
+
297
+ MIT
298
+
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Cognigy API client for making HTTP requests
3
+ */
4
+ import { AxiosRequestConfig } from 'axios';
5
+ export interface CognigyApiClientConfig {
6
+ baseUrl: string;
7
+ apiKey: string;
8
+ }
9
+ export declare class CognigyApiClient {
10
+ private client;
11
+ private apiKey;
12
+ constructor(config: CognigyApiClientConfig);
13
+ /**
14
+ * Format error responses according to RFC 7807
15
+ */
16
+ private formatError;
17
+ /**
18
+ * Make a GET request
19
+ */
20
+ get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
21
+ /**
22
+ * Make a POST request
23
+ */
24
+ post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
25
+ /**
26
+ * Make a PUT request
27
+ */
28
+ put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
29
+ /**
30
+ * Make a PATCH request
31
+ */
32
+ patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
33
+ /**
34
+ * Make a DELETE request
35
+ */
36
+ delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
37
+ }
38
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAc,EAAiB,kBAAkB,EAAiB,MAAM,OAAO,CAAC;AAGhF,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,sBAAsB;IA+C1C;;OAEG;IACH,OAAO,CAAC,WAAW;IAcnB;;OAEG;IACG,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKxE;;OAEG;IACG,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKrF;;OAEG;IACG,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKpF;;OAEG;IACG,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKtF;;OAEG;IACG,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;CAI5E"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Cognigy API client for making HTTP requests
3
+ */
4
+ import axios from 'axios';
5
+ import { logger } from '../utils/logger.js';
6
+ export class CognigyApiClient {
7
+ client;
8
+ apiKey;
9
+ constructor(config) {
10
+ this.apiKey = config.apiKey;
11
+ this.client = axios.create({
12
+ baseURL: config.baseUrl,
13
+ headers: {
14
+ 'Content-Type': 'application/json',
15
+ 'Accept': 'application/json',
16
+ },
17
+ timeout: 30000,
18
+ });
19
+ // Add request interceptor for authentication
20
+ this.client.interceptors.request.use((config) => {
21
+ config.headers['X-API-Key'] = this.apiKey;
22
+ logger.debug(`API Request: ${config.method?.toUpperCase()} ${config.url}`);
23
+ return config;
24
+ }, (error) => {
25
+ logger.error('API Request Error', { error: error.message });
26
+ return Promise.reject(error);
27
+ });
28
+ // Add response interceptor for logging
29
+ this.client.interceptors.response.use((response) => {
30
+ logger.debug(`API Response: ${response.status} ${response.config.url}`);
31
+ return response;
32
+ }, (error) => {
33
+ const status = error.response?.status || 'N/A';
34
+ const message = error.response?.data?.detail || error.message;
35
+ const traceId = error.response?.data?.traceId;
36
+ logger.error('API Response Error', {
37
+ status,
38
+ message,
39
+ traceId,
40
+ url: error.config?.url,
41
+ });
42
+ return Promise.reject(this.formatError(error));
43
+ });
44
+ }
45
+ /**
46
+ * Format error responses according to RFC 7807
47
+ */
48
+ formatError(error) {
49
+ if (error.response?.data) {
50
+ const data = error.response.data;
51
+ const message = data.detail || data.title || 'API request failed';
52
+ const enhancedError = new Error(message);
53
+ enhancedError.status = data.status || error.response.status;
54
+ enhancedError.code = data.code;
55
+ enhancedError.traceId = data.traceId;
56
+ enhancedError.details = data.details;
57
+ return enhancedError;
58
+ }
59
+ return error;
60
+ }
61
+ /**
62
+ * Make a GET request
63
+ */
64
+ async get(url, config) {
65
+ const response = await this.client.get(url, config);
66
+ return response.data;
67
+ }
68
+ /**
69
+ * Make a POST request
70
+ */
71
+ async post(url, data, config) {
72
+ const response = await this.client.post(url, data, config);
73
+ return response.data;
74
+ }
75
+ /**
76
+ * Make a PUT request
77
+ */
78
+ async put(url, data, config) {
79
+ const response = await this.client.put(url, data, config);
80
+ return response.data;
81
+ }
82
+ /**
83
+ * Make a PATCH request
84
+ */
85
+ async patch(url, data, config) {
86
+ const response = await this.client.patch(url, data, config);
87
+ return response.data;
88
+ }
89
+ /**
90
+ * Make a DELETE request
91
+ */
92
+ async delete(url, config) {
93
+ const response = await this.client.delete(url, config);
94
+ return response.data;
95
+ }
96
+ }
97
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAA2D,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAO5C,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAgB;IACtB,MAAM,CAAS;IAEvB,YAAY,MAA8B;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YACzB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,QAAQ,EAAE,kBAAkB;aAC7B;YACD,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;QAEH,6CAA6C;QAC7C,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAClC,CAAC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AAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAC5E,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK,CAAU,GAAW,EAAE,IAAU,EAAE,MAA2B;QACvE,MAAM,QAAQ,GAAqB,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAC9E,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAU,GAAW,EAAE,MAA2B;QAC5D,MAAM,QAAQ,GAAqB,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACzE,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Configuration for the Cognigy MCP Server
3
+ */
4
+ export interface Config {
5
+ apiBaseUrl: string;
6
+ apiKey: string;
7
+ serverName: string;
8
+ serverVersion: string;
9
+ logLevel: 'debug' | 'info' | 'warn' | 'error';
10
+ rateLimit: {
11
+ maxRequests: number;
12
+ windowMs: number;
13
+ };
14
+ }
15
+ /**
16
+ * Load configuration from environment variables
17
+ */
18
+ export declare function loadConfig(): Config;
19
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAC9C,SAAS,EAAE;QACT,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAuBnC"}
package/dist/config.js ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Load configuration from environment variables
3
+ */
4
+ export function loadConfig() {
5
+ const apiBaseUrl = process.env.COGNIGY_API_BASE_URL;
6
+ const apiKey = process.env.COGNIGY_API_KEY;
7
+ if (!apiBaseUrl) {
8
+ throw new Error('COGNIGY_API_BASE_URL environment variable is required');
9
+ }
10
+ if (!apiKey) {
11
+ throw new Error('COGNIGY_API_KEY environment variable is required');
12
+ }
13
+ return {
14
+ apiBaseUrl,
15
+ apiKey,
16
+ serverName: process.env.MCP_SERVER_NAME || 'cognigy-api-mcp',
17
+ serverVersion: process.env.MCP_SERVER_VERSION || '1.0.0',
18
+ logLevel: process.env.LOG_LEVEL || 'info',
19
+ rateLimit: {
20
+ maxRequests: parseInt(process.env.RATE_LIMIT_MAX_REQUESTS || '100', 10),
21
+ windowMs: parseInt(process.env.RATE_LIMIT_WINDOW_MS || '60000', 10),
22
+ },
23
+ };
24
+ }
25
+ //# sourceMappingURL=config.js.map