Menu

Building an annotation-driven MCP server in Java
πŸ“°

Building an annotation-driven MCP server in Java

DEV Community: javaΒ·Ayush SoniΒ·about 3 hours ago
#WX8KG8NW
#devtojava#devto#dev#method#json
Reading 0:00
15s threshold

Exposing a Java method to an AI agent should take one annotation. When I started using MCP servers daily with Claude Code and Cursor, I noticed that almost every example was written in Python or TypeScript β€” while most of the systems I'd want an agent to call are Spring Boot services.

So I wrote java-mcp-server : a small toolkit where this is the whole integration:

@Component public class MyTools {

@McpTool ( name = "greet" , description = "Say hello to someone" ) public String greet ( @McpParam ( value = "name" , description = "Person's name" ) String name ) { return "Hello, " + name + "!" ; }

@McpResource ( uri = "config://app/{key}" , description = "Read a config value" ) public String config ( @McpParam ( "key" ) String key ) { return System . getProperty ( key , "(not set)" ); } }

Enter fullscreen mode

Exit fullscreen mode

Start the app, and any MCP client can list and call greet and read config://app/java.version .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.