These sample Java files allow you to test the features supported in the Java version of the MCP Toolbox SDK.
-
First set up database (AlloyDB in this case) and ingest data for the tools referenced in this example. In order to demonstrate the use of tools across applications, we have considered a RETAIL STORE and TOY STORE application data together. In order to install cluster, instance and setup data, for this sample use case, follow the first 4 steps of the first codelab (hybrid search) and the 5th step of the second codelab (toystore app) below:
https://codelabs.developers.google.com/hybrid-search-on-cloudrun and https://codelabs.developers.google.com/toy-store-app
-
To start with tools, go ahead and create the MCP Toolbox Server for the sameple use case we are looking at.
-
To set up & install MCP Toolbox Server, install the latest version from here: https://mcp-toolbox.dev/documentation/introduction/#install-toolbox
-
Next, create tools.yaml, you can find the one we are using in our example in this repo.
-
Replace the placeholder variables in
tools.yamlwith values from your instance / environment.
Tip
Do not hardcode for production applications.
-
Once it's done, from within the folder where your MCP Toolbox binary &
tools.yamlare residing, run the following command:./toolbox --tools-file "tools.yaml" -
If you want to look at the toolset and tools in a simple web UI, use the command:
./toolbox --ui
-
You can then deploy this in Cloud Run to test the application or use the local instance running, while you try the example Java applications. In any case remember to change the
YOUR_TOOLBOX_SERVICE_ENDPOINTplaceholder in the respective files.If you decide to deploy your toolbox endpoint in cloud run, here's how you can do it: https://mcp-toolbox.dev/documentation/deploy-to/cloud-run/
Note
At this point you must be having a working MCP Toolbox server accessible.
-
You should be able to run the Java classes in this example to understand the usage of this library.
-
Use the
pom.xmlfrom this repo. Note that we have the dependencymcp-toolbox-sdk-javaincluded:<dependency> <groupId>com.google.cloud.mcp</groupId> <artifactId>mcp-toolbox-sdk-java</artifactId> <version>0.2.0</version> <!-- {x-version-update:mcp-toolbox-sdk-java:current} --> </dependency>
-
Compile the class that you want to test:
mvn compile
Now run the example class:
mvn clean compile exec:java -Dexec.mainClass="cloudcode.helloworld.ExampleUsage"