feat(wecom): 企微 API 插件增加 MCP Streamable HTTP 端点
与 REST/OpenAPI 并存,按实例权限自动 tools/list,免手填工具。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import { WecomPluginGuard } from './wecom-plugin.guard';
|
||||
import { WecomPluginQueryService } from './wecom-plugin-query.service';
|
||||
import { CurrentWecomPlugin } from './wecom-plugin.decorators';
|
||||
import type { WecomPluginRuntime } from './wecom-plugin.types';
|
||||
import { wecomPluginCaller } from './wecom-plugin.util';
|
||||
|
||||
@Controller('wecom/plugin')
|
||||
@UseGuards(WecomPluginGuard)
|
||||
@@ -28,7 +29,7 @@ export class WecomPluginController {
|
||||
@Query('page') page?: string,
|
||||
@Query('pageSize') pageSize?: string,
|
||||
) {
|
||||
return this.query.queryOrders(plugin, pluginCaller(req), q, page, pageSize);
|
||||
return this.query.queryOrders(plugin, wecomPluginCaller(req), q, page, pageSize);
|
||||
}
|
||||
|
||||
@Get('users')
|
||||
@@ -39,7 +40,7 @@ export class WecomPluginController {
|
||||
@Query('page') page?: string,
|
||||
@Query('pageSize') pageSize?: string,
|
||||
) {
|
||||
return this.query.queryUsers(plugin, pluginCaller(req), q, page, pageSize);
|
||||
return this.query.queryUsers(plugin, wecomPluginCaller(req), q, page, pageSize);
|
||||
}
|
||||
|
||||
@Get('stores')
|
||||
@@ -50,7 +51,7 @@ export class WecomPluginController {
|
||||
@Query('page') page?: string,
|
||||
@Query('pageSize') pageSize?: string,
|
||||
) {
|
||||
return this.query.queryStores(plugin, pluginCaller(req), q, page, pageSize);
|
||||
return this.query.queryStores(plugin, wecomPluginCaller(req), q, page, pageSize);
|
||||
}
|
||||
|
||||
@Get('store-audits')
|
||||
@@ -62,7 +63,7 @@ export class WecomPluginController {
|
||||
@Query('page') page?: string,
|
||||
@Query('pageSize') pageSize?: string,
|
||||
) {
|
||||
return this.query.queryStoreAudits(plugin, pluginCaller(req), q, status, page, pageSize);
|
||||
return this.query.queryStoreAudits(plugin, wecomPluginCaller(req), q, status, page, pageSize);
|
||||
}
|
||||
|
||||
@Get('store-info-audits')
|
||||
@@ -73,7 +74,7 @@ export class WecomPluginController {
|
||||
@Query('page') page?: string,
|
||||
@Query('pageSize') pageSize?: string,
|
||||
) {
|
||||
return this.query.queryStoreInfoAudits(plugin, pluginCaller(req), status, page, pageSize);
|
||||
return this.query.queryStoreInfoAudits(plugin, wecomPluginCaller(req), status, page, pageSize);
|
||||
}
|
||||
|
||||
@Get('store-info-audits/:id')
|
||||
@@ -82,7 +83,7 @@ export class WecomPluginController {
|
||||
@Req() req: Request,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.query.queryStoreInfoAuditDetail(plugin, pluginCaller(req), id);
|
||||
return this.query.queryStoreInfoAuditDetail(plugin, wecomPluginCaller(req), id);
|
||||
}
|
||||
|
||||
@Get('store-package-audits')
|
||||
@@ -93,7 +94,7 @@ export class WecomPluginController {
|
||||
@Query('page') page?: string,
|
||||
@Query('pageSize') pageSize?: string,
|
||||
) {
|
||||
return this.query.queryStorePackageAudits(plugin, pluginCaller(req), status, page, pageSize);
|
||||
return this.query.queryStorePackageAudits(plugin, wecomPluginCaller(req), status, page, pageSize);
|
||||
}
|
||||
|
||||
@Get('store-package-audits/:id')
|
||||
@@ -102,7 +103,7 @@ export class WecomPluginController {
|
||||
@Req() req: Request,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.query.queryStorePackageAuditDetail(plugin, pluginCaller(req), id);
|
||||
return this.query.queryStorePackageAuditDetail(plugin, wecomPluginCaller(req), id);
|
||||
}
|
||||
|
||||
@Get('redeems')
|
||||
@@ -113,7 +114,7 @@ export class WecomPluginController {
|
||||
@Query('page') page?: string,
|
||||
@Query('pageSize') pageSize?: string,
|
||||
) {
|
||||
return this.query.queryRedeems(plugin, pluginCaller(req), q, page, pageSize);
|
||||
return this.query.queryRedeems(plugin, wecomPluginCaller(req), q, page, pageSize);
|
||||
}
|
||||
|
||||
@Get('promo-codes')
|
||||
@@ -124,7 +125,7 @@ export class WecomPluginController {
|
||||
@Query('page') page?: string,
|
||||
@Query('pageSize') pageSize?: string,
|
||||
) {
|
||||
return this.query.queryPromoCodes(plugin, pluginCaller(req), q, page, pageSize);
|
||||
return this.query.queryPromoCodes(plugin, wecomPluginCaller(req), q, page, pageSize);
|
||||
}
|
||||
|
||||
@Get('promo-codes/:code/stats')
|
||||
@@ -133,7 +134,7 @@ export class WecomPluginController {
|
||||
@Req() req: Request,
|
||||
@Param('code') code: string,
|
||||
) {
|
||||
return this.query.queryPromoCodeStats(plugin, pluginCaller(req), code);
|
||||
return this.query.queryPromoCodeStats(plugin, wecomPluginCaller(req), code);
|
||||
}
|
||||
|
||||
@Get('partners')
|
||||
@@ -144,7 +145,7 @@ export class WecomPluginController {
|
||||
@Query('page') page?: string,
|
||||
@Query('pageSize') pageSize?: string,
|
||||
) {
|
||||
return this.query.queryPartners(plugin, pluginCaller(req), q, page, pageSize);
|
||||
return this.query.queryPartners(plugin, wecomPluginCaller(req), q, page, pageSize);
|
||||
}
|
||||
|
||||
@Get('partners/:partnerId/users')
|
||||
@@ -159,7 +160,7 @@ export class WecomPluginController {
|
||||
) {
|
||||
return this.query.queryPartnerUsers(
|
||||
plugin,
|
||||
pluginCaller(req),
|
||||
wecomPluginCaller(req),
|
||||
partnerId,
|
||||
from,
|
||||
to,
|
||||
@@ -180,7 +181,7 @@ export class WecomPluginController {
|
||||
) {
|
||||
return this.query.queryPartnerStores(
|
||||
plugin,
|
||||
pluginCaller(req),
|
||||
wecomPluginCaller(req),
|
||||
partnerId,
|
||||
from,
|
||||
to,
|
||||
@@ -201,7 +202,7 @@ export class WecomPluginController {
|
||||
) {
|
||||
return this.query.queryPartnerOrders(
|
||||
plugin,
|
||||
pluginCaller(req),
|
||||
wecomPluginCaller(req),
|
||||
partnerId,
|
||||
from,
|
||||
to,
|
||||
@@ -216,12 +217,6 @@ export class WecomPluginController {
|
||||
@Req() req: Request,
|
||||
@Query('kind') kind?: string,
|
||||
) {
|
||||
return this.query.queryMetrics(plugin, pluginCaller(req), kind);
|
||||
return this.query.queryMetrics(plugin, wecomPluginCaller(req), kind);
|
||||
}
|
||||
}
|
||||
|
||||
function pluginCaller(req: Request): 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';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user