Changesets · Branches · Tags · Compare
| Changeset | 0ac707eac6427b5127cd03bc11e32c39341ff31005ae939229bdc2432063d5c3 |
|---|---|
| Author | Nate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-05-25 22:19 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-05-25 22:19 -07:00 |
| Parents | fa514d4463b9, f90492cd23f3 |
4 files changed
modified core/context/mcp/MCPConnection.test.ts +35 −3
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | |
| 5 | 5 | describe("MCPConnection", () => { |
| 6 | 6 | beforeEach(() => { |
| 7 | - jest.clearAllMocks(); | |
| 7 | + jest.restoreAllMocks(); | |
| 8 | 8 | }); |
| 9 | 9 | |
| 10 | 10 | describe("constructor", () => { |
| @@ -173,11 +173,11 @@ | ||
| 173 | 173 | }); |
| 174 | 174 | |
| 175 | 175 | it("should handle custom connection timeout", async () => { |
| 176 | - const conn = new MCPConnection({ ...options, timeout: 11 }); | |
| 176 | + const conn = new MCPConnection({ ...options, timeout: 1500 }); | |
| 177 | 177 | const mockConnect = jest |
| 178 | 178 | .spyOn(Client.prototype, "connect") |
| 179 | 179 | .mockImplementation( |
| 180 | - () => new Promise((resolve) => setTimeout(resolve, 10)), | |
| 180 | + () => new Promise((resolve) => setTimeout(resolve, 1000)), | |
| 181 | 181 | ); |
| 182 | 182 | |
| 183 | 183 | const abortController = new AbortController(); |
| @@ -229,6 +229,38 @@ | ||
| 229 | 229 | expect(conn.errors[0]).toContain('command "test-cmd" not found'); |
| 230 | 230 | expect(mockConnect).toHaveBeenCalled(); |
| 231 | 231 | }); |
| 232 | + | |
| 233 | + it.skip("should include stderr output in error message when stdio command fails", async () => { | |
| 234 | + // Clear any existing mocks to ensure we get real behavior | |
| 235 | + jest.restoreAllMocks(); | |
| 236 | + | |
| 237 | + // Use a command that will definitely fail and produce stderr output | |
| 238 | + const failingOptions = { | |
| 239 | + name: "failing-mcp", | |
| 240 | + id: "failing-id", | |
| 241 | + transport: { | |
| 242 | + type: "stdio" as const, | |
| 243 | + command: "node", | |
| 244 | + args: [ | |
| 245 | + "-e", | |
| 246 | + "console.error('Custom error message from stderr'); process.exit(1);", | |
| 247 | + ], | |
| 248 | + }, | |
| 249 | + timeout: 5000, // Give enough time for the command to run and fail | |
| 250 | + }; | |
| 251 | + | |
| 252 | + const conn = new MCPConnection(failingOptions); | |
| 253 | + const abortController = new AbortController(); | |
| 254 | + | |
| 255 | + await conn.connectClient(false, abortController.signal); | |
| 256 | + | |
| 257 | + expect(conn.status).toBe("error"); | |
| 258 | + expect(conn.errors).toHaveLength(1); | |
| 259 | + expect(conn.errors[0]).toContain("Failed to connect"); | |
| 260 | + expect(conn.errors[0]).toContain("Process output:"); | |
| 261 | + expect(conn.errors[0]).toContain("STDERR:"); | |
| 262 | + expect(conn.errors[0]).toContain("Custom error message from stderr"); | |
| 263 | + }); | |
| 232 | 264 | }); |
| 233 | 265 | |
| 234 | 266 | describe.skip("actually connect to Filesystem MCP", () => { |
modified core/context/mcp/MCPConnection.ts +29 −1
| @@ -38,6 +38,10 @@ | ||
| 38 | 38 | public resources: MCPResource[] = []; |
| 39 | 39 | private transport: Transport; |
| 40 | 40 | private connectionPromise: Promise<unknown> | null = null; |
| 41 | + private stdioOutput: { stdout: string; stderr: string } = { | |
| 42 | + stdout: "", | |
| 43 | + stderr: "", | |
| 44 | + }; | |
| 41 | 45 | |
| 42 | 46 | constructor(public options: MCPOptions) { |
| 43 | 47 | this.transport = this.constructTransport(options); |
| @@ -91,6 +95,7 @@ | ||
| 91 | 95 | this.prompts = []; |
| 92 | 96 | this.resources = []; |
| 93 | 97 | this.errors = []; |
| 98 | + this.stdioOutput = { stdout: "", stderr: "" }; | |
| 94 | 99 | |
| 95 | 100 | this.abortController.abort(); |
| 96 | 101 | this.abortController = new AbortController(); |
| @@ -215,6 +220,20 @@ | ||
| 215 | 220 | } |
| 216 | 221 | } |
| 217 | 222 | |
| 223 | + // Include stdio output if available for stdio transport | |
| 224 | + if ( | |
| 225 | + this.options.transport.type === "stdio" && | |
| 226 | + (this.stdioOutput.stdout || this.stdioOutput.stderr) | |
| 227 | + ) { | |
| 228 | + errorMessage += "\n\nProcess output:"; | |
| 229 | + if (this.stdioOutput.stdout) { | |
| 230 | + errorMessage += `\nSTDOUT:\n${this.stdioOutput.stdout}`; | |
| 231 | + } | |
| 232 | + if (this.stdioOutput.stderr) { | |
| 233 | + errorMessage += `\nSTDERR:\n${this.stdioOutput.stderr}`; | |
| 234 | + } | |
| 235 | + } | |
| 236 | + | |
| 218 | 237 | this.status = "error"; |
| 219 | 238 | this.errors.push(errorMessage); |
| 220 | 239 | } finally { |
| @@ -284,11 +303,20 @@ | ||
| 284 | 303 | options.transport.args || [], |
| 285 | 304 | ); |
| 286 | 305 | |
| 287 | - return new StdioClientTransport({ | |
| 306 | + const transport = new StdioClientTransport({ | |
| 288 | 307 | command, |
| 289 | 308 | args, |
| 290 | 309 | env, |
| 310 | + stderr: "pipe", | |
| 291 | 311 | }); |
| 312 | + | |
| 313 | + // Capture stdio output for better error reporting | |
| 314 | + | |
| 315 | + transport.stderr?.on("data", (data: Buffer) => { | |
| 316 | + this.stdioOutput.stderr += data.toString(); | |
| 317 | + }); | |
| 318 | + | |
| 319 | + return transport; | |
| 292 | 320 | case "websocket": |
| 293 | 321 | return new WebSocketClientTransport(new URL(options.transport.url)); |
| 294 | 322 | case "sse": |
modified core/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
modified core/package.json +1 −1
| @@ -52,7 +52,7 @@ | ||
| 52 | 52 | "@continuedev/fetch": "^1.0.10", |
| 53 | 53 | "@continuedev/llm-info": "^1.0.8", |
| 54 | 54 | "@continuedev/openai-adapters": "^1.0.25", |
| 55 | - "@modelcontextprotocol/sdk": "^1.5.0", | |
| 55 | + "@modelcontextprotocol/sdk": "^1.12.0", | |
| 56 | 56 | "@mozilla/readability": "^0.5.0", |
| 57 | 57 | "@octokit/rest": "^20.1.1", |
| 58 | 58 | "@typescript-eslint/eslint-plugin": "^7.8.0", |