@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,306 @@
1
+ "use strict";
2
+ /**
3
+ * Clean Tool Registry with Dependency Injection
4
+ *
5
+ * No singletons, no statics - just clean, explicit tool registration
6
+ * with per-agent access control via dependency injection.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.ToolRegistry = exports.ToolGroup = void 0;
10
+ const zod_1 = require("zod");
11
+ const logger_1 = require("../lib/logger");
12
+ const logger = (0, logger_1.createLogger)({ component: 'tool-registry' });
13
+ /**
14
+ * Tool groups for access control
15
+ * READ: Safe read operations (workflows, activities, schemas)
16
+ * WRITE: Create/update operations (activities, discussions)
17
+ * PLAYGROUND: Admin/dev tools (workflow/app management)
18
+ * NUCLEAR: Destructive operations (remove workflows, apps, insights, templates)
19
+ */
20
+ var ToolGroup;
21
+ (function (ToolGroup) {
22
+ ToolGroup["READ"] = "read";
23
+ ToolGroup["WRITE"] = "write";
24
+ ToolGroup["PLAYGROUND"] = "playground";
25
+ ToolGroup["NUCLEAR"] = "nuclear";
26
+ })(ToolGroup || (exports.ToolGroup = ToolGroup = {}));
27
+ /**
28
+ * ToolRegistry - Clean, testable, dependency-injected tool registry
29
+ *
30
+ * NO SINGLETON PATTERN - instantiated explicitly and passed through DI
31
+ */
32
+ class ToolRegistry {
33
+ tools = new Map();
34
+ enableNuclearTools;
35
+ constructor(options = {}) {
36
+ this.enableNuclearTools = options.enableNuclearTools ?? false;
37
+ logger.debug('ToolRegistry instance created', {
38
+ enableNuclearTools: this.enableNuclearTools
39
+ });
40
+ }
41
+ /**
42
+ * Add a tool to the registry
43
+ */
44
+ addTool(tool) {
45
+ // Short-circuit: Skip NUCLEAR tools when not enabled
46
+ if (tool.group === ToolGroup.NUCLEAR && !this.enableNuclearTools) {
47
+ logger.info('Skipping NUCLEAR tool (not enabled)', {
48
+ name: tool.name,
49
+ group: tool.group
50
+ });
51
+ return;
52
+ }
53
+ if (this.tools.has(tool.name)) {
54
+ logger.warn('Tool already registered, replacing', { name: tool.name });
55
+ }
56
+ this.tools.set(tool.name, tool);
57
+ logger.debug('Tool registered', { name: tool.name, group: tool.group });
58
+ }
59
+ /**
60
+ * Get tool definitions with optional filtering
61
+ *
62
+ * @param filter - Optional filter configuration
63
+ * @param filter.allowedGroups - Filter by tool groups
64
+ * @param filter.allowedTools - Explicit whitelist of tool names
65
+ */
66
+ getToolDefinitions(filter) {
67
+ let toolsToExpose = Array.from(this.tools.values());
68
+ if (filter) {
69
+ if (filter.allowedTools) {
70
+ // Explicit whitelist by tool name (takes precedence)
71
+ toolsToExpose = toolsToExpose.filter(t => filter.allowedTools.includes(t.name));
72
+ logger.debug('Filtered tools by allowedTools', {
73
+ count: toolsToExpose.length,
74
+ allowedTools: filter.allowedTools
75
+ });
76
+ }
77
+ else if (filter.allowedGroups) {
78
+ // Filter by tool groups
79
+ toolsToExpose = toolsToExpose.filter(t => filter.allowedGroups.includes(t.group));
80
+ logger.debug('Filtered tools by allowedGroups', {
81
+ count: toolsToExpose.length,
82
+ allowedGroups: filter.allowedGroups
83
+ });
84
+ }
85
+ }
86
+ return toolsToExpose.map(tool => ({
87
+ name: tool.name,
88
+ description: tool.description,
89
+ inputSchema: this.convertZodSchemaToJsonSchema(tool.schema)
90
+ }));
91
+ }
92
+ /**
93
+ * Get specific tool schema on-demand
94
+ * Token-efficient: ~200 tokens per tool vs loading all tools upfront
95
+ */
96
+ getToolSchema(toolName) {
97
+ const tool = this.tools.get(toolName);
98
+ if (!tool) {
99
+ logger.warn('Tool not found', { toolName });
100
+ return null;
101
+ }
102
+ return {
103
+ name: tool.name,
104
+ description: tool.description,
105
+ inputSchema: this.convertZodSchemaToJsonSchema(tool.schema)
106
+ };
107
+ }
108
+ /**
109
+ * Execute tool with validation
110
+ */
111
+ async executeTool(name, args, context) {
112
+ const tool = this.tools.get(name);
113
+ if (!tool) {
114
+ throw new Error(`Tool "${name}" not found`);
115
+ }
116
+ logger.debug('Executing tool', {
117
+ name,
118
+ apiKey: context.apiKey.substring(0, 8) + '...'
119
+ });
120
+ // Zod validation
121
+ try {
122
+ const validated = tool.schema.parse(args);
123
+ return await tool.execute(validated, context);
124
+ }
125
+ catch (error) {
126
+ if (error instanceof zod_1.z.ZodError) {
127
+ const errorDetails = error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ');
128
+ logger.warn('Tool validation failed', {
129
+ toolName: name,
130
+ errors: errorDetails,
131
+ receivedArgs: JSON.stringify(args)
132
+ });
133
+ // Check if tool has a skill hint
134
+ const hasSkillHint = tool.description.includes('Use Skill');
135
+ const skillName = hasSkillHint ? tool.description.match(/`([^`]+)-skill`/)?.[1] + '-skill' : null;
136
+ const errorMessage = `❌ **Validation Error for \`${name}\`**
137
+
138
+ **Errors:** ${errorDetails}
139
+
140
+ **You provided:**
141
+ \`\`\`json
142
+ ${JSON.stringify(args, null, 2)}
143
+ \`\`\`
144
+
145
+ ${skillName ? `💡 **Next step:** Load the skill first to see correct format and examples:
146
+ \`\`\`
147
+ get_skill({ skillName: "${skillName}" })
148
+ \`\`\`
149
+
150
+ Then retry \`${name}\` with the correct format from the skill examples.` : `💡 **Next step:** Use \`tools/get_schema\` to see the full schema for \`${name}\`, then retry with correct parameters.`}`;
151
+ return {
152
+ content: [{
153
+ type: "text",
154
+ text: errorMessage
155
+ }]
156
+ };
157
+ }
158
+ throw error;
159
+ }
160
+ }
161
+ /**
162
+ * Get tool metadata (for access control checks)
163
+ */
164
+ getTool(name) {
165
+ return this.tools.get(name);
166
+ }
167
+ /**
168
+ * Get total tool count
169
+ */
170
+ getToolCount() {
171
+ return this.tools.size;
172
+ }
173
+ /**
174
+ * Get statistics for monitoring/debugging
175
+ */
176
+ getCacheStats() {
177
+ const byGroup = {
178
+ [ToolGroup.READ]: 0,
179
+ [ToolGroup.WRITE]: 0,
180
+ [ToolGroup.PLAYGROUND]: 0,
181
+ [ToolGroup.NUCLEAR]: 0
182
+ };
183
+ for (const tool of this.tools.values()) {
184
+ byGroup[tool.group]++;
185
+ }
186
+ return {
187
+ totalTools: this.tools.size,
188
+ toolNames: Array.from(this.tools.keys()),
189
+ byGroup
190
+ };
191
+ }
192
+ /**
193
+ * Convert Zod schema to JSON Schema format (required by MCP protocol)
194
+ */
195
+ convertZodSchemaToJsonSchema(zodSchema) {
196
+ // Handle ZodObject by extracting its shape
197
+ if (zodSchema._def?.typeName === 'ZodObject') {
198
+ zodSchema = zodSchema._def.shape();
199
+ }
200
+ const properties = {};
201
+ const required = [];
202
+ // Handle the schema object
203
+ for (const [key, value] of Object.entries(zodSchema)) {
204
+ if (value && typeof value === "object" && "_def" in value) {
205
+ const zodType = value;
206
+ const property = this.convertZodTypeToJsonSchema(zodType);
207
+ // Handle optional vs required - Check for ZodOptional and ZodDefault wrappers
208
+ const isOptional = zodType._def?.typeName === 'ZodOptional';
209
+ const hasDefault = zodType._def?.typeName === 'ZodDefault';
210
+ if (!isOptional && !hasDefault) {
211
+ required.push(key);
212
+ }
213
+ // Handle default values - Extract from ZodDefault wrapper
214
+ if (hasDefault && typeof zodType._def?.defaultValue === 'function') {
215
+ property.default = zodType._def.defaultValue();
216
+ }
217
+ properties[key] = property;
218
+ }
219
+ }
220
+ return {
221
+ type: "object",
222
+ properties,
223
+ required,
224
+ };
225
+ }
226
+ /**
227
+ * Convert a single Zod type to JSON Schema
228
+ */
229
+ convertZodTypeToJsonSchema(zodType) {
230
+ // Unwrap ZodOptional and ZodDefault wrappers to get the inner type
231
+ let unwrappedType = zodType;
232
+ while (unwrappedType._def?.typeName === 'ZodOptional' || unwrappedType._def?.typeName === 'ZodDefault') {
233
+ unwrappedType = unwrappedType._def.innerType;
234
+ }
235
+ const typeName = unwrappedType._def?.typeName;
236
+ const property = {};
237
+ // Add description if available (check both wrapped and unwrapped)
238
+ if (zodType._def?.description) {
239
+ property.description = zodType._def.description;
240
+ }
241
+ else if (unwrappedType._def?.description) {
242
+ property.description = unwrappedType._def.description;
243
+ }
244
+ switch (typeName) {
245
+ case "ZodString":
246
+ property.type = "string";
247
+ break;
248
+ case "ZodNumber":
249
+ property.type = "number";
250
+ break;
251
+ case "ZodBoolean":
252
+ property.type = "boolean";
253
+ break;
254
+ case "ZodArray":
255
+ property.type = "array";
256
+ // Handle array items
257
+ if (unwrappedType._def?.type) {
258
+ property.items = this.convertZodTypeToJsonSchema(unwrappedType._def.type);
259
+ }
260
+ else {
261
+ property.items = { type: "string" };
262
+ }
263
+ break;
264
+ case "ZodObject":
265
+ property.type = "object";
266
+ // Recursively handle object properties if needed
267
+ if (unwrappedType._def?.shape) {
268
+ const nestedSchema = this.convertZodSchemaToJsonSchema(unwrappedType._def.shape);
269
+ property.properties = nestedSchema.properties;
270
+ if (nestedSchema.required?.length > 0) {
271
+ property.required = nestedSchema.required;
272
+ }
273
+ }
274
+ break;
275
+ case "ZodRecord":
276
+ property.type = "object";
277
+ break;
278
+ case "ZodEnum":
279
+ property.type = "string";
280
+ // Handle enum values
281
+ if (unwrappedType._def?.values) {
282
+ property.enum = Array.from(unwrappedType._def.values);
283
+ }
284
+ break;
285
+ case "ZodUnion":
286
+ // For unions, try to extract types
287
+ if (unwrappedType._def?.options && unwrappedType._def.options.length > 0) {
288
+ const firstOption = unwrappedType._def.options[0];
289
+ const firstType = this.convertZodTypeToJsonSchema(firstOption);
290
+ property.type = firstType.type;
291
+ if (firstType.enum) {
292
+ property.enum = firstType.enum;
293
+ }
294
+ }
295
+ else {
296
+ property.type = "string";
297
+ }
298
+ break;
299
+ default:
300
+ property.type = "string";
301
+ }
302
+ return property;
303
+ }
304
+ }
305
+ exports.ToolRegistry = ToolRegistry;
306
+ //# sourceMappingURL=tool-registry.js.map
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Activity Tools - Clean Architecture Implementation
3
+ *
4
+ * Tools for managing Hailer activities:
5
+ * - List activities with filtering and pagination (READ)
6
+ * - Show activity details (READ)
7
+ * - Create new activities (WRITE)
8
+ * - Update existing activities (WRITE)
9
+ */
10
+ import { Tool } from '../tool-registry';
11
+ export declare const listActivitiesTool: Tool;
12
+ export declare const showActivityByIdTool: Tool;
13
+ export declare const createActivityTool: Tool;
14
+ export declare const updateActivityTool: Tool;
15
+ //# sourceMappingURL=activity.d.ts.map