fix(kiro): parse .mcp.json wrapper key and support remote MCP servers (#259)
* fix(kiro): parse .mcp.json wrapper key and support remote MCP servers * refactor: extract unwrapMcpServers helper to deduplicate parser logic Address review feedback by extracting the mcpServers unwrap logic into a shared helper used by both loadMcpServers and loadMcpPaths.
This commit is contained in:
@@ -53,7 +53,7 @@ export function convertClaudeToKiro(
|
||||
convertCommandToSkill(command, usedSkillNames, agentNames),
|
||||
)
|
||||
|
||||
// Convert MCP servers (stdio only)
|
||||
// Convert MCP servers (stdio and remote)
|
||||
const mcpServers = convertMcpServers(plugin.mcpServers)
|
||||
|
||||
// Build steering files from CLAUDE.md
|
||||
@@ -177,19 +177,20 @@ function convertMcpServers(
|
||||
|
||||
const result: Record<string, KiroMcpServer> = {}
|
||||
for (const [name, server] of Object.entries(servers)) {
|
||||
if (!server.command) {
|
||||
if (server.command) {
|
||||
const entry: KiroMcpServer = { command: server.command }
|
||||
if (server.args && server.args.length > 0) entry.args = server.args
|
||||
if (server.env && Object.keys(server.env).length > 0) entry.env = server.env
|
||||
result[name] = entry
|
||||
} else if (server.url) {
|
||||
const entry: KiroMcpServer = { url: server.url }
|
||||
if (server.headers && Object.keys(server.headers).length > 0) entry.headers = server.headers
|
||||
result[name] = entry
|
||||
} else {
|
||||
console.warn(
|
||||
`Warning: MCP server "${name}" has no command (HTTP/SSE transport). Kiro only supports stdio. Skipping.`,
|
||||
`Warning: MCP server "${name}" has no command or url. Skipping.`,
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
||||
const entry: KiroMcpServer = { command: server.command }
|
||||
if (server.args && server.args.length > 0) entry.args = server.args
|
||||
if (server.env && Object.keys(server.env).length > 0) entry.env = server.env
|
||||
|
||||
console.log(`MCP server "${name}" will execute: ${server.command}${server.args ? " " + server.args.join(" ") : ""}`)
|
||||
result[name] = entry
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -158,7 +158,8 @@ async function loadMcpServers(
|
||||
|
||||
const mcpPath = path.join(root, ".mcp.json")
|
||||
if (await pathExists(mcpPath)) {
|
||||
return readJson<Record<string, ClaudeMcpServer>>(mcpPath)
|
||||
const raw = await readJson<Record<string, unknown>>(mcpPath)
|
||||
return unwrapMcpServers(raw)
|
||||
}
|
||||
|
||||
return undefined
|
||||
@@ -232,12 +233,20 @@ async function loadMcpPaths(
|
||||
for (const entry of toPathList(value)) {
|
||||
const resolved = resolveWithinRoot(root, entry, "mcpServers path")
|
||||
if (await pathExists(resolved)) {
|
||||
configs.push(await readJson<Record<string, ClaudeMcpServer>>(resolved))
|
||||
const raw = await readJson<Record<string, unknown>>(resolved)
|
||||
configs.push(unwrapMcpServers(raw))
|
||||
}
|
||||
}
|
||||
return configs
|
||||
}
|
||||
|
||||
function unwrapMcpServers(raw: Record<string, unknown>): Record<string, ClaudeMcpServer> {
|
||||
if (raw.mcpServers && typeof raw.mcpServers === "object") {
|
||||
return raw.mcpServers as Record<string, ClaudeMcpServer>
|
||||
}
|
||||
return raw as Record<string, ClaudeMcpServer>
|
||||
}
|
||||
|
||||
function mergeMcpConfigs(configs: Record<string, ClaudeMcpServer>[]): Record<string, ClaudeMcpServer> {
|
||||
return configs.reduce((acc, config) => ({ ...acc, ...config }), {})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user