Skip to content

Commit c7888c4

Browse files
wanlin31copybara-github
authored andcommitted
feat: enable server side MCP and disable all other AFC when server side MCP is configured.
PiperOrigin-RevId: 873027776
1 parent eb3ef50 commit c7888c4

15 files changed

+2215
-0
lines changed

api-report/genai-node.api.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,6 +2542,12 @@ export enum MaskReferenceMode {
25422542
MASK_MODE_USER_PROVIDED = "MASK_MODE_USER_PROVIDED"
25432543
}
25442544

2545+
// @public
2546+
export interface McpServer {
2547+
name?: string;
2548+
streamableHttpTransport?: StreamableHttpTransport;
2549+
}
2550+
25452551
// @public
25462552
export function mcpToTool(...args: [...Client[], CallableToolConfig | Client]): CallableTool;
25472553

@@ -3240,6 +3246,15 @@ export enum StartSensitivity {
32403246
START_SENSITIVITY_UNSPECIFIED = "START_SENSITIVITY_UNSPECIFIED"
32413247
}
32423248

3249+
// @public
3250+
export interface StreamableHttpTransport {
3251+
headers?: Record<string, string>;
3252+
sseReadTimeout?: string;
3253+
terminateOnClose?: boolean;
3254+
timeout?: string;
3255+
url?: string;
3256+
}
3257+
32433258
// @public
32443259
export interface StringList {
32453260
values?: string[];
@@ -3404,6 +3419,7 @@ export interface Tool {
34043419
googleMaps?: GoogleMaps;
34053420
googleSearch?: GoogleSearch;
34063421
googleSearchRetrieval?: GoogleSearchRetrieval;
3422+
mcpServers?: McpServer[];
34073423
retrieval?: Retrieval;
34083424
urlContext?: UrlContext;
34093425
}

api-report/genai-web.api.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,6 +2542,12 @@ export enum MaskReferenceMode {
25422542
MASK_MODE_USER_PROVIDED = "MASK_MODE_USER_PROVIDED"
25432543
}
25442544

2545+
// @public
2546+
export interface McpServer {
2547+
name?: string;
2548+
streamableHttpTransport?: StreamableHttpTransport;
2549+
}
2550+
25452551
// @public
25462552
export function mcpToTool(...args: [...Client[], CallableToolConfig | Client]): CallableTool;
25472553

@@ -3240,6 +3246,15 @@ export enum StartSensitivity {
32403246
START_SENSITIVITY_UNSPECIFIED = "START_SENSITIVITY_UNSPECIFIED"
32413247
}
32423248

3249+
// @public
3250+
export interface StreamableHttpTransport {
3251+
headers?: Record<string, string>;
3252+
sseReadTimeout?: string;
3253+
terminateOnClose?: boolean;
3254+
timeout?: string;
3255+
url?: string;
3256+
}
3257+
32433258
// @public
32443259
export interface StringList {
32453260
values?: string[];
@@ -3404,6 +3419,7 @@ export interface Tool {
34043419
googleMaps?: GoogleMaps;
34053420
googleSearch?: GoogleSearch;
34063421
googleSearchRetrieval?: GoogleSearchRetrieval;
3422+
mcpServers?: McpServer[];
34073423
retrieval?: Retrieval;
34083424
urlContext?: UrlContext;
34093425
}

api-report/genai.api.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,6 +2542,12 @@ export enum MaskReferenceMode {
25422542
MASK_MODE_USER_PROVIDED = "MASK_MODE_USER_PROVIDED"
25432543
}
25442544

2545+
// @public
2546+
export interface McpServer {
2547+
name?: string;
2548+
streamableHttpTransport?: StreamableHttpTransport;
2549+
}
2550+
25452551
// @public
25462552
export function mcpToTool(...args: [...Client[], CallableToolConfig | Client]): CallableTool;
25472553

@@ -3240,6 +3246,15 @@ export enum StartSensitivity {
32403246
START_SENSITIVITY_UNSPECIFIED = "START_SENSITIVITY_UNSPECIFIED"
32413247
}
32423248

3249+
// @public
3250+
export interface StreamableHttpTransport {
3251+
headers?: Record<string, string>;
3252+
sseReadTimeout?: string;
3253+
terminateOnClose?: boolean;
3254+
timeout?: string;
3255+
url?: string;
3256+
}
3257+
32433258
// @public
32443259
export interface StringList {
32453260
values?: string[];
@@ -3404,6 +3419,7 @@ export interface Tool {
34043419
googleMaps?: GoogleMaps;
34053420
googleSearch?: GoogleSearch;
34063421
googleSearchRetrieval?: GoogleSearchRetrieval;
3422+
mcpServers?: McpServer[];
34073423
retrieval?: Retrieval;
34083424
urlContext?: UrlContext;
34093425
}

src/converters/_batches_converters.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,5 +1838,16 @@ export function toolToMldev(fromObject: types.Tool): Record<string, unknown> {
18381838
common.setValueByPath(toObject, ['urlContext'], fromUrlContext);
18391839
}
18401840

1841+
const fromMcpServers = common.getValueByPath(fromObject, ['mcpServers']);
1842+
if (fromMcpServers != null) {
1843+
let transformedList = fromMcpServers;
1844+
if (Array.isArray(transformedList)) {
1845+
transformedList = transformedList.map((item) => {
1846+
return item;
1847+
});
1848+
}
1849+
common.setValueByPath(toObject, ['mcpServers'], transformedList);
1850+
}
1851+
18411852
return toObject;
18421853
}

src/converters/_caches_converters.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,17 @@ export function toolToMldev(fromObject: types.Tool): Record<string, unknown> {
854854
common.setValueByPath(toObject, ['urlContext'], fromUrlContext);
855855
}
856856

857+
const fromMcpServers = common.getValueByPath(fromObject, ['mcpServers']);
858+
if (fromMcpServers != null) {
859+
let transformedList = fromMcpServers;
860+
if (Array.isArray(transformedList)) {
861+
transformedList = transformedList.map((item) => {
862+
return item;
863+
});
864+
}
865+
common.setValueByPath(toObject, ['mcpServers'], transformedList);
866+
}
867+
857868
return toObject;
858869
}
859870

@@ -931,6 +942,10 @@ export function toolToVertex(fromObject: types.Tool): Record<string, unknown> {
931942
common.setValueByPath(toObject, ['urlContext'], fromUrlContext);
932943
}
933944

945+
if (common.getValueByPath(fromObject, ['mcpServers']) !== undefined) {
946+
throw new Error('mcpServers parameter is not supported in Vertex AI.');
947+
}
948+
934949
return toObject;
935950
}
936951

src/converters/_live_converters.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,17 @@ export function toolToMldev(fromObject: types.Tool): Record<string, unknown> {
18931893
common.setValueByPath(toObject, ['urlContext'], fromUrlContext);
18941894
}
18951895

1896+
const fromMcpServers = common.getValueByPath(fromObject, ['mcpServers']);
1897+
if (fromMcpServers != null) {
1898+
let transformedList = fromMcpServers;
1899+
if (Array.isArray(transformedList)) {
1900+
transformedList = transformedList.map((item) => {
1901+
return item;
1902+
});
1903+
}
1904+
common.setValueByPath(toObject, ['mcpServers'], transformedList);
1905+
}
1906+
18961907
return toObject;
18971908
}
18981909

@@ -1970,6 +1981,10 @@ export function toolToVertex(fromObject: types.Tool): Record<string, unknown> {
19701981
common.setValueByPath(toObject, ['urlContext'], fromUrlContext);
19711982
}
19721983

1984+
if (common.getValueByPath(fromObject, ['mcpServers']) !== undefined) {
1985+
throw new Error('mcpServers parameter is not supported in Vertex AI.');
1986+
}
1987+
19731988
return toObject;
19741989
}
19751990

src/converters/_models_converters.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4805,6 +4805,17 @@ export function toolToMldev(
48054805
common.setValueByPath(toObject, ['urlContext'], fromUrlContext);
48064806
}
48074807

4808+
const fromMcpServers = common.getValueByPath(fromObject, ['mcpServers']);
4809+
if (fromMcpServers != null) {
4810+
let transformedList = fromMcpServers;
4811+
if (Array.isArray(transformedList)) {
4812+
transformedList = transformedList.map((item) => {
4813+
return item;
4814+
});
4815+
}
4816+
common.setValueByPath(toObject, ['mcpServers'], transformedList);
4817+
}
4818+
48084819
return toObject;
48094820
}
48104821

@@ -4885,6 +4896,10 @@ export function toolToVertex(
48854896
common.setValueByPath(toObject, ['urlContext'], fromUrlContext);
48864897
}
48874898

4899+
if (common.getValueByPath(fromObject, ['mcpServers']) !== undefined) {
4900+
throw new Error('mcpServers parameter is not supported in Vertex AI.');
4901+
}
4902+
48884903
return toObject;
48894904
}
48904905

src/converters/_tokens_converters.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,5 +657,16 @@ export function toolToMldev(fromObject: types.Tool): Record<string, unknown> {
657657
common.setValueByPath(toObject, ['urlContext'], fromUrlContext);
658658
}
659659

660+
const fromMcpServers = common.getValueByPath(fromObject, ['mcpServers']);
661+
if (fromMcpServers != null) {
662+
let transformedList = fromMcpServers;
663+
if (Array.isArray(transformedList)) {
664+
transformedList = transformedList.map((item) => {
665+
return item;
666+
});
667+
}
668+
common.setValueByPath(toObject, ['mcpServers'], transformedList);
669+
}
670+
660671
return toObject;
661672
}

src/types.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,28 @@ export declare interface GoogleSearchRetrieval {
20122012
/** Tool to support URL context. */
20132013
export declare interface UrlContext {}
20142014

2015+
/** A transport that can stream HTTP requests and responses. Next ID: 6. This data type is not supported in Vertex AI. */
2016+
export declare interface StreamableHttpTransport {
2017+
/** Optional: Fields for authentication headers, timeouts, etc., if needed. */
2018+
headers?: Record<string, string>;
2019+
/** Timeout for SSE read operations. */
2020+
sseReadTimeout?: string;
2021+
/** Whether to close the client session when the transport closes. */
2022+
terminateOnClose?: boolean;
2023+
/** HTTP timeout for regular operations. */
2024+
timeout?: string;
2025+
/** The full URL for the MCPServer endpoint. Example: "https://api.example.com/mcp". */
2026+
url?: string;
2027+
}
2028+
2029+
/** A MCPServer is a server that can be called by the model to perform actions. It is a server that implements the MCP protocol. Next ID: 5. This data type is not supported in Vertex AI. */
2030+
export declare interface McpServer {
2031+
/** The name of the MCPServer. */
2032+
name?: string;
2033+
/** A transport that can stream HTTP requests and responses. */
2034+
streamableHttpTransport?: StreamableHttpTransport;
2035+
}
2036+
20152037
/** Tool details of a tool that the model may use to generate a response. */
20162038
export declare interface Tool {
20172039
/** Optional. Retrieval tool type. System will always execute the provided retrieval tool(s) to get external knowledge to answer the prompt. Retrieval results are presented to the model for generation. This field is not supported in Gemini API. */
@@ -2036,6 +2058,8 @@ export declare interface Tool {
20362058
googleSearchRetrieval?: GoogleSearchRetrieval;
20372059
/** Optional. Tool to support URL context retrieval. */
20382060
urlContext?: UrlContext;
2061+
/** Optional. MCP Servers to connect to. This field is not supported in Vertex AI. */
2062+
mcpServers?: McpServer[];
20392063
}
20402064

20412065
/** An object that represents a latitude/longitude pair.

test/system/node/chats_test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,34 @@ describe('Chats Tests', () => {
201201
'What is the title of the story?',
202202
],
203203
},
204+
{
205+
name: 'multiple messages with server side MCP tools',
206+
clientParams: {vertexai: false, apiKey: GEMINI_API_KEY},
207+
model: 'gemini-2.5-flash',
208+
config: {
209+
tools: [
210+
{
211+
mcpServers: [
212+
{
213+
streamableHttpTransport: {
214+
url: 'https://gemini-api-demos.uc.r.appspot.com/mcp',
215+
headers: {
216+
'AUTHORIZATION': 'Bearer github_pat_XXXX',
217+
},
218+
timeout: '10s',
219+
},
220+
name: 'weather_server',
221+
},
222+
],
223+
},
224+
],
225+
},
226+
history: [],
227+
messages: [
228+
'What is the weather in San Francisco on 02/02/2026?',
229+
'What is the weather in Boston on 02/02/2026?',
230+
],
231+
},
204232
];
205233

206234
testCases.forEach(async (testCase) => {

0 commit comments

Comments
 (0)