From db1d621a06f01ef1c28eb5b7d06333ee18408844 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Dec 2025 02:18:20 +0000 Subject: [PATCH] Fix export/import for OpenAPI server type and improve handling Co-authored-by: samanhappy <2755122+samanhappy@users.noreply.github.com> --- frontend/src/components/JSONImportForm.tsx | 68 +++++++++++++++++++++- mcp_settings.json | 11 ++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/JSONImportForm.tsx b/frontend/src/components/JSONImportForm.tsx index d624760..192ff9a 100644 --- a/frontend/src/components/JSONImportForm.tsx +++ b/frontend/src/components/JSONImportForm.tsx @@ -14,6 +14,13 @@ interface McpServerConfig { type?: string; url?: string; headers?: Record; + openapi?: { + url?: string; + schema?: Record; + version?: string; + security?: any; + passthroughHeaders?: string[]; + }; } interface ImportJsonFormat { @@ -61,6 +68,34 @@ HTTP example: } } } +} + +OpenAPI example (correct format): +{ + "mcpServers": { + "openapi-server-example": { + "type": "openapi", + "openapi": { + "url": "http://localhost:3002/openapi.json" + }, + "headers": { + "X-API-Key": "your-api-key" + } + } + } +} + +OpenAPI example (legacy format, also supported): +{ + "mcpServers": { + "openapi-server-legacy": { + "type": "openapi", + "url": "http://localhost:3002/openapi.json", + "headers": { + "X-API-Key": "your-api-key" + } + } + } }`; const parseAndValidateJson = (input: string): ImportJsonFormat | null => { @@ -89,15 +124,34 @@ HTTP example: // Normalize config to MCPHub format const normalizedConfig: any = {}; + // Handle different server types if (config.type === 'sse' || config.type === 'streamable-http') { + // SSE and streamable-http servers use top-level url normalizedConfig.type = config.type; normalizedConfig.url = config.url; + if (config.headers) { + normalizedConfig.headers = config.headers; + } + } else if (config.type === 'openapi') { + // OpenAPI servers have special handling + normalizedConfig.type = 'openapi'; + + // Check if openapi configuration is already in correct format + if (config.openapi) { + normalizedConfig.openapi = config.openapi; + } else if (config.url) { + // Legacy format: convert top-level url to openapi.url + normalizedConfig.openapi = { + url: config.url, + }; + } + if (config.headers) { normalizedConfig.headers = config.headers; } } else { - // Default to stdio - normalizedConfig.type = 'stdio'; + // Command-based servers (stdio or unspecified type) + normalizedConfig.type = config.type || 'stdio'; normalizedConfig.command = config.command; normalizedConfig.args = config.args || []; if (config.env) { @@ -238,6 +292,16 @@ HTTP example: {t('server.url')}: {server.config.url} )} + {server.config.openapi?.url && ( +
+ OpenAPI URL: {server.config.openapi.url} +
+ )} + {server.config.openapi?.schema && ( +
+ OpenAPI Schema: (Inline schema provided) +
+ )} {server.config.env && Object.keys(server.config.env).length > 0 && (
{t('server.envVars')}:{' '} diff --git a/mcp_settings.json b/mcp_settings.json index 0ac4b5c..073bd5b 100644 --- a/mcp_settings.json +++ b/mcp_settings.json @@ -46,6 +46,17 @@ "env": { "TEST_VAR": "test-value" } + }, + "test-openapi-server-correct": { + "enabled": true, + "owner": "admin", + "type": "openapi", + "openapi": { + "url": "http://localhost:3002/openapi.json" + }, + "headers": { + "X-API-Key": "test-key" + } } }, "users": [