* Load MCP servers from a JSON file within a plugin * This is a simplified version that doesn't expand environment variables * and is specifically for plugin MCP configs
( pluginPath: string, relativePath: string, )
| 217 | * and is specifically for plugin MCP configs |
| 218 | */ |
| 219 | async function loadMcpServersFromFile( |
| 220 | pluginPath: string, |
| 221 | relativePath: string, |
| 222 | ): Promise<Record<string, McpServerConfig> | null> { |
| 223 | const fs = getFsImplementation() |
| 224 | const filePath = join(pluginPath, relativePath) |
| 225 | |
| 226 | let content: string |
| 227 | try { |
| 228 | content = await fs.readFile(filePath, { encoding: 'utf-8' }) |
| 229 | } catch (e: unknown) { |
| 230 | if (isENOENT(e)) { |
| 231 | return null |
| 232 | } |
| 233 | logForDebugging(`Failed to load MCP servers from ${filePath}: ${e}`, { |
| 234 | level: 'error', |
| 235 | }) |
| 236 | return null |
| 237 | } |
| 238 | |
| 239 | try { |
| 240 | const parsed = jsonParse(content) |
| 241 | |
| 242 | // Check if it's in the .mcp.json format with mcpServers key |
| 243 | const mcpServers = parsed.mcpServers || parsed |
| 244 | |
| 245 | // Validate each server config |
| 246 | const validatedServers: Record<string, McpServerConfig> = {} |
| 247 | for (const [name, config] of Object.entries(mcpServers)) { |
| 248 | const result = McpServerConfigSchema().safeParse(config) |
| 249 | if (result.success) { |
| 250 | validatedServers[name] = result.data |
| 251 | } else { |
| 252 | logForDebugging( |
| 253 | `Invalid MCP server config for ${name} in ${filePath}: ${result.error.message}`, |
| 254 | { level: 'error' }, |
| 255 | ) |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | return validatedServers |
| 260 | } catch (error) { |
| 261 | logForDebugging(`Failed to load MCP servers from ${filePath}: ${error}`, { |
| 262 | level: 'error', |
| 263 | }) |
| 264 | return null |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * A channel entry from a plugin's manifest whose userConfig has not yet been |
no test coverage detected