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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand Down
32 changes: 32 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

steps:
- id: Install library requirements
name: 'maven:3.9.6-eclipse-temurin-17'
entrypoint: 'mvn'
args: ['clean', 'install', '-DskipTests']
- id: Run integration tests
name: 'maven:3.9.6-eclipse-temurin-17'
entrypoint: 'mvn'
args: ['test']
env:
- GOOGLE_CLOUD_PROJECT=$PROJECT_ID
- TOOLBOX_VERSION=${_TOOLBOX_VERSION}
- TOOLBOX_MANIFEST_VERSION=${_TOOLBOX_MANIFEST_VERSION}
substitutions:
_TOOLBOX_VERSION: '0.26.0'
_TOOLBOX_MANIFEST_VERSION: '34'
options:
logging: CLOUD_LOGGING_ONLY
25 changes: 24 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@
<maven.compiler.release>17</maven.compiler.release>
<jackson.version>2.15.2</jackson.version>
<google.auth.version>1.23.0</google.auth.version>
<langchain4j.version>0.35.0</langchain4j.version>
<animal.sniffer.skip>true</animal.sniffer.skip>
<checkstyle.header.file>java.header</checkstyle.header.file>
<checkstyle.header.file>java.header</checkstyle.header.file
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -93,6 +94,20 @@
<artifactId>google-auth-library-oauth2-http</artifactId>
</dependency>

<!-- LangChain4j Integration -->
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-core</artifactId>
<version>${langchain4j.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j</artifactId>
<version>${langchain4j.version}</version>
<optional>true</optional>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -122,6 +137,14 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/com/google/cloud/mcp/LangChain4jTool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.mcp;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import dev.langchain4j.agent.tool.ToolExecutionRequest;
import dev.langchain4j.agent.tool.ToolSpecification;
import dev.langchain4j.service.tool.ToolExecutor;
import java.util.Map;
import java.util.stream.Collectors;

/** Adapter for LangChain4j Tools. */
public class LangChain4jTool {

private static final ObjectMapper mapper = new ObjectMapper();
private final Tool tool;

public LangChain4jTool(Tool tool) {
this.tool = tool;
}

public ToolSpecification specification() {
return ToolSpecification.builder()
.name(tool.name())
.description(tool.definition().description())
// In a real implementation, we would map parameters here.
// For now, we assume dynamic arguments.
.build();
}

public ToolExecutor executor() {
return (request, memoryId) -> {
try {
Map<String, Object> arguments =
mapper.readValue(request.arguments(), new TypeReference<Map<String, Object>>() {});
ToolResult result = tool.execute(arguments).join();
return result.content().stream()
.map(ToolResult.Content::text)
.collect(Collectors.joining("\n"));
} catch (Exception e) {
throw new RuntimeException("Failed to execute tool", e);
}
};
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/google/cloud/mcp/McpToolboxClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ CompletableFuture<Map<String, Tool>> loadToolset(
CompletableFuture<ToolResult> invokeTool(
String toolName, Map<String, Object> arguments, Map<String, String> extraHeaders);

/** Returns a synchronous version of this client. */
default SyncMcpToolboxClient sync() {
return new SyncMcpToolboxClient(this);
}

/**
* Builder pattern for creating client instances.
*
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/com/google/cloud/mcp/SyncMcpToolboxClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.mcp;

import java.util.Map;

/**
* Synchronous client for interacting with a Toolbox service. A wrapper around {@link
* McpToolboxClient} that blocks on operations.
*/
public class SyncMcpToolboxClient {

private final McpToolboxClient asyncClient;

public SyncMcpToolboxClient(McpToolboxClient asyncClient) {
this.asyncClient = asyncClient;
}

/** Blocks and retrieves the list of tools from the server. */
public Map<String, ToolDefinition> listTools() {
return asyncClient.listTools().join();
}

/** Blocks and loads a tool definition. */
public Tool loadTool(String toolName) {
return asyncClient.loadTool(toolName).join();
}

/** Blocks and invokes a tool. */
public ToolResult invokeTool(String toolName, Map<String, Object> arguments) {
return asyncClient.invokeTool(toolName, arguments).join();
}
}
41 changes: 41 additions & 0 deletions src/test/java/com/google/cloud/mcp/LangChain4jToolTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.mcp;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.jupiter.api.Test;

public class LangChain4jToolTest {

@Test
public void testSpecification() {
Tool mockTool = mock(Tool.class);
ToolDefinition mockDef = mock(ToolDefinition.class);
when(mockTool.name()).thenReturn("test-tool");
when(mockTool.definition()).thenReturn(mockDef);
when(mockDef.description()).thenReturn("test-description");

LangChain4jTool adapter = new LangChain4jTool(mockTool);
assertNotNull(adapter.specification());
assertEquals("test-tool", adapter.specification().name());
assertEquals("test-description", adapter.specification().description());
}
}