@uwa4d/openapi-mcp 0.2.0-beta.1 → 0.2.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -2
- package/dist/cli.js +18 -6
- package/dist/composite/helpers.d.ts +19 -0
- package/dist/composite/helpers.js +90 -0
- package/dist/composite/index.d.ts +25 -0
- package/dist/composite/index.js +46 -0
- package/dist/composite/overview-view.d.ts +33 -0
- package/dist/composite/overview-view.js +373 -0
- package/dist/composite/report-diagnosis.d.ts +2 -0
- package/dist/composite/report-diagnosis.js +174 -0
- package/dist/composite/route-overview.d.ts +72 -0
- package/dist/composite/route-overview.js +233 -0
- package/dist/composite/stack-agg.d.ts +65 -0
- package/dist/composite/stack-agg.js +257 -0
- package/dist/composite/top-functions.d.ts +16 -0
- package/dist/composite/top-functions.js +133 -0
- package/dist/composite/top-resources.d.ts +12 -0
- package/dist/composite/top-resources.js +263 -0
- package/dist/composite/types.d.ts +25 -0
- package/dist/composite/types.js +2 -0
- package/dist/presets.js +4 -0
- package/dist/server.d.ts +6 -1
- package/dist/server.js +29 -4
- package/dist/tools.js +5 -0
- package/dist/version-guide.d.ts +9 -0
- package/dist/version-guide.js +90 -0
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z, type ZodTypeAny } from 'zod';
|
|
2
|
+
import type { Engine } from '../spec.js';
|
|
3
|
+
import type { UwaClient } from '../client.js';
|
|
4
|
+
import type { NameCase } from '../tools.js';
|
|
5
|
+
import type { ToolResult } from '../tools.js';
|
|
6
|
+
export interface CompositeContext {
|
|
7
|
+
client: UwaClient;
|
|
8
|
+
maxChars: number;
|
|
9
|
+
nameCase: NameCase;
|
|
10
|
+
namePrefix: string;
|
|
11
|
+
/** --engine 过滤,'all' 表示不过滤 */
|
|
12
|
+
engine: Engine | 'all';
|
|
13
|
+
}
|
|
14
|
+
export interface CompositeTool {
|
|
15
|
+
id: string;
|
|
16
|
+
title: string;
|
|
17
|
+
description: string;
|
|
18
|
+
/** 适用引擎;过滤 --engine 时用 */
|
|
19
|
+
engines: Engine[];
|
|
20
|
+
/** --tool 过滤键,除 id 外还可含 composite / preset.default 等 */
|
|
21
|
+
filterKeys: string[];
|
|
22
|
+
inputSchema: Record<string, ZodTypeAny>;
|
|
23
|
+
handler: (args: Record<string, unknown>, ctx: CompositeContext) => Promise<ToolResult>;
|
|
24
|
+
}
|
|
25
|
+
export { z };
|
package/dist/presets.js
CHANGED
|
@@ -25,6 +25,10 @@ export const PRESET_DEFAULT = [
|
|
|
25
25
|
'gotonline_overview_memory_manage_data_report',
|
|
26
26
|
'gotonline_overview_method_group_statistic',
|
|
27
27
|
'gotonline_overview_stack_stutter_full_presign',
|
|
28
|
+
// 复合工具(手写,见 src/composite/)
|
|
29
|
+
'top_resources',
|
|
30
|
+
'top_functions',
|
|
31
|
+
'report_diagnosis',
|
|
28
32
|
];
|
|
29
33
|
/**
|
|
30
34
|
* 每个接口对应的一组过滤键,用户在 --tool 里写任意一个即可命中。
|
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { COMPOSITE_TOOLS, selectCompositeTools } from './composite/index.js';
|
|
2
3
|
import { type Engine } from './spec.js';
|
|
3
4
|
import { type NameCase } from './tools.js';
|
|
4
5
|
export interface ServerOptions {
|
|
@@ -16,10 +17,14 @@ export interface ServerOptions {
|
|
|
16
17
|
timeoutMs: number;
|
|
17
18
|
specPath?: string;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
/** 与 package.json 同步,避免 MCP 握手版本和 npm 包不一致。 */
|
|
21
|
+
export declare const PACKAGE_VERSION: string;
|
|
20
22
|
export declare function createServer(opts: ServerOptions): {
|
|
21
23
|
server: McpServer;
|
|
22
24
|
toolCount: number;
|
|
23
25
|
total: number;
|
|
26
|
+
atomicCount: number;
|
|
27
|
+
compositeCount: number;
|
|
24
28
|
};
|
|
25
29
|
export declare function startStdio(opts: ServerOptions): Promise<void>;
|
|
30
|
+
export { selectCompositeTools, COMPOSITE_TOOLS };
|
package/dist/server.js
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
1
4
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
5
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
6
|
import { UwaClient } from './client.js';
|
|
7
|
+
import { registerCompositeTools, COMPOSITE_TOOLS, selectCompositeTools } from './composite/index.js';
|
|
4
8
|
import { selectOperations } from './presets.js';
|
|
5
9
|
import { loadSpec } from './spec.js';
|
|
6
10
|
import { makeHandler, toolConfig, toolName } from './tools.js';
|
|
7
|
-
|
|
11
|
+
function readPackageVersion() {
|
|
12
|
+
try {
|
|
13
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const pkg = JSON.parse(readFileSync(join(here, '..', 'package.json'), 'utf8'));
|
|
15
|
+
return pkg.version ?? '0.0.0';
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return '0.0.0';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** 与 package.json 同步,避免 MCP 握手版本和 npm 包不一致。 */
|
|
22
|
+
export const PACKAGE_VERSION = readPackageVersion();
|
|
8
23
|
export function createServer(opts) {
|
|
9
24
|
const spec = loadSpec(opts.specPath);
|
|
10
25
|
const operations = selectOperations(spec.operations, { tools: opts.tools, engine: opts.engine });
|
|
@@ -17,11 +32,21 @@ export function createServer(opts) {
|
|
|
17
32
|
for (const op of operations) {
|
|
18
33
|
server.registerTool(toolName(op.id, opts.nameCase, opts.namePrefix), toolConfig(op), makeHandler(op, client, opts.maxRows, opts.maxChars));
|
|
19
34
|
}
|
|
20
|
-
|
|
35
|
+
const compositeCount = registerCompositeTools(server, client, {
|
|
36
|
+
tools: opts.tools,
|
|
37
|
+
engine: opts.engine,
|
|
38
|
+
nameCase: opts.nameCase,
|
|
39
|
+
namePrefix: opts.namePrefix,
|
|
40
|
+
maxChars: opts.maxChars,
|
|
41
|
+
});
|
|
42
|
+
const toolCount = operations.length + compositeCount;
|
|
43
|
+
const total = spec.operations.length + COMPOSITE_TOOLS.length;
|
|
44
|
+
return { server, toolCount, total, atomicCount: operations.length, compositeCount };
|
|
21
45
|
}
|
|
22
46
|
export async function startStdio(opts) {
|
|
23
|
-
const { server, toolCount, total } = createServer(opts);
|
|
47
|
+
const { server, toolCount, total, atomicCount, compositeCount } = createServer(opts);
|
|
24
48
|
// stdout 是 MCP 协议通道,任何日志都必须走 stderr
|
|
25
|
-
console.error(`[uwa-openapi-mcp] 已加载 ${toolCount}/${total}
|
|
49
|
+
console.error(`[uwa-openapi-mcp] 已加载 ${toolCount}/${total} 个工具(原子 ${atomicCount} + 复合 ${compositeCount}),接口地址 ${opts.baseUrl}`);
|
|
26
50
|
await server.connect(new StdioServerTransport());
|
|
27
51
|
}
|
|
52
|
+
export { selectCompositeTools, COMPOSITE_TOOLS };
|
package/dist/tools.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { UwaApiError } from './client.js';
|
|
3
|
+
import { versionGuideFor } from './version-guide.js';
|
|
3
4
|
const ENGINE_LABEL = { unity: 'Unity', unreal: 'UE' };
|
|
4
5
|
/**
|
|
5
6
|
* 预签名数据默认完整返回,不按条数截断——实测各接口解压后在 10 KB ~ 500 KB 之间,
|
|
@@ -36,6 +37,10 @@ function zodFor(param) {
|
|
|
36
37
|
*/
|
|
37
38
|
function describe(op) {
|
|
38
39
|
const lines = [op.summary || op.name];
|
|
40
|
+
// v1/v2 选用规则放在最前,避免模型淹没在长 notes 里选错接口
|
|
41
|
+
const guide = versionGuideFor(op.id);
|
|
42
|
+
if (guide)
|
|
43
|
+
lines.push(guide);
|
|
39
44
|
const engines = op.engines.map((e) => ENGINE_LABEL[e]).join(' / ');
|
|
40
45
|
lines.push(`适用引擎:${engines}|模块:${op.modules.join(',')}|${op.method} ${op.path}`);
|
|
41
46
|
const sdk = op.variants.find((v) => v.sdkRequirement)?.sdkRequirement;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 版本成对工具的选用规则。
|
|
3
|
+
*
|
|
4
|
+
* 集中手写、挂到 describe() 首段,避免散落在 notes 里被模型漏读。
|
|
5
|
+
* 不塞进 docs/ 生成链路——刷新官方文档镜像不会冲掉这里。
|
|
6
|
+
*/
|
|
7
|
+
/** 写入工具 description 的「选用规则」块,key 为 operation id。 */
|
|
8
|
+
export declare const VERSION_GUIDE: Record<string, string>;
|
|
9
|
+
export declare function versionGuideFor(opId: string): string | undefined;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 版本成对工具的选用规则。
|
|
3
|
+
*
|
|
4
|
+
* 集中手写、挂到 describe() 首段,避免散落在 notes 里被模型漏读。
|
|
5
|
+
* 不塞进 docs/ 生成链路——刷新官方文档镜像不会冲掉这里。
|
|
6
|
+
*/
|
|
7
|
+
/** 写入工具 description 的「选用规则」块,key 为 operation id。 */
|
|
8
|
+
export const VERSION_GUIDE = {
|
|
9
|
+
get_overview_statistic_v1: [
|
|
10
|
+
'【选用规则——务必先看】',
|
|
11
|
+
'- Unity:仅适用于解析日 < 2026-07-09 的 Overview 报告。新报告请改用 get_overview_statistic_v2。',
|
|
12
|
+
'- UE:仅适用于提交日 ≤ 2026-03-25 的 Overview 报告。新报告请改用 get_ue_overview_statistic_v2。',
|
|
13
|
+
'- 不确定日期时:先调 get_report_detail 看 createDate / engine / sdkVersion;或直接用复合工具 report_diagnosis / top_functions(内部自动路由)。',
|
|
14
|
+
].join('\n'),
|
|
15
|
+
get_overview_statistic_v2: [
|
|
16
|
+
'【选用规则——务必先看】',
|
|
17
|
+
'- 仅 Unity。解析日 ≥ 2026-07-09 且 SDK ≥ 2.5.1 的 Overview 报告。',
|
|
18
|
+
'- 更早的 Unity 报告请用 get_overview_statistic_v1。UE 报告请用 get_ue_overview_statistic_v2(或旧报告用 get_overview_statistic_v1)。',
|
|
19
|
+
'- 不确定时用复合工具 report_diagnosis / top_functions,无需自己选版本。',
|
|
20
|
+
].join('\n'),
|
|
21
|
+
get_ue_overview_statistic_v2: [
|
|
22
|
+
'【选用规则——务必先看】',
|
|
23
|
+
'- 仅 UE。提交日 > 2026-03-25 的 Overview 报告。',
|
|
24
|
+
'- 更早的 UE 报告请用 get_overview_statistic_v1。Unity 报告请用 get_overview_statistic_v1 或 get_overview_statistic_v2。',
|
|
25
|
+
'- 单次批量最多 30 份(文档写 50,实测上限 30)。不确定时用复合工具自动路由。',
|
|
26
|
+
].join('\n'),
|
|
27
|
+
get_scene_statistic_v1: [
|
|
28
|
+
'【选用规则——务必先看】',
|
|
29
|
+
'- 仅 Unity。解析日 < 2026-07-09 的 Overview 报告场景统计。',
|
|
30
|
+
'- 新报告请改用 get_scene_statistic_v2。',
|
|
31
|
+
].join('\n'),
|
|
32
|
+
get_scene_statistic_v2: [
|
|
33
|
+
'【选用规则——务必先看】',
|
|
34
|
+
'- 仅 Unity。解析日 ≥ 2026-07-09 且 SDK ≥ 2.5.1 的 Overview 报告场景统计。',
|
|
35
|
+
'- 更早的报告请用 get_scene_statistic_v1。',
|
|
36
|
+
].join('\n'),
|
|
37
|
+
gotonline_overview_custom_dashboard: [
|
|
38
|
+
'【选用规则——务必先看】',
|
|
39
|
+
'- 自定义面板统计 1.0(抽帧曲线)。不支持 GPU 类面板。',
|
|
40
|
+
'- 需要 GPU 指标或更多统计值类型时,改用 gotonline_overview_indicator_statistic_dashboard(2.0,需 SDK ≥ 2.5.1)。',
|
|
41
|
+
'- 逐帧曲线用 gotonline_overview_indicator_curve_dashboard(2.0,最多 3 个面板)。',
|
|
42
|
+
].join('\n'),
|
|
43
|
+
gotonline_overview_indicator_statistic_dashboard: [
|
|
44
|
+
'【选用规则——务必先看】',
|
|
45
|
+
'- 自定义面板统计 2.0。需 SDK ≥ 2.5.1,支持 GPU 指标,最多 15 个面板。',
|
|
46
|
+
'- 旧接口(抽帧、无 GPU)见 gotonline_overview_custom_dashboard。',
|
|
47
|
+
'- 只要逐帧曲线不要统计值时用 gotonline_overview_indicator_curve_dashboard。',
|
|
48
|
+
].join('\n'),
|
|
49
|
+
gotonline_overview_indicator_curve_dashboard: [
|
|
50
|
+
'【选用规则——务必先看】',
|
|
51
|
+
'- 自定义面板帧数据 2.0。需 SDK ≥ 2.5.1,最多 3 个面板;不支持内存类面板。',
|
|
52
|
+
'- 要统计值(含场景维度)用 gotonline_overview_indicator_statistic_dashboard。',
|
|
53
|
+
'- 【横轴——勿混用】外层 x_axis 为逐帧共享横轴(1、2、3…);y_axis.{指标名}.x_axis 为该曲线专属横轴(常见步长 30:0、30、60…)。',
|
|
54
|
+
'- 读取某条曲线时:若存在专属 x_axis 必须用专属,否则才用外层共享 x_axis。把共享横轴套到 FPS 等专属曲线会错位。',
|
|
55
|
+
'- 响应另含 _axisBinding / _axisHint,按其中 xAxisSource 取值即可。',
|
|
56
|
+
].join('\n'),
|
|
57
|
+
gotonline_overview_memory_usage_snapshot: [
|
|
58
|
+
'【选用规则——务必先看】',
|
|
59
|
+
'- 资源快照帧号 1.0。仅适用于解析日 < 2026-07-09 的报告。',
|
|
60
|
+
'- 新报告请用 gotonline_overview_dump_frames(快照帧 2.0)。',
|
|
61
|
+
].join('\n'),
|
|
62
|
+
gotonline_overview_dump_frames: [
|
|
63
|
+
'【选用规则——务必先看】',
|
|
64
|
+
'- 快照帧 2.0。仅适用于解析日 ≥ 2026-07-09 且 SDK ≥ 2.5.1 的报告。',
|
|
65
|
+
'- 更早的报告请用 gotonline_overview_memory_usage_snapshot。',
|
|
66
|
+
].join('\n'),
|
|
67
|
+
gotonline_overview_log_export: [
|
|
68
|
+
'【选用规则——务必先看】',
|
|
69
|
+
'- 运行日志 1.0。Unity:解析日 < 2026-07-09;UE:提交日 ≤ 2026-03-25。',
|
|
70
|
+
'- 新报告请用 gotonline_lg_runtime_log_entries_presign(运行日志 2.0)。',
|
|
71
|
+
].join('\n'),
|
|
72
|
+
gotonline_lg_runtime_log_entries_presign: [
|
|
73
|
+
'【选用规则——务必先看】',
|
|
74
|
+
'- 运行日志 2.0(预签名)。解析日 ≥ 2026-07-09 且 SDK ≥ 2.5.1。',
|
|
75
|
+
'- 更早的报告请用 gotonline_overview_log_export。',
|
|
76
|
+
].join('\n'),
|
|
77
|
+
gotonline_overview_group_export: [
|
|
78
|
+
'【选用规则——务必先看】',
|
|
79
|
+
'- UE 自定义函数组统计 1.0。仅适用于提交日 ≤ 2026-03-25 的 UE 报告。',
|
|
80
|
+
'- 新 UE 报告请用 gotonline_overview_method_group_statistic(需 Header api 版本 v1.0.2)。',
|
|
81
|
+
].join('\n'),
|
|
82
|
+
gotonline_overview_method_group_statistic: [
|
|
83
|
+
'【选用规则——务必先看】',
|
|
84
|
+
'- 自定义函数组统计(Unity SDK ≥ 2.5.1;UE 提交日 > 2026-03-25,且 api 版本须 v1.0.2)。',
|
|
85
|
+
'- UE 旧报告请用 gotonline_overview_group_export。',
|
|
86
|
+
].join('\n'),
|
|
87
|
+
};
|
|
88
|
+
export function versionGuideFor(opId) {
|
|
89
|
+
return VERSION_GUIDE[opId];
|
|
90
|
+
}
|