A Model Context Protocol (MCP) server implementation in Java using Spring AI.
This is a minimal MCP server skeleton that demonstrates how to build MCP servers using Java and Spring AI. It provides a basic tool implementation that you can use as a starting point for your own MCP server.
- Tools: Example job search tool that returns mock job data
- Spring Boot Integration: Built on Spring Boot for easy configuration and deployment
- Maven Support: Uses Maven for dependency management and building
- Minimal Setup: Only includes essential components needed to demonstrate MCP functionality
SSE Transport Limitation: This server currently uses Server-Sent Events (SSE) transport because Spring AI does not yet support Streamable HTTP. SSE has known reliability issues:
- Connection drops: SSE connections may drop after several minutes of activity
- Intermittent connectivity: You may experience periodic disconnections requiring manual reconnection
- Deprecated protocol: SSE has been officially deprecated in favor of Streamable HTTP
Spring AI 1.1.0 (planned release: September 30th, 2025) will include support for Streamable HTTP. This template will be updated once that version is available.
Recommendation: For production use, consider using Python or TypeScript MCP templates which support Streamable-HTTP and do not have these reliability issues.
Follow spring-projects/spring-ai#3145 for Spring AI Streamable-HTTP support updates.
- Java 17 or higher
- Maven 3.6+ (or use the included Maven wrapper)
./mvnw clean compile
./mvnw spring-boot:run
mvn clean compile
mvn spring-boot:run
You can configure the application by creating application-local.yml
in src/main/resources/
for local development:
# Add your configuration here
logging:
level:
com.example.mcp: DEBUG
-
Start the server:
./mvnw spring-boot:run
-
Run MCP Inspector:
npx @modelcontextprotocol/inspector
-
Configure the inspector:
- Set
Transport Type
toStreamable HTTP
- Set
URL
tohttp://localhost:8080/mcp
- Click
Connect
- Set
-
Test the available tools from the inspector interface
-
Add this configuration to your Cursor Code
mcp.json
:{ "mcpServers": { "java-mcp": { "url": "http://localhost:8082/mcp" } } }
-
Build the JAR file first:
./mvnw clean package
-
Update the path in
settings.json
to point to your JAR file intarget/mcp-java-skeleton-1.0.0.jar
-
Start the server in VS Code and test with GitHub Copilot Chat:
Show me a few Software Engineer jobs in Austin
src/
├── main/java/com/example/mcp/java/skeleton/
│ ├── SkeletonMcpDaemon.java # Main application class
│ ├── tools/
│ │ ├── JobsToolsService.java # Tool implementations
│ │ └── dto/JobDto.java # Data transfer objects
│ └── configuration/
│ ├── JobsToolsConfiguration.java # Tool configuration
│ ├── PromptConfiguration.java # Prompt configuration
│ └── ResourceConfiguration.java # Resource configuration
└── test/ # Unit tests
- Create a service class in the
tools
package - Annotate methods with
@Tool
to expose them as MCP tools - Register the service in a configuration class
Example:
@Service
public class MyToolsService {
@Tool(description = "My custom tool")
public String myTool(String input) {
return "Result: " + input;
}
}
- Create a new configuration class similar to
JobsToolsConfiguration
- Add
SyncResourceSpecification
beans - Implement resource handlers
- Create a new configuration class for prompts
- Add
SyncPromptSpecification
beans - Implement prompt handlers
./mvnw test
./mvnw clean package
The executable JAR will be created in target/mcp-java-skeleton-1.0.0.jar
.
java -jar target/mcp-java-skeleton-1.0.0.jar
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request