PoC of MCP (Model Context Protocol) integration into Micronaut framework.
This project demonstrates how to integrate the Model Context Protocol (MCP) with the Micronaut framework. It provides a way to expose Micronaut beans as MCP tools that can be called by AI models or other MCP clients.
- JDK 17 or higher
./gradlew build
./gradlew run
- Create a Micronaut bean with methods annotated with
@Tool
:
@Singleton
class MyTool {
@Tool(
name = "myTool",
description = "A tool that does something useful"
)
fun doSomething(
@ToolArg(description = "First parameter") param1: String,
@ToolArg(description = "Second parameter") param2: Int
): String {
return "Result: $param1 $param2"
}
}
-
The tool will be automatically registered with the MCP server when the application starts.
-
Clients can call the tool using the MCP protocol over standard input/output.
MicronautMcpCliCommand.kt
- Main command class that sets up the MCP serverServerWrapper.kt
- Wrapper for the MCP serverToolBuilder.kt
- Processes methods annotated with@Tool
and registers them as MCP toolsToolAnnotations.kt
- Defines the@Tool
and@ToolArg
annotationsTypeConverter.kt
- Converts JDK types to MCP typesArgumentConverter.kt
- Converts MCP arguments to JDK typesFooTool.kt
- Example tool implementation
- Not a library now, just example App
- CLI (StdInOut) communication only
- Tools only (no Prompts...)
- Only int, boolean, number and strings and arrays (one or multidimensional) as parameters
- Only one String on output, no pictures, music
- no configuration of the server
- Temporary (?) package
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache License 2.0.