A Model Context Protocol (MCP) server implementation built with Spring Boot and Java 21. This project demonstrates how to create an MCP server that provides user management tools for AI assistants.
shell
git clone https://github.com/yourusername/mcp-spring-java.git
cd mcp-spring-java
shell
mvn clean package
shell
java -jar target/mcp-spring-java-0.0.1-SNAPSHOT.jar
The MCP server is configured in application.yml
:
- Server runs on port 8090
- Server name: my-dummy-users-server
- Synchronous communication mode
- Supports STDIO transport for terminal-based communication
- Exposes /mcp/message
endpoint for SSE communication
The server exposes the following user management tools:
- getAllUsers
- Get all users with pagination
- getAllUsersDefault
- Get all users with default pagination
- getUserById
- Get a single user by ID
- searchUsers
- Search for users by query
- addUser
- Add a new user
- updateUser
- Update a user
- deleteUser
- Delete a user
You can use Postman to test the MCP server endpoints:
http://localhost:8090/mcp/message
json
{
"message": {
"toolCalls": [
{
"id": "call-123",
"name": "[TOOL_NAME]",
"parameters": {
"[PARAMETER_NAME]": "[PARAMETER_VALUE]"
}
}
]
}
}
{
"message": {
"toolCalls": [
{
"id": "call-123",
"name": "getAllUsersDefault",
"parameters": {}
}
]
}
}
{
"message": {
"toolCalls": [
{
"id": "call-123",
"name": "getUserById",
"parameters": {
"id": 1
}
}
]
}
}
{
"message": {
"toolCalls": [
{
"id": "call-123",
"name": "searchUsers",
"parameters": {
"query": "John"
}
}
]
}
}
The response will contain a JSON object with the results from the tool execution.
You can configure this server in MCP client applications using the following configuration:
{
"mcpServers": {
"dummy-user-server": {
"command": "java",
"args": [
"-Dspring.ai.mcp.server.stdio=true",
"-Dspring.main.web-application-type=none",
"-Dlogging.pattern.console=",
"-jar",
"path/to/mcp-spring-java-0.0.1-SNAPSHOT.jar"
]
}
}
}
This project is licensed under the terms provided in the LICENSE file.
MCP Server using Spring Boot Java
No releases published
No packages published