Skip to content
Merged
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: 1 addition & 1 deletion src/commands/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export const registerServerCommands = (program: Command) => {
if (transport !== 'stdio' && (options.env || options.cwd !== undefined || options.args)) throw new Error('env, cwd and args require a stdio server');
if (transport === 'stdio' && (options.header || auth)) throw new Error('Headers and OAuth require an HTTP/SSE server');
if (options.command) updates.command = options.command;
if (options.args) updates.args = options.args;
if (options.args !== undefined) updates.args = options.args === true ? [] : options.args;
if (options.url) updates.url = options.url;
if (options.type) updates.type = options.type;
if (options.cwd !== undefined) updates.cwd = options.cwd;
Expand Down
39 changes: 39 additions & 0 deletions src/tests/integration/server-cli.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { mkdtempSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { resolve, join } from 'node:path';
import { spawnSync } from 'node:child_process';

describe('server update CLI', () => {
const directory = mkdtempSync(join(tmpdir(), 'mcps-update-'));
const config = join(directory, 'mcp.json');
const original = { mcpServers: { fixture: { command: 'node', args: ['old'] } } };
const run = (...args: string[]) => spawnSync(process.execPath,
[resolve('dist/index.js'), 'update', 'fixture', ...args],
{ env: { ...process.env, MCPS_CONFIG_DIR: directory }, encoding: 'utf8', timeout: 5000 });
const saved = () => JSON.parse(readFileSync(config, 'utf8')).mcpServers.fixture;

beforeAll(() => writeFileSync(config, JSON.stringify(original)));
afterAll(() => rmSync(directory, { recursive: true, force: true }));

it('keeps omitted arguments, clears bare --args, and preserves an explicit empty argument', () => {
expect(run('--command', 'node').status).toBe(0);
expect(saved().args).toEqual(['old']);
expect(run('--args').status).toBe(0);
expect(saved().args).toEqual([]);
expect(run('--args', '').status).toBe(0);
expect(saved().args).toEqual(['']);
expect(run('--args', 'new').status).toBe(0);
expect(saved().args).toEqual(['new']);
});

it('returns nonzero for an invalid update and preserves the previous configuration', () => {
writeFileSync(config, JSON.stringify(original));
const before = readFileSync(config, 'utf8');
const result = run('--url', 'not-a-url');
expect(result.error).toBeUndefined();
expect(result.status).toBeGreaterThan(0);
expect(result.stderr).toContain('Error updating server');
expect(readFileSync(config, 'utf8')).toBe(before);
});
});
Loading