salesflare-mcp-server 1.0.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.
Files changed (73) hide show
  1. package/API.md +691 -0
  2. package/CHANGELOG.md +49 -0
  3. package/CLAUDE.md +117 -0
  4. package/CONTRIBUTING.md +399 -0
  5. package/FIX_PLAN.md +70 -0
  6. package/INSPECTOR.md +191 -0
  7. package/LICENSE +21 -0
  8. package/PUBLISH.md +73 -0
  9. package/README.md +383 -0
  10. package/dist/auth/api-key-auth.d.ts +75 -0
  11. package/dist/auth/api-key-auth.d.ts.map +1 -0
  12. package/dist/auth/api-key-auth.js +103 -0
  13. package/dist/auth/oauth-auth.d.ts +81 -0
  14. package/dist/auth/oauth-auth.d.ts.map +1 -0
  15. package/dist/auth/oauth-auth.js +123 -0
  16. package/dist/auth/token-manager.d.ts +105 -0
  17. package/dist/auth/token-manager.d.ts.map +1 -0
  18. package/dist/auth/token-manager.js +87 -0
  19. package/dist/client/salesflare-client.d.ts +219 -0
  20. package/dist/client/salesflare-client.d.ts.map +1 -0
  21. package/dist/client/salesflare-client.js +484 -0
  22. package/dist/index.d.ts +15 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +82 -0
  25. package/dist/server.d.ts +39 -0
  26. package/dist/server.d.ts.map +1 -0
  27. package/dist/server.js +140 -0
  28. package/dist/tools/companies.d.ts +45 -0
  29. package/dist/tools/companies.d.ts.map +1 -0
  30. package/dist/tools/companies.js +392 -0
  31. package/dist/tools/contacts.d.ts +45 -0
  32. package/dist/tools/contacts.d.ts.map +1 -0
  33. package/dist/tools/contacts.js +290 -0
  34. package/dist/tools/deals.d.ts +46 -0
  35. package/dist/tools/deals.d.ts.map +1 -0
  36. package/dist/tools/deals.js +442 -0
  37. package/dist/tools/pipeline.d.ts +43 -0
  38. package/dist/tools/pipeline.d.ts.map +1 -0
  39. package/dist/tools/pipeline.js +328 -0
  40. package/dist/tools/tasks.d.ts +44 -0
  41. package/dist/tools/tasks.d.ts.map +1 -0
  42. package/dist/tools/tasks.js +406 -0
  43. package/dist/transport/http-transport.d.ts +36 -0
  44. package/dist/transport/http-transport.d.ts.map +1 -0
  45. package/dist/transport/http-transport.js +173 -0
  46. package/dist/transport/stdio-transport.d.ts +37 -0
  47. package/dist/transport/stdio-transport.d.ts.map +1 -0
  48. package/dist/transport/stdio-transport.js +129 -0
  49. package/dist/types/company.d.ts +223 -0
  50. package/dist/types/company.d.ts.map +1 -0
  51. package/dist/types/company.js +8 -0
  52. package/dist/types/contact.d.ts +166 -0
  53. package/dist/types/contact.d.ts.map +1 -0
  54. package/dist/types/contact.js +8 -0
  55. package/dist/types/deal.d.ts +203 -0
  56. package/dist/types/deal.d.ts.map +1 -0
  57. package/dist/types/deal.js +8 -0
  58. package/dist/types/pipeline.d.ts +116 -0
  59. package/dist/types/pipeline.d.ts.map +1 -0
  60. package/dist/types/pipeline.js +8 -0
  61. package/dist/types/task.d.ts +154 -0
  62. package/dist/types/task.d.ts.map +1 -0
  63. package/dist/types/task.js +8 -0
  64. package/dist/utils/errors.d.ts +128 -0
  65. package/dist/utils/errors.d.ts.map +1 -0
  66. package/dist/utils/errors.js +205 -0
  67. package/dist/utils/validation.d.ts +354 -0
  68. package/dist/utils/validation.d.ts.map +1 -0
  69. package/dist/utils/validation.js +716 -0
  70. package/package.json +49 -0
  71. package/test-tasks-debug.js +21 -0
  72. package/test-tasks-params.js +52 -0
  73. package/test-tools.js +171 -0
package/API.md ADDED
@@ -0,0 +1,691 @@
1
+ # Salesflare MCP Server - API Reference
2
+
3
+ Complete API reference for all MCP tools exposed by the Salesflare MCP Server.
4
+
5
+ ## Overview
6
+
7
+ This MCP server provides 15 tools across 5 entity types, enabling LLMs to interact with Salesflare CRM data through natural language.
8
+
9
+ ## Authentication
10
+
11
+ All tools require authentication via API key:
12
+
13
+ ```bash
14
+ export SALESFLARE_API_KEY="your_api_key_here"
15
+ ```
16
+
17
+ The API key is validated at server startup. All requests include the Authorization header:
18
+ ```
19
+ Authorization: Bearer {SALESFLARE_API_KEY}
20
+ ```
21
+
22
+ ## Rate Limiting
23
+
24
+ The Salesflare API has rate limits. The MCP server implements:
25
+ - Automatic retry with exponential backoff for 429 responses
26
+ - Maximum 3 retries before failing
27
+ - Retryable error flag for LLM context
28
+
29
+ ## Common Response Format
30
+
31
+ All tools return responses in MCP format:
32
+
33
+ ```json
34
+ {
35
+ "content": [
36
+ {
37
+ "type": "text",
38
+ "text": "Human-readable summary"
39
+ },
40
+ {
41
+ "type": "text",
42
+ "text": "{\"json\": \"data\"}"
43
+ }
44
+ ],
45
+ "isError": false
46
+ }
47
+ ```
48
+
49
+ ## Contacts
50
+
51
+ ### salesflare_contacts_list
52
+
53
+ List contacts from Salesflare CRM with optional filtering and pagination.
54
+
55
+ **Input Schema:**
56
+ ```json
57
+ {
58
+ "type": "object",
59
+ "properties": {
60
+ "filter": {
61
+ "type": "object",
62
+ "properties": {
63
+ "email": { "type": "string", "description": "Filter by exact email match" },
64
+ "name": { "type": "string", "description": "Filter by name (partial match)" },
65
+ "company_id": { "type": "string", "description": "Filter by associated company" },
66
+ "tags": { "type": "array", "items": { "type": "string" } },
67
+ "owner": { "type": "string", "description": "Filter by owner user ID" },
68
+ "domain": { "type": "string", "description": "Filter by email domain" },
69
+ "search": { "type": "string", "description": "Free-text search" }
70
+ }
71
+ },
72
+ "pagination": {
73
+ "type": "object",
74
+ "properties": {
75
+ "limit": { "type": "number", "minimum": 1, "maximum": 500, "default": 50 },
76
+ "cursor": { "type": "string", "description": "Pagination cursor" }
77
+ }
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
83
+ **Output:** Array of Contact objects
84
+
85
+ **Example:**
86
+ ```json
87
+ {
88
+ "filter": { "email": "john@example.com" },
89
+ "pagination": { "limit": 10 }
90
+ }
91
+ ```
92
+
93
+ ### salesflare_contacts_create
94
+
95
+ Create a new contact in Salesflare.
96
+
97
+ **Input Schema:**
98
+ ```json
99
+ {
100
+ "type": "object",
101
+ "properties": {
102
+ "email": { "type": "string", "format": "email" },
103
+ "name": { "type": "string" },
104
+ "phone": { "type": "string" },
105
+ "company_id": { "type": "string" },
106
+ "tags": { "type": "array", "items": { "type": "string" } },
107
+ "owner": { "type": "string" }
108
+ },
109
+ "required": ["email"]
110
+ }
111
+ ```
112
+
113
+ **Output:** Created Contact object with generated ID
114
+
115
+ ### salesflare_contacts_update
116
+
117
+ Update an existing contact.
118
+
119
+ **Input Schema:**
120
+ ```json
121
+ {
122
+ "type": "object",
123
+ "properties": {
124
+ "id": { "type": "string", "format": "uuid" },
125
+ "email": { "type": "string", "format": "email" },
126
+ "name": { "type": "string" },
127
+ "phone": { "type": "string" },
128
+ "company_id": { "type": "string" },
129
+ "tags": { "type": "array", "items": { "type": "string" } },
130
+ "owner": { "type": "string" }
131
+ },
132
+ "required": ["id"]
133
+ }
134
+ ```
135
+
136
+ **Output:** Updated Contact object
137
+
138
+ ### salesflare_contacts_delete
139
+
140
+ Delete a contact by ID.
141
+
142
+ **Input Schema:**
143
+ ```json
144
+ {
145
+ "type": "object",
146
+ "properties": {
147
+ "id": { "type": "string", "format": "uuid" }
148
+ },
149
+ "required": ["id"]
150
+ }
151
+ ```
152
+
153
+ **Output:** Success confirmation
154
+
155
+ ## Companies
156
+
157
+ ### salesflare_companies_list
158
+
159
+ List companies with filtering and pagination.
160
+
161
+ **Input Schema:**
162
+ ```json
163
+ {
164
+ "type": "object",
165
+ "properties": {
166
+ "filter": {
167
+ "type": "object",
168
+ "properties": {
169
+ "name": { "type": "string", "description": "Filter by name (partial match)" },
170
+ "industry": { "type": "string", "description": "Filter by industry (exact match)" },
171
+ "tags": { "type": "array", "items": { "type": "string" } },
172
+ "owner": { "type": "string" },
173
+ "search": { "type": "string", "description": "Free-text search" }
174
+ }
175
+ },
176
+ "pagination": {
177
+ "type": "object",
178
+ "properties": {
179
+ "limit": { "type": "number", "minimum": 1, "maximum": 500, "default": 50 },
180
+ "cursor": { "type": "string" }
181
+ }
182
+ }
183
+ }
184
+ }
185
+ ```
186
+
187
+ **Output:** Array of Company objects with contacts_count
188
+
189
+ ### salesflare_companies_create
190
+
191
+ Create a new company.
192
+
193
+ **Input Schema:**
194
+ ```json
195
+ {
196
+ "type": "object",
197
+ "properties": {
198
+ "name": { "type": "string" },
199
+ "website": { "type": "string" },
200
+ "industry": { "type": "string" },
201
+ "address": {
202
+ "type": "object",
203
+ "properties": {
204
+ "street": { "type": "string" },
205
+ "city": { "type": "string" },
206
+ "state": { "type": "string" },
207
+ "postal_code": { "type": "string" },
208
+ "country": { "type": "string" }
209
+ }
210
+ },
211
+ "owner": { "type": "string" }
212
+ },
213
+ "required": ["name"]
214
+ }
215
+ ```
216
+
217
+ **Output:** Created Company object
218
+
219
+ ### salesflare_companies_update
220
+
221
+ Update an existing company.
222
+
223
+ **Input Schema:**
224
+ ```json
225
+ {
226
+ "type": "object",
227
+ "properties": {
228
+ "id": { "type": "string", "format": "uuid" },
229
+ "name": { "type": "string" },
230
+ "website": { "type": "string" },
231
+ "industry": { "type": "string" },
232
+ "address": { "type": "object" },
233
+ "owner": { "type": "string" }
234
+ },
235
+ "required": ["id"]
236
+ }
237
+ ```
238
+
239
+ **Output:** Updated Company object
240
+
241
+ ### salesflare_companies_delete
242
+
243
+ Delete a company by ID. **Note:** Unlinks associated contacts before deletion.
244
+
245
+ **Input Schema:**
246
+ ```json
247
+ {
248
+ "type": "object",
249
+ "properties": {
250
+ "id": { "type": "string", "format": "uuid" }
251
+ },
252
+ "required": ["id"]
253
+ }
254
+ ```
255
+
256
+ **Output:** Success confirmation with unlinked contacts count
257
+
258
+ ## Deals
259
+
260
+ ### salesflare_deals_list
261
+
262
+ List deals with filtering and pagination.
263
+
264
+ **Input Schema:**
265
+ ```json
266
+ {
267
+ "type": "object",
268
+ "properties": {
269
+ "filter": {
270
+ "type": "object",
271
+ "properties": {
272
+ "status": { "type": "string", "enum": ["open", "won", "lost"] },
273
+ "pipeline_id": { "type": "string" },
274
+ "stage_id": { "type": "string" },
275
+ "assigned_user_id": { "type": "string" },
276
+ "min_value": { "type": "number", "description": "Minimum value in cents" },
277
+ "max_value": { "type": "number", "description": "Maximum value in cents" },
278
+ "search": { "type": "string" }
279
+ }
280
+ },
281
+ "pagination": {
282
+ "type": "object",
283
+ "properties": {
284
+ "limit": { "type": "number", "default": 50 },
285
+ "cursor": { "type": "string" }
286
+ }
287
+ }
288
+ }
289
+ }
290
+ ```
291
+
292
+ **Output:** Array of Deal objects with formatted value
293
+
294
+ ### salesflare_deals_create
295
+
296
+ Create a new deal.
297
+
298
+ **Input Schema:**
299
+ ```json
300
+ {
301
+ "type": "object",
302
+ "properties": {
303
+ "name": { "type": "string" },
304
+ "value": { "type": "number", "description": "Value in dollars (converted to cents)" },
305
+ "currency": { "type": "string", "default": "USD" },
306
+ "pipeline_id": { "type": "string" },
307
+ "stage_id": { "type": "string" },
308
+ "close_date": { "type": "string", "format": "date" },
309
+ "assigned_user_id": { "type": "string" }
310
+ },
311
+ "required": ["name", "value"]
312
+ }
313
+ ```
314
+
315
+ **Output:** Created Deal object (value in cents)
316
+
317
+ ### salesflare_deals_update
318
+
319
+ Update an existing deal.
320
+
321
+ **Input Schema:**
322
+ ```json
323
+ {
324
+ "type": "object",
325
+ "properties": {
326
+ "id": { "type": "string", "format": "uuid" },
327
+ "name": { "type": "string" },
328
+ "value": { "type": "number", "description": "Value in dollars" },
329
+ "status": { "type": "string", "enum": ["open", "won", "lost"] },
330
+ "close_date": { "type": "string", "format": "date" },
331
+ "assigned_user_id": { "type": "string" }
332
+ },
333
+ "required": ["id"]
334
+ }
335
+ ```
336
+
337
+ **Output:** Updated Deal object
338
+
339
+ ### salesflare_deals_delete
340
+
341
+ Delete a deal by ID.
342
+
343
+ **Input Schema:**
344
+ ```json
345
+ {
346
+ "type": "object",
347
+ "properties": {
348
+ "id": { "type": "string", "format": "uuid" }
349
+ },
350
+ "required": ["id"]
351
+ }
352
+ ```
353
+
354
+ **Output:** Success confirmation
355
+
356
+ ### salesflare_deals_move_stage
357
+
358
+ Move a deal to a different pipeline stage.
359
+
360
+ **Input Schema:**
361
+ ```json
362
+ {
363
+ "type": "object",
364
+ "properties": {
365
+ "id": { "type": "string", "format": "uuid" },
366
+ "stage_id": { "type": "string", "format": "uuid" }
367
+ },
368
+ "required": ["id", "stage_id"]
369
+ }
370
+ ```
371
+
372
+ **Output:** Updated Deal with new stage_id
373
+
374
+ ## Tasks
375
+
376
+ ### salesflare_tasks_list
377
+
378
+ List tasks with filtering.
379
+
380
+ **Input Schema:**
381
+ ```json
382
+ {
383
+ "type": "object",
384
+ "properties": {
385
+ "filter": {
386
+ "type": "object",
387
+ "properties": {
388
+ "status": { "type": "string", "enum": ["open", "completed"] },
389
+ "assigned_user_id": { "type": "string" },
390
+ "due_date": { "type": "string", "format": "date" },
391
+ "overdue": { "type": "boolean" },
392
+ "related_contact_id": { "type": "string" },
393
+ "related_deal_id": { "type": "string" }
394
+ }
395
+ },
396
+ "pagination": {
397
+ "type": "object",
398
+ "properties": {
399
+ "limit": { "type": "number", "default": 50 },
400
+ "cursor": { "type": "string" }
401
+ }
402
+ }
403
+ }
404
+ }
405
+ ```
406
+
407
+ **Output:** Array of Task objects with is_overdue flag
408
+
409
+ ### salesflare_tasks_create
410
+
411
+ Create a new task.
412
+
413
+ **Input Schema:**
414
+ ```json
415
+ {
416
+ "type": "object",
417
+ "properties": {
418
+ "description": { "type": "string" },
419
+ "due_date": { "type": "string", "format": "date" },
420
+ "assigned_user_id": { "type": "string" },
421
+ "related_contact_id": { "type": "string" },
422
+ "related_deal_id": { "type": "string" },
423
+ "status": { "type": "string", "enum": ["open", "completed"], "default": "open" }
424
+ },
425
+ "required": ["description"]
426
+ }
427
+ ```
428
+
429
+ **Output:** Created Task object
430
+
431
+ ### salesflare_tasks_update
432
+
433
+ Update an existing task. **Note:** Setting status to "completed" automatically sets completed_at.
434
+
435
+ **Input Schema:**
436
+ ```json
437
+ {
438
+ "type": "object",
439
+ "properties": {
440
+ "id": { "type": "string", "format": "uuid" },
441
+ "description": { "type": "string" },
442
+ "due_date": { "type": "string", "format": "date" },
443
+ "assigned_user_id": { "type": "string" },
444
+ "status": { "type": "string", "enum": ["open", "completed"] }
445
+ },
446
+ "required": ["id"]
447
+ }
448
+ ```
449
+
450
+ **Output:** Updated Task object with completed_at if status changed to completed
451
+
452
+ ## Pipeline
453
+
454
+ ### salesflare_pipeline_list_stages
455
+
456
+ List all pipeline stages across all pipelines.
457
+
458
+ **Input Schema:**
459
+ ```json
460
+ {
461
+ "type": "object",
462
+ "properties": {}
463
+ }
464
+ ```
465
+
466
+ **Output:** Array of PipelineStage objects
467
+
468
+ ```json
469
+ {
470
+ "items": [
471
+ {
472
+ "id": "stage-uuid",
473
+ "name": "Prospecting",
474
+ "position": 1,
475
+ "pipeline_id": "pipeline-uuid",
476
+ "created_at": "2024-01-01T00:00:00Z"
477
+ }
478
+ ],
479
+ "total": 5
480
+ }
481
+ ```
482
+
483
+ ### salesflare_pipeline_get_overview
484
+
485
+ Get pipeline statistics and overview.
486
+
487
+ **Input Schema:**
488
+ ```json
489
+ {
490
+ "type": "object",
491
+ "properties": {
492
+ "pipeline_id": { "type": "string", "description": "Optional: specific pipeline ID" }
493
+ }
494
+ }
495
+ ```
496
+
497
+ **Output:** Pipeline statistics
498
+
499
+ ```json
500
+ {
501
+ "pipeline": {
502
+ "id": "pipeline-uuid",
503
+ "name": "Sales Pipeline",
504
+ "currency": "USD"
505
+ },
506
+ "stages": [
507
+ {
508
+ "id": "stage-uuid",
509
+ "name": "Prospecting",
510
+ "position": 1,
511
+ "deals_count": 5,
512
+ "total_value": 500000
513
+ }
514
+ ],
515
+ "total_deals": 15,
516
+ "total_value": 2500000,
517
+ "currency": "USD"
518
+ }
519
+ ```
520
+
521
+ ## Common Types
522
+
523
+ ### Contact
524
+ ```typescript
525
+ {
526
+ id: string;
527
+ email: string;
528
+ name?: string;
529
+ phone?: string;
530
+ company_id?: string;
531
+ tags?: string[];
532
+ owner?: string;
533
+ created_at: string;
534
+ updated_at?: string;
535
+ }
536
+ ```
537
+
538
+ ### Company
539
+ ```typescript
540
+ {
541
+ id: string;
542
+ name: string;
543
+ website?: string;
544
+ industry?: string;
545
+ address?: Address;
546
+ contacts_count: number;
547
+ owner?: string;
548
+ created_at: string;
549
+ }
550
+ ```
551
+
552
+ ### Deal
553
+ ```typescript
554
+ {
555
+ id: string;
556
+ name: string;
557
+ value: number; // In cents
558
+ currency: string;
559
+ pipeline_id: string;
560
+ stage_id: string;
561
+ status: "open" | "won" | "lost";
562
+ close_date?: string;
563
+ assigned_user_id?: string;
564
+ created_at: string;
565
+ }
566
+ ```
567
+
568
+ ### Task
569
+ ```typescript
570
+ {
571
+ id: string;
572
+ description: string;
573
+ status: "open" | "completed";
574
+ due_date?: string;
575
+ completed_at?: string;
576
+ assigned_user_id?: string;
577
+ related_contact_id?: string;
578
+ related_deal_id?: string;
579
+ is_overdue: boolean;
580
+ created_at: string;
581
+ }
582
+ ```
583
+
584
+ ### PipelineStage
585
+ ```typescript
586
+ {
587
+ id: string;
588
+ name: string;
589
+ position: number;
590
+ pipeline_id: string;
591
+ created_at: string;
592
+ }
593
+ ```
594
+
595
+ ## Error Handling
596
+
597
+ All errors follow the SalesflareError format:
598
+
599
+ ### Error Codes
600
+
601
+ | Code | HTTP Status | Description | Retryable |
602
+ |------|-------------|-------------|-----------|
603
+ | `AUTH_INVALID` | 401 | Invalid or missing API key | ❌ |
604
+ | `AUTH_EXPIRED` | 401 | Authentication expired | ❌ |
605
+ | `NOT_FOUND` | 404 | Resource not found | ❌ |
606
+ | `VALIDATION_ERROR` | 400 | Input validation failed | ❌ |
607
+ | `RATE_LIMIT` | 429 | Rate limit exceeded | ✅ |
608
+ | `NETWORK_ERROR` | - | Network connectivity issue | ✅ |
609
+ | `SERVER_ERROR` | 500+ | Salesflare API error | ✅ |
610
+ | `UNKNOWN_ERROR` | - | Unexpected error | ❌ |
611
+
612
+ ### Error Response Format
613
+
614
+ ```json
615
+ {
616
+ "content": [
617
+ {
618
+ "type": "text",
619
+ "text": "Error [VALIDATION_ERROR]: Invalid email format"
620
+ },
621
+ {
622
+ "type": "text",
623
+ "text": "{\"code\":\"VALIDATION_ERROR\",\"message\":\"Invalid email format\",\"retryable\":false}"
624
+ }
625
+ ],
626
+ "isError": true
627
+ }
628
+ ```
629
+
630
+ ## Pagination
631
+
632
+ All list tools support cursor-based pagination:
633
+
634
+ **Request:**
635
+ ```json
636
+ {
637
+ "pagination": {
638
+ "limit": 50,
639
+ "cursor": "next_page_token"
640
+ }
641
+ }
642
+ ```
643
+
644
+ **Response includes:**
645
+ ```json
646
+ {
647
+ "items": [...],
648
+ "total": 150,
649
+ "has_more": true,
650
+ "next_cursor": "next_page_token"
651
+ }
652
+ ```
653
+
654
+ - **Default limit:** 50 items
655
+ - **Maximum limit:** 500 items
656
+ - **Cursor:** Opaque token from previous response
657
+
658
+ ## Value Formatting
659
+
660
+ ### Currency
661
+
662
+ Deals use currency codes (ISO 4217): USD, EUR, GBP, etc.
663
+
664
+ ### Deal Values
665
+
666
+ - **Input:** Dollars (e.g., 50000 for $50,000)
667
+ - **API:** Cents (e.g., 5000000)
668
+ - **Automatic conversion** between input and API
669
+
670
+ **Example:**
671
+ ```json
672
+ // Input
673
+ { "value": 50000, "currency": "USD" }
674
+
675
+ // Stored as
676
+ { "value": 5000000, "currency": "USD", "formatted": "$50,000.00" }
677
+ ```
678
+
679
+ ## Testing
680
+
681
+ Use the MCP Inspector to test all tools:
682
+
683
+ ```bash
684
+ npm run inspector
685
+ ```
686
+
687
+ See [INSPECTOR.md](INSPECTOR.md) for detailed testing scenarios.
688
+
689
+ ## Changelog
690
+
691
+ See [CHANGELOG.md](CHANGELOG.md) for version history.