-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9915ea
commit db7c54f
Showing
4 changed files
with
83 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as os from 'os'; | ||
|
||
interface MCPServerConfig { | ||
command: string; | ||
args: string[]; | ||
} | ||
|
||
interface ClaudeConfig { | ||
mcpServers?: Record<string, MCPServerConfig>; | ||
[key: string]: any; | ||
} | ||
|
||
export function getConfigPath(): string { | ||
const configDir = path.join(os.homedir(), 'Library', 'Application Support', 'Claude'); | ||
return path.join(configDir, 'claude_desktop_config.json'); | ||
} | ||
|
||
export function readConfig(): ClaudeConfig { | ||
const configPath = getConfigPath(); | ||
if (!fs.existsSync(configPath)) { | ||
return {}; | ||
} | ||
return JSON.parse(fs.readFileSync(configPath, 'utf8')); | ||
} | ||
|
||
export function writeConfig(config: ClaudeConfig): void { | ||
const configPath = getConfigPath(); | ||
const configDir = path.dirname(configPath); | ||
|
||
if (!fs.existsSync(configDir)) { | ||
fs.mkdirSync(configDir, { recursive: true }); | ||
} | ||
|
||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); | ||
} | ||
|
||
export function installMCPServer(packageName: string): void { | ||
const config = readConfig(); | ||
const serverName = packageName; | ||
|
||
if (!config.mcpServers) { | ||
config.mcpServers = {}; | ||
} | ||
|
||
config.mcpServers[serverName] = { | ||
command: 'npx', | ||
args: ['-y', packageName] | ||
}; | ||
|
||
writeConfig(config); | ||
} |