Skip to content

Commit 1cb339d

Browse files
Most tests passing
1 parent 52232e2 commit 1cb339d

File tree

8 files changed

+349
-237
lines changed

8 files changed

+349
-237
lines changed

src/server/TaskManager.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,23 @@ export class TaskManager {
232232
});
233233
return await this.createProject(prompt, object.tasks, object.projectPlan);
234234
} catch (err: any) {
235-
// Handle specific error cases
236-
if (err.name === 'LoadAPIKeyError' || err.message.includes('API key is missing')) {
235+
if (err.name === 'LoadAPIKeyError' ||
236+
err.message.includes('API key is missing') ||
237+
err.message.includes('You didn\'t provide an API key') ||
238+
err.message.includes('unregistered callers') ||
239+
(err.responseBody && err.responseBody.includes('Authentication Fails'))) {
237240
throw new AppError(
238-
"Invalid or missing API key. Please check your environment variables.",
239-
AppErrorCode.LLMConfigurationError,
241+
`Missing API key environment variable required for ${provider}`,
242+
AppErrorCode.ConfigurationError,
240243
err
241244
);
242245
}
243-
if (err.message.includes('authentication') || err.message.includes('unauthorized')) {
246+
// Check for invalid model errors by looking at the error code, type, and message
247+
if ((err.data?.error?.code === 'model_not_found') &&
248+
err.message.includes('model')) {
244249
throw new AppError(
245-
"Authentication failed with the LLM provider. Please check your credentials.",
246-
AppErrorCode.LLMConfigurationError,
250+
`Invalid model: ${model} is not available for ${provider}`,
251+
AppErrorCode.InvalidModel,
247252
err
248253
);
249254
}
@@ -584,6 +589,7 @@ export class TaskManager {
584589
initialPrompt: project.initialPrompt,
585590
projectPlan: project.projectPlan,
586591
completed: project.completed,
592+
autoApprove: project.autoApprove,
587593
tasks: project.tasks,
588594
};
589595
}

src/server/toolExecutors.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -190,23 +190,6 @@ const generateProjectPlanToolExecutor: ToolExecutor = {
190190
const provider = validateRequiredStringParam(args.provider, "provider");
191191
const model = validateRequiredStringParam(args.model, "model");
192192

193-
// Validate provider is one of the allowed values
194-
if (!["openai", "google", "deepseek"].includes(provider)) {
195-
throw new AppError(
196-
`Invalid provider: ${provider}. Must be one of: openai, google, deepseek`,
197-
AppErrorCode.InvalidArgument
198-
);
199-
}
200-
201-
// Check that the corresponding API key is set
202-
const envKey = provider === "google" ? "GOOGLE_GENERATIVE_AI_API_KEY" : `${provider.toUpperCase()}_API_KEY`;
203-
if (!process.env[envKey]) {
204-
throw new AppError(
205-
`Missing ${envKey} environment variable required for ${provider}`,
206-
AppErrorCode.ConfigurationError
207-
);
208-
}
209-
210193
// Validate optional attachments
211194
let attachments: string[] = [];
212195
if (args.attachments !== undefined) {

src/types/errors.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
export enum AppErrorCode {
33
// Protocol Errors (ERR_1xxx)
44
MissingParameter = 'ERR_1000', // General missing param (mapped to protocol -32602)
5-
InvalidArgument = 'ERR_1002', // Extra / invalid param (mapped to protocol -32602)
5+
InvalidArgument = 'ERR_1002', // Extra param / invalid type (mapped to protocol -32602)
66

77
// Validation / Resource Not Found (ERR_2xxx)
88
ConfigurationError = 'ERR_2000', // e.g., Missing API Key for generate_project_plan
99
ProjectNotFound = 'ERR_2001',
1010
TaskNotFound = 'ERR_2002',
1111
InvalidState = 'ERR_2003', // e.g., invalid state filter
1212
InvalidProvider = 'ERR_2004', // e.g., invalid model provider
13+
InvalidModel = 'ERR_2005', // e.g., invalid model name or model not accessible
1314

1415
// No need for EmptyTaskFile code, handle during load
1516

src/types/response.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface ProjectCreationSuccessData {
6161
initialPrompt: string;
6262
projectPlan: string;
6363
completed: boolean;
64+
autoApprove?: boolean;
6465
tasks: Task[];
6566
}
6667

tests/mcp/test-helpers.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export interface TestContext {
2424
/**
2525
* Sets up a test context with MCP client, transport, and temp directory
2626
*/
27-
export async function setupTestContext(customFilePath?: string, skipFileInit: boolean = false): Promise<TestContext> {
27+
export async function setupTestContext(
28+
customFilePath?: string,
29+
skipFileInit: boolean = false,
30+
customEnv?: Record<string, string>
31+
): Promise<TestContext> {
2832
// Create a unique temp directory for test
2933
const tempDir = path.join(os.tmpdir(), `mcp-client-integration-test-${Date.now()}-${Math.floor(Math.random() * 10000)}`);
3034
await fs.mkdir(tempDir, { recursive: true });
@@ -46,9 +50,12 @@ export async function setupTestContext(customFilePath?: string, skipFileInit: bo
4650
TASK_MANAGER_FILE_PATH: testFilePath,
4751
NODE_ENV: "test",
4852
DEBUG: "mcp:*", // Enable MCP debug logging
49-
// Pass API keys from the test runner's env to the child process env
50-
OPENAI_API_KEY: process.env.OPENAI_API_KEY ?? '',
51-
GOOGLE_GENERATIVE_AI_API_KEY: process.env.GOOGLE_GENERATIVE_AI_API_KEY ?? ''
53+
// Use custom env if provided, otherwise use default API keys
54+
...(customEnv || {
55+
OPENAI_API_KEY: process.env.OPENAI_API_KEY ?? '',
56+
GOOGLE_GENERATIVE_AI_API_KEY: process.env.GOOGLE_GENERATIVE_AI_API_KEY ?? '',
57+
DEEPSEEK_API_KEY: process.env.DEEPSEEK_API_KEY ?? ''
58+
})
5259
}
5360
});
5461

0 commit comments

Comments
 (0)