From db7c54f418064d2c45f536edcfd3fa2cb1cbd33a Mon Sep 17 00:00:00 2001 From: Michael Latman Date: Tue, 26 Nov 2024 22:20:26 -0500 Subject: [PATCH] Push --- .github/workflows/update-packages.yml | 14 ++--- .../modelcontextprotocol-extractor.ts | 3 +- src/install.ts | 29 +++++++--- src/utils/config.ts | 53 +++++++++++++++++++ 4 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 src/utils/config.ts diff --git a/.github/workflows/update-packages.yml b/.github/workflows/update-packages.yml index b1cacdb..163cd5a 100644 --- a/.github/workflows/update-packages.yml +++ b/.github/workflows/update-packages.yml @@ -71,10 +71,10 @@ jobs: automated pr automerge - # - name: Enable Auto-Merge - # if: steps.git-check.outputs.changes == 'true' - # run: | - # PR_NUMBER=$(gh pr list --json number --jq '.[0].number') - # gh pr merge $PR_NUMBER --auto --merge - # env: - # GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + - name: Enable Auto-Merge + if: steps.git-check.outputs.changes == 'true' + run: | + PR_NUMBER=$(gh pr list --json number --jq '.[0].number') + gh pr merge $PR_NUMBER --auto --merge + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/src/extractors/modelcontextprotocol-extractor.ts b/src/extractors/modelcontextprotocol-extractor.ts index 88d78cf..ed33995 100644 --- a/src/extractors/modelcontextprotocol-extractor.ts +++ b/src/extractors/modelcontextprotocol-extractor.ts @@ -108,10 +108,11 @@ export async function extractPackageInfo(): Promise { fs.writeFileSync(outputPath, JSON.stringify(mergedPackages, null, 2)); console.log('Package list updated successfully'); - // Write commit message + // Write commit message with total number of changes if (changes.length === 0) { changes.push('- Initial package list creation'); } + commitMsg = `chore(packages): update MCP package list (${changes.length} packages)\n\nChanges:\n`; commitMsg += changes.join('\n'); fs.writeFileSync(commitMsgPath, commitMsg); console.log('Commit message generated'); diff --git a/src/install.ts b/src/install.ts index 59e4eb8..d7d0c6b 100644 --- a/src/install.ts +++ b/src/install.ts @@ -3,20 +3,33 @@ import { join } from 'path'; import { fileURLToPath } from 'url'; import { dirname } from 'path'; import { Package } from './types/index.js'; +import { installMCPServer } from './utils/config'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const packageListPath = join(__dirname, '../packages/package-list.json'); -export async function installPackage(pkg: Package): Promise { - console.log(`Installing package: ${pkg.name}`); - console.log(`Description: ${pkg.description}`); - console.log(`Vendor: ${pkg.vendor}`); - console.log(`Source URL: ${pkg.sourceUrl}`); - console.log(`License: ${pkg.license}`); +export async function installPackage(packageName: string): Promise { + try { + console.log(`Installing package: ${packageName}`); + console.log(`Description: ${packageName}`); + console.log(`Vendor: ${packageName}`); + console.log(`Source URL: ${packageName}`); + console.log(`License: ${packageName}`); - // Here you can add the logic to download and install the package from the sourceUrl + // Here you can add the logic to download and install the package from the sourceUrl + + // After successful installation, update the config + if (packageName.startsWith('@modelcontextprotocol/server-')) { + installMCPServer(packageName); + console.log('Updated Claude desktop configuration'); + } + + } catch (error) { + console.error('Failed to install package:', error); + throw error; + } } export async function install(packageName: string): Promise { @@ -28,5 +41,5 @@ export async function install(packageName: string): Promise { process.exit(1); } - await installPackage(pkg); + await installPackage(pkg.name); } diff --git a/src/utils/config.ts b/src/utils/config.ts new file mode 100644 index 0000000..b4af06b --- /dev/null +++ b/src/utils/config.ts @@ -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; + [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); +} \ No newline at end of file