@modelbay/mcp 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,252 @@
1
+ import { listTools } from "./generate.mjs";
2
+ import { normalizeArguments } from "./arguments.mjs";
3
+ import { JobRegistry, deliver, deliveredIntact, outputDirectory, pollUntil, settle, waitSeconds } from "./jobs.mjs";
4
+ import { lifecycleNotice, missingSecrets, selectDefaultModel, toBase64 } from "modelbay";
5
+ // src/routing.ts
6
+ /**
7
+ * 把 tools/list 与 tools/call 接到生成器结果、PlatformAdapter 与 AdapterContext。
8
+ * tools/call 按生成时记录的 route 分发:
9
+ * submit → adapter.submit;native → adapter.native;local → 本地只读回答。
10
+ * 未配置 key / 适配器未就绪时返回清晰错误(isError 结果),绝不抛到 stdio 循环里。
11
+ */
12
+ function toText(value) {
13
+ return typeof value === "string" ? value : JSON.stringify(value, null, 2);
14
+ }
15
+ /**
16
+ * 把结果里的字节(`Uint8Array`)拆成 MCP 标准内容块:图片 / 音频用 base64 的 image / audio 块,
17
+ * 其他文件用内嵌资源。文本和结构化结果里只留 `bytes` 与内容块序号,不把字节序列化成 JSON。
18
+ */
19
+ function splitBinary(value, blocks) {
20
+ if (value instanceof Uint8Array) return { bytes: value.byteLength };
21
+ if (Array.isArray(value)) return value.map((item) => splitBinary(item, blocks));
22
+ if (typeof value !== "object" || value === null) return value;
23
+ const record = value;
24
+ if (record.data instanceof Uint8Array) {
25
+ const data = toBase64(record.data);
26
+ const mimeType = typeof record.mime === "string" ? record.mime : "application/octet-stream";
27
+ const kind = record.kind;
28
+ blocks.push(kind === "image" || kind === "audio" ? {
29
+ type: kind,
30
+ data,
31
+ mimeType
32
+ } : {
33
+ type: "resource",
34
+ resource: {
35
+ uri: `modelbay://output/${blocks.length}/${String(record.name ?? "file")}`,
36
+ mimeType,
37
+ blob: data
38
+ }
39
+ });
40
+ const { data: _bytes, ...rest } = record;
41
+ return {
42
+ ...rest,
43
+ bytes: record.data.byteLength,
44
+ content: blocks.length
45
+ };
46
+ }
47
+ return Object.fromEntries(Object.entries(record).map(([k, v]) => [k, splitBinary(v, blocks)]));
48
+ }
49
+ function result(value) {
50
+ const blocks = [];
51
+ const plain = splitBinary(value, blocks);
52
+ const structured = typeof plain === "object" && plain !== null ? plain : void 0;
53
+ return {
54
+ content: [{
55
+ type: "text",
56
+ text: toText(plain)
57
+ }, ...blocks],
58
+ ...structured ? { structuredContent: structured } : {}
59
+ };
60
+ }
61
+ function errorResult(message) {
62
+ return {
63
+ content: [{
64
+ type: "text",
65
+ text: message
66
+ }],
67
+ isError: true
68
+ };
69
+ }
70
+ function firstCapability(set) {
71
+ for (const tool of set.all) if (tool.route.kind === "submit") return tool.route.capability;
72
+ return "";
73
+ }
74
+ /**
75
+ * 传给适配器的模型:工具没传 model 时按能力取声明里的默认模型(只认 active、只在主渠道里选),
76
+ * 并统一去掉适配器自己渠道的 `渠道:` 前缀,适配器拿到的永远是渠道内 ID。
77
+ * 其他渠道的前缀(如方舟 MCP 里的 `ark-plan:`)原样保留,让适配器的渠道校验照常生效。
78
+ */
79
+ function modelFor(args, capability, adapter, primaryChannel) {
80
+ const given = typeof args.model === "string" ? args.model.trim() : "";
81
+ if (given) return stripChannel(given, adapter.channels);
82
+ const channel = primaryChannel ?? adapter.channels[0];
83
+ return selectDefaultModel(adapter.models, capability, channel)?.channel.id ?? "";
84
+ }
85
+ function stripChannel(model, channels) {
86
+ const colon = model.indexOf(":");
87
+ if (colon < 0) return model;
88
+ return channels.includes(model.slice(0, colon)) ? model.slice(colon + 1) : model;
89
+ }
90
+ function localResult(handler, args, set, models) {
91
+ switch (handler) {
92
+ case "tool-help": {
93
+ const name = typeof args.tool === "string" ? args.tool : void 0;
94
+ const tool = name ? set.byName.get(name) : void 0;
95
+ if (tool) return result(tool.description);
96
+ return result(`可用工具:\n${[...set.byName.keys()].sort().join("\n")}`);
97
+ }
98
+ case "capabilities": return result({
99
+ capabilities: [...new Set(set.all.filter((tool) => tool.route.kind === "submit").map((tool) => tool.route.kind === "submit" ? tool.route.capability : ""))].sort(),
100
+ nativeOperations: [...new Set(set.all.filter((tool) => tool.route.kind === "native").map((tool) => tool.route.kind === "native" ? tool.route.op : ""))].sort()
101
+ });
102
+ case "models": {
103
+ const filter = typeof args.capability === "string" ? args.capability : void 0;
104
+ return result({ models: models.filter((model) => !filter || model.capabilities.some((cap) => cap === filter)).map((model) => ({
105
+ canonicalId: model.canonicalId,
106
+ title: model.title,
107
+ capabilities: model.capabilities,
108
+ status: model.lifecycle.status,
109
+ notice: lifecycleNotice(model)
110
+ })) });
111
+ }
112
+ case "voices": {
113
+ const voices = models.flatMap((model) => (model.voices ?? []).map((voice) => ({
114
+ model: model.canonicalId,
115
+ ...voice
116
+ })));
117
+ return result(voices.length > 0 ? { voices } : {
118
+ voices: [],
119
+ note: "当前声明未登记预置音色;音色列表来自平台侧,需联网查询"
120
+ });
121
+ }
122
+ case "usage-examples": return result({
123
+ note: "按工具名调用 get_tool_help 读取完整用法;工具清单见 tools/list。",
124
+ tools: [...set.byName.keys()].sort()
125
+ });
126
+ default: return errorResult(`未知的本地处理器 ${String(handler)}`);
127
+ }
128
+ }
129
+ function createHandlers(options) {
130
+ const { set, adapter, context, groups, secrets, serverInfo, primaryChannel } = options;
131
+ const models = adapter?.models ?? [];
132
+ const fallbackCapability = firstCapability(set);
133
+ const jobs = new JobRegistry();
134
+ /** 任务结果:交付文件(给了输出目录就落盘),异步任务带上 job_id / task_id。 */
135
+ async function jobResult(tool, id, value, outDir) {
136
+ const ids = id ? {
137
+ job_id: id,
138
+ task_id: id
139
+ } : {};
140
+ const record = id ? jobs.get(id) : void 0;
141
+ if (value.state === "pending") return result({
142
+ ...ids,
143
+ job_state: "running",
144
+ completed: false,
145
+ ..."progress" in value && value.progress !== void 0 ? { progress: value.progress } : {},
146
+ ...id ? { next: "用 get_job 查询进度,可传 wait(1–90 秒)等待完成" } : {}
147
+ });
148
+ if (value.state === "failed") {
149
+ if (record) record.state = "failed";
150
+ return {
151
+ ...result({
152
+ ...ids,
153
+ job_state: "failed",
154
+ completed: false,
155
+ error: value.error
156
+ }),
157
+ isError: true
158
+ };
159
+ }
160
+ if (value.state !== "succeeded" || !Array.isArray(value.outputs)) return result(value);
161
+ const outputs = await deliver(value.outputs, outDir, tool, context);
162
+ const payload = {
163
+ ...ids,
164
+ job_state: "delivered",
165
+ completed: true,
166
+ outputs,
167
+ ...value.usage ? { usage: value.usage } : {}
168
+ };
169
+ if (record) {
170
+ record.state = "delivered";
171
+ if (outDir) record.delivered = {
172
+ outDir,
173
+ payload
174
+ };
175
+ }
176
+ return result(payload);
177
+ }
178
+ function listJobs(args) {
179
+ const limit = Number(args.limit ?? 20);
180
+ return result({
181
+ jobs: jobs.list(Number.isFinite(limit) && limit > 0 ? limit : 20),
182
+ note: "只列出本进程提交的任务;任务记录不落盘,重启后用 task_id 调 get_job 仍可查询。"
183
+ });
184
+ }
185
+ async function callJobs(name, args) {
186
+ const id = [args.job_id, args.task_id].find((value) => typeof value === "string" && value.trim() !== "");
187
+ if (!id) return errorResult(`${name} 需要 job_id 或 task_id`);
188
+ if (typeof args.job_id === "string" && typeof args.task_id === "string" && args.job_id && args.task_id && args.job_id !== args.task_id) return errorResult("job_id 与 task_id 不属于同一任务");
189
+ const record = jobs.get(id) ?? jobs.remember(id, name, void 0);
190
+ const outDir = outputDirectory(args) ?? record.outDir;
191
+ if (record.delivered && record.delivered.outDir === outDir && await deliveredIntact(record.delivered.payload)) return result(record.delivered.payload);
192
+ const value = await pollUntil(adapter, id, context, waitSeconds(args));
193
+ return jobResult(record.tool, id, value, outDir);
194
+ }
195
+ async function callTool(name, args) {
196
+ const tool = set.byName.get(name);
197
+ if (!tool) return errorResult(`未知工具 ${name}`);
198
+ const route = tool.route;
199
+ if (route.kind === "local" && (route.handler !== "jobs" || name === "list_jobs")) return name === "list_jobs" ? listJobs(args) : localResult(route.handler, args, set, models);
200
+ const missing = missingSecrets(secrets, (name) => Boolean(context.secret(name)));
201
+ if (missing.length > 0 || !adapter) {
202
+ const reason = !adapter ? "平台适配器尚未就绪" : `未配置访问密钥:${missing.join("、")}`;
203
+ context.log("modelbay-mcp: 调用被拒绝", {
204
+ tool: name,
205
+ reason
206
+ });
207
+ return errorResult(`${reason},工具 ${name} 无法调用。请在环境变量中配置后重试。`);
208
+ }
209
+ if (route.kind === "local") return callJobs(name, args);
210
+ const given = Object.fromEntries(Object.entries(args).filter(([, value]) => value !== null));
211
+ if (route.kind === "native") {
212
+ const params = tool.mapArguments ? tool.mapArguments(given, { model: "" }) : given;
213
+ if (adapter.native) return result(await adapter.native(route.op, params, context));
214
+ const request = {
215
+ capability: fallbackCapability,
216
+ model: "",
217
+ input: {},
218
+ native: {
219
+ op: route.op,
220
+ params
221
+ }
222
+ };
223
+ return result(await adapter.submit(request, context));
224
+ }
225
+ const model = modelFor(args, route.capability, adapter, primaryChannel);
226
+ const outDir = outputDirectory(given);
227
+ const wait = waitSeconds(given);
228
+ const mapped = tool.mapArguments ? tool.mapArguments(given, { model }) : given;
229
+ const input = normalizeArguments(route.capability, mapped);
230
+ for (const key of [
231
+ "model",
232
+ "wait",
233
+ "out_dir",
234
+ "output_directory"
235
+ ]) delete input[key];
236
+ const request = {
237
+ capability: route.capability,
238
+ model,
239
+ input
240
+ };
241
+ const submitted = await adapter.submit(request, context);
242
+ const id = submitted.state === "pending" ? submitted.remoteId : void 0;
243
+ if (id) jobs.remember(id, name, outDir);
244
+ return jobResult(name, id, await settle(adapter, submitted, context, wait), outDir);
245
+ }
246
+ return {
247
+ serverInfo,
248
+ listTools: () => listTools(set, groups),
249
+ callTool
250
+ };
251
+ }
252
+ export { createHandlers };
@@ -0,0 +1,5 @@
1
+ import { JsonRpcResponse, ServerHandlers } from "./types.mjs";
2
+ export interface McpServer {
3
+ handle(request: unknown): Promise<JsonRpcResponse | null>;
4
+ }
5
+ export declare function createServer(handlers: ServerHandlers): McpServer;
@@ -0,0 +1,85 @@
1
+ // src/server.ts
2
+ const DEFAULT_PROTOCOL_VERSION = "2024-11-05";
3
+ function isObject(value) {
4
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5
+ }
6
+ function ok(id, result) {
7
+ return {
8
+ jsonrpc: "2.0",
9
+ id,
10
+ result
11
+ };
12
+ }
13
+ function fail(id, error) {
14
+ return {
15
+ jsonrpc: "2.0",
16
+ id,
17
+ error
18
+ };
19
+ }
20
+ function idOf(value) {
21
+ if (isObject(value) && "id" in value) {
22
+ const id = value.id;
23
+ if (typeof id === "number" || typeof id === "string") return id;
24
+ }
25
+ return null;
26
+ }
27
+ function errorMessage(error) {
28
+ return error instanceof Error ? error.message : String(error);
29
+ }
30
+ function createServer(handlers) {
31
+ async function handle(request) {
32
+ if (!isObject(request) || request.jsonrpc !== "2.0" || typeof request.method !== "string") return fail(idOf(request), {
33
+ code: -32600,
34
+ message: "Invalid Request"
35
+ });
36
+ const req = request;
37
+ if (!("id" in req)) return null;
38
+ const id = idOf(req) ?? null;
39
+ const params = req.params ?? {};
40
+ switch (req.method) {
41
+ case "initialize": {
42
+ const requested = params.protocolVersion;
43
+ return ok(id, {
44
+ protocolVersion: typeof requested === "string" ? requested : DEFAULT_PROTOCOL_VERSION,
45
+ capabilities: {
46
+ tools: { listChanged: false },
47
+ resources: {},
48
+ prompts: {}
49
+ },
50
+ serverInfo: handlers.serverInfo
51
+ });
52
+ }
53
+ case "ping": return ok(id, {});
54
+ case "tools/list": return ok(id, { tools: await handlers.listTools() });
55
+ case "tools/call": {
56
+ const name = params.name;
57
+ if (typeof name !== "string") return fail(id, {
58
+ code: -32602,
59
+ message: "tools/call 需要字符串 name"
60
+ });
61
+ const args = isObject(params.arguments) ? params.arguments : {};
62
+ try {
63
+ return ok(id, await handlers.callTool(name, args));
64
+ } catch (error) {
65
+ return ok(id, {
66
+ content: [{
67
+ type: "text",
68
+ text: errorMessage(error)
69
+ }],
70
+ isError: true
71
+ });
72
+ }
73
+ }
74
+ case "resources/list": return ok(id, { resources: [] });
75
+ case "resources/templates/list": return ok(id, { resourceTemplates: [] });
76
+ case "prompts/list": return ok(id, { prompts: [] });
77
+ default: return fail(id, {
78
+ code: -32601,
79
+ message: `Method not found: ${req.method}`
80
+ });
81
+ }
82
+ }
83
+ return { handle };
84
+ }
85
+ export { createServer };
@@ -0,0 +1,10 @@
1
+ import { JsonRpcResponse } from "./types.mjs";
2
+ import { Readable, Writable } from "node:stream";
3
+ export interface StdioServerLike {
4
+ handle(request: unknown): Promise<JsonRpcResponse | null>;
5
+ }
6
+ export interface StdioTransportOptions {
7
+ onError?: (error: unknown) => void;
8
+ }
9
+ /** 返回解绑函数,便于测试与优雅退出。 */
10
+ export declare function attachStdioTransport(server: StdioServerLike, input: Readable, output: Writable, options?: StdioTransportOptions): () => void;
@@ -0,0 +1,38 @@
1
+ import { FramedReader, encodeMessage } from "./framing.mjs";
2
+ // src/stdio-transport.ts
3
+ function idOf(message) {
4
+ if (message && typeof message === "object" && "id" in message) {
5
+ const id = message.id;
6
+ if (typeof id === "number" || typeof id === "string") return id;
7
+ }
8
+ return null;
9
+ }
10
+ async function dispatch(server, message, framing, output, options) {
11
+ try {
12
+ const response = await server.handle(message);
13
+ if (response !== null) output.write(encodeMessage(response, framing));
14
+ } catch (error) {
15
+ options.onError?.(error);
16
+ const fallback = {
17
+ jsonrpc: "2.0",
18
+ id: idOf(message),
19
+ error: {
20
+ code: -32603,
21
+ message: "Internal error"
22
+ }
23
+ };
24
+ output.write(encodeMessage(fallback, framing));
25
+ }
26
+ }
27
+ /** 返回解绑函数,便于测试与优雅退出。 */
28
+ function attachStdioTransport(server, input, output, options = {}) {
29
+ const reader = new FramedReader();
30
+ const onData = (chunk) => {
31
+ for (const { message, framing } of reader.push(chunk)) dispatch(server, message, framing, output, options);
32
+ };
33
+ input.on("data", onData);
34
+ return () => {
35
+ input.off?.("data", onData);
36
+ };
37
+ }
38
+ export { attachStdioTransport };
@@ -0,0 +1,17 @@
1
+ import { LocalHandler, ToolGroup, ToolNature } from "./types.mjs";
2
+ /**
3
+ * 超出基线的新工具:从声明派生可用模型与生命周期,避免客户端硬编码模型清单。
4
+ * 名字要符合 MCP 客户端的工具名约束 `^[a-zA-Z0-9_-]{1,64}$`(Claude 会拒绝带冒号的名字),
5
+ * 所以不用 `models:list`;也不叫 `list_models`,那是百炼基线里的官方模型目录查询,语义不同。
6
+ */
7
+ export declare const EXTRA_TOOL_NAMES: readonly ['list_declared_models'];
8
+ export interface ToolMeta {
9
+ capability?: string;
10
+ localHandler?: LocalHandler;
11
+ nature: ToolNature;
12
+ group: ToolGroup;
13
+ }
14
+ /** 按通用工具名约定推断元数据;平台在工具定义里写明的字段优先于这里。 */
15
+ export declare function deriveMeta(name: string): ToolMeta;
16
+ /** 供文档/测试使用:某工具是否被分到可选组。 */
17
+ export declare function isOptionalGroup(group: ToolGroup): boolean;
@@ -0,0 +1,54 @@
1
+ // src/tool-meta.ts
2
+ /** 通用工具名 → 归一化能力(0003),用于模型参数派生与 submit 路由。 */
3
+ const TOOL_CAPABILITY = {
4
+ chat: "text.chat",
5
+ embed: "text.embed",
6
+ generate_image: "image.generate",
7
+ generate_video: "video.generate",
8
+ text_to_speech: "audio.speech",
9
+ speech_to_text: "audio.transcribe",
10
+ clone_voice: "voice.clone",
11
+ design_voice: "voice.design"
12
+ };
13
+ /** MCP 本地工具:由 server 直接从生成结果 / 声明 / 任务存储回答,处理器实现在本包。 */
14
+ const TOOL_LOCAL = {
15
+ get_tool_help: "tool-help",
16
+ list_capabilities: "capabilities",
17
+ list_speech_capabilities: "capabilities",
18
+ get_speech_usage_examples: "usage-examples",
19
+ list_models: "models",
20
+ list_jobs: "jobs",
21
+ get_job: "jobs",
22
+ recover_job: "jobs",
23
+ get_voice: "voices",
24
+ list_voices: "voices"
25
+ };
26
+ /** 本地工具里联网查询的那几个(其余本地工具都是不联网的 `local`)。 */
27
+ const QUERY_TOOLS = /* @__PURE__ */ new Set([
28
+ "get_job",
29
+ "recover_job",
30
+ "get_voice",
31
+ "list_voices"
32
+ ]);
33
+ /**
34
+ * 超出基线的新工具:从声明派生可用模型与生命周期,避免客户端硬编码模型清单。
35
+ * 名字要符合 MCP 客户端的工具名约束 `^[a-zA-Z0-9_-]{1,64}$`(Claude 会拒绝带冒号的名字),
36
+ * 所以不用 `models:list`;也不叫 `list_models`,那是百炼基线里的官方模型目录查询,语义不同。
37
+ */
38
+ const EXTRA_TOOL_NAMES = ["list_declared_models"];
39
+ /** 按通用工具名约定推断元数据;平台在工具定义里写明的字段优先于这里。 */
40
+ function deriveMeta(name) {
41
+ const localHandler = TOOL_LOCAL[name];
42
+ const local = localHandler !== void 0 || EXTRA_TOOL_NAMES.includes(name);
43
+ return {
44
+ ...TOOL_CAPABILITY[name] ? { capability: TOOL_CAPABILITY[name] } : {},
45
+ ...localHandler ? { localHandler } : {},
46
+ nature: QUERY_TOOLS.has(name) ? "query" : local ? "local" : "generate",
47
+ group: "core"
48
+ };
49
+ }
50
+ /** 供文档/测试使用:某工具是否被分到可选组。 */
51
+ function isOptionalGroup(group) {
52
+ return group !== "core";
53
+ }
54
+ export { EXTRA_TOOL_NAMES, deriveMeta, isOptionalGroup };
@@ -0,0 +1,121 @@
1
+ import { ToolSpec as ToolSpec$1 } from "modelbay";
2
+ /** 打开哪些工具组的环境变量(逗号分隔)。 */
3
+ export declare const GROUP_ENV_VAR = "MODELBAY_MCP_GROUPS";
4
+ /** 工具组开关。默认只暴露 core;其余三组默认不启用。 */
5
+ export declare const TOOL_GROUPS: readonly ["core", "realtime", "management", "node"];
6
+ export type ToolGroup = (typeof TOOL_GROUPS)[number];
7
+ export declare const MCP_TOOL_GROUPS: {
8
+ readonly all: readonly ToolGroup[];
9
+ readonly default: readonly ToolGroup[];
10
+ readonly optional: readonly ToolGroup[];
11
+ };
12
+ /**
13
+ * 工具的操作性质,是「能力元数据」的一部分:annotations 与路由都从它派生,
14
+ * 不直接照抄基线(基线条目有缺 destructiveHint 的情况)。
15
+ */
16
+ export declare const TOOL_NATURES: readonly ["generate", "query", "mutate", "local", "realtime"];
17
+ export type ToolNature = (typeof TOOL_NATURES)[number];
18
+ export interface JsonSchema {
19
+ type?: string;
20
+ title?: string;
21
+ description?: string;
22
+ properties?: Record<string, Record<string, unknown>>;
23
+ required?: string[];
24
+ [key: string]: unknown;
25
+ }
26
+ export interface ToolAnnotations {
27
+ readOnlyHint: boolean;
28
+ destructiveHint: boolean;
29
+ idempotentHint: boolean;
30
+ openWorldHint: boolean;
31
+ }
32
+ /** MCP tools/list 返回的工具(公开形状,不含内部字段)。 */
33
+ export interface MCPTool {
34
+ name: string;
35
+ description: string;
36
+ inputSchema: JsonSchema;
37
+ outputSchema?: JsonSchema;
38
+ annotations: ToolAnnotations;
39
+ }
40
+ /** tools/call 的路由描述。 */
41
+ export type ToolRoute = {
42
+ kind: 'submit';
43
+ capability: string;
44
+ nature: ToolNature;
45
+ } | {
46
+ kind: 'native';
47
+ op: string;
48
+ nature: ToolNature;
49
+ } | {
50
+ kind: 'local';
51
+ handler: LocalHandler;
52
+ nature: ToolNature;
53
+ };
54
+ export type LocalHandler = 'tool-help' | 'capabilities' | 'models' | 'jobs' | 'voices' | 'usage-examples';
55
+ /** 生成后的工具(含内部字段,供 server 路由与分组过滤用)。 */
56
+ export interface GeneratedTool extends MCPTool {
57
+ group: ToolGroup;
58
+ route: ToolRoute;
59
+ mapArguments?: ToolSpec$1['mapArguments'];
60
+ }
61
+ export interface GeneratedToolSet {
62
+ /** 平台键(`PlatformDescriptor.key`)。 */
63
+ platform: string;
64
+ /** 全量工具(含所有组)。 */
65
+ all: GeneratedTool[];
66
+ routes: Map<string, ToolRoute>;
67
+ byName: Map<string, GeneratedTool>;
68
+ }
69
+ /** tools/call 的内容块:文本,或 MCP 标准的 base64 图片 / 音频 / 内嵌资源。 */
70
+ export interface TextContent {
71
+ type: 'text';
72
+ text: string;
73
+ }
74
+ export type CallToolContent = TextContent | {
75
+ type: 'image' | 'audio';
76
+ data: string;
77
+ mimeType: string;
78
+ } | {
79
+ type: 'resource';
80
+ resource: {
81
+ uri: string;
82
+ mimeType: string;
83
+ blob: string;
84
+ };
85
+ };
86
+ export interface CallToolResult {
87
+ /** 第一个块总是文本说明;字节结果跟在后面 */
88
+ content: [TextContent, ...CallToolContent[]];
89
+ isError?: boolean;
90
+ structuredContent?: unknown;
91
+ }
92
+ /** JSON-RPC 2.0 消息。 */
93
+ export interface JsonRpcRequest {
94
+ jsonrpc: '2.0';
95
+ id?: number | string | null;
96
+ method: string;
97
+ params?: Record<string, unknown>;
98
+ }
99
+ export interface JsonRpcError {
100
+ code: number;
101
+ message: string;
102
+ data?: unknown;
103
+ }
104
+ export interface JsonRpcResponse {
105
+ jsonrpc: '2.0';
106
+ id: number | string | null;
107
+ result?: unknown;
108
+ error?: JsonRpcError;
109
+ }
110
+ export interface ServerInfo {
111
+ name: string;
112
+ version: string;
113
+ }
114
+ /** createServer 的处理器由调用方注入,server 本身不依赖 core / 适配器。 */
115
+ export interface ServerHandlers {
116
+ serverInfo: ServerInfo;
117
+ protocolVersion?: string;
118
+ listTools(): MCPTool[] | Promise<MCPTool[]>;
119
+ callTool(name: string, args: Record<string, unknown>): Promise<CallToolResult>;
120
+ }
121
+ export type { ToolSpec$1 as ToolSpec };
package/dist/types.mjs ADDED
@@ -0,0 +1,31 @@
1
+ // src/types.ts
2
+ /** 打开哪些工具组的环境变量(逗号分隔)。 */
3
+ const GROUP_ENV_VAR = "MODELBAY_MCP_GROUPS";
4
+ /** 工具组开关。默认只暴露 core;其余三组默认不启用。 */
5
+ const TOOL_GROUPS = [
6
+ "core",
7
+ "realtime",
8
+ "management",
9
+ "node"
10
+ ];
11
+ const MCP_TOOL_GROUPS = {
12
+ all: TOOL_GROUPS,
13
+ default: ["core"],
14
+ optional: [
15
+ "realtime",
16
+ "management",
17
+ "node"
18
+ ]
19
+ };
20
+ /**
21
+ * 工具的操作性质,是「能力元数据」的一部分:annotations 与路由都从它派生,
22
+ * 不直接照抄基线(基线条目有缺 destructiveHint 的情况)。
23
+ */
24
+ const TOOL_NATURES = [
25
+ "generate",
26
+ "query",
27
+ "mutate",
28
+ "local",
29
+ "realtime"
30
+ ];
31
+ export { GROUP_ENV_VAR, MCP_TOOL_GROUPS, TOOL_GROUPS, TOOL_NATURES };
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@modelbay/mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "MCP tool generator and per-platform servers",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/hoobnn/modelbay.git",
9
+ "directory": "packages/mcp"
10
+ },
11
+ "homepage": "https://github.com/hoobnn/modelbay/tree/main/packages/mcp#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/hoobnn/modelbay/issues"
14
+ },
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.mts",
23
+ "default": "./dist/index.mjs"
24
+ }
25
+ },
26
+ "bin": {
27
+ "modelbay-mcp": "./dist/bin/modelbay-mcp.mjs"
28
+ },
29
+ "peerDependencies": {
30
+ "zod": "^4.6"
31
+ },
32
+ "dependencies": {
33
+ "modelbay": "0.1.0"
34
+ },
35
+ "devDependencies": {
36
+ "@modelbay/ark": "0.1.0",
37
+ "@modelbay/bailian": "0.1.0",
38
+ "@modelbay/doubao-speech": "0.1.0",
39
+ "@modelbay/minimax": "0.1.0",
40
+ "@types/node": "^26.6.6",
41
+ "typescript": "^7.0.2",
42
+ "zod": "4.6.7",
43
+ "@modelbay/core": "0.1.0"
44
+ },
45
+ "scripts": {
46
+ "typecheck": "tsc -p .",
47
+ "build": "vp pack"
48
+ }
6
49
  }