Skip to content

Commit

Permalink
Implement read from claude config
Browse files Browse the repository at this point in the history
  • Loading branch information
andylouisqin committed Dec 21, 2024
1 parent 790d648 commit 618b1a3
Showing 1 changed file with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion src/commands/install.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {Args, Command, Flags} from '@oclif/core'
import * as fs from 'fs/promises'
import * as path from 'path'
import * as os from 'os'

export default class Install extends Command {
static args = {
Expand Down Expand Up @@ -30,6 +33,74 @@ export default class Install extends Command {
public async run(): Promise<void> {
const {args, flags} = await this.parse(Install)

this.log(`Installing MCP server: ${args.server}\nwith client: ${flags.client}`)
// TODO: check if server exists in registry

// Detect operating system
const platform = process.platform

if (platform !== 'darwin' && platform !== 'win32') {
this.error('This command is only supported on macOS and Windows')
return
}

this.log(`Installing MCP server: ${args.server}`)
this.log(`Platform: ${platform === 'darwin' ? 'macOS' : 'Windows'}`)
this.log(`Client: ${flags.client}`)

try {
if (platform === 'darwin') {
await this.installOnMacOS(args.server, flags.client)
} else {
await this.installOnWindows(args.server, flags.client)
}
} catch (error: unknown) {
if (error instanceof Error) {
this.error(`Failed to install server: ${error.message}`)
} else {
this.error('An unknown error occurred during installation')
}
}
}

private async installOnMacOS(serverName: string, client: string): Promise<void> {
if (client === 'claude') {
const configPath = path.join(
os.homedir(),
'Library',
'Application Support',
'Claude',
'claude_desktop_config.json'
)

try {
// Check if file exists
await fs.access(configPath)

// Read and parse the config file
const configContent = await fs.readFile(configPath, 'utf-8')
const config = JSON.parse(configContent)

this.log('Current config:', JSON.stringify(config, null, 2))

} catch (error: unknown) {
if (error instanceof Error) {
if ('code' in error && error.code === 'ENOENT') {
this.error(`Config file not found at ${configPath}. Is Claude Desktop installed?`)
} else {
this.error(`Error reading config: ${error.message}`)
}
} else {
this.error('An unknown error occurred')
}
}
} else {
// TODO: Handle 'continue' client case
throw new Error('Continue client installation not implemented yet')
}
}

private async installOnWindows(serverName: string, client: string): Promise<void> {
// TODO: Implement Windows-specific installation logic
throw new Error('Windows installation not implemented yet')
}
}

0 comments on commit 618b1a3

Please sign in to comment.