Skip to content

matteoroxis/operations-mcp-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

operations-mcp-client

An Enterprise Operations Assistant built with Model Context Protocol (MCP), Java 25 and Spring Boot 3.5.

πŸš€ Description

This project integrates:

  • Model Context Protocol (MCP): for communication with external tools via McpSyncClient
  • Spring AI 1.1.2: for OpenAI GPT-4 integration
  • Spring Boot 3.5: for enterprise architecture

The application retrieves system metrics and recent incidents via MCP, processes them and provides intelligent operational recommendations using GPT-4.

πŸ“‹ Prerequisites

  • JDK 25 (or JDK 21+)
  • Maven 3.8+
  • MCP Server running at http://localhost:8081/mcp (Streamable HTTP)
  • OpenAI API Key

βš™οΈ Configuration

1. Set the OpenAI API Key

Windows (PowerShell):

$env:OPENAI_API_KEY="sk-your-api-key-here"

Linux/Mac:

export OPENAI_API_KEY="sk-your-api-key-here"

Or edit src/main/resources/application.properties and replace ${OPENAI_API_KEY} with your key directly.

2. Configure the MCP Server

The client expects a Streamable HTTP MCP server available at:

http://localhost:8081/mcp

The server must expose the following tools:

  • getSystemMetrics β†’ returns { avgLatencyMs, errorRate }
  • getRecentIncidents β†’ returns a list of [{ id, title, timestamp, status }]

3. Application Properties

spring.application.name=operations-mcp-client

# MCP Client
spring.ai.mcp.client.type=SYNC
spring.ai.mcp.client.request-timeout=30s
spring.ai.mcp.client.toolcallback.enabled=false
spring.ai.mcp.client.streamable-http.connections.tools-server.url=http://localhost:8081
spring.ai.mcp.client.streamable-http.connections.tools-server.endpoint=/mcp

# OpenAI
spring.ai.openai.api-key=${OPENAI_API_KEY}
spring.ai.openai.chat.options.model=gpt-4
spring.ai.openai.chat.options.temperature=0.7

4. Install Dependencies

mvn clean install

πŸƒ Running the Application

mvn spring-boot:run

Testing the Endpoint

curl http://localhost:8080/api/incidents/analyze

Or open in browser: http://localhost:8080/api/incidents/analyze

πŸ“ Project Structure

operations-mcp-client/
β”œβ”€β”€ src/main/java/it/matteoroxis/operations_mcp_client/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ McpClientConfig.java           # McpSyncClient configuration
β”‚   β”‚   └── SpringAIConfig.java            # Spring AI ChatClient configuration
β”‚   β”œβ”€β”€ controller/
β”‚   β”‚   └── IncidentController.java        # REST controller GET /api/incidents/analyze
β”‚   β”œβ”€β”€ model/
β”‚   β”‚   β”œβ”€β”€ Incident.java                  # Record: id, title, timestamp, status
β”‚   β”‚   └── SystemMetrics.java             # Record: avgLatencyMs, errorRate, timestamp
β”‚   β”œβ”€β”€ service/
β”‚   β”‚   └── IncidentAnalysisService.java   # Core analysis service
β”‚   └── OperationsMcpClientApplication.java
└── src/main/resources/
    └── application.properties

πŸ”§ How It Works

Execution Flow

GET /api/incidents/analyze
        β”‚
        β–Ό
IncidentAnalysisService.analyze()
        β”‚
        β”œβ”€β”€ McpSyncClient β†’ callTool("getSystemMetrics")   β†’ SystemMetrics
        β”œβ”€β”€ McpSyncClient β†’ callTool("getRecentIncidents") β†’ List<Incident>
        β”‚
        β–Ό
ChatClient (OpenAI GPT-4)
        β”‚
        β–Ό
Operational recommendations in natural language

Models

Incident

public record Incident(String id, String title, Instant timestamp, String status) {}

SystemMetrics

public record SystemMetrics(int avgLatencyMs, double errorRate, Instant timestamp) {}

REST Endpoint

Method Path Description
GET /api/incidents/analyze Analyses metrics and incidents, returns GPT-4 recommendations

Prompt sent to GPT-4

The service dynamically builds a prompt containing:

  • System metrics: average latency, error rate, timestamp
  • Recent incidents list: ID, title, status, timestamp
  • Analysis constraints: likely causes, prioritised actions, additional metrics to collect

πŸ“¦ Main Dependencies

Dependency Version Purpose
spring-boot-starter-web 3.5.10 REST API
spring-ai-starter-mcp-client 1.1.2 MCP Client
spring-ai-starter-model-openai 1.1.2 OpenAI integration
jackson-databind - JSON parsing of MCP responses

πŸ› Troubleshooting

Error: "Connection refused" on startup

The MCP server is not available at http://localhost:8081. Make sure the server is running before starting the client.

Error: "No compiler is provided"

Maven cannot find the JDK. Make sure JAVA_HOME points to a JDK:

# Windows
$env:JAVA_HOME="C:\Program Files\Java\jdk-25"

Error: "Invalid API Key"

Verify that the OPENAI_API_KEY environment variable is set correctly.

Incident fields show "N/A" or "UNKNOWN"

Make sure the MCP server returns JSON in the expected format:

[
  { "id": "INC-42", "title": "...", "timestamp": 1234567890, "status": "Resolved" }
]

The timestamp field must be an epoch number in seconds (not an ISO-8601 string).

πŸ“š Technologies Used

  • Java 25
  • Spring Boot 3.5.10
  • Spring AI 1.1.2
  • MCP Java SDK (via spring-ai-starter-mcp-client)
  • OpenAI GPT-4
  • Jackson
  • Maven

πŸ“„ License

This project is an educational example.

πŸ‘€ Author

Matteo Roxis

About

An Enterprise Operations Assistant Built on MCP with Java and Spring Boot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages