Building a Java Capability for Wanaku
This guide will walk you through creating a simple "echo" capability for Wanaku using Java.
This service will read the value of an environment variable and return it, demonstrating the basic principles of the Wanaku Capabilities SDK.
What You Will Need
- Java Development Kit (JDK)
- Apache Maven
- An IDE of your choice (e.g., VS Code, IntelliJ IDEA)
Step 1: Project Setup
First, generate a new capability project using the Wanaku SDK's Maven archetype. This command creates a complete project structure for you.
mvn -B archetype:generate \
-DarchetypeGroupId=ai.wanaku.sdk \
-DarchetypeArtifactId=capabilities-archetypes-java-tool \
-DarchetypeVersion=0.1.0 \
-DgroupId=net.orpiske \
-Dpackage=net.orpiske \
-DartifactId=echo \
-Dname=EchoService \
-Dwanaku-sdk-version=0.1.0IMPORTANT
Make sure the DarchetypeVersion and Dwanaku-sdk-version match the version of Wanaku you are using.
Once the project is created, run an initial build to compile the code and download dependencies.
mvn clean packageStep 2: Implementing the Capability Logic
Now, let's write the Java code for our echo service. We only need to modify two files.
Configure Properties in ProvisionBase
Since our service doesn't require any arguments from Wanaku, we can simplify the properties method in the ProvisionBase.java class to return an empty Map.
public Map<String, PropertySchema> properties() {
// This service has no server-sent properties, so an empty map is sufficient.
return Map.of();
}Implement the Tool Logic in AppTool
Next, we'll implement the core logic in AppTool.java. The goal is to read an environment variable named MCP_ECHO and send its value back to Wanaku. The boilerplate code is already there; you just need to add the line that gets the environment variable.
public void invokeTool(ToolInvokeRequest request, StreamObserver<ToolInvokeReply> responseObserver) {
try {
// Get the value of the environment variable.
String response = System.getenv("MCP_ECHO");
// Build the response for Wanaku.
responseObserver.onNext(
ToolInvokeReply.newBuilder()
.setIsError(false)
.addAllContent(List.of(response)).build());
responseObserver.onCompleted();
} finally {
// Perform any cleanup if necessary.
}
}Step 3: Packaging the Application
The archetype already includes the maven-assembly-plugin configuration, so packaging is straightforward.
Build the project to create the executable JAR:
mvn clean packageYou should now find the final artifact at target/echo-app.jar.
Step 4: Running and Verifying the Capability
Let's launch the service and test it with Wanaku.
Test the JAR Run the JAR with the
--helpflag to ensure it's executable.shelljava -jar target/echo-app.jar --helpStart Wanaku In a separate terminal, start a local Wanaku instance. You can use the
wanakuCLI or a container.shell# Example using Podman podman run -d -p 8080:8080 quay.io/wanaku/wanaku-router-backend:0.1.0Set the Environment Variable Export the
MCP_ECHOvariable with a test value.shellexport MCP_ECHO="Hello from the Echo Service!"Launch the Capability Service Run your new capability, telling it how to connect to Wanaku.
shelljava -jar target/echo-app.jar --registration-url http://localhost:8080 --registration-announce-address localhost --grpc-port 9191 --name echo-serviceNote: If Wanaku is running in a container, set
--registration-announce-addressto an address reachable from the container, likehost.docker.internalor your machine's IP.Check Registration ✅
After a few seconds, use thewanakuCLI to see if your capability has registered successfully.shellwanaku capabilities listAdd a Tool Create a tool in Wanaku that uses your new capability.
shellwanaku tools add --name "echo-tool" \ --description "This tool echoes a value set in an environment variable." \ --uri "echo://my-echo" \ --type echo-serviceFinal Test Finally, use the MCP Inspector or another client to invoke your
echo-tool. It should reply with "Hello from the Echo Service!"shellnpx @modelcontextprotocol/inspector
You can find the complete sample code for this example in the wanaku-echo-capability-example repository.
What's Next?
- Camel Assistant (demo 5.01) — build an AI assistant backed by Apache Camel documentation and Wanaku tools
If you find a bug, please report it. To get in touch with the community, visit the Wanaku project.