feat(mcp): complete action results and invocation examples

Document result shapes and practical calls for all built-in actions,
including prerequisites, streaming workflows and compatibility limits.

Preserve existing interfaces and execution behavior, and verify the
catalog against action validation and representative responses.
This commit is contained in:
DrSmoothl committed 2026-10-23 15:45:07 +08:00
1 parent 34a73084e0
commit 2d659b0ceb
27 files changed
+14140 -33

No files matched your search

+51
View File
@@ -2,6 +2,9 @@
// declarative action and renders coherent metadata/markdown.
import { describe, it, expect } from 'vitest';
import { collectActionDocs, renderActionDocsMarkdown } from '../src/action-docs';
import { ACTION_REGISTRY } from '../src/actions';
import { defineAction, defineStreamAction } from '../src/action-kit';
import { okResponse } from '../src/types';
describe('action-docs', () => {
const docs = collectActionDocs();
@@ -75,6 +78,54 @@ describe('action-docs', () => {
expect(md).toContain('# OneBot Actions');
expect(md).toContain('`set_group_ban`');
expect(md).toContain('| 参数 | 类型 | 必填 | 默认 | 说明 |');
expect(md).toContain('"action": "set_group_ban"');
expect(md).toContain('"duration": 600');
});
it.each(ACTION_REGISTRY.actions)(
'$canonical examples pass the real parameter parser',
({ spec, doc }) => {
expect(doc.returnsSchema).toBeTypeOf('object');
expect(doc.examples?.length).toBeGreaterThan(0);
// Both built-in spec kinds expose a pure parser; do not call handlers
// here, since examples include writes and process-lifecycle actions.
if (!('parse' in spec) || typeof spec.parse !== 'function') {
throw new Error(`${doc.name} has no pure parameter parser`);
}
for (const example of doc.examples ?? []) {
expect(example.summary).not.toBe('');
const keys = new Set(doc.params.map((param) => param.name));
for (const key of Object.keys(example.params)) {
expect(keys.has(key), `${doc.name} unknown example param ${key}`).toBe(true);
}
expect(spec.parse(example.params), `${doc.name}: ${example.summary}`).toMatchObject(
{ ok: true },
);
}
},
);
it('keeps documentation metadata optional for existing custom specs', () => {
for (const define of [defineAction, defineStreamAction]) {
const spec = define({ name: 'custom', params: {}, run: () => okResponse() });
expect(spec.describe().examples).toBeUndefined();
expect(spec.describe().returnsSchema).toBeUndefined();
expect(spec.parse({})).toMatchObject({ ok: true });
}
});
it('isolates collected examples and schemas from caller mutations', () => {
const copy = collectActionDocs();
const action = copy.find((doc) => doc.name === 'send_group_msg')!;
action.examples![0].params.group_id = 99999;
action.returnsSchema!.type = 'null';
const fresh = collectActionDocs().find((doc) => doc.name === action.name)!;
expect(fresh.examples![0].params.group_id).toBe(20001);
expect(fresh.returnsSchema!.type).toBe('object');
});
it('documents custom reply content on every forward entry point', () => {