@hailer/mcp 0.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 (163) hide show
  1. package/.claude/commands/tool-builder.md +37 -0
  2. package/.claude/commands/ws-pull.md +44 -0
  3. package/.claude/settings.json +8 -0
  4. package/.claude/settings.local.json +49 -0
  5. package/.claude/skills/activity-api/SKILL.md +96 -0
  6. package/.claude/skills/activity-api/references/activity-endpoints.md +845 -0
  7. package/.claude/skills/add-app-member-skill/SKILL.md +977 -0
  8. package/.claude/skills/agent-building/SKILL.md +243 -0
  9. package/.claude/skills/agent-building/references/architecture-patterns.md +446 -0
  10. package/.claude/skills/agent-building/references/code-examples.md +587 -0
  11. package/.claude/skills/agent-building/references/implementation-guide.md +619 -0
  12. package/.claude/skills/app-api/SKILL.md +219 -0
  13. package/.claude/skills/app-api/references/app-endpoints.md +759 -0
  14. package/.claude/skills/building-hailer-apps-skill/SKILL.md +548 -0
  15. package/.claude/skills/create-app-skill/SKILL.md +1101 -0
  16. package/.claude/skills/create-insight-skill/SKILL.md +1317 -0
  17. package/.claude/skills/get-insight-data-skill/SKILL.md +1053 -0
  18. package/.claude/skills/hailer-api/SKILL.md +283 -0
  19. package/.claude/skills/hailer-api/references/activities.md +620 -0
  20. package/.claude/skills/hailer-api/references/authentication.md +216 -0
  21. package/.claude/skills/hailer-api/references/datasets.md +437 -0
  22. package/.claude/skills/hailer-api/references/files.md +301 -0
  23. package/.claude/skills/hailer-api/references/insights.md +469 -0
  24. package/.claude/skills/hailer-api/references/workflows.md +720 -0
  25. package/.claude/skills/hailer-api/references/workspaces-users.md +445 -0
  26. package/.claude/skills/insight-api/SKILL.md +185 -0
  27. package/.claude/skills/insight-api/references/insight-endpoints.md +514 -0
  28. package/.claude/skills/install-workflow-skill/SKILL.md +1056 -0
  29. package/.claude/skills/list-apps-skill/SKILL.md +1010 -0
  30. package/.claude/skills/list-workflows-minimal-skill/SKILL.md +992 -0
  31. package/.claude/skills/local-first-skill/SKILL.md +570 -0
  32. package/.claude/skills/mcp-tools/SKILL.md +419 -0
  33. package/.claude/skills/mcp-tools/references/api-endpoints.md +499 -0
  34. package/.claude/skills/mcp-tools/references/data-structures.md +554 -0
  35. package/.claude/skills/mcp-tools/references/implementation-patterns.md +717 -0
  36. package/.claude/skills/preview-insight-skill/SKILL.md +1290 -0
  37. package/.claude/skills/publish-hailer-app-skill/SKILL.md +453 -0
  38. package/.claude/skills/remove-app-member-skill/SKILL.md +671 -0
  39. package/.claude/skills/remove-app-skill/SKILL.md +985 -0
  40. package/.claude/skills/remove-insight-skill/SKILL.md +1011 -0
  41. package/.claude/skills/remove-workflow-skill/SKILL.md +920 -0
  42. package/.claude/skills/scaffold-hailer-app-skill/SKILL.md +1034 -0
  43. package/.claude/skills/skill-testing/README.md +137 -0
  44. package/.claude/skills/skill-testing/SKILL.md +348 -0
  45. package/.claude/skills/skill-testing/references/test-patterns.md +705 -0
  46. package/.claude/skills/skill-testing/references/testing-guide.md +603 -0
  47. package/.claude/skills/skill-testing/references/validation-checklist.md +537 -0
  48. package/.claude/skills/tool-builder/SKILL.md +328 -0
  49. package/.claude/skills/update-app-skill/SKILL.md +970 -0
  50. package/.claude/skills/update-workflow-field-skill/SKILL.md +1098 -0
  51. package/.env.example +81 -0
  52. package/.mcp.json +13 -0
  53. package/README.md +297 -0
  54. package/dist/app.d.ts +4 -0
  55. package/dist/app.js +74 -0
  56. package/dist/cli.d.ts +3 -0
  57. package/dist/cli.js +5 -0
  58. package/dist/client/adaptive-documentation-bot.d.ts +108 -0
  59. package/dist/client/adaptive-documentation-bot.js +475 -0
  60. package/dist/client/adaptive-documentation-types.d.ts +66 -0
  61. package/dist/client/adaptive-documentation-types.js +9 -0
  62. package/dist/client/agent-activity-bot.d.ts +51 -0
  63. package/dist/client/agent-activity-bot.js +166 -0
  64. package/dist/client/agent-tracker.d.ts +499 -0
  65. package/dist/client/agent-tracker.js +659 -0
  66. package/dist/client/description-updater.d.ts +56 -0
  67. package/dist/client/description-updater.js +259 -0
  68. package/dist/client/log-parser.d.ts +72 -0
  69. package/dist/client/log-parser.js +387 -0
  70. package/dist/client/mcp-client.d.ts +50 -0
  71. package/dist/client/mcp-client.js +532 -0
  72. package/dist/client/message-processor.d.ts +35 -0
  73. package/dist/client/message-processor.js +352 -0
  74. package/dist/client/multi-bot-manager.d.ts +24 -0
  75. package/dist/client/multi-bot-manager.js +74 -0
  76. package/dist/client/providers/anthropic-provider.d.ts +19 -0
  77. package/dist/client/providers/anthropic-provider.js +631 -0
  78. package/dist/client/providers/llm-provider.d.ts +47 -0
  79. package/dist/client/providers/llm-provider.js +367 -0
  80. package/dist/client/providers/openai-provider.d.ts +23 -0
  81. package/dist/client/providers/openai-provider.js +621 -0
  82. package/dist/client/simple-llm-caller.d.ts +19 -0
  83. package/dist/client/simple-llm-caller.js +100 -0
  84. package/dist/client/skill-generator.d.ts +81 -0
  85. package/dist/client/skill-generator.js +386 -0
  86. package/dist/client/test-adaptive-bot.d.ts +9 -0
  87. package/dist/client/test-adaptive-bot.js +82 -0
  88. package/dist/client/token-pricing.d.ts +38 -0
  89. package/dist/client/token-pricing.js +127 -0
  90. package/dist/client/token-tracker.d.ts +232 -0
  91. package/dist/client/token-tracker.js +457 -0
  92. package/dist/client/token-usage-bot.d.ts +53 -0
  93. package/dist/client/token-usage-bot.js +153 -0
  94. package/dist/client/tool-executor.d.ts +69 -0
  95. package/dist/client/tool-executor.js +159 -0
  96. package/dist/client/tool-schema-loader.d.ts +60 -0
  97. package/dist/client/tool-schema-loader.js +178 -0
  98. package/dist/client/types.d.ts +69 -0
  99. package/dist/client/types.js +7 -0
  100. package/dist/config.d.ts +162 -0
  101. package/dist/config.js +296 -0
  102. package/dist/core.d.ts +26 -0
  103. package/dist/core.js +147 -0
  104. package/dist/lib/context-manager.d.ts +111 -0
  105. package/dist/lib/context-manager.js +431 -0
  106. package/dist/lib/logger.d.ts +74 -0
  107. package/dist/lib/logger.js +277 -0
  108. package/dist/lib/materialize.d.ts +3 -0
  109. package/dist/lib/materialize.js +101 -0
  110. package/dist/lib/normalizedName.d.ts +7 -0
  111. package/dist/lib/normalizedName.js +48 -0
  112. package/dist/lib/prompt-length-manager.d.ts +81 -0
  113. package/dist/lib/prompt-length-manager.js +457 -0
  114. package/dist/lib/terminal-prompt.d.ts +9 -0
  115. package/dist/lib/terminal-prompt.js +108 -0
  116. package/dist/mcp/UserContextCache.d.ts +56 -0
  117. package/dist/mcp/UserContextCache.js +163 -0
  118. package/dist/mcp/auth.d.ts +2 -0
  119. package/dist/mcp/auth.js +29 -0
  120. package/dist/mcp/hailer-clients.d.ts +42 -0
  121. package/dist/mcp/hailer-clients.js +246 -0
  122. package/dist/mcp/signal-handler.d.ts +45 -0
  123. package/dist/mcp/signal-handler.js +317 -0
  124. package/dist/mcp/tool-registry.d.ts +100 -0
  125. package/dist/mcp/tool-registry.js +306 -0
  126. package/dist/mcp/tools/activity.d.ts +15 -0
  127. package/dist/mcp/tools/activity.js +955 -0
  128. package/dist/mcp/tools/app.d.ts +20 -0
  129. package/dist/mcp/tools/app.js +1488 -0
  130. package/dist/mcp/tools/discussion.d.ts +19 -0
  131. package/dist/mcp/tools/discussion.js +950 -0
  132. package/dist/mcp/tools/file.d.ts +15 -0
  133. package/dist/mcp/tools/file.js +119 -0
  134. package/dist/mcp/tools/insight.d.ts +17 -0
  135. package/dist/mcp/tools/insight.js +806 -0
  136. package/dist/mcp/tools/skill.d.ts +10 -0
  137. package/dist/mcp/tools/skill.js +279 -0
  138. package/dist/mcp/tools/user.d.ts +10 -0
  139. package/dist/mcp/tools/user.js +108 -0
  140. package/dist/mcp/tools/workflow-template.d.ts +19 -0
  141. package/dist/mcp/tools/workflow-template.js +822 -0
  142. package/dist/mcp/tools/workflow.d.ts +18 -0
  143. package/dist/mcp/tools/workflow.js +1362 -0
  144. package/dist/mcp/utils/api-errors.d.ts +45 -0
  145. package/dist/mcp/utils/api-errors.js +160 -0
  146. package/dist/mcp/utils/data-transformers.d.ts +102 -0
  147. package/dist/mcp/utils/data-transformers.js +194 -0
  148. package/dist/mcp/utils/file-upload.d.ts +33 -0
  149. package/dist/mcp/utils/file-upload.js +148 -0
  150. package/dist/mcp/utils/hailer-api-client.d.ts +120 -0
  151. package/dist/mcp/utils/hailer-api-client.js +323 -0
  152. package/dist/mcp/utils/index.d.ts +13 -0
  153. package/dist/mcp/utils/index.js +39 -0
  154. package/dist/mcp/utils/logger.d.ts +42 -0
  155. package/dist/mcp/utils/logger.js +103 -0
  156. package/dist/mcp/utils/types.d.ts +286 -0
  157. package/dist/mcp/utils/types.js +7 -0
  158. package/dist/mcp/workspace-cache.d.ts +42 -0
  159. package/dist/mcp/workspace-cache.js +97 -0
  160. package/dist/mcp-server.d.ts +42 -0
  161. package/dist/mcp-server.js +280 -0
  162. package/package.json +56 -0
  163. package/tsconfig.json +23 -0
@@ -0,0 +1,445 @@
1
+ # Hailer Workspaces & Users API
2
+
3
+ ## Workspaces
4
+
5
+ Workspaces are top-level organizational units containing activities, datasets, files, and users.
6
+
7
+ ### Get Workspace
8
+
9
+ ```http
10
+ GET /v3/workspaces/{workspace_id}
11
+ ```
12
+
13
+ **Response:**
14
+ ```json
15
+ {
16
+ "id": "ws_123",
17
+ "name": "Rekna Production",
18
+ "description": "Main workspace for Rekna operations",
19
+ "created_at": "2024-01-01T00:00:00Z",
20
+ "settings": {
21
+ "timezone": "Europe/Helsinki",
22
+ "language": "fi",
23
+ "date_format": "DD.MM.YYYY"
24
+ },
25
+ "member_count": 25,
26
+ "activity_count": 1523
27
+ }
28
+ ```
29
+
30
+ ### List Workspaces
31
+
32
+ ```http
33
+ GET /v3/workspaces
34
+ ```
35
+
36
+ Returns all workspaces the authenticated user has access to.
37
+
38
+ ### Create Workspace
39
+
40
+ ```http
41
+ POST /v3/workspaces
42
+ Content-Type: application/json
43
+
44
+ {
45
+ "name": "New Project Workspace",
46
+ "description": "Workspace for new project",
47
+ "settings": {
48
+ "timezone": "Europe/Helsinki",
49
+ "language": "fi"
50
+ }
51
+ }
52
+ ```
53
+
54
+ ### Update Workspace
55
+
56
+ ```http
57
+ PATCH /v3/workspaces/{workspace_id}
58
+ Content-Type: application/json
59
+
60
+ {
61
+ "name": "Updated Workspace Name",
62
+ "description": "New description"
63
+ }
64
+ ```
65
+
66
+ ### Delete Workspace
67
+
68
+ ```http
69
+ DELETE /v3/workspaces/{workspace_id}
70
+ ```
71
+
72
+ ⚠️ **Warning:** Deletes all activities, datasets, files, and content within the workspace.
73
+
74
+ ## Workspace Settings
75
+
76
+ ### Update Settings
77
+
78
+ ```http
79
+ PATCH /v3/workspaces/{workspace_id}/settings
80
+ Content-Type: application/json
81
+
82
+ {
83
+ "timezone": "Europe/Helsinki",
84
+ "language": "fi",
85
+ "date_format": "DD.MM.YYYY",
86
+ "time_format": "24h",
87
+ "first_day_of_week": 1,
88
+ "working_hours": {
89
+ "start": "08:00",
90
+ "end": "17:00"
91
+ }
92
+ }
93
+ ```
94
+
95
+ ## Users
96
+
97
+ ### Get User Profile
98
+
99
+ ```http
100
+ GET /v3/users/me
101
+ ```
102
+
103
+ **Response:**
104
+ ```json
105
+ {
106
+ "id": "user_123",
107
+ "name": "Johan Rekna",
108
+ "email": "johan@rekna.fi",
109
+ "avatar_url": "https://avatars.hailer.com/user_123",
110
+ "timezone": "Europe/Helsinki",
111
+ "language": "fi",
112
+ "created_at": "2023-01-01T00:00:00Z"
113
+ }
114
+ ```
115
+
116
+ ### Update User Profile
117
+
118
+ ```http
119
+ PATCH /v3/users/me
120
+ Content-Type: application/json
121
+
122
+ {
123
+ "name": "Johan Rekna",
124
+ "timezone": "Europe/Helsinki",
125
+ "language": "fi"
126
+ }
127
+ ```
128
+
129
+ ### Get User by ID
130
+
131
+ ```http
132
+ GET /v3/users/{user_id}
133
+ ```
134
+
135
+ ### List Users in Workspace
136
+
137
+ ```http
138
+ GET /v3/workspaces/{workspace_id}/users
139
+ ```
140
+
141
+ **Response:**
142
+ ```json
143
+ {
144
+ "data": [
145
+ {
146
+ "id": "user_123",
147
+ "name": "Johan Rekna",
148
+ "email": "johan@rekna.fi",
149
+ "role": "admin",
150
+ "joined_at": "2023-01-01T00:00:00Z"
151
+ }
152
+ ]
153
+ }
154
+ ```
155
+
156
+ ## Workspace Members
157
+
158
+ ### Add Member to Workspace
159
+
160
+ ```http
161
+ POST /v3/workspaces/{workspace_id}/members
162
+ Content-Type: application/json
163
+
164
+ {
165
+ "email": "newuser@company.com",
166
+ "role": "member",
167
+ "send_invitation": true
168
+ }
169
+ ```
170
+
171
+ **Roles:**
172
+ - `admin` - Full workspace control
173
+ - `member` - Standard access
174
+ - `guest` - Limited access (read-only to assigned activities)
175
+
176
+ ### Update Member Role
177
+
178
+ ```http
179
+ PATCH /v3/workspaces/{workspace_id}/members/{user_id}
180
+ Content-Type: application/json
181
+
182
+ {
183
+ "role": "admin"
184
+ }
185
+ ```
186
+
187
+ ### Remove Member
188
+
189
+ ```http
190
+ DELETE /v3/workspaces/{workspace_id}/members/{user_id}
191
+ ```
192
+
193
+ ## Permissions System
194
+
195
+ ### Permission Levels
196
+
197
+ Hailer uses role-based and object-based permissions:
198
+
199
+ **Workspace Level:**
200
+ - `admin` - Full control
201
+ - `member` - Standard access
202
+ - `guest` - Limited access
203
+
204
+ **Activity Level:**
205
+ - `owner` - Created the activity
206
+ - `assigned` - Assigned to activity
207
+ - `follower` - Following activity
208
+ - `workspace_member` - Has workspace access
209
+
210
+ **Dataset Level:**
211
+ - `admin` - Full control
212
+ - `editor` - Can modify records
213
+ - `viewer` - Read-only
214
+
215
+ ### Check Permissions
216
+
217
+ ```http
218
+ GET /v3/activities/{activity_id}/permissions/me
219
+ ```
220
+
221
+ **Response:**
222
+ ```json
223
+ {
224
+ "can_read": true,
225
+ "can_update": true,
226
+ "can_delete": false,
227
+ "can_assign": true,
228
+ "can_comment": true
229
+ }
230
+ ```
231
+
232
+ ### List Activity Permissions
233
+
234
+ ```http
235
+ GET /v3/activities/{activity_id}/permissions
236
+ ```
237
+
238
+ **Response:**
239
+ ```json
240
+ {
241
+ "data": [
242
+ {
243
+ "user_id": "user_123",
244
+ "name": "Johan Rekna",
245
+ "role": "owner",
246
+ "permissions": ["read", "update", "delete", "assign"]
247
+ },
248
+ {
249
+ "user_id": "user_456",
250
+ "name": "Team Member",
251
+ "role": "assigned",
252
+ "permissions": ["read", "update", "comment"]
253
+ }
254
+ ]
255
+ }
256
+ ```
257
+
258
+ ### Set Activity Permissions
259
+
260
+ ```http
261
+ POST /v3/activities/{activity_id}/permissions
262
+ Content-Type: application/json
263
+
264
+ {
265
+ "user_id": "user_456",
266
+ "role": "assigned"
267
+ }
268
+ ```
269
+
270
+ ### Grant Workspace-Wide Permissions
271
+
272
+ ```http
273
+ POST /v3/workspaces/{workspace_id}/permissions
274
+ Content-Type: application/json
275
+
276
+ {
277
+ "user_id": "user_456",
278
+ "permissions": {
279
+ "can_create_activities": true,
280
+ "can_create_datasets": false,
281
+ "can_manage_workflows": false
282
+ }
283
+ }
284
+ ```
285
+
286
+ ## Teams
287
+
288
+ Groups of users within a workspace.
289
+
290
+ ### Create Team
291
+
292
+ ```http
293
+ POST /v3/workspaces/{workspace_id}/teams
294
+ Content-Type: application/json
295
+
296
+ {
297
+ "name": "Development Team",
298
+ "description": "Software development team",
299
+ "member_ids": ["user_123", "user_456"]
300
+ }
301
+ ```
302
+
303
+ ### Add Users to Team
304
+
305
+ ```http
306
+ POST /v3/teams/{team_id}/members
307
+ Content-Type: application/json
308
+
309
+ {
310
+ "user_ids": ["user_789"]
311
+ }
312
+ ```
313
+
314
+ ### Assign Team to Activity
315
+
316
+ ```http
317
+ POST /v3/activities/{activity_id}/assignments
318
+ Content-Type: application/json
319
+
320
+ {
321
+ "team_id": "team_123"
322
+ }
323
+ ```
324
+
325
+ ## API Keys
326
+
327
+ Create API keys for programmatic access:
328
+
329
+ ### Create API Key
330
+
331
+ ```http
332
+ POST /v3/api-keys
333
+ Content-Type: application/json
334
+
335
+ {
336
+ "name": "Automation Script",
337
+ "workspace_id": "ws_123",
338
+ "scopes": ["activities:read", "activities:write", "datasets:read"],
339
+ "expires_at": "2026-12-31T23:59:59Z"
340
+ }
341
+ ```
342
+
343
+ **Response:**
344
+ ```json
345
+ {
346
+ "id": "key_789",
347
+ "name": "Automation Script",
348
+ "key": "hsk_abc123def456...",
349
+ "scopes": ["activities:read", "activities:write", "datasets:read"],
350
+ "created_at": "2025-01-15T10:30:00Z",
351
+ "expires_at": "2026-12-31T23:59:59Z"
352
+ }
353
+ ```
354
+
355
+ ⚠️ **Warning:** API key is only shown once. Store it securely.
356
+
357
+ ### List API Keys
358
+
359
+ ```http
360
+ GET /v3/api-keys
361
+ ```
362
+
363
+ ### Revoke API Key
364
+
365
+ ```http
366
+ DELETE /v3/api-keys/{key_id}
367
+ ```
368
+
369
+ ## Available Scopes
370
+
371
+ ### Activity Scopes
372
+ - `activities:read` - Read activities
373
+ - `activities:write` - Create/update activities
374
+ - `activities:delete` - Delete activities
375
+
376
+ ### Dataset Scopes
377
+ - `datasets:read` - Read datasets and records
378
+ - `datasets:write` - Create/update datasets and records
379
+ - `datasets:delete` - Delete datasets and records
380
+
381
+ ### File Scopes
382
+ - `files:read` - Read files
383
+ - `files:write` - Upload files
384
+ - `files:delete` - Delete files
385
+
386
+ ### Workspace Scopes
387
+ - `workspaces:read` - Read workspace information
388
+ - `workspaces:write` - Update workspace settings
389
+ - `workspaces:admin` - Full workspace administration
390
+
391
+ ### User Scopes
392
+ - `users:read` - Read user information
393
+ - `users:write` - Update user profiles
394
+
395
+ ## Audit Logs
396
+
397
+ Track actions within workspace:
398
+
399
+ ### List Audit Logs
400
+
401
+ ```http
402
+ GET /v3/workspaces/{workspace_id}/audit-logs
403
+ ```
404
+
405
+ **Query Parameters:**
406
+ - `user_id` - Filter by user
407
+ - `action` - Filter by action type
408
+ - `resource_type` - Filter by resource (activity, dataset, etc.)
409
+ - `start_date` - ISO 8601 timestamp
410
+ - `end_date` - ISO 8601 timestamp
411
+
412
+ **Response:**
413
+ ```json
414
+ {
415
+ "data": [
416
+ {
417
+ "id": "log_123",
418
+ "action": "activity.created",
419
+ "user": {
420
+ "id": "user_123",
421
+ "name": "Johan Rekna"
422
+ },
423
+ "resource": {
424
+ "type": "activity",
425
+ "id": "act_456"
426
+ },
427
+ "timestamp": "2025-01-15T10:30:00Z",
428
+ "metadata": {
429
+ "ip_address": "192.168.1.1",
430
+ "user_agent": "Mozilla/5.0..."
431
+ }
432
+ }
433
+ ]
434
+ }
435
+ ```
436
+
437
+ ## Best Practices
438
+
439
+ 1. **Use teams for group permissions** - Easier than managing individual user permissions
440
+ 2. **Create API keys with minimal scopes** - Principle of least privilege
441
+ 3. **Rotate API keys regularly** - Set expiration dates
442
+ 4. **Monitor audit logs** - Track suspicious activity
443
+ 5. **Remove inactive members** - Clean up workspace regularly
444
+ 6. **Use guest role for external collaborators** - Limit access appropriately
445
+ 7. **Check permissions before operations** - Avoid unnecessary API calls
@@ -0,0 +1,185 @@
1
+ ---
2
+ name: Insight API Reference
3
+ description: Complete reference for Hailer Insight API (SQL-like reporting over workflow data) - use when building insight-related MCP tools
4
+ ---
5
+
6
+ # Insight API Reference Skill
7
+
8
+ This skill provides comprehensive documentation for Hailer Insight API endpoints. Insights are SQL-like reports that query activity data from workflows, with support for joins across multiple workflows.
9
+
10
+ ## When to Use This Skill
11
+
12
+ Invoke this skill when:
13
+ - Building insight/reporting MCP tools
14
+ - Creating SQL queries over workflow data
15
+ - Working with cross-workflow data analysis
16
+ - Implementing data visualization features
17
+ - Managing insight permissions and sharing
18
+
19
+ ## What are Insights?
20
+
21
+ **Insights = SQL queries over Hailer workflow data**
22
+
23
+ Think of it as:
24
+ - **Workflows** = Database tables
25
+ - **Activities** = Rows in those tables
26
+ - **Fields** = Columns in those tables
27
+ - **Insights** = SQL SELECT queries with JOINs
28
+
29
+ ## Quick Navigation
30
+
31
+ ### Core Insight Operations
32
+ - **v3.insight.create** - Create new insight with SQL query
33
+ - **v3.insight.update** - Update existing insight
34
+ - **v3.insight.list** - List all insights in workspace
35
+ - **v3.insight.data** - Get query results (execute the SQL)
36
+ - **v3.insight.preview** - Preview insight while designing (debugging)
37
+ - **v3.insight.remove** - Delete an insight
38
+
39
+ ### Insight Management
40
+ - **v3.insight.copy** - Duplicate an insight
41
+ - **v3.insight.public** - Get public insight data (shared insights)
42
+ - **v3.insight.member.add** - Add member permissions
43
+ - **v3.insight.member.remove** - Remove member permissions
44
+
45
+ ## Key Concepts
46
+
47
+ ### Insight Structure
48
+
49
+ ```javascript
50
+ {
51
+ name: 'Insight Name',
52
+ public: false, // Whether insight is publicly accessible
53
+ sources: [
54
+ {
55
+ name: 'books', // Table alias for SQL
56
+ workflowId: '<id>', // Which workflow to query
57
+ fields: [
58
+ { name: 'title', meta: 'name' }, // Activity name
59
+ { name: 'publishDate', fieldId: '<fieldId>' } // Custom field
60
+ ]
61
+ }
62
+ ],
63
+ query: 'SELECT title, publishDate FROM books' // Standard SQL
64
+ }
65
+ ```
66
+
67
+ ### Field References
68
+
69
+ **Meta fields** (built-in):
70
+ - `meta: '_id'` - Activity ID (for JOINs)
71
+ - `meta: 'uid'` - User ID (creator)
72
+ - `meta: 'team'` - Owner team ID
73
+ - `meta: 'createdBy'` - Creator user ID
74
+ - `meta: 'name'` - Activity name/title
75
+ - `meta: 'created'` - Creation timestamp
76
+ - `meta: 'updated'` - Last update timestamp
77
+ - `meta: 'phaseId'` - Current phase ID
78
+ - `meta: 'phaseName'` - Current phase name
79
+ - `meta: 'phaseLastMove'` - Last phase change timestamp
80
+ - `meta: 'workflowId'` - Workflow ID
81
+ - `meta: 'workflowName'` - Workflow name
82
+ - `meta: 'priority'` - Activity priority
83
+
84
+ **Custom fields**:
85
+ - `fieldId: '<fieldId>'` - Reference a workflow field by ID
86
+
87
+ ### SQL Query Support
88
+
89
+ - Standard SELECT syntax
90
+ - JOINs across multiple workflows
91
+ - WHERE clauses
92
+ - GROUP BY, ORDER BY
93
+ - Aggregation functions (COUNT, SUM, AVG, etc.)
94
+
95
+ ## Common Use Cases
96
+
97
+ 1. **Single Workflow Report**: Query activities from one workflow
98
+ 2. **Cross-Workflow Join**: Join data from related workflows (via ActivityLinks)
99
+ 3. **Aggregated Reports**: COUNT, SUM, AVG across activities
100
+ 4. **Filtered Views**: WHERE clauses to filter activity data
101
+ 5. **Public Dashboards**: Share insights publicly with `public: true`
102
+
103
+ ## Documentation
104
+
105
+ See [Insight API Endpoints](references/insight-endpoints.md) for complete endpoint documentation with request/response schemas and examples.
106
+
107
+ ## MCP Tool Building Rules
108
+
109
+ When building Insight MCP tools:
110
+
111
+ 1. **Use PlaygroundTools.ts** for testing first
112
+ 2. **Follow the three-part pattern**:
113
+ - Description method (with SQL examples)
114
+ - Schema method (Zod validation)
115
+ - Handler method (implementation)
116
+ 3. **Use HailerApiClient** with socket calls
117
+ 4. **Validate SQL queries** before sending (basic syntax check)
118
+ 5. **Format responses** as markdown tables for readability
119
+ 6. **Handle permissions** - only workspace admins can modify sources
120
+
121
+ ## Example Patterns
122
+
123
+ ### Simple Report
124
+ ```javascript
125
+ create_insight({
126
+ name: 'All Books',
127
+ sources: [{
128
+ name: 'books',
129
+ workflowId: bookWorkflowId,
130
+ fields: [
131
+ { name: 'title', meta: 'name' },
132
+ { name: 'author', fieldId: authorFieldId }
133
+ ]
134
+ }],
135
+ query: 'SELECT title, author FROM books'
136
+ })
137
+ ```
138
+
139
+ ### Cross-Workflow Join
140
+ ```javascript
141
+ create_insight({
142
+ name: 'Books with Authors',
143
+ sources: [
144
+ {
145
+ name: 'books',
146
+ workflowId: bookWorkflowId,
147
+ fields: [
148
+ { name: 'title', meta: 'name' },
149
+ { name: 'authorId', fieldId: authorLinkFieldId }
150
+ ]
151
+ },
152
+ {
153
+ name: 'authors',
154
+ workflowId: authorWorkflowId,
155
+ fields: [
156
+ { name: 'id', meta: '_id' },
157
+ { name: 'authorName', meta: 'name' }
158
+ ]
159
+ }
160
+ ],
161
+ query: `
162
+ SELECT books.title, authors.authorName
163
+ FROM books
164
+ LEFT JOIN authors ON books.authorId = authors.id
165
+ `
166
+ })
167
+ ```
168
+
169
+ ## Preview vs Execute
170
+
171
+ **v3.insight.preview**:
172
+ - Used during design/debugging
173
+ - Limited to ~20 activities for performance
174
+ - Can be called frequently
175
+ - Shows errors in SQL syntax
176
+
177
+ **v3.insight.data**:
178
+ - Executes full query on all activities
179
+ - Returns complete results
180
+ - Use after insight is finalized
181
+
182
+ ## Next Steps
183
+
184
+ For complete endpoint documentation with request/response schemas and SQL examples, see:
185
+ - [Insight API Endpoints](references/insight-endpoints.md) - All v3.insight.* endpoints