Skip to content

Commit

Permalink
Add help menu and README update
Browse files Browse the repository at this point in the history
  • Loading branch information
michaellatman committed Nov 27, 2024
1 parent 7b69b16 commit 37fd804
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 42 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This tool helps you install and manage MCP servers that connect Claude to variou
### Install a Package

```
npx @michaellatman/mcp-get install @modelcontextprotocol/server-brave-search
npx @michaellatman/mcp-get@latest install @modelcontextprotocol/server-brave-search
```

Sample output:
Expand All @@ -44,7 +44,7 @@ Installation complete.
### List Packages

```
npx @michaellatman/mcp-get list
npx @michaellatman/mcp-get@latest list
```

Sample output:
Expand All @@ -60,7 +60,7 @@ Found 11 packages
### Uninstall a Package

```
npx @michaellatman/mcp-get uninstall @modelcontextprotocol/server-brave-search
npx @michaellatman/mcp-get@latest uninstall @modelcontextprotocol/server-brave-search
```

Sample output:
Expand All @@ -69,6 +69,20 @@ Uninstalling @modelcontextprotocol/server-brave-search...
Uninstallation complete.
```

### Update the Tool

The tool automatically checks for updates when running commands. You can also manually update:

```
npx @michaellatman/mcp-get@latest update
```

Sample output:
```
Updating mcp-get...
Update complete.
```

## Contributing

We welcome contributions to the project! If you would like to contribute, please follow these guidelines:
Expand Down
4 changes: 0 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@michaellatman/mcp-get",
"version": "1.0.2",
"version": "1.0.1",
"description": "A NPX command to install and list packages",
"main": "dist/index.js",
"scripts": {
Expand Down
30 changes: 20 additions & 10 deletions src/auto-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { exec } from 'child_process';
import { promisify } from 'util';
import { readFileSync } from 'fs';
import { join } from 'path';
import chalk from 'chalk';

const execAsync = promisify(exec);

Expand All @@ -15,17 +16,26 @@ async function getLatestVersion(): Promise<string> {
return stdout.trim();
}

async function updatePackage(): Promise<void> {
const currentVersion = await getCurrentVersion();
const latestVersion = await getLatestVersion();
export async function updatePackage(): Promise<void> {
try {
const currentVersion = await getCurrentVersion();
const latestVersion = await getLatestVersion();

if (currentVersion !== latestVersion) {
console.log(`Updating @michaellatman/mcp-get from version ${currentVersion} to ${latestVersion}`);
await execAsync('npm install -g @michaellatman/mcp-get');
console.log('Update complete.');
} else {
console.log('@michaellatman/mcp-get is already up to date.');
if (currentVersion !== latestVersion) {
console.log(chalk.yellow(`\nA new version of mcp-get is available: ${latestVersion} (current: ${currentVersion})`));
console.log(chalk.cyan('Installing update...'));

// Use npx to ensure we get the latest version
await execAsync('npx --yes @michaellatman/mcp-get@latest');

console.log(chalk.green('✓ Update complete\n'));

// Exit after update to ensure the new version is used
process.exit(0);
}
} catch (error) {
// Log update check failure but continue with execution
console.log(chalk.yellow('\nFailed to check for updates. Continuing with current version.'));
}
}
export { updatePackage };

89 changes: 65 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,78 @@ import inquirer from 'inquirer';
import autocomplete from 'inquirer-autocomplete-prompt';
import { listInstalledPackages } from './installed.js';
import { uninstall } from './uninstall.js';
import { updatePackage } from './auto-update.js';
import chalk from 'chalk';

inquirer.registerPrompt('autocomplete', autocomplete);

const args = process.argv.slice(2);
const command = args[0];

switch (command) {
case 'install':
const packageName = args[1];
if (!packageName) {
console.error('Please provide a package name.');
process.exit(1);
const skipUpdateCommands = ['update', 'version', 'help'];

function displayHelp() {
console.log(chalk.bold.cyan('\nMCP-Get - Model Context Protocol Package Manager\n'));
console.log('Usage: mcp-get <command>\n');
console.log('Commands:');
console.log(' install <package> Install a package');
console.log(' uninstall <package> Uninstall a package');
console.log(' ls, list List available packages');
console.log(' installed List installed packages');
console.log(' update Update mcp-get to the latest version');
console.log(' help Display this help message\n');
console.log('Examples:');
console.log(' mcp-get install @modelcontextprotocol/server-brave-search');
console.log(' mcp-get ls');
console.log(' mcp-get installed\n');
console.log('For more information, visit: https://modelcontextprotocol.io\n');
}

async function main() {
try {
if (!skipUpdateCommands.includes(command)) {
await updatePackage();
}
install(packageName);
break;
case 'uninstall':
const pkgToUninstall = args[1];
if (!pkgToUninstall) {
console.error('Please provide a package name to uninstall.');
process.exit(1);

switch (command) {
case undefined:
case 'help':
displayHelp();
break;
case 'install':
const packageName = args[1];
if (!packageName) {
console.error('Please provide a package name.');
process.exit(1);
}
await install(packageName);
break;
case 'uninstall':
const pkgToUninstall = args[1];
if (!pkgToUninstall) {
console.error('Please provide a package name to uninstall.');
process.exit(1);
}
uninstall(pkgToUninstall);
break;
case 'ls':
case 'list':
list();
break;
case 'installed':
listInstalledPackages();
break;
case 'update':
await updatePackage();
break;
default:
console.error(`Unknown command: ${command}`);
process.exit(1);
}
uninstall(pkgToUninstall);
break;
case 'ls':
case 'list':
list();
break;
case 'installed':
listInstalledPackages();
break;
default:
console.error(`Unknown command: ${command}`);
} catch (error) {
console.error('Error:', error);
process.exit(1);
}
}

main();

0 comments on commit 37fd804

Please sign in to comment.