()
| 96 | } |
| 97 | |
| 98 | export async function readClaudeDesktopMcpServers(): Promise< |
| 99 | Record<string, McpServerConfig> |
| 100 | > { |
| 101 | if (!SUPPORTED_PLATFORMS.includes(getPlatform())) { |
| 102 | throw new Error( |
| 103 | 'Unsupported platform - Claude Desktop integration only works on macOS and WSL.', |
| 104 | ) |
| 105 | } |
| 106 | try { |
| 107 | const configPath = await getClaudeDesktopConfigPath() |
| 108 | |
| 109 | let configContent: string |
| 110 | try { |
| 111 | configContent = await readFile(configPath, { encoding: 'utf8' }) |
| 112 | } catch (e: unknown) { |
| 113 | const code = getErrnoCode(e) |
| 114 | if (code === 'ENOENT') { |
| 115 | return {} |
| 116 | } |
| 117 | throw e |
| 118 | } |
| 119 | |
| 120 | const config = safeParseJSON(configContent) |
| 121 | |
| 122 | if (!config || typeof config !== 'object') { |
| 123 | return {} |
| 124 | } |
| 125 | |
| 126 | const mcpServers = (config as Record<string, unknown>).mcpServers |
| 127 | if (!mcpServers || typeof mcpServers !== 'object') { |
| 128 | return {} |
| 129 | } |
| 130 | |
| 131 | const servers: Record<string, McpServerConfig> = {} |
| 132 | |
| 133 | for (const [name, serverConfig] of Object.entries( |
| 134 | mcpServers as Record<string, unknown>, |
| 135 | )) { |
| 136 | if (!serverConfig || typeof serverConfig !== 'object') { |
| 137 | continue |
| 138 | } |
| 139 | |
| 140 | const result = McpStdioServerConfigSchema().safeParse(serverConfig) |
| 141 | |
| 142 | if (result.success) { |
| 143 | servers[name] = result.data |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | return servers |
| 148 | } catch (error) { |
| 149 | logError(error) |
| 150 | return {} |
| 151 | } |
| 152 | } |
| 153 |
no test coverage detected