@@ -5,7 +5,13 @@ import { ExitCode } from "../errors/codes.ts";
55import { request , requestJson , type HttpDeps , type RequestOpts } from "./http.ts" ;
66import { buildAcsCanonicalQuery , signAcsRequest , type AcsQueryParams } from "./acs.ts" ;
77import { imageFileToDataUri , isLocalFile , resolveFileUrl } from "../files/upload.ts" ;
8- import { McpClient } from "./mcp.ts" ;
8+ import {
9+ bailianMcpPath ,
10+ bailianMcpSsePath ,
11+ connectBailianMcpWithFallback ,
12+ McpClient ,
13+ type McpConnectedClient ,
14+ } from "./mcp.ts" ;
915import { callConsoleGateway } from "../console/gateway.ts" ;
1016import { refreshAccessToken } from "../auth/refresh-token.ts" ;
1117import { maskToken } from "../utils/token.ts" ;
@@ -164,6 +170,25 @@ export class Client {
164170 return new McpClient ( this . http , url , this . deps . apiCred ?. token ) ;
165171 }
166172
173+ /**
174+ * Connect to a Bailian MCP: try Streamable HTTP, then SSE on 405+streamableHttp (except WebSearch).
175+ * `urlOverride` maps to `--url` and uses Streamable only (no fallback).
176+ */
177+ connectBailianMcp (
178+ serverCode : string ,
179+ urlOverride ?: string ,
180+ ) : Promise < { client : McpConnectedClient ; url : string } > {
181+ this . requireApi ( ) ;
182+ return connectBailianMcpWithFallback ( {
183+ deps : this . http ,
184+ authToken : this . deps . apiCred ?. token ,
185+ httpUrl : this . url ( bailianMcpPath ( serverCode ) ) ,
186+ sseUrl : this . url ( bailianMcpSsePath ( serverCode ) ) ,
187+ serverCode,
188+ urlOverride,
189+ } ) ;
190+ }
191+
167192 async console < T > ( api : string , data : Record < string , unknown > ) : Promise < T > {
168193 if ( ! this . deps . consoleCred ) {
169194 throw new BailianError ( "This command needs a console access token." , ExitCode . AUTH ) ;
0 commit comments