We talked about Tools and then MCP. In this post let's talk how to use Quarkus and lanchaing4j to connect your intelligent application to MCP servers!
Requirements
- Java Open JDK (24 is preferred)
- Maven
- Ollama with at least one LLM model that you can locally. Notice that you could use other providers such as ramalama and vllm, but you will need to use the correct dependencies for OpenAI API.
- jbang, npx or other tool required top run the MCP server
The LLM client application
Our application simple needs the dependencies quarkus-langchain4j-mcp, quarkus-langchain4j-ollama and quarkus-rest. You can generate your application online using Code Quarkus. About the code, you only need one single interface:
Once this code is added, The next step is to configure the application. Open the file application.properties and configure at least the ollama model that you will use. Other configuration are also possible as described in Quarkus langchain4j documentation.
That's all to have a working assistant! You can run the app using your IDE (for example, using Quarkus VS Code extension) or go to a terminal, navigate to the project root and run mvn clean compile quarkus:dev
Once the server is started, you can navigate to DEVUI, select the langchain4j card and chat with your LLM:
Registering MCP Server
A MCP Server can bring many functionalities to your LLM and there are thousand MCP Servers ready for use! In our example let's use the JDBC MCP Server. What you need to do is simply configure this provider. See how it looks like in our application.properties :
In this configuration we simply declare the transport type (how our MCP client will comunicate with the MCP Server) and the parameters to start the MCP server! We can also use a JDBC connection URL, if you don't provide it, then the MCP Server will use an in memory H2 database. For example, if we want to use sqlite you simply have to use the following configuration:
Now if you restart your application and go back to the DEV UI you will see that your client can handle a SQL Database in plain English!
MCP advantages
There's a good discussion about what MCP brings to the table. If you are on future, probably you know if MCP is a standard for plugging Tools into LLM or not. In our example the advantage is clear: we gave superpowers to our application by simply modifying a configuration!
My wish list for Quarkus Langchain4j MCP extension is only a good web UI that shows the registered MCP Servers and possibly even allow us to interact with it!
Conclusion
MCP and LLMs, Agents and event the new A2A protocol are another world, but it is still programming , exciting times we live on! I was very surprise how easy it was to create this post and test MCP Servers using Quarkus, the most powerful Java framework.
See the code on my Github
Comentários
Postar um comentário