souzamarcos/mcp-server
If you are the rightful owner of mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This document provides a comprehensive overview of an MCP (Model Context Protocol) server implementation using Spring AI, detailing its structure, features, and usage.
MCP Server Example
This is an example implementation of an MCP (Model Context Protocol) server using Spring AI. The application demonstrates how to create tools that can be called through the MCP protocol.
Prerequisites
- Java 21 or higher
- Gradle 8.x (or use the wrapper included in the project)
Project Structure
src/
āāā main/
ā āāā java/
ā āāā com/
ā āāā marcos/
ā āāā mcpserver/
ā āāā McpServerApplication.java
ā āāā core/
ā āāā service/
ā āāā WeatherService.java
āāā test/
āāā java/
āāā com/
āāā marcos/
āāā mcpserver/
āāā core/
āāā service/
āāā WeatherServiceTest.java
Features
The project includes an example service (WeatherService
) that exposes three MCP tools:
getWeather
: Returns weather information for a specific citygetWeatherForecastByLocation
: Returns weather forecast for specific coordinatesgetAlerts
: Returns weather alerts for a US state
How to Run
Using Gradle Wrapper
# Run the application
./gradlew bootRun
Using the JAR
# Generate the JAR
./gradlew build
# Run the JAR
java -jar build/libs/mcp-server-0.0.1-SNAPSHOT.jar
Tests
To run unit tests:
# Run all tests
./gradlew test
# Run a specific test
./gradlew test --tests "com.marcos.mcpserver.core.service.WeatherServiceTest"
Configuration
The MCP server configuration is in the application.yml
file:
spring:
ai:
mcp:
server:
enabled: true
stdio: true
name: mcp-server
version: 1.0.0
Using MCP Server with Copilot
To use this MCP server with GitHub Copilot, you need to configure the mcp.json
file located at:
- Windows:
%LOCALAPPDATA%\github-copilot\intellij\mcp.json
- macOS:
~/Library/Application Support/github-copilot/intellij/mcp.json
- Linux:
~/.config/github-copilot/intellij/mcp.json
Add the following configuration to the file:
{
"servers": {
"weather-mcp-server": {
"type": "stdio",
"command": "java -jar",
"args": [".\\build\\libs\\mcp-server-0.0.1-SNAPSHOT.jar"],
"cwd": "C:/Repository/mcp-server"
}
}
}
Alternatively, you can use Gradle to run the server:
{
"servers": {
"weather-mcp-server": {
"type": "stdio",
"command": "C:/Repository/mcp-server/gradlew.bat",
"args": ["bootRun"],
"cwd": "C:/Repository/mcp-server"
}
}
}
Configuration Details
weather-mcp-server
: Unique name to identify your servertype
: Server type (use "stdio" for standard input/output communication)command
: Command to run the server (can bejava -jar
or the gradlew path)args
: Arguments to run the application (JAR path orbootRun
)cwd
: Working directory where the server will run
Note: Adjust the paths according to your project location.
Build
To perform a complete project build:
# Clean and rebuild the project
./gradlew clean build
# Build without running tests
./gradlew build -x test
Development
To add new tools to the MCP server:
- Create a new service class
- Annotate methods with
@Tool
- Configure the tool name and description
- Spring AI will handle exposing these tools through the MCP protocol
Example:
@Service
public class MyService {
@Tool(name = "myTool", description = "Tool description")
public String myTool(String input) {
return "Result";
}
}
Technologies Used
- Spring Boot 3.5.0
- Spring AI (MCP Server) 1.0.0-M6
- JUnit 5 for testing
- Gradle as build system