feat(wecom): 企微 API 插件增加 MCP Streamable HTTP 端点

与 REST/OpenAPI 并存,按实例权限自动 tools/list,免手填工具。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-08 16:57:42 +08:00
parent cae426fbc2
commit 976bde37cc
23 changed files with 1212 additions and 63 deletions
@@ -0,0 +1,26 @@
import { HttpException } from '@nestjs/common';
export function wecomPluginCaller(req: { headers: Record<string, unknown> }): string {
const raw = req.headers['x-wecom-userid'] ?? req.headers['userid'];
const v = Array.isArray(raw) ? raw[0] : raw;
return String(v || 'plugin').trim() || 'plugin';
}
export function wecomPluginMcpErrorText(e: unknown): string {
if (e instanceof HttpException) {
const res = e.getResponse();
if (typeof res === 'string') return res;
if (res && typeof res === 'object' && 'message' in res) {
const message = (res as { message?: string | string[] }).message;
return Array.isArray(message) ? message.join(', ') : String(message ?? e.message);
}
return e.message;
}
return e instanceof Error ? e.message : String(e);
}
export function wecomPluginQueryArg(v?: string | number): string | undefined {
if (v == null) return undefined;
const s = String(v).trim();
return s ? s : undefined;
}