Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mcp/src/tools/gateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,13 @@ describe("gateway tools", () => {
targetName: "helloFn",
total: 1,
domains: ["env-test.app.tcloudbase.com", "api.example.com"],
defaultDomain: "env-test.app.tcloudbase.com",
customDomains: ["api.example.com"],
urls: [
"https://env-test.app.tcloudbase.com/api/hello",
"https://api.example.com/api/hello",
],
defaultUrl: "https://env-test.app.tcloudbase.com/api/hello",
enableService: true,
},
nextActions: [
Expand Down
14 changes: 14 additions & 0 deletions mcp/src/tools/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ export function registerGatewayTools(server: ExtendedMcpServer) {
{
action: input.action,
domains: result.domains,
defaultDomain: result.raw.DefaultDomain,
customDomains: result.raw.ServiceSet?.map((item) => item.Domain) ?? [],
enableService: result.enableService,
raw: result.raw,
},
Expand All @@ -226,6 +228,7 @@ export function registerGatewayTools(server: ExtendedMcpServer) {
{
action: input.action,
domains: result.raw.ServiceSet ?? [],
defaultDomain: result.raw.DefaultDomain,
total: (result.raw.ServiceSet ?? []).length,
raw: result.raw,
},
Expand All @@ -241,6 +244,7 @@ export function registerGatewayTools(server: ExtendedMcpServer) {
action: input.action,
routes,
total: result.TotalCount ?? routes.length,
defaultDomain: result.OriginDomain,
raw: result,
},
`已获取 ${result.TotalCount ?? routes.length} 条 HTTP 路由`,
Expand All @@ -260,6 +264,7 @@ export function registerGatewayTools(server: ExtendedMcpServer) {
action: input.action,
routeId: input.routeId ?? null,
route,
defaultDomain: result.OriginDomain,
raw: result,
},
route ? "已获取路由详情" : "未找到对应路由",
Expand Down Expand Up @@ -289,6 +294,12 @@ export function registerGatewayTools(server: ExtendedMcpServer) {
),
);

// 使用默认域名生成外部调用 URL,避免使用自定义域名导致 SSL 证书不匹配
const defaultDomain = domainInfo.raw.DefaultDomain;
const defaultUrl = (accessList.APISet || []).length > 0
? `https://${defaultDomain}${normalizeAccessPath(accessList.APISet[0].Path)}`
Comment on lines +299 to +300
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard defaultUrl when default domain is missing

In queryGateway(action=getAccess), defaultUrl is now built whenever APISet is non-empty, but it does not verify that DefaultDomain exists. If an environment has routes but the default domain is not initialized/returned, this produces an invalid URL like https://undefined/...; downstream callers that prioritize defaultUrl will then fail requests despite valid entries in urls. Build defaultUrl only when defaultDomain is truthy (or fall back to a known valid URL).

Useful? React with 👍 / 👎.

: null;

return buildEnvelope(
{
action: input.action,
Expand All @@ -297,7 +308,10 @@ export function registerGatewayTools(server: ExtendedMcpServer) {
apis: accessList.APISet || [],
total: accessList.Total || 0,
domains: domainInfo.domains,
defaultDomain,
customDomains: domainInfo.raw.ServiceSet?.map((item) => item.Domain) ?? [],
urls,
defaultUrl,
enableService:
accessList.EnableService ?? domainInfo.enableService ?? false,
raw: {
Expand Down
Loading