Skip to content
Discussion options

You must be logged in to vote

Here is how to implement MCP-based tool calling in Spring AI:

1. Add MCP Dependency

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-mcp</artifactId>
</dependency>

2. Configure MCP Server

@Configuration
public class McpConfig {
    @Bean
    public McpServer mcpServer() {
        return McpServer.builder()
            .tools(new WeatherTool(), new CalculatorTool())
            .build();
    }
}

3. Define a Custom Tool

@Component
public class WeatherTool implements ToolCallback {
    @Override
    public String getName() { return "getWeather"; }

    @Override
    public String getDescription() {
        return "Get current weather for a city";
    }

    @

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by however-yir
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants