STDIO MCP servers read from stdin and exit on EOF. Docker containers close stdin by default, causing all STDIO servers to crash immediately. Added OpenStdin: true to container creation. Describe instance now resolves server names (like logs command), preferring RUNNING instances. Added 7 new describe tests covering server name resolution, healthcheck display, events section, and template detail. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
291 lines
9.5 KiB
TypeScript
291 lines
9.5 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { createDescribeCommand } from '../../src/commands/describe.js';
|
|
import type { DescribeCommandDeps } from '../../src/commands/describe.js';
|
|
import type { ApiClient } from '../../src/api-client.js';
|
|
|
|
function mockClient(): ApiClient {
|
|
return {
|
|
get: vi.fn(async () => []),
|
|
post: vi.fn(async () => ({})),
|
|
put: vi.fn(async () => ({})),
|
|
delete: vi.fn(async () => {}),
|
|
} as unknown as ApiClient;
|
|
}
|
|
|
|
function makeDeps(item: unknown = {}): DescribeCommandDeps & { output: string[] } {
|
|
const output: string[] = [];
|
|
return {
|
|
output,
|
|
client: mockClient(),
|
|
fetchResource: vi.fn(async () => item),
|
|
log: (...args: string[]) => output.push(args.join(' ')),
|
|
};
|
|
}
|
|
|
|
describe('describe command', () => {
|
|
it('shows detailed server info with sections', async () => {
|
|
const deps = makeDeps({
|
|
id: 'srv-1',
|
|
name: 'slack',
|
|
transport: 'STDIO',
|
|
packageName: '@slack/mcp',
|
|
dockerImage: null,
|
|
env: [],
|
|
createdAt: '2025-01-01',
|
|
});
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'server', 'srv-1']);
|
|
|
|
expect(deps.fetchResource).toHaveBeenCalledWith('servers', 'srv-1');
|
|
const text = deps.output.join('\n');
|
|
expect(text).toContain('=== Server: slack ===');
|
|
expect(text).toContain('Name:');
|
|
expect(text).toContain('slack');
|
|
expect(text).toContain('Transport:');
|
|
expect(text).toContain('STDIO');
|
|
expect(text).toContain('Package:');
|
|
expect(text).toContain('@slack/mcp');
|
|
expect(text).toContain('Metadata:');
|
|
expect(text).toContain('ID:');
|
|
});
|
|
|
|
it('resolves resource aliases', async () => {
|
|
const deps = makeDeps({ id: 's1' });
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'sec', 's1']);
|
|
expect(deps.fetchResource).toHaveBeenCalledWith('secrets', 's1');
|
|
});
|
|
|
|
it('outputs JSON format', async () => {
|
|
const deps = makeDeps({ id: 'srv-1', name: 'slack' });
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'server', 'srv-1', '-o', 'json']);
|
|
|
|
const parsed = JSON.parse(deps.output[0] ?? '');
|
|
expect(parsed.name).toBe('slack');
|
|
});
|
|
|
|
it('outputs YAML format', async () => {
|
|
const deps = makeDeps({ id: 'srv-1', name: 'slack' });
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'server', 'srv-1', '-o', 'yaml']);
|
|
expect(deps.output[0]).toContain('name: slack');
|
|
});
|
|
|
|
it('shows project detail', async () => {
|
|
const deps = makeDeps({
|
|
id: 'proj-1',
|
|
name: 'my-project',
|
|
description: 'A test project',
|
|
ownerId: 'user-1',
|
|
createdAt: '2025-01-01',
|
|
});
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'project', 'proj-1']);
|
|
|
|
const text = deps.output.join('\n');
|
|
expect(text).toContain('=== Project: my-project ===');
|
|
expect(text).toContain('A test project');
|
|
expect(text).toContain('user-1');
|
|
});
|
|
|
|
it('shows secret detail with masked values', async () => {
|
|
const deps = makeDeps({
|
|
id: 'sec-1',
|
|
name: 'ha-creds',
|
|
data: { TOKEN: 'abc123', URL: 'https://ha.local' },
|
|
createdAt: '2025-01-01',
|
|
});
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'secret', 'sec-1']);
|
|
|
|
const text = deps.output.join('\n');
|
|
expect(text).toContain('=== Secret: ha-creds ===');
|
|
expect(text).toContain('TOKEN');
|
|
expect(text).toContain('***');
|
|
expect(text).not.toContain('abc123');
|
|
expect(text).toContain('use --show-values to reveal');
|
|
});
|
|
|
|
it('shows secret detail with revealed values when --show-values', async () => {
|
|
const deps = makeDeps({
|
|
id: 'sec-1',
|
|
name: 'ha-creds',
|
|
data: { TOKEN: 'abc123' },
|
|
createdAt: '2025-01-01',
|
|
});
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'secret', 'sec-1', '--show-values']);
|
|
|
|
const text = deps.output.join('\n');
|
|
expect(text).toContain('abc123');
|
|
expect(text).not.toContain('***');
|
|
});
|
|
|
|
it('shows instance detail with container info', async () => {
|
|
const deps = makeDeps({
|
|
id: 'inst-1',
|
|
serverId: 'srv-1',
|
|
status: 'RUNNING',
|
|
containerId: 'abc123',
|
|
port: 3000,
|
|
createdAt: '2025-01-01',
|
|
});
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'instance', 'inst-1']);
|
|
|
|
const text = deps.output.join('\n');
|
|
expect(text).toContain('=== Instance: inst-1 ===');
|
|
expect(text).toContain('RUNNING');
|
|
expect(text).toContain('abc123');
|
|
});
|
|
|
|
it('resolves server name to instance for describe instance', async () => {
|
|
const deps = makeDeps({
|
|
id: 'inst-1',
|
|
serverId: 'srv-1',
|
|
server: { name: 'my-grafana' },
|
|
status: 'RUNNING',
|
|
containerId: 'abc123',
|
|
port: 3000,
|
|
});
|
|
// resolveNameOrId will throw (not a CUID, name won't match instances)
|
|
vi.mocked(deps.client.get)
|
|
.mockResolvedValueOnce([] as never) // instances list (no name match)
|
|
.mockResolvedValueOnce([{ id: 'srv-1', name: 'my-grafana' }] as never) // servers list
|
|
.mockResolvedValueOnce([{ id: 'inst-1', status: 'RUNNING' }] as never); // instances for server
|
|
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'instance', 'my-grafana']);
|
|
|
|
expect(deps.fetchResource).toHaveBeenCalledWith('instances', 'inst-1');
|
|
});
|
|
|
|
it('resolves server name and picks running instance over stopped', async () => {
|
|
const deps = makeDeps({
|
|
id: 'inst-2',
|
|
serverId: 'srv-1',
|
|
server: { name: 'my-ha' },
|
|
status: 'RUNNING',
|
|
containerId: 'def456',
|
|
});
|
|
vi.mocked(deps.client.get)
|
|
.mockResolvedValueOnce([] as never) // instances list
|
|
.mockResolvedValueOnce([{ id: 'srv-1', name: 'my-ha' }] as never)
|
|
.mockResolvedValueOnce([
|
|
{ id: 'inst-1', status: 'ERROR' },
|
|
{ id: 'inst-2', status: 'RUNNING' },
|
|
] as never);
|
|
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'instance', 'my-ha']);
|
|
|
|
expect(deps.fetchResource).toHaveBeenCalledWith('instances', 'inst-2');
|
|
});
|
|
|
|
it('throws when no instances found for server name', async () => {
|
|
const deps = makeDeps();
|
|
vi.mocked(deps.client.get)
|
|
.mockResolvedValueOnce([] as never) // instances list
|
|
.mockResolvedValueOnce([{ id: 'srv-1', name: 'my-server' }] as never)
|
|
.mockResolvedValueOnce([] as never); // no instances
|
|
|
|
const cmd = createDescribeCommand(deps);
|
|
await expect(cmd.parseAsync(['node', 'test', 'instance', 'my-server'])).rejects.toThrow(
|
|
/No instances found/,
|
|
);
|
|
});
|
|
|
|
it('shows instance with server name in header', async () => {
|
|
const deps = makeDeps({
|
|
id: 'inst-1',
|
|
serverId: 'srv-1',
|
|
server: { name: 'my-grafana' },
|
|
status: 'RUNNING',
|
|
containerId: 'abc123',
|
|
port: 3000,
|
|
});
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'instance', 'inst-1']);
|
|
|
|
const text = deps.output.join('\n');
|
|
expect(text).toContain('=== Instance: my-grafana ===');
|
|
});
|
|
|
|
it('shows instance health and events', async () => {
|
|
const deps = makeDeps({
|
|
id: 'inst-1',
|
|
serverId: 'srv-1',
|
|
server: { name: 'my-grafana' },
|
|
status: 'RUNNING',
|
|
containerId: 'abc123',
|
|
healthStatus: 'healthy',
|
|
lastHealthCheck: '2025-01-15T10:30:00Z',
|
|
events: [
|
|
{ timestamp: '2025-01-15T10:30:00Z', type: 'Normal', message: 'Health check passed (45ms)' },
|
|
],
|
|
});
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'instance', 'inst-1']);
|
|
|
|
const text = deps.output.join('\n');
|
|
expect(text).toContain('Health:');
|
|
expect(text).toContain('healthy');
|
|
expect(text).toContain('Events:');
|
|
expect(text).toContain('Health check passed');
|
|
});
|
|
|
|
it('shows server healthCheck section', async () => {
|
|
const deps = makeDeps({
|
|
id: 'srv-1',
|
|
name: 'my-grafana',
|
|
transport: 'STDIO',
|
|
healthCheck: {
|
|
tool: 'list_datasources',
|
|
arguments: {},
|
|
intervalSeconds: 60,
|
|
timeoutSeconds: 10,
|
|
failureThreshold: 3,
|
|
},
|
|
});
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'server', 'srv-1']);
|
|
|
|
const text = deps.output.join('\n');
|
|
expect(text).toContain('Health Check:');
|
|
expect(text).toContain('list_datasources');
|
|
expect(text).toContain('60s');
|
|
expect(text).toContain('Failure Threshold:');
|
|
});
|
|
|
|
it('shows template detail with healthCheck and usage', async () => {
|
|
const deps = makeDeps({
|
|
id: 'tpl-1',
|
|
name: 'grafana',
|
|
transport: 'STDIO',
|
|
version: '1.0.0',
|
|
packageName: '@leval/mcp-grafana',
|
|
env: [
|
|
{ name: 'GRAFANA_URL', required: true, description: 'Grafana instance URL' },
|
|
],
|
|
healthCheck: {
|
|
tool: 'list_datasources',
|
|
arguments: {},
|
|
intervalSeconds: 60,
|
|
timeoutSeconds: 10,
|
|
failureThreshold: 3,
|
|
},
|
|
});
|
|
const cmd = createDescribeCommand(deps);
|
|
await cmd.parseAsync(['node', 'test', 'template', 'tpl-1']);
|
|
|
|
const text = deps.output.join('\n');
|
|
expect(text).toContain('=== Template: grafana ===');
|
|
expect(text).toContain('@leval/mcp-grafana');
|
|
expect(text).toContain('GRAFANA_URL');
|
|
expect(text).toContain('Health Check:');
|
|
expect(text).toContain('list_datasources');
|
|
expect(text).toContain('mcpctl create server my-grafana --from-template=grafana');
|
|
});
|
|
});
|