Skip to content

🙌 OpenHands: AI-Driven Development

fix: show header-specific MCP validation errors (#17966)

pei7117889d8f9d865
diff --git a/.pr/bugs/mcp-header-error-after.png b/.pr/bugs/mcp-header-error-after.png
new file mode 100644
index 0000000000..6cb07cb402
Binary files /dev/null and b/.pr/bugs/mcp-header-error-after.png differ
diff --git a/.pr/bugs/mcp-header-error-before.png b/.pr/bugs/mcp-header-error-before.png
new file mode 100644
index 0000000000..a6a19e2ab0
Binary files /dev/null and b/.pr/bugs/mcp-header-error-before.png differ
diff --git a/__tests__/components/features/settings/mcp-settings/mcp-server-form.validation.test.tsx b/__tests__/components/features/settings/mcp-settings/mcp-server-form.validation.test.tsx
index 1de7709896..3f6e68b455 100644
--- a/__tests__/components/features/settings/mcp-settings/mcp-server-form.validation.test.tsx
+++ b/__tests__/components/features/settings/mcp-settings/mcp-server-form.validation.test.tsx
@@ -56,6 +56,40 @@ describe("MCPServerForm validation", () => {
expect(onSubmit).toHaveBeenCalledTimes(1);
});
+ it("uses a header-specific format error for malformed header auth", () => {
+ const onSubmit = vi.fn();
+
+ render(
+ <MCPServerForm
+ mode="add"
+ server={{
+ id: "tmp",
+ type: "sse",
+ auth: { strategy: "header", headers: {} },
+ }}
+ existingServers={[]}
+ onSubmit={onSubmit}
+ onCancel={noop}
+ />,
+ );
+
+ fireEvent.change(screen.getByTestId("url-input"), {
+ target: { value: "https://api.example.com/mcp" },
+ });
+ fireEvent.change(screen.getByTestId("headers-input"), {
+ target: { value: "NOEQUALS" },
+ });
+ fireEvent.click(screen.getByTestId("submit-button"));
+
+ expect(
+ screen.getByText("SETTINGS$MCP_ERROR_HEADER_INVALID_FORMAT"),
+ ).toBeInTheDocument();
+ expect(
+ screen.queryByText("SETTINGS$MCP_ERROR_ENV_INVALID_FORMAT"),
+ ).not.toBeInTheDocument();
+ expect(onSubmit).not.toHaveBeenCalled();
+ });
+
it("includes an optional server name for sse/shttp servers", () => {
const onSubmit = vi.fn();
diff --git a/src/components/features/settings/mcp-settings/mcp-server-form.tsx b/src/components/features/settings/mcp-settings/mcp-server-form.tsx
index 2649ca5d49..ba1f534d03 100644
--- a/src/components/features/settings/mcp-settings/mcp-server-form.tsx
+++ b/src/components/features/settings/mcp-settings/mcp-server-form.tsx
@@ -170,16 +170,19 @@ export function MCPServerForm({
return null;
};
- const validateEnvFormat = (envString: string): string | null => {
+ const validateEnvFormat = (
+ envString: string,
+ errorKey: I18nKey = I18nKey.SETTINGS$MCP_ERROR_ENV_INVALID_FORMAT,
+ ): string | null => {
if (!envString.trim()) return null;
const lines = envString.split("\n");
for (let i = 0; i < lines.length; i += 1) {
const trimmed = lines[i].trim();
if (trimmed) {
const eq = trimmed.indexOf("=");
- if (eq === -1) return t(I18nKey.SETTINGS$MCP_ERROR_ENV_INVALID_FORMAT);
+ if (eq === -1) return t(errorKey);
const key = trimmed.substring(0, eq).trim();
- if (!key) return t(I18nKey.SETTINGS$MCP_ERROR_ENV_INVALID_FORMAT);
+ if (!key) return t(errorKey);
}
}
return null;
@@ -190,7 +193,10 @@ export function MCPServerForm({
const headerString = formData.get("headers")?.toString() || "";
if (!headerString.trim())
return t(I18nKey.SETTINGS$MCP_ERROR_HEADER_REQUIRED);
- return validateEnvFormat(headerString);
+ return validateEnvFormat(
+ headerString,
+ I18nKey.SETTINGS$MCP_ERROR_HEADER_INVALID_FORMAT,
+ );
}
if (authMode === "oauth2") {
const clientId = formData.get("oauth_client_id")?.toString().trim();
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index ec99673182..73dc3a97ce 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -26128,6 +26128,23 @@
"uk": "read write",
"ca": "read write"
},
+ "SETTINGS$MCP_ERROR_HEADER_INVALID_FORMAT": {
+ "en": "Headers must follow KEY=value format",
+ "ja": "ヘッダーは KEY=value 形式に従う必要があります",
+ "zh-CN": "请求头必须遵循 KEY=value 格式",
+ "zh-TW": "標頭必須遵循 KEY=value 格式",
+ "ko-KR": "헤더는 KEY=value 형식을 따라야 합니다",
+ "no": "Headere må følge formatet KEY=value",
+ "it": "Le intestazioni devono seguire il formato KEY=value",
+ "pt": "Os cabeçalhos devem seguir o formato KEY=value",
+ "es": "Los encabezados deben seguir el formato KEY=value",
+ "ar": "يجب أن تتبع الترويسات تنسيق KEY=value",
+ "fr": "Les en-têtes doivent suivre le format KEY=value",
+ "tr": "Üst bilgiler KEY=value biçiminde olmalıdır",
+ "de": "Header müssen dem Format KEY=value folgen",
+ "uk": "Заголовки мають відповідати формату KEY=value",
+ "ca": "Les capçaleres han de seguir el format KEY=value"
+ },
"SETTINGS$MCP_ERROR_HEADER_REQUIRED": {
"en": "Header authentication requires a header",
"ja": "ヘッダー認証にはヘッダーが必要です",