Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"https-proxy-agent": "^7.0.6",
"json5": "^2.2.3",
"prompts": "^2.4.2",
"semver": "^7.7.3",
"source-map-support": "^0.5.21",
"tiktoken": "^1.0.22",
"uuid": "^13.0.0",
Expand All @@ -127,6 +128,7 @@
"@types/express": "^5.0.0",
"@types/node": "^24.0.0",
"@types/prompts": "^2.4.9",
"@types/semver": "^7.7.1",
"@types/supertest": "^6.0.3",
"@types/yargs": "^17.0.33",
"@typescript-eslint/eslint-plugin": "^8.27.0",
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

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

54 changes: 53 additions & 1 deletion src/commands/mcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import { globalOptions } from '@src/globalOptions.js';

import type { Argv } from 'yargs';

import { buildSearchCommand as buildRegistrySearchCommand } from '../registry/search.js';
import { buildAddCommand } from './add.js';
import { buildDisableCommand, buildEnableCommand } from './enable.js';
import { buildInstallCommand } from './install.js';
import { buildListCommand } from './list.js';
import { buildRemoveCommand } from './remove.js';
import { buildStatusCommand } from './status.js';
import { buildTokensCommand } from './tokens.js';
import { buildUninstallCommand } from './uninstall.js';
import { buildUpdateCommand } from './update.js';

/**
Expand Down Expand Up @@ -48,6 +51,15 @@ export function setupMcpCommands(yargs: Argv): Argv {
}
},
})
.command({
command: 'install [serverName]',
describe: 'Install an MCP server from the registry (interactive wizard if no serverName)',
builder: buildInstallCommand,
handler: async (argv) => {
const { installCommand } = await import('./install.js');
await installCommand(argv);
},
})
.command({
command: 'remove <name>',
describe: 'Remove an MCP server from the configuration',
Expand All @@ -57,6 +69,15 @@ export function setupMcpCommands(yargs: Argv): Argv {
await removeCommand(argv);
},
})
.command({
command: 'uninstall <serverName>',
describe: 'Uninstall an MCP server',
builder: buildUninstallCommand,
handler: async (argv) => {
const { uninstallCommand } = await import('./uninstall.js');
await uninstallCommand(argv);
},
})
.command({
command: 'update <name>',
describe: 'Update an existing MCP server configuration',
Expand Down Expand Up @@ -122,15 +143,46 @@ export function setupMcpCommands(yargs: Argv): Argv {
await tokensCommand(argv);
},
})
.command({
command: 'search [query]',
describe: 'Search registry for MCP servers (alias for registry search)',
builder: (yargs) => buildRegistrySearchCommand(yargs),
handler: async (argv) => {
// Delegate to registry search command
const { searchCommand } = await import('../registry/search.js');
const searchArgs = {
query: argv.query,
status: argv.status,
type: argv.type,
transport: argv.transport,
limit: argv.limit,
cursor: argv.cursor,
format: argv.format,
_: argv._ || [],
$0: argv.$0 || '1mcp',
config: argv.config,
'config-dir': argv['config-dir'],
url: argv['url'],
timeout: argv['timeout'],
'cache-ttl': argv['cache-ttl'],
'cache-max-size': argv['cache-max-size'],
'cache-cleanup-interval': argv['cache-cleanup-interval'],
proxy: argv['proxy'],
'proxy-auth': argv['proxy-auth'],
} as Parameters<typeof searchCommand>[0];
await searchCommand(searchArgs);
},
})
.demandCommand(1, 'You must specify a subcommand')
.help().epilogue(`
MCP Command Group - Local MCP Server Configuration Management

The mcp command group helps you manage local MCP server configurations in your 1mcp instance.

This allows you to:
• Install MCP servers from the registry
• Add new MCP servers with various transport types (stdio, HTTP, SSE)
• Remove servers you no longer need
• Remove or uninstall servers you no longer need
• Update server configurations including environment variables and tags
• Enable/disable servers without removing them
• List and filter servers by tags or status
Expand Down
159 changes: 159 additions & 0 deletions src/commands/mcp/install.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import * as serverManagementIndex from '@src/domains/server-management/index.js';

import { beforeEach, describe, expect, it, vi } from 'vitest';

import * as configUtils from './utils/configUtils.js';
import { buildInstallCommand, installCommand } from './install.js';

// Mock dependencies
vi.mock('@src/domains/server-management/index.js', () => {
const installServer = vi.fn();
const startOperation = vi.fn();
const updateProgress = vi.fn();
const completeOperation = vi.fn();
const failOperation = vi.fn();
return {
createServerInstallationService: vi.fn(() => ({ installServer })),
getProgressTrackingService: vi.fn(() => ({
startOperation,
updateProgress,
completeOperation,
failOperation,
})),
};
});

vi.mock('./utils/configUtils.js', () => {
return {
initializeConfigContext: vi.fn(),
serverExists: vi.fn(),
backupConfig: vi.fn(() => '/tmp/config.backup'),
reloadMcpConfig: vi.fn(),
setServer: vi.fn(),
getAllServers: vi.fn(),
};
});

vi.mock('./utils/serverUtils.js', () => ({
generateOperationId: vi.fn(() => 'op_test_123'),
parseServerNameVersion: vi.fn((input: string) => {
const parts = input.split('@');
return { name: parts[0], version: parts[1] };
}),
validateServerName: vi.fn(),
validateVersion: vi.fn((v?: string) => (v ? /^\d+\.\d+\.\d+/.test(v) : true)),
}));

vi.mock('@src/logger/logger.js', () => ({
default: {
info: vi.fn(),
error: vi.fn(),
debug: vi.fn(),
},
}));

const consoleLogMock = vi.fn();
console.log = consoleLogMock;

describe('Install Command', () => {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(configUtils.serverExists as any).mockReturnValue(false);
vi.mocked((serverManagementIndex as any).createServerInstallationService().installServer).mockResolvedValue({
success: true,
serverName: 'test-server',
version: '1.0.0',
installedAt: new Date(),
configPath: '/path/to/config',
warnings: [],
errors: [],
operationId: 'op_test_123',
});
});

describe('buildInstallCommand', () => {
it('should configure command with correct options', () => {
const yargsMock = {
positional: vi.fn().mockReturnThis(),
option: vi.fn().mockReturnThis(),
example: vi.fn().mockReturnThis(),
};

buildInstallCommand(yargsMock as any);

expect(yargsMock.positional).toHaveBeenCalledWith('serverName', expect.anything());
expect(yargsMock.option).toHaveBeenCalledWith('force', expect.anything());
expect(yargsMock.option).toHaveBeenCalledWith('dry-run', expect.anything());
expect(yargsMock.option).toHaveBeenCalledWith('verbose', expect.anything());
});
});

describe('installCommand', () => {
it('should reject on invalid version format', async () => {
const args = {
serverName: 'test-server@bad',
dryRun: false,
force: false,
verbose: false,
};

await expect(installCommand(args as any)).rejects.toThrow(/Invalid version format/);
expect((serverManagementIndex as any).getProgressTrackingService().startOperation).not.toHaveBeenCalled();
});

it('should perform dry-run without invoking installation', async () => {
const args = {
serverName: 'test-server@1.2.3',
dryRun: true,
force: false,
verbose: false,
};

await installCommand(args as any);

expect((serverManagementIndex as any).createServerInstallationService().installServer).not.toHaveBeenCalled();
expect((serverManagementIndex as any).getProgressTrackingService().startOperation).not.toHaveBeenCalled();
expect(consoleLogMock).toHaveBeenCalled();
});

it('should throw if server exists and not forced', async () => {
vi.mocked(configUtils.serverExists as any).mockReturnValue(true);
const args = {
serverName: 'exists@1.2.3',
dryRun: false,
force: false,
verbose: false,
};

await expect(installCommand(args as any)).rejects.toThrow(/already exists/);
expect((configUtils.backupConfig as any).mock.calls.length).toBe(0);
});

it('should create backup when reinstalling with --force and reload config', async () => {
vi.mocked(configUtils.serverExists as any).mockReturnValue(true);
const args = {
serverName: 'test-server@1.2.3',
dryRun: false,
force: true,
verbose: true,
};

await installCommand(args as any);

expect((serverManagementIndex as any).getProgressTrackingService().startOperation).toHaveBeenCalledWith(
'op_test_123',
'install',
5,
);
expect((serverManagementIndex as any).getProgressTrackingService().updateProgress).toHaveBeenCalled();
expect((configUtils.backupConfig as any).mock.calls.length).toBeGreaterThan(0);
expect((serverManagementIndex as any).createServerInstallationService().installServer).toHaveBeenCalledWith(
'test-server',
'1.2.3',
expect.any(Object),
);
expect((configUtils.reloadMcpConfig as any).mock.calls.length).toBeGreaterThan(0);
expect((serverManagementIndex as any).getProgressTrackingService().completeOperation).toHaveBeenCalled();
});
});
});
Loading
Loading