You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Explanation of Error Flow and Transformations:**
47
-
48
-
Errors primarily originate from two places:
49
-
50
-
1. **Core Logic (`TaskManager`, `FileSystemService`):** These modules throw standard JavaScript `Error` objects, often subclassed (e.g., `ProjectNotFoundError`, `FileReadError`) but *without* any special MCP/JSON-RPC tagging (`jsonRpcCode`). These represent application-specific or file system problems.
51
-
2. **Tool Executors (`toolExecutors.ts`) Validation:** Before calling `TaskManager`, the executors validate input arguments. If validation fails, they create a *new* `Error` object and explicitly *tag* it with `jsonRpcCode = -32602` (Invalid Params).
52
-
53
-
The handling differs significantly between the CLI and the MCP Server:
54
-
55
-
**1. CLI Error Path (`cli.ts`)**
56
-
57
-
1. **Origination:** An untagged application error (e.g., `ProjectNotFoundError`) is thrown by `TaskManager`.
58
-
2. **Propagation:** The error propagates directly up the call stack to the `catch` block within the specific command's action handler in `cli.ts`.
59
-
3. **Transformation (`formatCliError`):**
60
-
* The `catch` block calls `formatCliError` from `src/client/errors.ts`.
61
-
* `formatCliError` takes the raw `Error` object.
62
-
* It checks the error's `name` (e.g., 'ReadOnlyFileSystemError', 'FileReadError') to provide specific user-friendly messages for known file system issues.
63
-
* For other errors, it checks if the error has a `.code` property (like the internal `ErrorCode` enum values, e.g., 'ERR_2000') and prepends it to the error message.
4. **Output:** The formatted string is printed to `console.error`.
66
-
67
-
**2. MCP Server Error Path (`server/index.ts` via `tools.ts`)**
45
+
**Explanation of Updated Error Flow and Transformations:**
68
46
69
-
1. **Origination:**
70
-
* **Validation Error:** A *tagged* protocol error (`jsonRpcCode = -32602`) is thrown by `toolExecutors.ts` validation.
71
-
* **Execution Error:** An *untagged* application error (e.g., `TaskNotDone`) is thrown by `TaskManager`.
72
-
2. **Catching (`executeToolAndHandleErrors`):** Both types of errors are caught by the `try...catch` block in `executeToolAndHandleErrors` within `src/server/tools.ts`.
73
-
3. **Branching & Transformation:**
74
-
* **If Tagged Protocol Error:** `executeToolAndHandleErrors` detects the `jsonRpcCode` property and *re-throws* the error unchanged.
75
-
* **If Untagged App Error:**
76
-
* `executeToolAndHandleErrors` calls `normalizeError` from `src/utils/errors.ts`.
77
-
* `normalizeError` takes the raw `Error` object.
78
-
* It converts the error into an `McpError` object, typically assigning the `code` to `-32000` (Server Error - a generic JSON-RPC code for implementation-defined errors). It preserves the original error message (stripping any internal `[ERR_CODE]` prefix) and potentially includes the stack trace in the `data` field for debugging.
* `executeToolAndHandleErrors` then formats this `McpError` into the MCP `isError: true` structure: `{ content: [{ type: "text", text: "Tool execution failed: <normalized_message>" }], isError: true }`.
81
-
* **Shape Change:** `McpError` object -> MCP Tool Result `object` with `isError: true`.
82
-
4. **SDK Handling (`@modelcontextprotocol/sdk Server`):** The MCP SDK `Server` instance (used in `server/index.ts`) handles the outcome from `executeToolAndHandleErrors`:
83
-
* **If Error was Re-thrown (Tagged Protocol Error):** The SDK catches the *thrown* error. It automatically formats this into a standard JSON-RPC top-level error response (e.g., `{"jsonrpc": "2.0", "error": {"code": -32602, "message": "...", "data": ...}, "id": ...}`).
84
-
* **If `isError: true` Object was Returned (Normalized App Error):** The SDK receives the *returned* object. It treats this as a *successful* tool execution from a protocol perspective, but one where the tool itself reported an error. It formats a standard JSON-RPC success response, placing the `isError: true` object inside the `result` field (e.g., `{"jsonrpc": "2.0", "result": {"content": [...], "isError": true}, "id": ...}`).
85
-
5. **Output:** The final JSON-RPC response (either an error response or a success response containing an `isError` result) is sent to the connected MCP Client.
47
+
Errors are consistently through a unified `AppError` system:
86
48
87
-
**Key Functions Changing Error Shapes:**
49
+
1. **Validation Errors** (`APP-1xxx` series)
50
+
- Used for validation issues (e.g., MissingParameter, InvalidArgument)
51
+
- Thrown by tool executors during parameter validation
52
+
- Mapped to protocol-level McpErrors in `executeToolAndHandleErrors`
88
53
89
-
1. **`toolExecutors.ts` (Validation Logic):** Creates *new* `Error` objects and *tags* them with `jsonRpcCode`. (Raw Error -> Tagged Error)
90
-
2. **`normalizeError` (`src/utils/errors.ts`):** Standardizes various error inputs into `McpError` objects, often using the generic `-32000` code for application errors. (Raw Error -> McpError)
91
-
3. **`executeToolAndHandleErrors` (`src/server/tools.ts`):** Packages the `McpError` from `normalizeError` into the MCP-specific `{ content: [...], isError: true }` return format. (McpError -> MCP Result Object)
92
-
4. **`formatCliError` (`src/client/errors.ts`):** Converts `Error` objects into user-friendly `string` messages for the CLI. (Error -> String)
93
-
5. **`@modelcontextprotocol/sdk Server`:** Formats *thrown*, tagged errors into the top-level JSON-RPC `error` object and *returned* `isError: true` results into the JSON-RPC `result` object. (Tagged Error -> JSON-RPC Error / MCP Result Object -> JSON-RPC Result)
54
+
2. **Business Logic Errors** (`APP-2xxx` and higher)
55
+
- Used for all business logic and application-specific errors
56
+
- Include specific error codes (e.g., APP-2000 for ProjectNotFoundError)
57
+
- Returned as serialized CallToolResults with `isError: true`
Copy file name to clipboardExpand all lines: README.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,14 +40,14 @@ This will show the available commands and options.
40
40
The task manager supports multiple LLM providers for generating project plans. You can configure one or more of the following environment variables depending on which providers you want to use:
41
41
42
42
-`OPENAI_API_KEY`: Required for using OpenAI models (e.g., GPT-4)
43
-
-`GEMINI_API_KEY`: Required for using Google's Gemini models
43
+
-`GOOGLE_GENERATIVE_AI_API_KEY`: Required for using Google's Gemini models
44
44
-`DEEPSEEK_API_KEY`: Required for using Deepseek models
45
45
46
46
To generate project plans using the CLI, set these environment variables in your shell:
47
47
48
48
```bash
49
49
export OPENAI_API_KEY="your-api-key"
50
-
exportGEMINI_API_KEY="your-api-key"
50
+
exportGOOGLE_GENERATIVE_AI_API_KEY="your-api-key"
51
51
export DEEPSEEK_API_KEY="your-api-key"
52
52
```
53
53
@@ -61,7 +61,7 @@ Or you can include them in your MCP client configuration to generate project pla
0 commit comments