@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.
- package/.claude/commands/tool-builder.md +37 -0
- package/.claude/commands/ws-pull.md +44 -0
- package/.claude/settings.json +8 -0
- package/.claude/settings.local.json +49 -0
- package/.claude/skills/activity-api/SKILL.md +96 -0
- package/.claude/skills/activity-api/references/activity-endpoints.md +845 -0
- package/.claude/skills/add-app-member-skill/SKILL.md +977 -0
- package/.claude/skills/agent-building/SKILL.md +243 -0
- package/.claude/skills/agent-building/references/architecture-patterns.md +446 -0
- package/.claude/skills/agent-building/references/code-examples.md +587 -0
- package/.claude/skills/agent-building/references/implementation-guide.md +619 -0
- package/.claude/skills/app-api/SKILL.md +219 -0
- package/.claude/skills/app-api/references/app-endpoints.md +759 -0
- package/.claude/skills/building-hailer-apps-skill/SKILL.md +548 -0
- package/.claude/skills/create-app-skill/SKILL.md +1101 -0
- package/.claude/skills/create-insight-skill/SKILL.md +1317 -0
- package/.claude/skills/get-insight-data-skill/SKILL.md +1053 -0
- package/.claude/skills/hailer-api/SKILL.md +283 -0
- package/.claude/skills/hailer-api/references/activities.md +620 -0
- package/.claude/skills/hailer-api/references/authentication.md +216 -0
- package/.claude/skills/hailer-api/references/datasets.md +437 -0
- package/.claude/skills/hailer-api/references/files.md +301 -0
- package/.claude/skills/hailer-api/references/insights.md +469 -0
- package/.claude/skills/hailer-api/references/workflows.md +720 -0
- package/.claude/skills/hailer-api/references/workspaces-users.md +445 -0
- package/.claude/skills/insight-api/SKILL.md +185 -0
- package/.claude/skills/insight-api/references/insight-endpoints.md +514 -0
- package/.claude/skills/install-workflow-skill/SKILL.md +1056 -0
- package/.claude/skills/list-apps-skill/SKILL.md +1010 -0
- package/.claude/skills/list-workflows-minimal-skill/SKILL.md +992 -0
- package/.claude/skills/local-first-skill/SKILL.md +570 -0
- package/.claude/skills/mcp-tools/SKILL.md +419 -0
- package/.claude/skills/mcp-tools/references/api-endpoints.md +499 -0
- package/.claude/skills/mcp-tools/references/data-structures.md +554 -0
- package/.claude/skills/mcp-tools/references/implementation-patterns.md +717 -0
- package/.claude/skills/preview-insight-skill/SKILL.md +1290 -0
- package/.claude/skills/publish-hailer-app-skill/SKILL.md +453 -0
- package/.claude/skills/remove-app-member-skill/SKILL.md +671 -0
- package/.claude/skills/remove-app-skill/SKILL.md +985 -0
- package/.claude/skills/remove-insight-skill/SKILL.md +1011 -0
- package/.claude/skills/remove-workflow-skill/SKILL.md +920 -0
- package/.claude/skills/scaffold-hailer-app-skill/SKILL.md +1034 -0
- package/.claude/skills/skill-testing/README.md +137 -0
- package/.claude/skills/skill-testing/SKILL.md +348 -0
- package/.claude/skills/skill-testing/references/test-patterns.md +705 -0
- package/.claude/skills/skill-testing/references/testing-guide.md +603 -0
- package/.claude/skills/skill-testing/references/validation-checklist.md +537 -0
- package/.claude/skills/tool-builder/SKILL.md +328 -0
- package/.claude/skills/update-app-skill/SKILL.md +970 -0
- package/.claude/skills/update-workflow-field-skill/SKILL.md +1098 -0
- package/.env.example +81 -0
- package/.mcp.json +13 -0
- package/README.md +297 -0
- package/dist/app.d.ts +4 -0
- package/dist/app.js +74 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +5 -0
- package/dist/client/adaptive-documentation-bot.d.ts +108 -0
- package/dist/client/adaptive-documentation-bot.js +475 -0
- package/dist/client/adaptive-documentation-types.d.ts +66 -0
- package/dist/client/adaptive-documentation-types.js +9 -0
- package/dist/client/agent-activity-bot.d.ts +51 -0
- package/dist/client/agent-activity-bot.js +166 -0
- package/dist/client/agent-tracker.d.ts +499 -0
- package/dist/client/agent-tracker.js +659 -0
- package/dist/client/description-updater.d.ts +56 -0
- package/dist/client/description-updater.js +259 -0
- package/dist/client/log-parser.d.ts +72 -0
- package/dist/client/log-parser.js +387 -0
- package/dist/client/mcp-client.d.ts +50 -0
- package/dist/client/mcp-client.js +532 -0
- package/dist/client/message-processor.d.ts +35 -0
- package/dist/client/message-processor.js +352 -0
- package/dist/client/multi-bot-manager.d.ts +24 -0
- package/dist/client/multi-bot-manager.js +74 -0
- package/dist/client/providers/anthropic-provider.d.ts +19 -0
- package/dist/client/providers/anthropic-provider.js +631 -0
- package/dist/client/providers/llm-provider.d.ts +47 -0
- package/dist/client/providers/llm-provider.js +367 -0
- package/dist/client/providers/openai-provider.d.ts +23 -0
- package/dist/client/providers/openai-provider.js +621 -0
- package/dist/client/simple-llm-caller.d.ts +19 -0
- package/dist/client/simple-llm-caller.js +100 -0
- package/dist/client/skill-generator.d.ts +81 -0
- package/dist/client/skill-generator.js +386 -0
- package/dist/client/test-adaptive-bot.d.ts +9 -0
- package/dist/client/test-adaptive-bot.js +82 -0
- package/dist/client/token-pricing.d.ts +38 -0
- package/dist/client/token-pricing.js +127 -0
- package/dist/client/token-tracker.d.ts +232 -0
- package/dist/client/token-tracker.js +457 -0
- package/dist/client/token-usage-bot.d.ts +53 -0
- package/dist/client/token-usage-bot.js +153 -0
- package/dist/client/tool-executor.d.ts +69 -0
- package/dist/client/tool-executor.js +159 -0
- package/dist/client/tool-schema-loader.d.ts +60 -0
- package/dist/client/tool-schema-loader.js +178 -0
- package/dist/client/types.d.ts +69 -0
- package/dist/client/types.js +7 -0
- package/dist/config.d.ts +162 -0
- package/dist/config.js +296 -0
- package/dist/core.d.ts +26 -0
- package/dist/core.js +147 -0
- package/dist/lib/context-manager.d.ts +111 -0
- package/dist/lib/context-manager.js +431 -0
- package/dist/lib/logger.d.ts +74 -0
- package/dist/lib/logger.js +277 -0
- package/dist/lib/materialize.d.ts +3 -0
- package/dist/lib/materialize.js +101 -0
- package/dist/lib/normalizedName.d.ts +7 -0
- package/dist/lib/normalizedName.js +48 -0
- package/dist/lib/prompt-length-manager.d.ts +81 -0
- package/dist/lib/prompt-length-manager.js +457 -0
- package/dist/lib/terminal-prompt.d.ts +9 -0
- package/dist/lib/terminal-prompt.js +108 -0
- package/dist/mcp/UserContextCache.d.ts +56 -0
- package/dist/mcp/UserContextCache.js +163 -0
- package/dist/mcp/auth.d.ts +2 -0
- package/dist/mcp/auth.js +29 -0
- package/dist/mcp/hailer-clients.d.ts +42 -0
- package/dist/mcp/hailer-clients.js +246 -0
- package/dist/mcp/signal-handler.d.ts +45 -0
- package/dist/mcp/signal-handler.js +317 -0
- package/dist/mcp/tool-registry.d.ts +100 -0
- package/dist/mcp/tool-registry.js +306 -0
- package/dist/mcp/tools/activity.d.ts +15 -0
- package/dist/mcp/tools/activity.js +955 -0
- package/dist/mcp/tools/app.d.ts +20 -0
- package/dist/mcp/tools/app.js +1488 -0
- package/dist/mcp/tools/discussion.d.ts +19 -0
- package/dist/mcp/tools/discussion.js +950 -0
- package/dist/mcp/tools/file.d.ts +15 -0
- package/dist/mcp/tools/file.js +119 -0
- package/dist/mcp/tools/insight.d.ts +17 -0
- package/dist/mcp/tools/insight.js +806 -0
- package/dist/mcp/tools/skill.d.ts +10 -0
- package/dist/mcp/tools/skill.js +279 -0
- package/dist/mcp/tools/user.d.ts +10 -0
- package/dist/mcp/tools/user.js +108 -0
- package/dist/mcp/tools/workflow-template.d.ts +19 -0
- package/dist/mcp/tools/workflow-template.js +822 -0
- package/dist/mcp/tools/workflow.d.ts +18 -0
- package/dist/mcp/tools/workflow.js +1362 -0
- package/dist/mcp/utils/api-errors.d.ts +45 -0
- package/dist/mcp/utils/api-errors.js +160 -0
- package/dist/mcp/utils/data-transformers.d.ts +102 -0
- package/dist/mcp/utils/data-transformers.js +194 -0
- package/dist/mcp/utils/file-upload.d.ts +33 -0
- package/dist/mcp/utils/file-upload.js +148 -0
- package/dist/mcp/utils/hailer-api-client.d.ts +120 -0
- package/dist/mcp/utils/hailer-api-client.js +323 -0
- package/dist/mcp/utils/index.d.ts +13 -0
- package/dist/mcp/utils/index.js +39 -0
- package/dist/mcp/utils/logger.d.ts +42 -0
- package/dist/mcp/utils/logger.js +103 -0
- package/dist/mcp/utils/types.d.ts +286 -0
- package/dist/mcp/utils/types.js +7 -0
- package/dist/mcp/workspace-cache.d.ts +42 -0
- package/dist/mcp/workspace-cache.js +97 -0
- package/dist/mcp-server.d.ts +42 -0
- package/dist/mcp-server.js +280 -0
- package/package.json +56 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Executor
|
|
3
|
+
*
|
|
4
|
+
* Handles MCP tool call execution and result processing.
|
|
5
|
+
* Shared between all LLM providers (Anthropic, OpenAI, etc.)
|
|
6
|
+
*
|
|
7
|
+
* Key Features:
|
|
8
|
+
* - Execute tool calls via MCP server
|
|
9
|
+
* - Handle tool call iterations and loops
|
|
10
|
+
* - Process and format tool results
|
|
11
|
+
* - Track tool execution metrics
|
|
12
|
+
*/
|
|
13
|
+
export interface ToolCall {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
arguments: any;
|
|
17
|
+
}
|
|
18
|
+
export interface ToolResult {
|
|
19
|
+
tool_use_id: string;
|
|
20
|
+
content: string;
|
|
21
|
+
isError?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface ExecuteToolOptions {
|
|
24
|
+
mcpServerUrl: string;
|
|
25
|
+
mcpServerApiKey: string;
|
|
26
|
+
toolCall: ToolCall;
|
|
27
|
+
}
|
|
28
|
+
export interface ToolExecutionMetrics {
|
|
29
|
+
toolName: string;
|
|
30
|
+
success: boolean;
|
|
31
|
+
duration: number;
|
|
32
|
+
error?: string;
|
|
33
|
+
}
|
|
34
|
+
export declare class ToolExecutor {
|
|
35
|
+
private executionMetrics;
|
|
36
|
+
/**
|
|
37
|
+
* Execute a tool call via MCP server
|
|
38
|
+
*/
|
|
39
|
+
executeTool(options: ExecuteToolOptions): Promise<ToolResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Execute multiple tool calls in parallel
|
|
42
|
+
*/
|
|
43
|
+
executeToolsParallel(options: Omit<ExecuteToolOptions, 'toolCall'>, toolCalls: ToolCall[]): Promise<ToolResult[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Get execution metrics
|
|
46
|
+
*/
|
|
47
|
+
getMetrics(): ToolExecutionMetrics[];
|
|
48
|
+
/**
|
|
49
|
+
* Get successful tool call count
|
|
50
|
+
*/
|
|
51
|
+
getSuccessCount(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Get total tool call count
|
|
54
|
+
*/
|
|
55
|
+
getTotalCount(): number;
|
|
56
|
+
/**
|
|
57
|
+
* Clear metrics
|
|
58
|
+
*/
|
|
59
|
+
clearMetrics(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Get list of tool names called
|
|
62
|
+
*/
|
|
63
|
+
getToolNamesCalled(): string[];
|
|
64
|
+
/**
|
|
65
|
+
* Call MCP tool via JSON-RPC
|
|
66
|
+
*/
|
|
67
|
+
private callMcpTool;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=tool-executor.d.ts.map
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool Executor
|
|
4
|
+
*
|
|
5
|
+
* Handles MCP tool call execution and result processing.
|
|
6
|
+
* Shared between all LLM providers (Anthropic, OpenAI, etc.)
|
|
7
|
+
*
|
|
8
|
+
* Key Features:
|
|
9
|
+
* - Execute tool calls via MCP server
|
|
10
|
+
* - Handle tool call iterations and loops
|
|
11
|
+
* - Process and format tool results
|
|
12
|
+
* - Track tool execution metrics
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ToolExecutor = void 0;
|
|
16
|
+
const logger_1 = require("../lib/logger");
|
|
17
|
+
const logger = (0, logger_1.createLogger)({ component: 'ToolExecutor' });
|
|
18
|
+
class ToolExecutor {
|
|
19
|
+
executionMetrics = [];
|
|
20
|
+
/**
|
|
21
|
+
* Execute a tool call via MCP server
|
|
22
|
+
*/
|
|
23
|
+
async executeTool(options) {
|
|
24
|
+
const { mcpServerUrl, mcpServerApiKey, toolCall } = options;
|
|
25
|
+
const startTime = Date.now();
|
|
26
|
+
try {
|
|
27
|
+
logger.debug("[tool_call] Tool call", {
|
|
28
|
+
toolName: toolCall.name,
|
|
29
|
+
arguments: toolCall.arguments
|
|
30
|
+
});
|
|
31
|
+
const result = await this.callMcpTool(mcpServerUrl, mcpServerApiKey, toolCall.name, toolCall.arguments);
|
|
32
|
+
const duration = Date.now() - startTime;
|
|
33
|
+
logger.debug("[tool_call] Tool call", {
|
|
34
|
+
toolName: toolCall.name,
|
|
35
|
+
arguments: toolCall.arguments,
|
|
36
|
+
duration
|
|
37
|
+
});
|
|
38
|
+
// Track metrics
|
|
39
|
+
this.executionMetrics.push({
|
|
40
|
+
toolName: toolCall.name,
|
|
41
|
+
success: true,
|
|
42
|
+
duration
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
tool_use_id: toolCall.id,
|
|
46
|
+
content: JSON.stringify(result),
|
|
47
|
+
isError: false
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
const duration = Date.now() - startTime;
|
|
52
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
53
|
+
logger.error("[tool_call] Tool call failed", {
|
|
54
|
+
toolName: toolCall.name,
|
|
55
|
+
error: errorMessage,
|
|
56
|
+
duration
|
|
57
|
+
});
|
|
58
|
+
// Track error metrics
|
|
59
|
+
this.executionMetrics.push({
|
|
60
|
+
toolName: toolCall.name,
|
|
61
|
+
success: false,
|
|
62
|
+
duration,
|
|
63
|
+
error: errorMessage
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
tool_use_id: toolCall.id,
|
|
67
|
+
content: `Error executing tool: ${errorMessage}`,
|
|
68
|
+
isError: true
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Execute multiple tool calls in parallel
|
|
74
|
+
*/
|
|
75
|
+
async executeToolsParallel(options, toolCalls) {
|
|
76
|
+
const promises = toolCalls.map(toolCall => this.executeTool({ ...options, toolCall }));
|
|
77
|
+
return Promise.all(promises);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get execution metrics
|
|
81
|
+
*/
|
|
82
|
+
getMetrics() {
|
|
83
|
+
return [...this.executionMetrics];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get successful tool call count
|
|
87
|
+
*/
|
|
88
|
+
getSuccessCount() {
|
|
89
|
+
return this.executionMetrics.filter(m => m.success).length;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get total tool call count
|
|
93
|
+
*/
|
|
94
|
+
getTotalCount() {
|
|
95
|
+
return this.executionMetrics.length;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Clear metrics
|
|
99
|
+
*/
|
|
100
|
+
clearMetrics() {
|
|
101
|
+
this.executionMetrics = [];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get list of tool names called
|
|
105
|
+
*/
|
|
106
|
+
getToolNamesCalled() {
|
|
107
|
+
return this.executionMetrics.map(m => m.toolName);
|
|
108
|
+
}
|
|
109
|
+
// ===== PRIVATE METHODS =====
|
|
110
|
+
/**
|
|
111
|
+
* Call MCP tool via JSON-RPC
|
|
112
|
+
*/
|
|
113
|
+
async callMcpTool(mcpServerUrl, mcpServerApiKey, toolName, args) {
|
|
114
|
+
const url = `${mcpServerUrl}${mcpServerUrl.includes("?") ? "&" : "?"}apiKey=${mcpServerApiKey}`;
|
|
115
|
+
const response = await fetch(url, {
|
|
116
|
+
method: "POST",
|
|
117
|
+
headers: {
|
|
118
|
+
"Content-Type": "application/json",
|
|
119
|
+
Accept: "application/json, text/event-stream",
|
|
120
|
+
},
|
|
121
|
+
body: JSON.stringify({
|
|
122
|
+
jsonrpc: "2.0",
|
|
123
|
+
id: Date.now(),
|
|
124
|
+
method: "tools/call",
|
|
125
|
+
params: {
|
|
126
|
+
name: toolName,
|
|
127
|
+
arguments: args,
|
|
128
|
+
},
|
|
129
|
+
}),
|
|
130
|
+
});
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
throw new Error(`MCP tool call failed with ${response.status}: ${response.statusText}`);
|
|
133
|
+
}
|
|
134
|
+
// Parse SSE response
|
|
135
|
+
const responseText = await response.text();
|
|
136
|
+
const lines = responseText.split("\n");
|
|
137
|
+
let jsonData = null;
|
|
138
|
+
for (const line of lines) {
|
|
139
|
+
if (line.startsWith("data: ")) {
|
|
140
|
+
try {
|
|
141
|
+
jsonData = JSON.parse(line.substring(6));
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
// Skip non-JSON lines
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!jsonData) {
|
|
150
|
+
throw new Error("Failed to parse MCP server response");
|
|
151
|
+
}
|
|
152
|
+
if (jsonData.error) {
|
|
153
|
+
throw new Error(`MCP server error: ${jsonData.error.message || jsonData.error}`);
|
|
154
|
+
}
|
|
155
|
+
return jsonData.result;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.ToolExecutor = ToolExecutor;
|
|
159
|
+
//# sourceMappingURL=tool-executor.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Schema Loader
|
|
3
|
+
*
|
|
4
|
+
* Manages MCP tool discovery, schema loading, and filtering.
|
|
5
|
+
* Shared between all LLM providers (Anthropic, OpenAI, etc.)
|
|
6
|
+
*
|
|
7
|
+
* Key Features:
|
|
8
|
+
* - Load lightweight tool index from MCP server
|
|
9
|
+
* - Filter tools by groups (READ, WRITE, PLAYGROUND)
|
|
10
|
+
* - Load full schemas on-demand (token-efficient)
|
|
11
|
+
* - Cache loaded schemas
|
|
12
|
+
*/
|
|
13
|
+
import { ToolGroup } from '../mcp/tool-registry';
|
|
14
|
+
export interface ToolIndexEntry {
|
|
15
|
+
name: string;
|
|
16
|
+
category: string;
|
|
17
|
+
description: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ToolDefinition {
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
input_schema: any;
|
|
23
|
+
}
|
|
24
|
+
export interface LoadToolsOptions {
|
|
25
|
+
mcpServerUrl: string;
|
|
26
|
+
mcpServerApiKey: string;
|
|
27
|
+
allowedGroups: ToolGroup[];
|
|
28
|
+
excludeMessageFetchTools?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare class ToolSchemaLoader {
|
|
31
|
+
private toolSchemaCache;
|
|
32
|
+
/**
|
|
33
|
+
* Load tool index with filtering
|
|
34
|
+
* Returns lightweight tool list with optional exclusions
|
|
35
|
+
*/
|
|
36
|
+
loadToolIndex(options: LoadToolsOptions): Promise<ToolIndexEntry[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Load full schema for a specific tool on-demand
|
|
39
|
+
*/
|
|
40
|
+
loadToolSchema(mcpServerUrl: string, mcpServerApiKey: string, toolName: string): Promise<any>;
|
|
41
|
+
/**
|
|
42
|
+
* Convert tool index to minimal tool definitions (stubs)
|
|
43
|
+
* Full schemas will be loaded on-demand when needed
|
|
44
|
+
* Returns any[] to allow provider-specific extensions (like Anthropic's cache_control)
|
|
45
|
+
*/
|
|
46
|
+
toMinimalToolDefinitions(toolIndex: ToolIndexEntry[]): any[];
|
|
47
|
+
/**
|
|
48
|
+
* Get count of loaded schemas
|
|
49
|
+
*/
|
|
50
|
+
getLoadedSchemaCount(): number;
|
|
51
|
+
/**
|
|
52
|
+
* Clear schema cache
|
|
53
|
+
*/
|
|
54
|
+
clearCache(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Fetch tool index from MCP server
|
|
57
|
+
*/
|
|
58
|
+
private fetchMcpToolIndex;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=tool-schema-loader.d.ts.map
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool Schema Loader
|
|
4
|
+
*
|
|
5
|
+
* Manages MCP tool discovery, schema loading, and filtering.
|
|
6
|
+
* Shared between all LLM providers (Anthropic, OpenAI, etc.)
|
|
7
|
+
*
|
|
8
|
+
* Key Features:
|
|
9
|
+
* - Load lightweight tool index from MCP server
|
|
10
|
+
* - Filter tools by groups (READ, WRITE, PLAYGROUND)
|
|
11
|
+
* - Load full schemas on-demand (token-efficient)
|
|
12
|
+
* - Cache loaded schemas
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ToolSchemaLoader = void 0;
|
|
16
|
+
const logger_1 = require("../lib/logger");
|
|
17
|
+
const logger = (0, logger_1.createLogger)({ component: 'ToolSchemaLoader' });
|
|
18
|
+
class ToolSchemaLoader {
|
|
19
|
+
toolSchemaCache = new Map(); // In-memory cache for tool schemas
|
|
20
|
+
/**
|
|
21
|
+
* Load tool index with filtering
|
|
22
|
+
* Returns lightweight tool list with optional exclusions
|
|
23
|
+
*/
|
|
24
|
+
async loadToolIndex(options) {
|
|
25
|
+
const { mcpServerUrl, mcpServerApiKey, allowedGroups, excludeMessageFetchTools } = options;
|
|
26
|
+
// Fetch tool index from MCP server with group filtering
|
|
27
|
+
let toolIndex = await this.fetchMcpToolIndex(mcpServerUrl, mcpServerApiKey, allowedGroups);
|
|
28
|
+
// Optionally exclude message fetch tools if explicitly requested
|
|
29
|
+
if (excludeMessageFetchTools) {
|
|
30
|
+
const excludedTools = ['fetch_discussion_messages', 'fetch_previous_discussion_messages'];
|
|
31
|
+
toolIndex = toolIndex.filter(tool => !excludedTools.includes(tool.name));
|
|
32
|
+
logger.info("Excluded message fetch tools (explicitly requested)", { excludedTools });
|
|
33
|
+
}
|
|
34
|
+
logger.info("Loaded tool index", {
|
|
35
|
+
toolCount: toolIndex.length,
|
|
36
|
+
allowedGroups: allowedGroups.join(', ')
|
|
37
|
+
});
|
|
38
|
+
return toolIndex;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Load full schema for a specific tool on-demand
|
|
42
|
+
*/
|
|
43
|
+
async loadToolSchema(mcpServerUrl, mcpServerApiKey, toolName) {
|
|
44
|
+
// Check cache first
|
|
45
|
+
if (this.toolSchemaCache.has(toolName)) {
|
|
46
|
+
logger.debug("Using cached tool schema", { toolName });
|
|
47
|
+
return this.toolSchemaCache.get(toolName);
|
|
48
|
+
}
|
|
49
|
+
// Fetch from MCP server
|
|
50
|
+
logger.info("Fetching full schema for tool on-demand", { toolName });
|
|
51
|
+
const url = `${mcpServerUrl}${mcpServerUrl.includes("?") ? "&" : "?"}apiKey=${mcpServerApiKey}`;
|
|
52
|
+
const response = await fetch(url, {
|
|
53
|
+
method: "POST",
|
|
54
|
+
headers: {
|
|
55
|
+
"Content-Type": "application/json",
|
|
56
|
+
Accept: "application/json, text/event-stream",
|
|
57
|
+
},
|
|
58
|
+
body: JSON.stringify({
|
|
59
|
+
jsonrpc: "2.0",
|
|
60
|
+
id: 1,
|
|
61
|
+
method: "tools/get_schema",
|
|
62
|
+
params: { name: toolName },
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
throw new Error(`MCP server responded with ${response.status}: ${response.statusText}`);
|
|
67
|
+
}
|
|
68
|
+
// Parse SSE response
|
|
69
|
+
const responseText = await response.text();
|
|
70
|
+
const lines = responseText.split("\n");
|
|
71
|
+
let jsonData = null;
|
|
72
|
+
for (const line of lines) {
|
|
73
|
+
if (line.startsWith("data: ")) {
|
|
74
|
+
try {
|
|
75
|
+
jsonData = JSON.parse(line.substring(6));
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
// Skip non-JSON lines
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!jsonData) {
|
|
84
|
+
throw new Error("Failed to parse MCP server response");
|
|
85
|
+
}
|
|
86
|
+
if (jsonData.error) {
|
|
87
|
+
throw new Error(`MCP server error: ${jsonData.error.message || jsonData.error}`);
|
|
88
|
+
}
|
|
89
|
+
const schema = jsonData.result;
|
|
90
|
+
// Cache the schema
|
|
91
|
+
this.toolSchemaCache.set(toolName, schema);
|
|
92
|
+
logger.debug("Cached tool schema", { toolName });
|
|
93
|
+
return schema;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Convert tool index to minimal tool definitions (stubs)
|
|
97
|
+
* Full schemas will be loaded on-demand when needed
|
|
98
|
+
* Returns any[] to allow provider-specific extensions (like Anthropic's cache_control)
|
|
99
|
+
*/
|
|
100
|
+
toMinimalToolDefinitions(toolIndex) {
|
|
101
|
+
return toolIndex.map((tool, index) => {
|
|
102
|
+
const toolDef = {
|
|
103
|
+
name: tool.name,
|
|
104
|
+
description: tool.description,
|
|
105
|
+
input_schema: {
|
|
106
|
+
type: "object",
|
|
107
|
+
properties: {},
|
|
108
|
+
required: [],
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
// Add cache control to last tool for Anthropic prompt caching
|
|
112
|
+
if (index === toolIndex.length - 1) {
|
|
113
|
+
toolDef.cache_control = { type: "ephemeral" };
|
|
114
|
+
}
|
|
115
|
+
return toolDef;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get count of loaded schemas
|
|
120
|
+
*/
|
|
121
|
+
getLoadedSchemaCount() {
|
|
122
|
+
return this.toolSchemaCache.size;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Clear schema cache
|
|
126
|
+
*/
|
|
127
|
+
clearCache() {
|
|
128
|
+
this.toolSchemaCache.clear();
|
|
129
|
+
logger.debug("Tool schema cache cleared");
|
|
130
|
+
}
|
|
131
|
+
// ===== PRIVATE METHODS =====
|
|
132
|
+
/**
|
|
133
|
+
* Fetch tool index from MCP server
|
|
134
|
+
*/
|
|
135
|
+
async fetchMcpToolIndex(mcpServerUrl, mcpServerApiKey, allowedGroups) {
|
|
136
|
+
const url = `${mcpServerUrl}${mcpServerUrl.includes("?") ? "&" : "?"}apiKey=${mcpServerApiKey}`;
|
|
137
|
+
const response = await fetch(url, {
|
|
138
|
+
method: "POST",
|
|
139
|
+
headers: {
|
|
140
|
+
"Content-Type": "application/json",
|
|
141
|
+
Accept: "application/json, text/event-stream",
|
|
142
|
+
},
|
|
143
|
+
body: JSON.stringify({
|
|
144
|
+
jsonrpc: "2.0",
|
|
145
|
+
id: 1,
|
|
146
|
+
method: "tools/list",
|
|
147
|
+
params: allowedGroups ? { groups: allowedGroups } : {},
|
|
148
|
+
}),
|
|
149
|
+
});
|
|
150
|
+
if (!response.ok) {
|
|
151
|
+
throw new Error(`MCP server responded with ${response.status}: ${response.statusText}`);
|
|
152
|
+
}
|
|
153
|
+
// Parse SSE response format
|
|
154
|
+
const responseText = await response.text();
|
|
155
|
+
const lines = responseText.split("\n");
|
|
156
|
+
let jsonData = null;
|
|
157
|
+
for (const line of lines) {
|
|
158
|
+
if (line.startsWith("data: ")) {
|
|
159
|
+
try {
|
|
160
|
+
jsonData = JSON.parse(line.substring(6));
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
// Skip non-JSON lines
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (!jsonData) {
|
|
169
|
+
throw new Error("Failed to parse MCP server response");
|
|
170
|
+
}
|
|
171
|
+
if (jsonData.error) {
|
|
172
|
+
throw new Error(`MCP server error: ${jsonData.error.message || jsonData.error}`);
|
|
173
|
+
}
|
|
174
|
+
return jsonData.result.tools;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.ToolSchemaLoader = ToolSchemaLoader;
|
|
178
|
+
//# sourceMappingURL=tool-schema-loader.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Client Types
|
|
3
|
+
* Defines interfaces for the MCP client system that supports multiple LLM providers
|
|
4
|
+
*/
|
|
5
|
+
import { HailerSignal } from "../mcp/signal-handler";
|
|
6
|
+
export interface McpClientConfig {
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
mcpServerUrl: string;
|
|
9
|
+
mcpServerApiKey: string;
|
|
10
|
+
providers: LlmProviderConfig[];
|
|
11
|
+
mcpAgentIds: string[];
|
|
12
|
+
botConfigs: BotClientConfig[];
|
|
13
|
+
enableDirectMessages: boolean;
|
|
14
|
+
tokenUsageBotEnabled: boolean;
|
|
15
|
+
agentActivityBotEnabled: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface LlmProviderConfig {
|
|
18
|
+
name: string;
|
|
19
|
+
type: "openai" | "anthropic" | "gemini";
|
|
20
|
+
apiKey: string;
|
|
21
|
+
model: string;
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
maxTokens?: number;
|
|
24
|
+
temperature?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ChatMessage {
|
|
27
|
+
id: string;
|
|
28
|
+
content: string;
|
|
29
|
+
timestamp: number;
|
|
30
|
+
discussionId: string;
|
|
31
|
+
userId: string;
|
|
32
|
+
userName: string;
|
|
33
|
+
workspaceId?: string;
|
|
34
|
+
mentionedOrDirectMessagedBotId: string;
|
|
35
|
+
}
|
|
36
|
+
export interface McpResponse {
|
|
37
|
+
success: boolean;
|
|
38
|
+
messageId?: string;
|
|
39
|
+
toolCalls?: ToolCallInfo[];
|
|
40
|
+
response?: string;
|
|
41
|
+
error?: string;
|
|
42
|
+
tokens?: {
|
|
43
|
+
input: number;
|
|
44
|
+
output: number;
|
|
45
|
+
total: number;
|
|
46
|
+
cacheCreation?: number;
|
|
47
|
+
cacheRead?: number;
|
|
48
|
+
cost?: number;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface ToolCallInfo {
|
|
52
|
+
toolName: string;
|
|
53
|
+
args: any;
|
|
54
|
+
result?: any;
|
|
55
|
+
error?: string;
|
|
56
|
+
duration?: number;
|
|
57
|
+
}
|
|
58
|
+
export interface MessageProcessor {
|
|
59
|
+
shouldProcess(signal: HailerSignal): boolean;
|
|
60
|
+
extractMessage(signal: HailerSignal): Promise<ChatMessage[]>;
|
|
61
|
+
postMessage(discussionId: string, content: string, workspaceId?: string, botId?: string): Promise<boolean>;
|
|
62
|
+
}
|
|
63
|
+
export interface BotClientConfig {
|
|
64
|
+
email: string;
|
|
65
|
+
password: string;
|
|
66
|
+
apiBaseUrl: string;
|
|
67
|
+
mcpServerApiKey: string;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Universal Application Configuration
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth that replaces all scattered config files:
|
|
5
|
+
* - lib/env.ts - Environment variable loading
|
|
6
|
+
* - mcp/config.ts - getClientConfig() function
|
|
7
|
+
* - client/config.ts - Client configuration creation
|
|
8
|
+
* - mcp/mcp-config.ts - MCP context optimization settings
|
|
9
|
+
*
|
|
10
|
+
* Key Features:
|
|
11
|
+
* - Map-based CLIENT_CONFIGS for O(1) API key lookups
|
|
12
|
+
* - Preserves existing excellent connection architecture
|
|
13
|
+
* - Comprehensive Zod validation with clear error messages
|
|
14
|
+
* - Development defaults for seamless local setup
|
|
15
|
+
*/
|
|
16
|
+
import { ToolGroup } from './mcp/tool-registry';
|
|
17
|
+
/**
|
|
18
|
+
* Validated environment - single source of truth
|
|
19
|
+
*/
|
|
20
|
+
export declare const environment: {
|
|
21
|
+
NODE_ENV: "production" | "development" | "test";
|
|
22
|
+
LOG_LEVEL: "error" | "debug" | "info" | "warn";
|
|
23
|
+
DISABLE_MCP_SERVER: boolean;
|
|
24
|
+
MCP_CLIENT_ENABLED: boolean;
|
|
25
|
+
ENABLE_NUCLEAR_TOOLS: boolean;
|
|
26
|
+
PORT: number;
|
|
27
|
+
CORS_ORIGINS: string[];
|
|
28
|
+
CLIENT_CONFIGS: Record<string, {
|
|
29
|
+
email: string;
|
|
30
|
+
password: string;
|
|
31
|
+
apiBaseUrl: string;
|
|
32
|
+
}>;
|
|
33
|
+
MCP_SERVER_URL: string;
|
|
34
|
+
MCP_CLIENT_API_KEY: string;
|
|
35
|
+
MCP_CLIENT_AGENT_IDS: string[];
|
|
36
|
+
TOKEN_USAGE_BOT_ENABLED: boolean;
|
|
37
|
+
AGENT_ACTIVITY_BOT_ENABLED: boolean;
|
|
38
|
+
ADAPTIVE_DOCUMENTATION_BOT_ENABLED: boolean;
|
|
39
|
+
ADAPTIVE_AUTO_UPDATE: boolean;
|
|
40
|
+
ADAPTIVE_UPDATE_INTERVAL: number;
|
|
41
|
+
ADAPTIVE_MIN_ERROR_COUNT: number;
|
|
42
|
+
ADAPTIVE_SKILL_GENERATION: boolean;
|
|
43
|
+
MCP_EXCLUDE_TRANSLATIONS: boolean;
|
|
44
|
+
MCP_COMPACT_DATA: boolean;
|
|
45
|
+
MCP_INCLUDE_WORKSPACE_NAMES: boolean;
|
|
46
|
+
CONTEXT_SAFETY_MARGIN_PERCENT: number;
|
|
47
|
+
CONTEXT_ENABLE_AUTO_SUMMARIZATION: boolean;
|
|
48
|
+
CONTEXT_MAX_SUMMARIZATION_CHUNKS: number;
|
|
49
|
+
WORKSPACE_CONFIG_PATH?: string | undefined;
|
|
50
|
+
DEV_APPS_PATH?: string | undefined;
|
|
51
|
+
OPENAI_API_KEY?: string | undefined;
|
|
52
|
+
ANTHROPIC_API_KEY?: string | undefined;
|
|
53
|
+
};
|
|
54
|
+
export interface HailerAccount {
|
|
55
|
+
email: string;
|
|
56
|
+
password: string;
|
|
57
|
+
apiBaseUrl: string;
|
|
58
|
+
allowedTools?: string[];
|
|
59
|
+
allowedGroups?: ToolGroup[];
|
|
60
|
+
}
|
|
61
|
+
export interface LlmProvider {
|
|
62
|
+
name: string;
|
|
63
|
+
type: 'openai' | 'anthropic';
|
|
64
|
+
apiKey: string;
|
|
65
|
+
model: string;
|
|
66
|
+
enabled: boolean;
|
|
67
|
+
}
|
|
68
|
+
export interface ServerConfig {
|
|
69
|
+
port: number;
|
|
70
|
+
corsOrigins: string[];
|
|
71
|
+
enableMcpServer: boolean;
|
|
72
|
+
enableClient: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** MCP context optimization settings (replaces mcp-config.ts exports) */
|
|
75
|
+
export interface McpConfig {
|
|
76
|
+
excludeTranslations: boolean;
|
|
77
|
+
excludeSystemMessages: boolean;
|
|
78
|
+
excludeEmptyFields: boolean;
|
|
79
|
+
compactUserData: boolean;
|
|
80
|
+
includeWorkspaceNamesInTools: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** Context management configuration */
|
|
83
|
+
export interface ContextConfig {
|
|
84
|
+
safetyMarginPercent: number;
|
|
85
|
+
enableAutoSummarization: boolean;
|
|
86
|
+
maxSummarizationChunks: number;
|
|
87
|
+
}
|
|
88
|
+
/** MCP Client configuration (replaces client/config.ts exports) */
|
|
89
|
+
export interface McpClientConfig {
|
|
90
|
+
enabled: boolean;
|
|
91
|
+
mcpServerUrl: string;
|
|
92
|
+
mcpServerApiKey: string;
|
|
93
|
+
providers: LlmProvider[];
|
|
94
|
+
mcpAgentIds: string[];
|
|
95
|
+
botConfigs: BotClientConfig[];
|
|
96
|
+
enableDirectMessages: boolean;
|
|
97
|
+
tokenUsageBotEnabled: boolean;
|
|
98
|
+
agentActivityBotEnabled: boolean;
|
|
99
|
+
}
|
|
100
|
+
/** Bot client configuration for MultiBotManager compatibility */
|
|
101
|
+
export interface BotClientConfig {
|
|
102
|
+
email: string;
|
|
103
|
+
password: string;
|
|
104
|
+
apiBaseUrl: string;
|
|
105
|
+
mcpServerApiKey: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Universal Application Configuration
|
|
109
|
+
*
|
|
110
|
+
* Single class that provides all configuration for the entire application.
|
|
111
|
+
* Replaces all scattered config files with one clean interface.
|
|
112
|
+
*/
|
|
113
|
+
export declare class ApplicationConfig {
|
|
114
|
+
constructor();
|
|
115
|
+
get server(): ServerConfig;
|
|
116
|
+
/**
|
|
117
|
+
* Efficient Map-based Hailer accounts (replaces CLIENT_CONFIGS array)
|
|
118
|
+
*/
|
|
119
|
+
get hailerAccounts(): Record<string, HailerAccount>;
|
|
120
|
+
get llmProviders(): LlmProvider[];
|
|
121
|
+
/**
|
|
122
|
+
* MCP context optimization settings
|
|
123
|
+
*/
|
|
124
|
+
get mcpConfig(): McpConfig;
|
|
125
|
+
/**
|
|
126
|
+
* Context management settings for token limits and summarization
|
|
127
|
+
*/
|
|
128
|
+
get contextConfig(): ContextConfig;
|
|
129
|
+
/**
|
|
130
|
+
* Adaptive Documentation Bot configuration
|
|
131
|
+
*/
|
|
132
|
+
get adaptiveDocumentation(): {
|
|
133
|
+
enabled: boolean;
|
|
134
|
+
autoUpdate: boolean;
|
|
135
|
+
updateInterval: number;
|
|
136
|
+
minErrorCount: number;
|
|
137
|
+
skillGeneration: boolean;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Create MCP Client configuration (replaces createMcpClientConfig())
|
|
141
|
+
*/
|
|
142
|
+
get mcpClient(): McpClientConfig | null;
|
|
143
|
+
/**
|
|
144
|
+
* Find account by API key - O(1) lookup (replaces getClientConfig())
|
|
145
|
+
* This is the key efficiency improvement that eliminates array filtering
|
|
146
|
+
*/
|
|
147
|
+
getClientConfig(apiKey: string | null): HailerAccount;
|
|
148
|
+
/**
|
|
149
|
+
* Alternative method with null return (safer)
|
|
150
|
+
*/
|
|
151
|
+
findAccountByApiKey(apiKey: string): HailerAccount | null;
|
|
152
|
+
/**
|
|
153
|
+
* Get enabled LLM providers only
|
|
154
|
+
*/
|
|
155
|
+
getEnabledLlmProviders(): LlmProvider[];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Create application configuration
|
|
159
|
+
* Configuration is determined by environment variables (DISABLE_MCP_SERVER, MCP_CLIENT_ENABLED)
|
|
160
|
+
*/
|
|
161
|
+
export declare function createApplicationConfig(): ApplicationConfig;
|
|
162
|
+
//# sourceMappingURL=config.d.ts.map
|