@auto-engineer/ai-gateway 0.4.2 → 0.4.5
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/.turbo/turbo-build.log +6 -5
- package/.turbo/turbo-format.log +14 -12
- package/.turbo/turbo-lint.log +5 -4
- package/.turbo/turbo-test.log +8 -15
- package/.turbo/turbo-type-check.log +1 -1
- package/CHANGELOG.md +6 -0
- package/DEBUG.md +212 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +35 -8
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +270 -88
- package/dist/index.js.map +1 -1
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +46 -6
- package/dist/mcp-server.js.map +1 -1
- package/package.json +2 -1
- package/src/config.ts +46 -9
- package/src/index.ts +340 -104
- package/src/mcp-server.ts +49 -6
- package/tsconfig.tsbuildinfo +1 -1
package/dist/mcp-server.js
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import createDebug from 'debug';
|
|
5
|
+
const debug = createDebug('ai-gateway:mcp');
|
|
6
|
+
const debugServer = createDebug('ai-gateway:mcp:server');
|
|
7
|
+
const debugTools = createDebug('ai-gateway:mcp:tools');
|
|
8
|
+
const debugRegistry = createDebug('ai-gateway:mcp:registry');
|
|
9
|
+
const debugExecution = createDebug('ai-gateway:mcp:execution');
|
|
10
|
+
debugServer('Creating MCP server instance - name: frontend-implementation, version: 0.1.0');
|
|
4
11
|
const server = new McpServer({
|
|
5
12
|
name: 'frontend-implementation',
|
|
6
13
|
version: '0.1.0',
|
|
7
14
|
});
|
|
8
15
|
const transport = new StdioServerTransport();
|
|
16
|
+
debugServer('StdioServerTransport created');
|
|
9
17
|
let isStarted = false;
|
|
10
18
|
const toolRegistry = new Map();
|
|
19
|
+
debugRegistry('Tool registry initialized');
|
|
11
20
|
async function cleanup() {
|
|
21
|
+
debug('Cleanup initiated');
|
|
12
22
|
console.log('Cleaning up...');
|
|
13
23
|
await transport.close();
|
|
24
|
+
debugServer('Transport closed');
|
|
14
25
|
process.exit(0);
|
|
15
26
|
}
|
|
16
27
|
process.on('SIGTERM', () => {
|
|
@@ -22,26 +33,31 @@ process.on('SIGINT', () => {
|
|
|
22
33
|
export { server };
|
|
23
34
|
function createMcpHandler(handler) {
|
|
24
35
|
return (args, _extra) => {
|
|
36
|
+
debugExecution('MCP handler invoked with args: %o', args);
|
|
25
37
|
return handler(args);
|
|
26
38
|
};
|
|
27
39
|
}
|
|
28
40
|
function createAiSdkTool(description, handler) {
|
|
29
41
|
const parameterSchema = Object.keys(description.inputSchema).length > 0 ? z.object(description.inputSchema) : z.object({}).passthrough();
|
|
42
|
+
debugTools('Creating AI SDK tool with %d parameters', Object.keys(description.inputSchema).length);
|
|
30
43
|
return {
|
|
31
44
|
parameters: parameterSchema,
|
|
32
45
|
description: description.description,
|
|
33
46
|
execute: async (args) => {
|
|
47
|
+
debugExecution('AI SDK tool execute called with args: %o', args);
|
|
34
48
|
const result = await handler(args);
|
|
35
49
|
const textOutput = result.content[0]?.text || '';
|
|
50
|
+
debugExecution('Tool execution result length: %d', textOutput.length);
|
|
36
51
|
// If a schema is provided, parse and validate the JSON output
|
|
37
52
|
if (description.schema) {
|
|
38
53
|
try {
|
|
39
54
|
const parsed = JSON.parse(textOutput);
|
|
40
55
|
description.schema.parse(parsed);
|
|
56
|
+
debugExecution('Tool output validated against schema successfully');
|
|
41
57
|
return textOutput; // Return original text output for consistency
|
|
42
58
|
}
|
|
43
59
|
catch (parseError) {
|
|
44
|
-
|
|
60
|
+
debugExecution('Tool failed to parse/validate JSON output: %O', parseError);
|
|
45
61
|
return textOutput; // Fallback to raw text
|
|
46
62
|
}
|
|
47
63
|
}
|
|
@@ -53,8 +69,10 @@ function createAiSdkTool(description, handler) {
|
|
|
53
69
|
};
|
|
54
70
|
}
|
|
55
71
|
export function registerTool(name, description, handler) {
|
|
72
|
+
debugRegistry('Registering MCP tool: %s', name);
|
|
56
73
|
console.log(`🔧 Registering MCP tool: ${name}`);
|
|
57
74
|
if (isStarted) {
|
|
75
|
+
debugRegistry('ERROR: Cannot register tool %s after server has started', name);
|
|
58
76
|
throw new Error('Cannot register tools after server has started');
|
|
59
77
|
}
|
|
60
78
|
const mcpHandler = createMcpHandler(handler);
|
|
@@ -67,55 +85,77 @@ export function registerTool(name, description, handler) {
|
|
|
67
85
|
};
|
|
68
86
|
toolRegistry.set(name, registeredTool);
|
|
69
87
|
server.registerTool(name, description, mcpHandler);
|
|
88
|
+
debugRegistry('Tool %s registered successfully. Total tools: %d', name, toolRegistry.size);
|
|
70
89
|
console.log(`✅ Tool ${name} registered successfully. Total tools: ${toolRegistry.size}`);
|
|
71
90
|
}
|
|
72
91
|
export function registerTools(tools) {
|
|
92
|
+
debugRegistry('Batch registering %d tools', tools.length);
|
|
73
93
|
if (isStarted) {
|
|
94
|
+
debugRegistry('ERROR: Cannot register tools after server has started');
|
|
74
95
|
throw new Error('Cannot register tools after server has started');
|
|
75
96
|
}
|
|
76
97
|
tools.forEach((tool) => {
|
|
77
98
|
registerTool(tool.name, tool.description, tool.handler);
|
|
78
99
|
});
|
|
100
|
+
debugRegistry('Batch registration complete');
|
|
79
101
|
}
|
|
80
102
|
export async function startServer() {
|
|
81
|
-
if (isStarted)
|
|
103
|
+
if (isStarted) {
|
|
104
|
+
debugServer('Server already started, skipping');
|
|
82
105
|
return;
|
|
106
|
+
}
|
|
107
|
+
debugServer('Starting MCP server...');
|
|
83
108
|
await server.connect(transport);
|
|
84
109
|
isStarted = true;
|
|
110
|
+
debugServer('MCP server started successfully');
|
|
85
111
|
}
|
|
86
112
|
export function isServerStarted() {
|
|
113
|
+
debugServer('Checking server status: %s', isStarted ? 'started' : 'not started');
|
|
87
114
|
return isStarted;
|
|
88
115
|
}
|
|
89
116
|
export function getRegisteredTools() {
|
|
90
|
-
|
|
117
|
+
const tools = Array.from(toolRegistry.values());
|
|
118
|
+
debugRegistry('Getting all registered tools: %d tools', tools.length);
|
|
119
|
+
return tools;
|
|
91
120
|
}
|
|
92
121
|
export function getRegisteredToolsForAI() {
|
|
122
|
+
debugRegistry('Getting registered tools for AI. Registry size: %d', toolRegistry.size);
|
|
93
123
|
console.log(`📋 Getting registered tools for AI. Registry size: ${toolRegistry.size}`);
|
|
94
124
|
const tools = {};
|
|
95
125
|
for (const tool of toolRegistry.values()) {
|
|
96
126
|
tools[tool.name] = tool.aiSdkTool;
|
|
127
|
+
debugRegistry(' - Tool: %s', tool.name);
|
|
97
128
|
console.log(` - Tool: ${tool.name}`);
|
|
98
129
|
}
|
|
130
|
+
debugRegistry('Returning %d tools for AI', Object.keys(tools).length);
|
|
99
131
|
console.log(`📊 Returning ${Object.keys(tools).length} tools for AI`);
|
|
100
132
|
return tools;
|
|
101
133
|
}
|
|
102
134
|
export function getToolHandler(name) {
|
|
103
|
-
|
|
135
|
+
const handler = toolRegistry.get(name)?.handler;
|
|
136
|
+
debugRegistry('Getting tool handler for %s: %s', name, handler ? 'found' : 'not found');
|
|
137
|
+
return handler;
|
|
104
138
|
}
|
|
105
139
|
export async function executeRegisteredTool(name, params) {
|
|
140
|
+
debugExecution('Executing registered tool: %s with params: %o', name, params);
|
|
106
141
|
const tool = toolRegistry.get(name);
|
|
107
142
|
if (!tool) {
|
|
143
|
+
debugExecution('ERROR: Tool %s not found', name);
|
|
108
144
|
throw new Error(`Tool '${name}' not found`);
|
|
109
145
|
}
|
|
110
|
-
|
|
146
|
+
const result = await tool.handler(params);
|
|
147
|
+
debugExecution('Tool %s executed successfully', name);
|
|
148
|
+
return result;
|
|
111
149
|
}
|
|
112
150
|
export function getSchemaByName(schemaName) {
|
|
113
|
-
|
|
151
|
+
debugRegistry('Looking for schema with name: %s', schemaName);
|
|
114
152
|
for (const tool of toolRegistry.values()) {
|
|
115
153
|
if (tool.description?.schemaName === schemaName) {
|
|
154
|
+
debugRegistry('Schema %s found in tool %s', schemaName, tool.name);
|
|
116
155
|
return tool.description.schema;
|
|
117
156
|
}
|
|
118
157
|
}
|
|
158
|
+
debugRegistry('Schema %s not found', schemaName);
|
|
119
159
|
return undefined;
|
|
120
160
|
}
|
|
121
161
|
//# sourceMappingURL=mcp-server.js.map
|
package/dist/mcp-server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,WAAW,MAAM,OAAO,CAAC;AAEhC,MAAM,KAAK,GAAG,WAAW,CAAC,gBAAgB,CAAC,CAAC;AAC5C,MAAM,WAAW,GAAG,WAAW,CAAC,uBAAuB,CAAC,CAAC;AACzD,MAAM,UAAU,GAAG,WAAW,CAAC,sBAAsB,CAAC,CAAC;AACvD,MAAM,aAAa,GAAG,WAAW,CAAC,yBAAyB,CAAC,CAAC;AAC7D,MAAM,cAAc,GAAG,WAAW,CAAC,0BAA0B,CAAC,CAAC;AAiC/D,WAAW,CAAC,8EAA8E,CAAC,CAAC;AAC5F,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAC3B,IAAI,EAAE,yBAAyB;IAC/B,OAAO,EAAE,OAA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AAI,CAAC,WAAW,EAAE,UAAU,KAAK,UAAU,EAAE,CAAC;YAChD,aAAa,CAAC,4BAA4B,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YACnE,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QACjC,CAAC;IACH,CAAC;IACD,aAAa,CAAC,qBAAqB,EAAE,UAAU,CAAC,CAAC;IACjD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auto-engineer/ai-gateway",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@ai-sdk/xai": "^1.2.16",
|
|
31
31
|
"@modelcontextprotocol/sdk": "^1.3.0",
|
|
32
32
|
"ai": "^4.3.16",
|
|
33
|
+
"debug": "^4.4.0",
|
|
33
34
|
"dotenv": "^16.4.5",
|
|
34
35
|
"zod": "^3.25.67"
|
|
35
36
|
},
|
package/src/config.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import dotenv from 'dotenv';
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
3
|
import { dirname, resolve } from 'path';
|
|
4
|
+
import createDebug from 'debug';
|
|
5
|
+
|
|
6
|
+
const debug = createDebug('ai-gateway:config');
|
|
7
|
+
const debugEnv = createDebug('ai-gateway:config:env');
|
|
8
|
+
|
|
4
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
5
10
|
const __dirname = dirname(__filename);
|
|
6
|
-
|
|
11
|
+
const envPath = resolve(__dirname, '../../../.env');
|
|
12
|
+
debug('Loading environment from: %s', envPath);
|
|
13
|
+
dotenv.config({ path: envPath });
|
|
7
14
|
|
|
8
15
|
export interface AIConfig {
|
|
9
16
|
openai?: {
|
|
@@ -20,20 +27,50 @@ export interface AIConfig {
|
|
|
20
27
|
};
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
// Helper to log provider configuration
|
|
31
|
+
function logProviderConfig(providerName: string, apiKey: string | undefined): void {
|
|
32
|
+
if (apiKey !== undefined) {
|
|
33
|
+
debug('%s provider configured with API key ending in: ...%s', providerName, apiKey.slice(-4));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Helper to build provider config
|
|
38
|
+
function buildProviderConfig(): AIConfig {
|
|
39
|
+
return {
|
|
25
40
|
openai: process.env.OPENAI_API_KEY != null ? { apiKey: process.env.OPENAI_API_KEY } : undefined,
|
|
26
41
|
anthropic: process.env.ANTHROPIC_API_KEY != null ? { apiKey: process.env.ANTHROPIC_API_KEY } : undefined,
|
|
27
|
-
google:
|
|
28
|
-
process.env.GOOGLE_GENERATIVE_AI_API_KEY != null
|
|
29
|
-
? { apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY }
|
|
30
|
-
: undefined,
|
|
42
|
+
google: process.env.GEMINI_API_KEY != null ? { apiKey: process.env.GEMINI_API_KEY } : undefined,
|
|
31
43
|
xai: process.env.XAI_API_KEY != null ? { apiKey: process.env.XAI_API_KEY } : undefined,
|
|
32
44
|
};
|
|
33
|
-
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function configureAIProvider(): AIConfig {
|
|
48
|
+
debugEnv('Checking environment variables for AI providers');
|
|
49
|
+
|
|
50
|
+
const config = buildProviderConfig();
|
|
51
|
+
|
|
52
|
+
// Log which providers are configured (without exposing keys)
|
|
53
|
+
debugEnv('OpenAI configured: %s', config.openai != null);
|
|
54
|
+
debugEnv('Anthropic configured: %s', config.anthropic != null);
|
|
55
|
+
debugEnv('Google configured: %s', config.google != null);
|
|
56
|
+
debugEnv('XAI configured: %s', config.xai != null);
|
|
57
|
+
|
|
58
|
+
// Log provider configurations
|
|
59
|
+
logProviderConfig('OpenAI', config.openai?.apiKey);
|
|
60
|
+
logProviderConfig('Anthropic', config.anthropic?.apiKey);
|
|
61
|
+
logProviderConfig('Google', config.google?.apiKey);
|
|
62
|
+
logProviderConfig('XAI', config.xai?.apiKey);
|
|
63
|
+
|
|
64
|
+
const configuredProviders = [config.openai, config.anthropic, config.google, config.xai].filter((p) => p != null);
|
|
65
|
+
|
|
66
|
+
if (configuredProviders.length === 0) {
|
|
67
|
+
debug('ERROR: No AI providers configured');
|
|
34
68
|
throw new Error(
|
|
35
|
-
'At least one AI provider must be configured. Please set OPENAI_API_KEY, ANTHROPIC_API_KEY,
|
|
69
|
+
'At least one AI provider must be configured. Please set OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY, or XAI_API_KEY environment variables.',
|
|
36
70
|
);
|
|
37
71
|
}
|
|
72
|
+
|
|
73
|
+
debug('AI configuration complete - %d provider(s) available', configuredProviders.length);
|
|
74
|
+
|
|
38
75
|
return config;
|
|
39
76
|
}
|