Skip to content

Commit 1cbc8fb

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

12 files changed

Lines changed: 548 additions & 0 deletions

File tree

src/main/java/com/google/genai/AfcUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ static ImmutableList<Integer> findAfcIncompatibleToolIndexes(GenerateContentConf
8181
if (tool.functionDeclarations().isPresent() && !tool.functionDeclarations().get().isEmpty()) {
8282
incompatibleToolsIndexesBuilder.add(i);
8383
}
84+
if (tool.mcpServers().isPresent() && !tool.mcpServers().get().isEmpty()) {
85+
incompatibleToolsIndexesBuilder.add(i);
86+
}
8487
}
8588

8689
return incompatibleToolsIndexesBuilder.build();

src/main/java/com/google/genai/Batches.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,13 @@ ObjectNode toolToMldev(JsonNode fromObject, ObjectNode parentObject) {
18621862
Common.getValueByPath(fromObject, new String[] {"urlContext"}));
18631863
}
18641864

1865+
if (Common.getValueByPath(fromObject, new String[] {"mcpServers"}) != null) {
1866+
Common.setValueByPath(
1867+
toObject,
1868+
new String[] {"mcpServers"},
1869+
Common.getValueByPath(fromObject, new String[] {"mcpServers"}));
1870+
}
1871+
18651872
return toObject;
18661873
}
18671874

src/main/java/com/google/genai/Caches.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,13 @@ ObjectNode toolToMldev(JsonNode fromObject, ObjectNode parentObject) {
872872
Common.getValueByPath(fromObject, new String[] {"urlContext"}));
873873
}
874874

875+
if (Common.getValueByPath(fromObject, new String[] {"mcpServers"}) != null) {
876+
Common.setValueByPath(
877+
toObject,
878+
new String[] {"mcpServers"},
879+
Common.getValueByPath(fromObject, new String[] {"mcpServers"}));
880+
}
881+
875882
return toObject;
876883
}
877884

@@ -950,6 +957,10 @@ ObjectNode toolToVertex(JsonNode fromObject, ObjectNode parentObject) {
950957
Common.getValueByPath(fromObject, new String[] {"urlContext"}));
951958
}
952959

960+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"mcpServers"}))) {
961+
throw new IllegalArgumentException("mcpServers parameter is not supported in Vertex AI.");
962+
}
963+
953964
return toObject;
954965
}
955966

src/main/java/com/google/genai/LiveConverters.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,13 @@ ObjectNode toolToMldev(JsonNode fromObject, ObjectNode parentObject) {
16301630
Common.getValueByPath(fromObject, new String[] {"urlContext"}));
16311631
}
16321632

1633+
if (Common.getValueByPath(fromObject, new String[] {"mcpServers"}) != null) {
1634+
Common.setValueByPath(
1635+
toObject,
1636+
new String[] {"mcpServers"},
1637+
Common.getValueByPath(fromObject, new String[] {"mcpServers"}));
1638+
}
1639+
16331640
return toObject;
16341641
}
16351642

@@ -1708,6 +1715,10 @@ ObjectNode toolToVertex(JsonNode fromObject, ObjectNode parentObject) {
17081715
Common.getValueByPath(fromObject, new String[] {"urlContext"}));
17091716
}
17101717

1718+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"mcpServers"}))) {
1719+
throw new IllegalArgumentException("mcpServers parameter is not supported in Vertex AI.");
1720+
}
1721+
17111722
return toObject;
17121723
}
17131724

src/main/java/com/google/genai/Models.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4573,6 +4573,13 @@ ObjectNode toolToMldev(JsonNode fromObject, ObjectNode parentObject, JsonNode ro
45734573
Common.getValueByPath(fromObject, new String[] {"urlContext"}));
45744574
}
45754575

4576+
if (Common.getValueByPath(fromObject, new String[] {"mcpServers"}) != null) {
4577+
Common.setValueByPath(
4578+
toObject,
4579+
new String[] {"mcpServers"},
4580+
Common.getValueByPath(fromObject, new String[] {"mcpServers"}));
4581+
}
4582+
45764583
return toObject;
45774584
}
45784585

@@ -4652,6 +4659,10 @@ ObjectNode toolToVertex(JsonNode fromObject, ObjectNode parentObject, JsonNode r
46524659
Common.getValueByPath(fromObject, new String[] {"urlContext"}));
46534660
}
46544661

4662+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"mcpServers"}))) {
4663+
throw new IllegalArgumentException("mcpServers parameter is not supported in Vertex AI.");
4664+
}
4665+
46554666
return toObject;
46564667
}
46574668

src/main/java/com/google/genai/TokensConverters.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,13 @@ ObjectNode toolToMldev(JsonNode fromObject, ObjectNode parentObject) {
611611
Common.getValueByPath(fromObject, new String[] {"urlContext"}));
612612
}
613613

614+
if (Common.getValueByPath(fromObject, new String[] {"mcpServers"}) != null) {
615+
Common.setValueByPath(
616+
toObject,
617+
new String[] {"mcpServers"},
618+
Common.getValueByPath(fromObject, new String[] {"mcpServers"}));
619+
}
620+
614621
return toObject;
615622
}
616623
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Auto-generated code. Do not edit.
18+
19+
package com.google.genai.types;
20+
21+
import com.fasterxml.jackson.annotation.JsonCreator;
22+
import com.fasterxml.jackson.annotation.JsonProperty;
23+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
24+
import com.google.auto.value.AutoValue;
25+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
26+
import com.google.genai.JsonSerializable;
27+
import java.util.Optional;
28+
29+
/**
30+
* A MCPServer is a server that can be called by the model to perform actions. It is a server that
31+
* implements the MCP protocol. Next ID: 5. This data type is not supported in Vertex AI.
32+
*/
33+
@AutoValue
34+
@JsonDeserialize(builder = McpServer.Builder.class)
35+
public abstract class McpServer extends JsonSerializable {
36+
/** The name of the MCPServer. */
37+
@JsonProperty("name")
38+
public abstract Optional<String> name();
39+
40+
/** A transport that can stream HTTP requests and responses. */
41+
@JsonProperty("streamableHttpTransport")
42+
public abstract Optional<StreamableHttpTransport> streamableHttpTransport();
43+
44+
/** Instantiates a builder for McpServer. */
45+
@ExcludeFromGeneratedCoverageReport
46+
public static Builder builder() {
47+
return new AutoValue_McpServer.Builder();
48+
}
49+
50+
/** Creates a builder with the same values as this instance. */
51+
public abstract Builder toBuilder();
52+
53+
/** Builder for McpServer. */
54+
@AutoValue.Builder
55+
public abstract static class Builder {
56+
/** For internal usage. Please use `McpServer.builder()` for instantiation. */
57+
@JsonCreator
58+
private static Builder create() {
59+
return new AutoValue_McpServer.Builder();
60+
}
61+
62+
/**
63+
* Setter for name.
64+
*
65+
* <p>name: The name of the MCPServer.
66+
*/
67+
@JsonProperty("name")
68+
public abstract Builder name(String name);
69+
70+
@ExcludeFromGeneratedCoverageReport
71+
abstract Builder name(Optional<String> name);
72+
73+
/** Clears the value of name field. */
74+
@ExcludeFromGeneratedCoverageReport
75+
@CanIgnoreReturnValue
76+
public Builder clearName() {
77+
return name(Optional.empty());
78+
}
79+
80+
/**
81+
* Setter for streamableHttpTransport.
82+
*
83+
* <p>streamableHttpTransport: A transport that can stream HTTP requests and responses.
84+
*/
85+
@JsonProperty("streamableHttpTransport")
86+
public abstract Builder streamableHttpTransport(
87+
StreamableHttpTransport streamableHttpTransport);
88+
89+
/**
90+
* Setter for streamableHttpTransport builder.
91+
*
92+
* <p>streamableHttpTransport: A transport that can stream HTTP requests and responses.
93+
*/
94+
@CanIgnoreReturnValue
95+
public Builder streamableHttpTransport(
96+
StreamableHttpTransport.Builder streamableHttpTransportBuilder) {
97+
return streamableHttpTransport(streamableHttpTransportBuilder.build());
98+
}
99+
100+
@ExcludeFromGeneratedCoverageReport
101+
abstract Builder streamableHttpTransport(
102+
Optional<StreamableHttpTransport> streamableHttpTransport);
103+
104+
/** Clears the value of streamableHttpTransport field. */
105+
@ExcludeFromGeneratedCoverageReport
106+
@CanIgnoreReturnValue
107+
public Builder clearStreamableHttpTransport() {
108+
return streamableHttpTransport(Optional.empty());
109+
}
110+
111+
public abstract McpServer build();
112+
}
113+
114+
/** Deserializes a JSON string to a McpServer object. */
115+
@ExcludeFromGeneratedCoverageReport
116+
public static McpServer fromJson(String jsonString) {
117+
return JsonSerializable.fromJsonString(jsonString, McpServer.class);
118+
}
119+
}

0 commit comments

Comments
 (0)