Skip to content

Commit 976ae72

Browse files
authored
Merge branch 'main' into AdkWebServerTest-UI
2 parents 4bf03ae + b34feaa commit 976ae72

File tree

17 files changed

+368
-35
lines changed

17 files changed

+368
-35
lines changed

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"redhat.java",
4+
"vscjava.vscode-java-pack",
5+
"josevseb.google-java-format-for-vs-code"
6+
]
7+
}

.vscode/settings.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
// formatOnType and formatOnPaste is a very bad idea for slow formatters
3+
// (such as an external Google Java Format invocation exec), so just on Save:
4+
"editor.formatOnSave": true,
5+
"editor.formatOnType": false,
6+
"editor.formatOnPaste": false,
7+
8+
"files.insertFinalNewline": true,
9+
"files.trimTrailingWhitespace": true,
10+
11+
"[java]": {
12+
"editor.tabSize": 2,
13+
// Format Java using https://github.com/google/google-java-format,
14+
// via https://github.com/JoseVSeb/google-java-format-for-vs-code
15+
"editor.defaultFormatter": "josevseb.google-java-format-for-vs-code",
16+
"editor.codeActionsOnSave": {
17+
// Used by at least JS as well as Java, so only overridden for [java]
18+
"source.organizeImports": "always",
19+
"source.addMissingImports": "never"
20+
}
21+
},
22+
// Keep this version in sync with the same version in pom.xml
23+
// NB: Changes to this are only taken into account on start-up, so need to restart.
24+
"java.format.settings.google.version": "1.27.0",
25+
// TODO https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/3050
26+
"java.compile.nullAnalysis.mode": "automatic",
27+
"java.completion.importOrder": ["#", "", "javax", "java"], //# is static
28+
"java.completion.favoriteStaticMembers": ["com.google.common.truth.Truth.*"],
29+
"java.configuration.updateBuildConfiguration": "automatic",
30+
"java.import.maven.enabled": true
31+
}

contrib/langchain4j/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
<properties>
3333
<mcp-schema.version>0.10.0</mcp-schema.version>
34-
<google.genai.version>1.0.0</google.genai.version>
34+
<google.genai.version>1.8.0</google.genai.version>
3535
<junit.version>5.11.4</junit.version>
3636
<mockito.version>5.17.0</mockito.version>
3737
<langchain4j.version>1.1.0</langchain4j.version>
@@ -136,4 +136,4 @@
136136
<scope>test</scope>
137137
</dependency>
138138
</dependencies>
139-
</project>
139+
</project>

contrib/langchain4j/src/main/java/com/google/adk/models/langchain4j/LangChain4j.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,11 @@ private ChatRequest toChatRequest(LlmRequest llmRequest) {
224224
.mode()
225225
.ifPresent(
226226
functionMode -> {
227-
if (functionMode
228-
.knownEnum()
229-
.equals(FunctionCallingConfigMode.Known.AUTO)) {
227+
if (FunctionCallingConfigMode.Known.AUTO.equals(
228+
functionMode.knownEnum())) {
230229
requestBuilder.toolChoice(ToolChoice.AUTO);
231-
} else if (functionMode
232-
.knownEnum()
233-
.equals(FunctionCallingConfigMode.Known.ANY)) {
230+
} else if (FunctionCallingConfigMode.Known.ANY.equals(
231+
functionMode.knownEnum())) {
234232
// TODO check if it's the correct
235233
// mapping
236234
requestBuilder.toolChoice(ToolChoice.REQUIRED);
@@ -246,9 +244,8 @@ private ChatRequest toChatRequest(LlmRequest llmRequest) {
246244
toolSpecification.name()))
247245
.toList());
248246
});
249-
} else if (functionMode
250-
.knownEnum()
251-
.equals(FunctionCallingConfigMode.Known.NONE)) {
247+
} else if (FunctionCallingConfigMode.Known.NONE.equals(
248+
functionMode.knownEnum())) {
252249
requestBuilder.toolSpecifications(List.of());
253250
}
254251
});
@@ -349,7 +346,7 @@ private List<ChatMessage> toUserOrToolResultMessage(Content content) {
349346
.mimeType(mimeType)
350347
.build());
351348
} else if (mimeType.startsWith("text/")
352-
|| mimeType.equals("application/json")
349+
|| "application/json".equals(mimeType)
353350
|| mimeType.endsWith("+json")
354351
|| mimeType.endsWith("+xml")) {
355352
// TODO are there missing text based mime types?
@@ -454,7 +451,7 @@ private List<ToolSpecification> toToolSpecifications(LlmRequest llmRequest) {
454451
}
455452

456453
private JsonObjectSchema toParameters(Schema schema) {
457-
if (schema.type().isPresent() && schema.type().get().knownEnum().equals(Type.Known.OBJECT)) {
454+
if (schema.type().isPresent() && Type.Known.OBJECT.equals(schema.type().get().knownEnum())) {
458455
return JsonObjectSchema.builder()
459456
.addProperties(toProperties(schema))
460457
.required(schema.required().orElse(List.of()))
@@ -490,7 +487,7 @@ private JsonSchemaElement toJsonSchemaElement(Schema schema) {
490487
.items(toJsonSchemaElement(schema.items().orElseThrow()))
491488
.build();
492489
case OBJECT -> toParameters(schema);
493-
case TYPE_UNSPECIFIED ->
490+
default ->
494491
throw new UnsupportedFeatureException(
495492
"LangChain4jLlm does not support schema of type: " + type);
496493
};

core/src/main/java/com/google/adk/agents/InvocationContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package com.google.adk.agents;
1818

1919
import com.google.adk.artifacts.BaseArtifactService;
20-
import com.google.adk.exceptions.LlmCallsLimitExceededException;
2120
import com.google.adk.memory.BaseMemoryService;
21+
import com.google.adk.models.LlmCallsLimitExceededException;
2222
import com.google.adk.sessions.BaseSessionService;
2323
import com.google.adk.sessions.Session;
2424
import com.google.errorprone.annotations.InlineMe;

core/src/main/java/com/google/adk/flows/llmflows/BaseLlmFlow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
import com.google.adk.agents.ReadonlyContext;
2929
import com.google.adk.agents.RunConfig.StreamingMode;
3030
import com.google.adk.events.Event;
31-
import com.google.adk.exceptions.LlmCallsLimitExceededException;
3231
import com.google.adk.flows.BaseFlow;
3332
import com.google.adk.flows.llmflows.RequestProcessor.RequestProcessingResult;
3433
import com.google.adk.flows.llmflows.ResponseProcessor.ResponseProcessingResult;
3534
import com.google.adk.models.BaseLlm;
3635
import com.google.adk.models.BaseLlmConnection;
36+
import com.google.adk.models.LlmCallsLimitExceededException;
3737
import com.google.adk.models.LlmRegistry;
3838
import com.google.adk.models.LlmRequest;
3939
import com.google.adk.models.LlmResponse;

core/src/main/java/com/google/adk/exceptions/LlmCallsLimitExceededException.java renamed to core/src/main/java/com/google/adk/models/LlmCallsLimitExceededException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.google.adk.exceptions;
16+
package com.google.adk.models;
1717

1818
/** An error indicating that the limit for calls to the LLM has been exceeded. */
1919
public final class LlmCallsLimitExceededException extends Exception {

core/src/main/java/com/google/adk/tools/mcp/AbstractMcpTool.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.fasterxml.jackson.core.type.TypeReference;
2121
import com.fasterxml.jackson.databind.ObjectMapper;
2222
import com.google.adk.tools.BaseTool;
23+
import com.google.adk.tools.mcp.McpToolException.McpToolDeclarationException;
2324
import com.google.common.collect.ImmutableMap;
2425
import com.google.genai.types.FunctionDeclaration;
2526
import io.modelcontextprotocol.spec.McpSchema.CallToolResult;
@@ -77,14 +78,20 @@ public T getMcpSession() {
7778
@Override
7879
public Optional<FunctionDeclaration> declaration() {
7980
JsonSchema schema = this.mcpTool.inputSchema();
80-
return Optional.ofNullable(schema)
81-
.map(
82-
value ->
83-
FunctionDeclaration.builder()
84-
.name(this.name())
85-
.description(this.description())
86-
.parametersJsonSchema(value)
87-
.build());
81+
try {
82+
return Optional.ofNullable(schema)
83+
.map(
84+
value ->
85+
FunctionDeclaration.builder()
86+
.name(this.name())
87+
.description(this.description())
88+
.parametersJsonSchema(value)
89+
.build());
90+
} catch (Exception e) {
91+
throw new McpToolDeclarationException(
92+
String.format("MCP tool:%s failed to get declaration, schema:%s.", this.name(), schema),
93+
e);
94+
}
8895
}
8996

9097
@SuppressWarnings("PreferredInterfaceType") // BaseTool.runAsync() returns Map<String, Object>

core/src/main/java/com/google/adk/tools/mcp/DefaultMcpTransportBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public McpClientTransport build(Object connectionParams) {
2121
return new StdioClientTransport(serverParameters);
2222
} else if (connectionParams instanceof SseServerParameters sseServerParams) {
2323
return HttpClientSseClientTransport.builder(sseServerParams.url())
24-
.sseEndpoint("sse")
24+
.sseEndpoint(
25+
sseServerParams.sseEndpoint() == null ? "sse" : sseServerParams.sseEndpoint())
2526
.customizeRequest(
2627
builder ->
2728
Optional.ofNullable(sseServerParams.headers())
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
* http://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+
package com.google.adk.tools.mcp;
17+
18+
import io.modelcontextprotocol.spec.McpSchema;
19+
import io.modelcontextprotocol.spec.McpSchema.LoggingMessageNotification;
20+
import java.util.function.Consumer;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
import org.slf4j.event.Level;
24+
25+
class McpServerLogConsumer implements Consumer<LoggingMessageNotification> {
26+
27+
@Override
28+
public void accept(LoggingMessageNotification notif) {
29+
Logger log = LoggerFactory.getLogger(notif.logger());
30+
log.atLevel(convert(notif.level())).log("{}", notif.data());
31+
}
32+
33+
private Level convert(McpSchema.LoggingLevel level) {
34+
return switch (level) {
35+
case DEBUG -> Level.DEBUG;
36+
case INFO, NOTICE -> Level.INFO;
37+
case WARNING -> Level.WARN;
38+
case ERROR, CRITICAL, ALERT, EMERGENCY -> Level.ERROR;
39+
};
40+
}
41+
}

0 commit comments

Comments
 (0)