Spring Boot MCP Server with GitHub Copilot
Give Copilot access to live application diagnostics using Model Context Protocol.
In this tutorial 10 sections
We already have a working spring-boot-diagnostics-mcp application. It manages orders and exposes live health, JVM, database connection pool and HTTP request diagnostics. In this tutorial, we will extend that application so GitHub Copilot can request the same information through MCP tools.
We will begin with one tool for application health, verify it from Copilot, and then add three more tools. The existing REST controllers and diagnostic calculations stay in place.
1. Start with the existing application
Open the existing project in your IDE. Our example uses Java 21, Spring Boot 3.5.16, Maven, Spring Web, Spring Data JPA, H2, Actuator and Micrometer. You will also need VS Code with GitHub Copilot access and a session that supports MCP tools.
The application contains the following layers:
com.javainuse.diagnostics
|-- DiagnosticsApplication.java
|-- order
| |-- Order.java
| |-- CreateOrderRequest.java
| |-- OrderController.java
| |-- OrderService.java
| |-- OrderRepository.java
| +-- SampleOrders.java
+-- diagnostics
|-- DiagnosticsController.java
+-- DiagnosticsService.java
The H2 database starts with 20 orders. The order entity contains id, customerName, productName, quantity, price and status.
| Endpoint | Purpose |
|---|---|
| GET /api/orders | List all orders. |
| GET /api/orders/{id} | Read one order. |
| POST /api/orders | Create an order. |
| GET /api/diagnostics/health | Application name, application health and database health. |
| GET /api/diagnostics/jvm | Heap used/max, live threads and process CPU usage. |
| GET /api/diagnostics/database | Maximum, active, idle and pending pool connections. |
| GET /api/diagnostics/http | Completed request count, durations and HTTP error count. |
From the project directory, check that Maven uses Java 21, then build and start:
mvn -version mvn clean verify java -jar target/spring-boot-diagnostics-mcp-0.0.1-SNAPSHOT.jar --spring.profiles.active=local --server.port=18080
The project's configured port is 8080. We use 18080 throughout this tutorial to avoid a conflict with another local service. Use the same port in every request and in the MCP client configuration. If an earlier instance is running, stop that instance before starting the rebuilt JAR.
curl http://localhost:18080/api/orders curl http://localhost:18080/api/diagnostics/health
A healthy application returns a response like this; the statuses are obtained from Actuator health contributors:
{
"applicationName": "spring-boot-diagnostics-mcp",
"applicationStatus": "UP",
"databaseStatus": "UP"
}
DiagnosticsService, rather than rebuilding order management.2. Understand the MCP request flow
When we ask Copilot to check application health, it needs a way to obtain current values from the running application. MCP exposes named tools with descriptions and input schemas that a compatible client can discover and call.
Copilot chat in VS Code
|
| MCP request over HTTP: get_application_health
v
Spring Boot /mcp endpoint
|
v
DiagnosticsTools
|
v
DiagnosticsService
|
v
Actuator health contributors / JVM / Micrometer / HikariCP
The MCP adapter calls the service directly in the same Java process. It does not make an HTTP call back to /api/diagnostics/health. Both the REST controller and the MCP tools reuse the same service.
Spring AI supplies the MCP server integration. Copilot supplies the conversational experience. This application does not need a model provider dependency, a chat client or a model API key.
3. Add the MCP server dependency
For this Spring Boot 3.5 application, pin Spring AI 1.1.8. The code below uses the 1.1 annotation packages; keep the version and imports together when following the example.
In the existing pom.xml, keep the Java 21 property and add the Spring AI version:
<properties>
<java.version>21</java.version>
<spring-ai.version>1.1.8</spring-ai.version>
</properties>
Add this dependency-management block as a child of <project>, outside the main <dependencies> block:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>${spring-ai.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Add this dependency alongside the existing Web, JPA, H2, Actuator and Micrometer dependencies:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
</dependency>
The WebMVC starter fits our existing servlet application. See the Spring AI 1.1 MCP starter reference for the supported transports.
4. Configure Streamable HTTP
In application.yml, merge the following ai section into the existing first spring: block. Keep the datasource, JPA and application-name settings. Do not create a second spring: key in the same YAML document.
spring:
ai:
mcp:
server:
name: spring-boot-diagnostics
version: 1.0.0
type: SYNC
protocol: STREAMABLE
streamable-http:
mcp-endpoint: /mcp
The MCP connection URL is now http://localhost:18080/mcp. SYNC matches our ordinary Java service methods. STREAMABLE selects the HTTP transport, and /mcp is its endpoint path. These settings are described in the Streamable HTTP server reference.
server.address: 127.0.0.1. The local profile exposes the selected Actuator URLs; MCP has its own endpoint and is not controlled by the Actuator exposure list. This example has no authentication and should remain bound to loopback.5. Create the first health tool
Create src/main/java/com/javainuse/diagnostics/mcp/DiagnosticsTools.java:
package com.javainuse.diagnostics.mcp;
import com.javainuse.diagnostics.diagnostics.DiagnosticsService;
import org.springaicommunity.mcp.annotation.McpTool;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
public class DiagnosticsTools {
private final DiagnosticsService diagnosticsService;
public DiagnosticsTools(DiagnosticsService diagnosticsService) {
this.diagnosticsService = diagnosticsService;
}
@McpTool(
name = "get_application_health",
description = "Read the application name, application health status "
+ "and database health status from the running application."
)
public Map<String, String> getApplicationHealth() {
return diagnosticsService.health();
}
}
@Component makes the class a Spring bean. In this Spring AI version, the MCP annotation scanner detects @McpTool methods and registers them. The tool name identifies the operation; the description explains when it is useful. See the MCP annotations reference.
The method has no parameters because it reads the current application's health. The return value comes directly from the existing service. There are no sample statuses embedded in the tool implementation.
get_application_health. Connect and call it successfully before adding the other three tools.6. Build and connect GitHub Copilot
Stop the earlier application instance, rebuild, and start the updated JAR:
mvn clean verify java -jar target/spring-boot-diagnostics-mcp-0.0.1-SNAPSHOT.jar --spring.profiles.active=local --server.port=18080
In VS Code, open the project and select your Copilot session. Run MCP: Add Server from the Command Palette, choose HTTP, and enter http://localhost:18080/mcp. Choose the configuration destination offered for your Copilot session and name the server springBootDiagnostics.
For a current native Copilot workspace configuration, the equivalent .mcp.json file at the project root is:
{
"mcpServers": {
"springBootDiagnostics": {
"type": "http",
"url": "http://localhost:18080/mcp",
"tools": ["*"]
}
}
}
Client configuration differs by VS Code/Copilot version. Older editor-managed setups use .vscode/mcp.json with a servers key. Prefer guided setup for your installed client and consult the VS Code MCP configuration reference rather than mixing the two formats.
Open the session's MCP server controls, connect to the server, and confirm that get_application_health appears. Enable the tool for the conversation and complete any trust or tool-call approval prompts. Then ask:
Use the springBootDiagnostics MCP server to call get_application_health. Report the application name and both health statuses from the tool result.
Expand the tool call in the chat to inspect the returned data. A successful connection should produce a real tool invocation, not just an explanation of how health checks work. The VS Code MCP walkthrough covers connecting and using tools.
/mcp as a normal browser page is not a complete MCP test. A client initializes the protocol session, discovers tools and sends a tool call. Use Copilot's tool result as the checkpoint.7. Add JVM, database and HTTP tools
After the health tool works, add these three methods inside the same DiagnosticsTools class, before its final closing brace. The imports already cover their return types.
@McpTool(
name = "get_jvm_metrics",
description = "Read current heap used and maximum in bytes, live JVM "
+ "thread count, and process CPU usage as a ratio from 0 to 1. "
+ "Preserve UNAVAILABLE measurements."
)
public Map<String, DiagnosticsService.Metric> getJvmMetrics() {
return diagnosticsService.jvm();
}
@McpTool(
name = "get_database_pool_metrics",
description = "Read the HikariCP pool maximum, active and idle connections "
+ "and pending connection requests. Preserve UNAVAILABLE measurements."
)
public Map<String, DiagnosticsService.Metric> getDatabasePoolMetrics() {
return diagnosticsService.database();
}
@McpTool(
name = "get_http_metrics",
description = "Read completed HTTP request count, 4xx and 5xx error count, "
+ "and total, mean and rolling maximum duration in milliseconds. "
+ "Counts are since startup. Preserve UNAVAILABLE measurements."
)
public Map<String, DiagnosticsService.Metric> getHttpMetrics() {
return diagnosticsService.http();
}
Rebuild and restart the application, then reconnect or refresh the MCP server in Copilot. You should now see all four tools.
| MCP tool | Service method | Runtime source |
|---|---|---|
| get_application_health | health() | Actuator health contributors |
| get_jvm_metrics | jvm() | JVM MemoryMXBean and Micrometer |
| get_database_pool_metrics | database() | HikariCP gauges |
| get_http_metrics | http() | Micrometer HTTP request timers |
The service returns measurements with status, value, unit and reason. For example, a missing CPU measurement is explicitly represented as:
{
"processCpuUsage": {
"status": "UNAVAILABLE",
"value": null,
"unit": "ratio",
"reason": "Metric not registered"
}
}
This is an example of the unavailable-value format, not a prediction of the response on your machine. A genuine zero remains an available measurement; missing data must not be converted to zero.
8. Try a complete diagnostics conversation
First generate some ordinary application traffic:
curl http://localhost:18080/api/orders curl http://localhost:18080/api/orders/1 curl http://localhost:18080/api/diagnostics/jvm
Then ask Copilot:
Use all four tools from springBootDiagnostics to inspect this running application. Summarize application and database health, heap usage, JVM thread count, process CPU usage, connection pool activity, and HTTP requests and errors. Include units and identify unavailable values. Base your answer on the tool results; do not infer a bottleneck from one snapshot.
Inspect the tool invocations and the response. Copilot may call tools sequentially, so measurements are not an atomic snapshot. A tool description guides selection, but the visible calls are the evidence that the application was queried.
9. Verify the results and troubleshoot
Compare the returned fields with /api/diagnostics/health, /api/diagnostics/jvm, /api/diagnostics/database and /api/diagnostics/http. Values can change between calls. Check the units and meaning, rather than expecting identical numbers.
- CPU: A ratio of 0.25 means 25%. The first sample may be unavailable.
- Heap: Used and maximum values are bytes. The maximum may be undefined on a particular runtime.
- Database: Pending requests are threads waiting for a pool connection. Zero active connections can be normal between requests.
- HTTP: Counts cover completed requests since startup, including diagnostics and Actuator traffic. Error count includes 4xx and 5xx responses. Maximum duration is a rolling-window value.
- Observation timing: A diagnostics HTTP request is counted after its response completes. MCP transport requests may also contribute to the HTTP meters; one tool call is not necessarily one HTTP request.
- Restart: Runtime counters and the in-memory order data reset when the application restarts.
| Symptom | Check |
|---|---|
| Connection refused | Start the rebuilt JAR and match the client URL to port 18080. |
| 404 at /mcp during client connection | Confirm the MCP starter, STREAMABLE configuration and endpoint path are present in the running build. |
| Server connects but tools are missing | Keep DiagnosticsTools under com.javainuse.diagnostics, include @Component and the Spring AI 1.1 @McpTool import, and reconnect after rebuilding. |
| Annotation does not compile | Use the pinned 1.1.8 BOM and org.springaicommunity.mcp.annotation.McpTool import together. Other Spring AI major versions use different packages. |
| Copilot answers without a tool call | Check the selected session, enabled tools and server connection; explicitly ask it to call a named tool. |
| UNAVAILABLE measurement | Read the reason; allow time for initialization or generate a normal request, then retry. Do not replace it with a guessed number. |
| Actuator URLs return 404 | Start with the local profile. Actuator exposure and MCP endpoint configuration are separate. |
Verification checklist: The existing Maven tests pass, the rebuilt application starts, Copilot lists all four tools, each tool returns runtime data, and the original order APIs still work. The baseline REST tests alone do not prove that MCP discovery and tool calls work.
10. Review the changes
The MCP extension consists of three application changes: a Maven dependency and BOM, MCP settings in application.yml, and the new DiagnosticsTools class. Copilot also needs its client-side server configuration.
The useful separation is already present in our application: DiagnosticsService collects the data, the REST controller exposes it to HTTP clients, and the MCP adapter exposes it as discoverable tools. Copilot can now request those measurements and explain the returned values in a conversation.