From 1f44a3de341582acd95298e2c5f25e715a43fd57 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 26 Nov 2025 11:03:28 -0800 Subject: [PATCH 1/6] fix: fall back to env vars --- extensions/cli/src/CLIPlatformClient.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/extensions/cli/src/CLIPlatformClient.ts b/extensions/cli/src/CLIPlatformClient.ts index 2f7c2dbfe..2f0046397 100644 --- a/extensions/cli/src/CLIPlatformClient.ts +++ b/extensions/cli/src/CLIPlatformClient.ts @@ -105,9 +105,10 @@ export class CLIPlatformClient implements PlatformClient { }, }); - // Merge API results into our results array + // Merge API results into our results array - but only if they have an actual value + // API can return found=true for secrets that exist but aren't accessible locally for (let i = 0; i < apiResults.length; i++) { - if (apiResults[i]?.found) { + if (apiResults[i]?.found && "value" in apiResults[i]) { results[i] = apiResults[i]; } } @@ -119,9 +120,10 @@ export class CLIPlatformClient implements PlatformClient { ); } - // For any secret that wasn't found via API, look in local .env files + // For any secret without a value (not just "not found"), look in local .env files + // This allows environment variables to override org/package secrets that aren't accessible for (let i = 0; i < fqsns.length; i++) { - if (!results[i]?.found) { + if (!results[i] || !("value" in results[i]!)) { const secretFromEnv = this.findSecretInLocalEnvFiles(fqsns[i]); if (secretFromEnv?.found) { results[i] = secretFromEnv; From fa96e30a3a5bca4035004bc63dc079e84551ff3e Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 26 Nov 2025 11:03:48 -0800 Subject: [PATCH 2/6] fix: improved unhandled error logging --- extensions/cli/src/index.ts | 21 ++++++++++++++++++++- extensions/cli/src/util/logger.ts | 13 +++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/extensions/cli/src/index.ts b/extensions/cli/src/index.ts index 4735f416f..a76a2fdc4 100644 --- a/extensions/cli/src/index.ts +++ b/extensions/cli/src/index.ts @@ -91,7 +91,26 @@ export function shouldShowExitMessage(): boolean { // Add global error handlers to prevent uncaught errors from crashing the process process.on("unhandledRejection", (reason, promise) => { - logger.error("Unhandled Rejection at:", { promise, reason }); + // Extract useful information from the reason + const errorDetails = { + promiseString: String(promise), + reasonType: typeof reason, + reasonConstructor: reason?.constructor?.name, + }; + + // If reason is an Error, use it directly for better stack traces + if (reason instanceof Error) { + logger.error("Unhandled Promise Rejection", reason, errorDetails); + } else { + // Convert non-Error reasons to Error for consistent handling + const error = new Error(`Unhandled rejection: ${String(reason)}`); + logger.error("Unhandled Promise Rejection", error, { + ...errorDetails, + originalReason: String(reason), + }); + } + + // Sentry capture remains the same sentryService.captureException( reason instanceof Error ? reason : new Error(String(reason)), { diff --git a/extensions/cli/src/util/logger.ts b/extensions/cli/src/util/logger.ts index 8f32e67fe..69a672c65 100644 --- a/extensions/cli/src/util/logger.ts +++ b/extensions/cli/src/util/logger.ts @@ -44,6 +44,19 @@ function createReplacer() { seen.add(value); } + // Handle Error objects explicitly - extract useful properties + if (value instanceof Error) { + const errorObj: any = { + name: value.name, + message: value.message, + stack: value.stack, + }; + if (value.cause) { + errorObj.cause = value.cause; + } + return errorObj; + } + // Handle functions if (typeof value === "function") { return "[Function]"; From d045072c08426dc281d478788bb826b6058b039b Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 26 Nov 2025 11:04:00 -0800 Subject: [PATCH 3/6] fix: unroll edge cases --- packages/config-yaml/src/load/unroll.test.ts | 72 ++++++++++++++++++++ packages/config-yaml/src/load/unroll.ts | 22 +++++- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/packages/config-yaml/src/load/unroll.test.ts b/packages/config-yaml/src/load/unroll.test.ts index 9a308dd9b..3357e9cfc 100644 --- a/packages/config-yaml/src/load/unroll.test.ts +++ b/packages/config-yaml/src/load/unroll.test.ts @@ -1,5 +1,7 @@ import { PackageIdentifier } from "../interfaces/slugs.js"; import { + fillTemplateVariables, + getTemplateVariables, parseMarkdownRuleOrAssistantUnrolled, replaceInputsWithSecrets, } from "./unroll.js"; @@ -274,3 +276,73 @@ data: expect(result).not.toContain("inputs.dbPassword"); }); }); + +describe("getTemplateVariables edge cases", () => { + it("handles undefined input gracefully", () => { + const result = getTemplateVariables(undefined as any); + expect(result).toEqual([]); + }); + + it("handles null input gracefully", () => { + const result = getTemplateVariables(null as any); + expect(result).toEqual([]); + }); + + it("handles non-string input gracefully", () => { + const result = getTemplateVariables(123 as any); + expect(result).toEqual([]); + }); + + it("handles empty string correctly", () => { + const result = getTemplateVariables(""); + expect(result).toEqual([]); + }); + + it("extracts template variables from valid input", () => { + const result = getTemplateVariables("\${{ secrets.apiKey }}"); + expect(result).toEqual(["secrets.apiKey"]); + }); + + it("extracts multiple template variables", () => { + const result = getTemplateVariables( + "\${{ secrets.key1 }} and \${{ inputs.key2 }}", + ); + expect(result).toContain("secrets.key1"); + expect(result).toContain("inputs.key2"); + expect(result.length).toBe(2); + }); +}); + +describe("fillTemplateVariables edge cases", () => { + it("handles undefined input gracefully", () => { + const result = fillTemplateVariables(undefined as any, {}); + expect(result).toBe(""); + }); + + it("handles null input gracefully", () => { + const result = fillTemplateVariables(null as any, {}); + expect(result).toBe(""); + }); + + it("handles non-string input gracefully", () => { + const result = fillTemplateVariables(123 as any, {}); + expect(result).toBe(""); + }); + + it("handles empty string correctly", () => { + const result = fillTemplateVariables("", {}); + expect(result).toBe(""); + }); + + it("fills template variables with valid input", () => { + const result = fillTemplateVariables("\${{ secrets.apiKey }}", { + "secrets.apiKey": "my-secret-key", + }); + expect(result).toBe("my-secret-key"); + }); + + it("leaves unfilled variables unchanged", () => { + const result = fillTemplateVariables("\${{ secrets.apiKey }}", {}); + expect(result).toBe("\${{ secrets.apiKey }}"); + }); +}); diff --git a/packages/config-yaml/src/load/unroll.ts b/packages/config-yaml/src/load/unroll.ts index eb2794965..49476925e 100644 --- a/packages/config-yaml/src/load/unroll.ts +++ b/packages/config-yaml/src/load/unroll.ts @@ -86,6 +86,11 @@ export function parseBlock(configYaml: string): Block { export const TEMPLATE_VAR_REGEX = /\${{[\s]*([^}\s]+)[\s]*}}/g; export function getTemplateVariables(templatedYaml: string): string[] { + // Defensive guard against undefined/null/non-string values + if (!templatedYaml || typeof templatedYaml !== "string") { + return []; + } + const variables = new Set(); const matches = templatedYaml.matchAll(TEMPLATE_VAR_REGEX); for (const match of matches) { @@ -98,6 +103,11 @@ export function fillTemplateVariables( templatedYaml: string, data: { [key: string]: string }, ): string { + // Defensive guard against undefined/null/non-string values + if (!templatedYaml || typeof templatedYaml !== "string") { + return ""; + } + return templatedYaml.replace(TEMPLATE_VAR_REGEX, (match, variableName) => { // Inject data if (variableName in data) { @@ -701,7 +711,7 @@ function injectLocalSourceFile( export async function resolveBlock( id: PackageIdentifier, - inputs: Record | undefined, + inputs: Record | undefined, registry: Registry, ): Promise { // Retrieve block raw yaml @@ -777,11 +787,19 @@ function parseYamlOrMarkdownRule( } function inputsToFQSNs( - inputs: Record, + inputs: Record, blockIdentifier: PackageIdentifier, ): Record { const renderedInputs: Record = {}; for (const [key, value] of Object.entries(inputs)) { + // Skip undefined, null, or non-string values + if (value === undefined || value === null || typeof value !== "string") { + console.warn( + `Skipping input "${key}" with invalid value type: ${typeof value}. Expected string.`, + ); + continue; + } + renderedInputs[key] = renderTemplateData(value, { secrets: extractFQSNMap(value, [blockIdentifier]), }); From 63489e9dd6f7a04452ddf8348244c6e9ff0fac33 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 26 Nov 2025 11:07:48 -0800 Subject: [PATCH 4/6] fix: mcp secret loading bug --- extensions/cli/src/services/MCPService.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/extensions/cli/src/services/MCPService.ts b/extensions/cli/src/services/MCPService.ts index 01f449eed..3860259ae 100644 --- a/extensions/cli/src/services/MCPService.ts +++ b/extensions/cli/src/services/MCPService.ts @@ -1,7 +1,4 @@ -import { - decodeSecretLocation, - getTemplateVariables, -} from "@continuedev/config-yaml"; +import { decodeFQSN, getTemplateVariables } from "@continuedev/config-yaml"; import { type AssistantConfig } from "@continuedev/sdk"; import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"; @@ -318,7 +315,7 @@ export class MCPService const vars = getTemplateVariables(JSON.stringify(serverConfig)); const secretVars = vars.filter((v) => v.startsWith("secrets.")); const unrendered = secretVars.map((v) => { - return decodeSecretLocation(v.replace("secrets.", "")).secretName; + return decodeFQSN(v.replace("secrets.", "")).secretName; }); try { From 9e1412c48487929e7cb7398fe2a47adae34b5978 Mon Sep 17 00:00:00 2001 From: "continue[bot]" Date: Wed, 26 Nov 2025 19:13:31 +0000 Subject: [PATCH 5/6] docs: document MCP secret resolution fallback behavior Adds documentation explaining how the CLI resolves secrets for MCP servers, including the fallback from org/package secrets to local environment variables. This documents the fix from PR #8899 that allows env vars to override inaccessible org secrets in devboxes and restricted environments. Co-authored-by: nate Generated with [Continue](https://continue.dev) Co-Authored-By: Continue --- extensions/cli/spec/mcp.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/extensions/cli/spec/mcp.md b/extensions/cli/spec/mcp.md index aefd19608..1ba40eb5f 100644 --- a/extensions/cli/spec/mcp.md +++ b/extensions/cli/spec/mcp.md @@ -4,6 +4,24 @@ Model Context Protocol is a protocol for giving models access to resources and tools. MCP servers can run locally (stdio) or be remote (http/streamable/etc). See https://modelcontextprotocol.io/specification. The Continue CLI uses MCP to extend model's capabilities with MCP prompts and tools. MCP server configurations are stored in the `mcpServers` field of an assistant/config.yaml configuration. +## Secret Resolution + +MCP server configurations often require secrets (API keys, tokens, etc.) referenced using template variables like `${{ secrets.API_KEY }}`. The CLI resolves these secrets in the following order: + +1. **Organization/Package Secrets**: First attempts to resolve secrets through the Continue API for organization or package-level secrets +2. **Local Environment Variables**: Falls back to local environment variables if: + - The API secret exists but isn't accessible locally (e.g., in devboxes or restricted environments) + - The secret isn't found in organization/package secrets + +Local environment variables are checked in this priority order: + +- `process.env` (runtime environment variables) +- `~/.continue/.env` +- `/.continue/.env` +- `/.env` + +This fallback mechanism ensures MCP servers can start successfully in environments where organization secrets aren't accessible, such as development containers or CI/CD pipelines, by allowing environment variables to provide the required credentials. + ## MCP Service The CLI has an MCP Service should manage connections to MCP servers and provide state to the terminal app regarding MCP server connections. From 4ec2b1bcb4fc1be75e3db76f5ffdf65e58d42979 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 26 Nov 2025 11:46:12 -0800 Subject: [PATCH 6/6] fix: no duplicate sentry error --- extensions/cli/src/index.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/extensions/cli/src/index.ts b/extensions/cli/src/index.ts index a76a2fdc4..76fef86d0 100644 --- a/extensions/cli/src/index.ts +++ b/extensions/cli/src/index.ts @@ -110,19 +110,13 @@ process.on("unhandledRejection", (reason, promise) => { }); } - // Sentry capture remains the same - sentryService.captureException( - reason instanceof Error ? reason : new Error(String(reason)), - { - promise: String(promise), - }, - ); + // Note: Sentry capture is handled by logger.error() above // Don't exit the process, just log the error }); process.on("uncaughtException", (error) => { logger.error("Uncaught Exception:", error); - sentryService.captureException(error); + // Note: Sentry capture is handled by logger.error() above // Don't exit the process, just log the error });