feat(cli): clean up command surface

This commit is contained in:
Andrey Avtomonov 2026-05-12 23:51:46 +02:00
parent 60457e9407
commit e15a4ebaec
61 changed files with 406 additions and 2076 deletions

View file

@ -3,8 +3,6 @@ import { cp, mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { promisify } from 'node:util';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
const execFileAsync = promisify(execFile);
@ -50,12 +48,6 @@ async function runBuiltCli(args: string[]): Promise<CliResult> {
}
}
function structuredContent<T extends object>(result: unknown): T {
const content = (result as { structuredContent?: unknown }).structuredContent;
expect(content).toBeDefined();
return content as T;
}
function parseJsonOutput<T>(stdout: string): T {
return JSON.parse(stdout) as T;
}
@ -132,121 +124,4 @@ describe('standalone local warehouse example', () => {
);
}, 30_000);
it('serves local wiki and semantic-layer MCP tools against the copied example project', async () => {
const projectDir = await copyExampleProject(tempDir);
const client = new Client({ name: 'ktx-example-client', version: '0.0.0' });
const transport = new StdioClientTransport({
command: process.execPath,
args: [CLI_BIN, 'serve', '--mcp', 'stdio', '--project-dir', projectDir, '--user-id', 'example-user'],
stderr: 'pipe',
});
try {
await client.connect(transport);
const knowledgeSearch = structuredContent<{
results: Array<{ key: string; summary: string; score: number }>;
totalFound: number;
}>(
await client.callTool({
name: 'knowledge_search',
arguments: { query: 'refund', limit: 5 },
}),
);
expect(knowledgeSearch.totalFound).toBe(1);
expect(knowledgeSearch.results[0]).toMatchObject({
key: 'revenue',
summary: 'Paid order value after refunds',
});
const knowledgeRead = structuredContent<{ key: string; summary: string; content: string; scope: string }>(
await client.callTool({ name: 'knowledge_read', arguments: { key: 'revenue' } }),
);
expect(knowledgeRead).toMatchObject({
key: 'revenue',
summary: 'Paid order value after refunds',
scope: 'GLOBAL',
});
expect(knowledgeRead.content).toContain('Revenue is paid order amount after refund adjustments.');
const knowledgeWrite = structuredContent<{ success: boolean; key: string; action: string }>(
await client.callTool({
name: 'knowledge_write',
arguments: {
key: 'gross_margin',
summary: 'Revenue after direct costs',
content: 'Gross margin subtracts direct order costs from revenue.',
tags: ['finance'],
sl_refs: ['warehouse.orders'],
},
}),
);
expect(knowledgeWrite).toEqual({ success: true, key: 'gross_margin', action: 'created' });
const slList = structuredContent<{
sources: Array<{
connectionId: string;
name: string;
description?: string;
columnCount: number;
measureCount: number;
joinCount: number;
}>;
totalSources: number;
}>(await client.callTool({ name: 'sl_list_sources', arguments: { connectionId: 'warehouse' } }));
expect(slList.totalSources).toBe(1);
expect(slList.sources[0]).toMatchObject({
connectionId: 'warehouse',
name: 'orders',
description: 'Orders placed through the storefront.',
columnCount: 3,
measureCount: 2,
joinCount: 0,
});
const slRead = structuredContent<{ sourceName: string; yaml: string }>(
await client.callTool({
name: 'sl_read_source',
arguments: { connectionId: 'warehouse', sourceName: 'orders' },
}),
);
expect(slRead.sourceName).toBe('orders');
expect(slRead.yaml).toContain('name: orders');
expect(slRead.yaml).toContain('total_revenue');
const slWrite = structuredContent<{ success: boolean; sourceName: string }>(
await client.callTool({
name: 'sl_write_source',
arguments: {
connectionId: 'warehouse',
sourceName: 'customers',
source: {
name: 'customers',
table: 'public.customers',
grain: ['id'],
columns: [{ name: 'id', type: 'number' }],
joins: [],
measures: [],
},
},
}),
);
expect(slWrite).toMatchObject({ success: true, sourceName: 'customers' });
const slValidate = structuredContent<{ success: boolean; errors: string[]; warnings: string[] }>(
await client.callTool({
name: 'sl_validate',
arguments: { connectionId: 'warehouse', names: ['orders', 'customers'] },
}),
);
expect(slValidate.success).toBe(true);
expect(slValidate.errors).toEqual([]);
expect(slValidate.warnings).toContain(
'Local stdio validation checks YAML shape only; Python semantic validation is not configured.',
);
} finally {
await client.close();
}
}, 30_000);
});