feat(mcp): improve agent discovery and execution feedback

Add structured results, optional keyword search and pagination, and runtime information with explicit connection checks. Preserve existing text responses and execution permissions.

Support request cancellation and transfer progress. Verify compatibility with the full CI suite and isolated MCP and HTTP integration tests.
This commit is contained in:
DrSmoothl committed 2026-10-23 15:14:18 +08:00
1 parent 9b5ce9b502
commit 34a73084e0
16 files changed
+1552 -155

No files matched your search

+275
View File
@@ -0,0 +1,275 @@
import { describe, expect, it, vi } from 'vitest';
import { callTool, computeTools } from '../src/tools';
import { ACTIONS } from '../src/generated/catalog';
import type { ActionClient, OneBotEnvelope } from '../src/client';
import { ActionCallError } from '../src/results';
const docs = { mode: 'docs' as const };
function client(
reply: OneBotEnvelope = { status: 'ok', retcode: 0, data: { message_id: -123 } },
): ActionClient {
return {
call: vi.fn(async () => reply),
callStream: vi.fn(async () => ({ frame_count: 1, frames: [], terminal: reply })),
};
}
function text(result: Awaited<ReturnType<typeof callTool>>) {
expect(result.content[0].type).toBe('text');
return result.content[0].type === 'text' ? result.content[0].text : '';
}
describe('additive structured results', () => {
it.each(['list_actions', 'list_categories', 'get_action', 'search_actions'])(
'keeps the original text payload for %s',
async (name) => {
const result = await callTool(name, { name: 'get_status', query: 'get_status' }, docs);
expect(result.structuredContent.result).toEqual(JSON.parse(text(result)));
expect(result.structuredContent.diagnostics).toEqual({ outcome: 'success' });
expect(
computeTools('docs').find((tool) => tool.name === name)?.outputSchema,
).toBeDefined();
},
);
it.each([
{ status: 'ok', retcode: 0, data: { message_id: -123 } },
{ status: 'failed', retcode: 1404, wording: 'not found' },
{ status: 'async', retcode: 1 },
])('preserves the OneBot envelope and isError contract ($status)', async (reply) => {
const result = await callTool(
'invoke_action',
{ action: 'send_group_msg' },
{ mode: 'write', client: client(reply) },
);
expect(text(result)).toBe(JSON.stringify(reply, null, 2));
expect(result.isError).toBeUndefined();
expect(result.structuredContent.result).toEqual(reply);
expect(result.structuredContent.diagnostics.outcome).toBe(
reply.status === 'ok' ? 'success' : reply.status === 'failed' ? 'failed' : 'unknown',
);
});
it('reports permission failures without contacting OneBot', async () => {
const onebot = client();
const result = await callTool(
'query_action',
{ action: 'send_group_msg' },
{ mode: 'read', client: onebot },
);
expect(result.isError).toBe(true);
expect(result.structuredContent.diagnostics).toMatchObject({
outcome: 'failed',
kind: 'permission',
});
expect(onebot.call).not.toHaveBeenCalled();
});
it.each(['timeout', 'cancelled', 'authentication', 'transport', 'invalid_response'] as const)(
'makes %s observable without claiming a write was rolled back',
async (kind) => {
const onebot = client();
onebot.call = vi.fn(async () => {
throw new ActionCallError('request failed', kind);
});
const result = await callTool(
'invoke_action',
{ action: 'send_group_msg' },
{ mode: 'write', client: onebot },
);
expect(result.isError).toBe(true);
expect(result.structuredContent.diagnostics).toMatchObject({
outcome: 'unknown',
kind,
});
expect(result.structuredContent.diagnostics.next_step).toContain('不代表撤销');
expect(onebot.call).toHaveBeenCalledTimes(1);
},
);
it('does not report an incomplete response as successful', async () => {
const onebot = client();
onebot.call = async () => JSON.parse('{"data":null}');
const result = await callTool(
'query_action',
{ action: 'get_status' },
{ mode: 'read', client: onebot },
);
expect(result.structuredContent.diagnostics).toMatchObject({
outcome: 'unknown',
kind: 'invalid_response',
});
expect(text(result)).toBe('{\n "data": null\n}');
});
it('keeps malformed peer fields in the original payload without breaking the diagnostics schema', async () => {
const onebot = client();
onebot.call = async () =>
JSON.parse('{"status":"failed","retcode":1400,"wording":{"unexpected":true}}');
const result = await callTool(
'query_action',
{ action: 'get_status' },
{ mode: 'read', client: onebot },
);
expect(result.structuredContent.diagnostics.message).toBe('retcode=1400');
expect(JSON.parse(text(result)).wording).toEqual({ unexpected: true });
});
});
describe('optional discovery controls', () => {
it('keeps legacy matching, ordering and response fields by default', async () => {
const result = await callTool('search_actions', { query: '群 禁言' }, docs);
expect(JSON.parse(text(result))).toEqual({ count: 0, actions: [] });
const all = JSON.parse(text(await callTool('list_actions', {}, docs)));
expect(Object.keys(all)).toEqual(['count', 'actions']);
expect(all.actions.map((action: { name: string }) => action.name)).toEqual(
ACTIONS.map((action) => action.name),
);
});
it.each([
['群 禁言', 'set_group_ban'],
['历史消息', 'get_group_msg_history'],
['私聊 history', 'get_friend_msg_history'],
['group mute', 'set_group_ban'],
])('finds %s with optional keyword matching', async (query, expected) => {
const data = JSON.parse(
text(await callTool('search_actions', { query, match: 'keywords' }, docs)),
);
expect(data.actions.map((action: { name: string }) => action.name)).toContain(expected);
});
it('ranks an exact alias first and combines filters', async () => {
const exact = JSON.parse(
text(
await callTool('search_actions', { query: 'nc_get_rkey', match: 'keywords' }, docs),
),
);
expect(exact.actions[0].name).toBe('get_rkey');
const filtered = JSON.parse(
text(
await callTool(
'search_actions',
{
query: '群',
match: 'keywords',
category: '群管理',
read_only: false,
stream: false,
},
docs,
),
),
);
expect(filtered.count).toBeGreaterThan(0);
expect(
filtered.actions.every(
(action: { category: string; readOnly: boolean; stream: boolean }) =>
action.category === '群管理' && !action.readOnly && !action.stream,
),
).toBe(true);
});
it('paginates deterministically with explicit totals and termination', async () => {
const names: string[] = [];
let offset: number | null = 0;
while (offset !== null) {
const data = JSON.parse(
text(await callTool('list_actions', { limit: 37, offset }, docs)),
);
expect(data.total).toBe(ACTIONS.length);
expect(data.count).toBe(data.actions.length);
names.push(...data.actions.map((action: { name: string }) => action.name));
offset = data.next_offset;
}
expect(names).toEqual(ACTIONS.map((action) => action.name));
const beyond = JSON.parse(text(await callTool('list_actions', { offset: 9999 }, docs)));
expect(beyond).toEqual({ count: 0, actions: [], total: ACTIONS.length, next_offset: null });
});
it.each([
{ limit: 0 },
{ limit: 201 },
{ offset: -1 },
{ offset: 0.5 },
{ stream: 'true' },
{ read_only: 1 },
{ match: 'typo' },
])('rejects invalid new options (%j)', async (options) => {
const result = await callTool('search_actions', { query: '', ...options }, docs);
expect(result.isError).toBe(true);
expect(result.structuredContent.diagnostics.kind).toBe('invalid_arguments');
});
});
describe('runtime overview and caller cancellation', () => {
it('does not contact OneBot for a local overview, even if a client exists in docs mode', async () => {
const onebot = client();
const result = await callTool('get_runtime_info', {}, { ...docs, client: onebot });
expect(result.structuredContent.result).toMatchObject({
mode: 'docs',
execution_enabled: false,
write_enabled: false,
transport: null,
connection_checked: false,
catalog: { action_count: ACTIONS.length, server_support: 'unknown' },
});
expect(onebot.call).not.toHaveBeenCalled();
const denied = await callTool(
'get_runtime_info',
{ check_connection: true },
{ ...docs, client: onebot },
);
expect(denied.isError).toBe(true);
expect(onebot.call).not.toHaveBeenCalled();
});
it('only performs the three explicit read-only checks and preserves individual failures', async () => {
const onebot = client();
const controller = new AbortController();
onebot.call = vi.fn(async (action, _params, options) => {
expect(options?.signal).toBe(controller.signal);
return action === 'get_status'
? { status: 'failed', retcode: 1401, wording: 'unauthorized' }
: { status: 'ok', retcode: 0, data: { action } };
});
const result = await callTool(
'get_runtime_info',
{ check_connection: true },
{ mode: 'read', client: onebot, signal: controller.signal },
);
expect(vi.mocked(onebot.call).mock.calls.map(([action]) => action)).toEqual([
'get_login_info',
'get_status',
'get_version_info',
]);
expect(result.structuredContent.diagnostics.outcome).toBe('failed');
expect(result.structuredContent.result).toMatchObject({
checks: {
get_status: { result: { retcode: 1401 }, diagnostics: { outcome: 'failed' } },
},
});
});
it('forwards ordinary request cancellation and does not start pre-cancelled calls', async () => {
const controller = new AbortController();
const onebot = client();
await callTool(
'query_action',
{ action: 'get_status' },
{ mode: 'read', client: onebot, signal: controller.signal },
);
expect(onebot.call).toHaveBeenCalledWith('get_status', {}, { signal: controller.signal });
controller.abort();
const result = await callTool(
'query_action',
{ action: 'get_status' },
{ mode: 'read', client: onebot, signal: controller.signal },
);
expect(onebot.call).toHaveBeenCalledTimes(1);
expect(result.structuredContent.diagnostics.kind).toBe('cancelled');
});
});
+124
View File
@@ -0,0 +1,124 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { createServer, type Server } from 'node:http';
import { mkdtempSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { makeHttpClient } from '../src/client';
const dirs: string[] = [];
const servers: Server[] = [];
afterEach(async () => {
for (const server of servers.splice(0)) {
server.closeAllConnections();
await new Promise<void>((resolve, reject) =>
server.close((error) => (error ? reject(error) : resolve())),
);
}
for (const dir of dirs.splice(0)) {
rmSync(dir, { recursive: true, force: true });
}
});
function directory() {
const dir = mkdtempSync(join(tmpdir(), 'mcp-cancel-'));
dirs.push(dir);
return dir;
}
describe('ordinary HTTP cancellation', () => {
it.each([false, true])(
'aborts the actual HTTP request (headers received: %s)',
async (sendHeaders) => {
const started = Promise.withResolvers<void>();
const disconnected = Promise.withResolvers<void>();
let count = 0;
const server = createServer((_request, response) => {
count++;
response.on('close', () => disconnected.resolve());
if (sendHeaders) {
response.writeHead(200, { 'Content-Type': 'application/json' });
response.write('{"status":');
}
started.resolve();
});
servers.push(server);
await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve));
const address = server.address();
if (!address || typeof address === 'string') {
throw new Error('missing test server port');
}
const client = makeHttpClient({
endpoint: `http://127.0.0.1:${address.port}`,
streamDir: directory(),
timeoutMs: 5000,
});
const controller = new AbortController();
const outcome = client
.call('get_status', {}, { signal: controller.signal })
.catch((error) => error);
await started.promise;
controller.abort(new Error('caller cancelled'));
expect(await outcome).toMatchObject({ kind: 'cancelled' });
await disconnected.promise;
expect(count).toBe(1);
},
);
it('does not issue an HTTP request when already cancelled', async () => {
const fetcher = vi.fn<typeof fetch>();
const client = makeHttpClient({
endpoint: 'http://unused.invalid',
streamDir: directory(),
fetch: fetcher,
});
await expect(
client.call('get_status', {}, { signal: AbortSignal.abort() }),
).rejects.toMatchObject({ kind: 'cancelled' });
expect(fetcher).not.toHaveBeenCalled();
});
it('retains the ordinary timeout and exposes its cause', async () => {
const fetcher: typeof fetch = vi.fn(
async (_input, init) =>
new Promise((_resolve, reject) => {
init?.signal?.addEventListener('abort', () => reject(init.signal?.reason), {
once: true,
});
}),
);
const client = makeHttpClient({
endpoint: 'http://unused.invalid',
streamDir: directory(),
fetch: fetcher,
timeoutMs: 20,
});
await expect(client.call('get_status', {})).rejects.toMatchObject({ kind: 'timeout' });
expect(fetcher).toHaveBeenCalledTimes(1);
});
it('reports resolved limits and paths without endpoint credentials', () => {
const dir = directory();
const client = makeHttpClient({
endpoint: 'https://user:[email protected]/path?token=secret',
accessToken: 'secret',
streamDir: dir,
uploadRoot: dir,
maxStreamBytes: 123,
timeoutMs: 456,
});
expect(client.info).toMatchObject({
timeout_ms: 456,
max_stream_bytes: 123,
download_quota_bytes: 246,
max_active_streams: 4,
upload_enabled: true,
});
expect(client.info?.upload_root).toBe(client.info?.download_directory);
expect(JSON.stringify(client.info)).not.toMatch(/secret|example\.invalid/);
});
});
+154 -6
View File
@@ -3,7 +3,12 @@ import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { createHash } from 'node:crypto';
import { makeHttpClient, parseMaxStreamBytes, parseTimeoutMs } from '../src/client';
import {
makeHttpClient,
parseMaxStreamBytes,
parseTimeoutMs,
type TransferProgress,
} from '../src/client';
const tempDirs: string[] = [];
@@ -169,7 +174,17 @@ describe('makeHttpClient — OneBot HTTP wiring', () => {
)) as unknown as typeof fetch;
const client = makeHttpClient({ endpoint: 'http://127.0.0.1:9999/', fetch: fakeFetch });
const result = await client.callStream('test_download_stream', {});
const progress: TransferProgress[] = [];
const result = await client.callStream(
'test_download_stream',
{},
{
onProgress: async (update) => {
progress.push(update);
},
},
);
expect(progress.map((update) => update.progress)).toEqual([1, 2]);
expect(result).toEqual({ frame_count: 2, frames: [frames[0]], terminal: frames[1] });
});
@@ -225,7 +240,18 @@ describe('makeHttpClient — OneBot HTTP wiring', () => {
streamDir,
});
const result = await client.callStream('download_file_stream', { file: 'remote-id' });
const progress: TransferProgress[] = [];
const result = await client.callStream(
'download_file_stream',
{ file: 'remote-id' },
{
onProgress: async (update) => {
progress.push(update);
},
},
);
expect(progress.map((update) => update.progress)).toEqual([0, 997, content.length]);
expect(progress.every((update) => update.total === content.length)).toBe(true);
expect(Object.keys(result).sort()).toEqual([
'file_path',
@@ -632,11 +658,19 @@ describe('makeHttpClient — OneBot HTTP wiring', () => {
uploadRoot: root,
});
const progress: TransferProgress[] = [];
const result = await client.callStream(
'upload_file_stream',
{ file_retention: 0 },
{ inputFile },
{
inputFile,
onProgress: async (update) => {
progress.push(update);
},
},
);
expect(progress.map((update) => update.progress)).toEqual([0, 512 * 1024, content.length]);
expect(progress.every((update) => update.total === content.length)).toBe(true);
expect(requests).toHaveLength(3);
expect(requests.every((request) => request.action === 'upload_file_stream')).toBe(true);
@@ -789,7 +823,21 @@ describe('makeHttpClient — OneBot HTTP wiring', () => {
uploadRoot: root,
});
const result = await client.callStream('upload_file_stream', {}, { inputFile });
const progress: TransferProgress[] = [];
const result = await client.callStream(
'upload_file_stream',
{},
{
inputFile,
onProgress: async (update) => {
progress.push(update);
},
},
);
expect(
progress.every((update) => update.progress === 0 && update.total === undefined),
).toBe(true);
expect(progress).toHaveLength(2);
expect(requests).toHaveLength(2);
expect(requests[0].params).toMatchObject({
@@ -941,10 +989,110 @@ describe('makeHttpClient — OneBot HTTP wiring', () => {
streamDir,
});
const result = await client.callStream('download_file_stream', {});
const progress: TransferProgress[] = [];
const result = await client.callStream(
'download_file_stream',
{},
{
onProgress: async (update) => {
progress.push(update);
},
},
);
expect(result.file_size).toBe(content.length);
expect(fs.readFileSync(result.file_path).equals(content)).toBe(true);
expect(progress.map((update) => update.progress)).toEqual([0, content.length]);
expect(progress.every((update) => update.total === undefined)).toBe(true);
});
it('cleans partial downloads and releases admission when progress delivery fails', async () => {
const streamDir = fs.mkdtempSync(path.join(os.tmpdir(), 'snowluma-mcp-progress-'));
tempDirs.push(streamDir);
const frame = {
status: 'ok',
retcode: 0,
data: { type: 'stream', data_type: 'file_info', file_name: 'test.bin', file_size: 3 },
};
const fakeFetch: typeof fetch = async () =>
new Response(`${JSON.stringify(frame)}\r\n\r\n`);
const client = makeHttpClient({
endpoint: 'http://unused.invalid',
streamDir,
maxStreamBytes: 3,
fetch: fakeFetch,
});
for (let attempt = 0; attempt < 5; attempt++) {
await expect(
client.callStream(
'download_file_stream',
{},
{
onProgress: async () => {
throw new Error('notification failed');
},
},
),
).rejects.toThrow('notification failed');
expect(fs.readdirSync(streamDir)).toEqual([]);
}
});
it('stops processing already-buffered frames after a cancellation during progress', async () => {
const streamDir = fs.mkdtempSync(path.join(os.tmpdir(), 'snowluma-mcp-progress-'));
tempDirs.push(streamDir);
const frames = [
{
status: 'ok',
retcode: 0,
data: {
type: 'stream',
data_type: 'file_info',
file_name: 'test.bin',
file_size: 1,
},
},
{
status: 'ok',
retcode: 0,
data: { type: 'stream', data_type: 'file_chunk', index: 0, size: 1, data: 'eA==' },
},
{
status: 'ok',
retcode: 0,
data: {
type: 'response',
data_type: 'file_complete',
total_bytes: 1,
total_chunks: 1,
},
},
];
const controller = new AbortController();
const fakeFetch: typeof fetch = async () =>
new Response(frames.map((frame) => `${JSON.stringify(frame)}\r\n\r\n`).join(''));
const client = makeHttpClient({
endpoint: 'http://unused.invalid',
streamDir,
fetch: fakeFetch,
});
const updates: number[] = [];
await expect(
client.callStream(
'download_file_stream',
{},
{
signal: controller.signal,
onProgress: async (update) => {
updates.push(update.progress);
controller.abort();
},
},
),
).rejects.toThrow(/cancelled/);
expect(updates).toEqual([0]);
expect(fs.readdirSync(streamDir)).toEqual([]);
});
it('requires file_info as the first successful frame for known file-download actions', async () => {
+198
View File
@@ -0,0 +1,198 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
import { createMcpServer } from '../src/server-factory';
import { createProgressReporter } from '../src/progress';
import type { ActionClient, TransferProgress } from '../src/client';
const close: Array<() => Promise<void>> = [];
afterEach(async () => {
for (const cleanup of close.splice(0).reverse()) {
await cleanup();
}
});
async function connect(onebot?: ActionClient) {
const server = createMcpServer({ mode: onebot ? 'write' : 'docs', client: onebot });
const client = new Client({ name: 'test-agent', version: '1.0.0' });
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
close.push(
() => server.close(),
() => client.close(),
);
await server.connect(serverTransport);
await client.connect(clientTransport);
return { client, serverTransport };
}
function fakeOneBot(): ActionClient {
return {
call: vi.fn(async () => ({ status: 'ok', retcode: 0, data: { online: true } })),
callStream: vi.fn(async (_action, _params, options) => {
for (const progress of [0, 3, 7]) {
await options?.onProgress?.({ progress, total: 7, message: 'transferred bytes' });
}
return { frame_count: 2, frames: [], terminal: { status: 'ok', retcode: 0 } };
}),
};
}
describe('MCP protocol compatibility', () => {
it('publishes output schemas that a real MCP client can validate for every tool', async () => {
const { client } = await connect(fakeOneBot());
const tools = await client.listTools();
for (const tool of tools.tools) {
expect(tool.outputSchema).toBeDefined();
const result = await client.callTool({
name: tool.name,
arguments: { name: 'get_status', query: 'history', action: 'get_status' },
});
expect(result.isError).toBeUndefined();
expect(result.structuredContent).toMatchObject({ diagnostics: { outcome: 'success' } });
}
const failure = await client.callTool({
name: 'get_action',
arguments: { name: 'missing_action' },
});
expect(failure.isError).toBe(true);
expect(failure.structuredContent).toMatchObject({ diagnostics: { kind: 'not_found' } });
const resources = await client.listResources();
expect(resources.resources.map((resource) => resource.uri)).toEqual([
'snowluma://onebot/actions',
]);
const catalog = await client.readResource({ uri: 'snowluma://onebot/actions' });
expect(catalog.contents).toHaveLength(1);
});
it('sends bounded progress only when requested and flushes the final update before the response', async () => {
const { client, serverTransport } = await connect(fakeOneBot());
const send = vi.spyOn(serverTransport, 'send');
await client.callTool({
name: 'invoke_action',
arguments: { action: 'test_download_stream' },
});
expect(
send.mock.calls.some(
([message]) => 'method' in message && message.method === 'notifications/progress',
),
).toBe(false);
const progress: number[] = [];
const result = await client.callTool(
{ name: 'invoke_action', arguments: { action: 'test_download_stream' } },
undefined,
{
onprogress: (update) => {
progress.push(update.progress);
},
},
);
expect(progress).toEqual([0, 7]);
expect(result.isError).toBeUndefined();
const count = progress.length;
await new Promise((resolve) => setImmediate(resolve));
expect(progress).toHaveLength(count);
});
it.each([0, 'upload-token'])('preserves progress token %j', async (token) => {
const { client, serverTransport } = await connect(fakeOneBot());
const send = vi.spyOn(serverTransport, 'send');
await client.request(
{
method: 'tools/call',
params: {
name: 'invoke_action',
arguments: { action: 'test_download_stream' },
_meta: { progressToken: token },
},
},
CallToolResultSchema,
);
const notifications = send.mock.calls
.map(([message]) => message)
.filter(
(message) => 'method' in message && message.method === 'notifications/progress',
);
expect(notifications).toHaveLength(2);
for (const notification of notifications) {
expect(notification).toMatchObject({ params: { progressToken: token } });
}
});
it('propagates a real MCP cancellation notification to ordinary execution', async () => {
const started = Promise.withResolvers<void>();
const aborted = Promise.withResolvers<void>();
const onebot = fakeOneBot();
onebot.call = vi.fn(
async (_action, _params, options) =>
new Promise((_resolve, reject) => {
options?.signal?.addEventListener(
'abort',
() => {
aborted.resolve();
reject(options.signal?.reason);
},
{ once: true },
);
started.resolve();
}),
);
const { client } = await connect(onebot);
const controller = new AbortController();
const outcome = client
.callTool({ name: 'query_action', arguments: { action: 'get_status' } }, undefined, {
signal: controller.signal,
})
.catch((error) => error);
await started.promise;
controller.abort(new Error('cancel wait'));
expect(await outcome).toBeInstanceOf(Error);
await aborted.promise;
expect(onebot.call).toHaveBeenCalledTimes(1);
});
});
describe('per-request progress', () => {
it('rate limits, enforces increasing values, and stops on cancellation', async () => {
let time = 0;
const controller = new AbortController();
const updates: TransferProgress[] = [];
const reporter = createProgressReporter(
async (value) => {
updates.push(value);
},
controller.signal,
() => time,
);
await reporter.report({ progress: 0, message: 'start' });
await reporter.report({ progress: 1, message: 'one' });
await reporter.report({ progress: 2, message: 'two' });
expect(updates.map((value) => value.progress)).toEqual([0]);
time = 250;
await reporter.report({ progress: 3, message: 'three' });
await reporter.report({ progress: 3, message: 'duplicate' });
await reporter.finish();
expect(updates.map((value) => value.progress)).toEqual([0, 3]);
await expect(reporter.report({ progress: 2, message: 'backwards' })).rejects.toThrow(
'Invalid transfer progress',
);
controller.abort();
time = 500;
await reporter.report({ progress: 4, message: 'cancelled' });
await reporter.finish();
expect(updates).toHaveLength(2);
});
it('surfaces notification delivery failure', async () => {
const reporter = createProgressReporter(async () => {
throw new Error('transport closed');
}, new AbortController().signal);
await expect(reporter.report({ progress: 1, message: 'one' })).rejects.toThrow(
'transport closed',
);
});
});
+2 -1
View File
@@ -49,12 +49,13 @@ describe('computeTools — mode gating', () => {
expect(() => parseMode(invalid), invalid).toThrow(/SNOWLUMA_MCP_MODE/);
}
});
it('docs mode exposes only the 4 catalog tools', () => {
it('docs mode exposes catalog tools and local runtime information', () => {
expect(computeTools('docs').map((t) => t.name)).toEqual([
'list_actions',
'get_action',
'search_actions',
'list_categories',
'get_runtime_info',
]);
});
it('read mode adds query_action only (no invoke_action)', () => {