public static void main(String[] args) throws Exception {

                ChatLanguageModel model = OpenAiOfficialChatModel.builder()
                                .isGitHubModels(true)
                                .apiKey(System.getenv("GITHUB_TOKEN"))
                                .timeout(Duration.ofSeconds(60))
                                .modelName("gpt-4.1-nano")
                                .timeout(Duration.ofSeconds(60))
                                .build();

                McpTransport transport = new HttpMcpTransport.Builder()
                                .sseUrl("http://localhost:8080/sse")
                                .timeout(Duration.ofSeconds(60))
                                .logRequests(true)
                                .logResponses(true)
                                .build();

                McpClient mcpClient = new DefaultMcpClient.Builder()
                                .transport(transport)
                                .build();

                ToolProvider toolProvider = McpToolProvider.builder()
                                .mcpClients(List.of(mcpClient))
                                .build();

                Bot bot = AiServices.builder(Bot.class)
                                .chatLanguageModel(model)
                                .toolProvider(toolProvider)
                                .build();
                try {
                        String response = bot.chat("Calculate the sum of 24.5 and 17.3 using the calculator service");
                        System.out.println(response);

                        response = bot.chat("What's the square root of 144?");
                        System.out.println(response);

                        response = bot.chat("Show me the help for the calculator service");
                        System.out.println(response);
                } finally {
                        mcpClient.close();
                }
        }
This example uses the calculator MCP server that provides basic calculator
operations.
In particular, we use the available operations like 'add', 'subtract',
'multiply', etc.
<p>
Before running this example, you need to start the calculator server in SSE
mode on localhost:8080.
<p>
Run the example and check the logs to verify that the model used the
calculator tools.
03-GettingStarted/samples/java/calculator/src/test/java/com/microsoft/mcp/sample/client/LangChain4jClient.java