Overview
The Java MCP SDK is the official library for building MCP servers in Java. It supports tools, resources, prompts, transports, and the stdio and streamable-http transport.
Installation
implementation 'io.modelcontextprotocol:sdk'Minimal Server Example
@SpringBootApplication
public class MyMcpServer {
@Bean
public McpServerFeatures.SyncToolSpecification addTool() {
return new McpServerFeatures.SyncToolSpecification(
new Tool("add", "Add two numbers",
Map.of("a", Map.of("type", "integer"),
"b", Map.of("type", "integer"))),
(exchange, args) -> new CallToolResult(
String.valueOf((int)args.get("a") + (int)args.get("b")))
);
}
}Adding a Tool
Tools are the primary way MCP servers expose functionality to clients. Each tool has a name, input schema, and handler function.
// Register additional tools as Spring @Bean methodsSupported Features
tools
resources
prompts
transports
Testing Your Server
- Start the server and verify it prints no startup errors.
- Run
npx @modelcontextprotocol/inspectorand connect over stdio. - Call your tools and verify they return the expected responses.
- Connect from Claude Desktop and confirm tool visibility.