Sponsored by Deepsite.site

Spring Boot Sample MCP Server

Created By
tobiassteidle8 months ago
Content

This is a sample implementation of a Model Context Protocol (MCP) server using Spring Boot. The server is designed to be used with the Model Context Protocol Inspector for testing and debugging. It provides a simple REST API to interact with the server and demonstrates how to set up a basic Spring Boot application. Unit tests are included to verify the functionality of the server.

📋 Table of Contents

🧠 What is MCP?

Model Context Protocol (MCP) is an open standard that defines how AI models communicate with external tools and data sources. It creates a standardized way for AI assistants like Claude to access:

  • 🌐 Real-time information
  • 📊 Custom databases
  • 🔄 APIs and services
  • 📁 File systems

Think of MCP as the "USB standard for AI" - it provides a common interface that allows any AI model to interact with various tools through a consistent protocol. Benefits of using MCP with Spring Boot:

  • 🔄 Seamless Integration: Easily expose your application's functionality to AI assistants
  • 🛠️ Tool Definition: Define custom tools using simple annotations
  • 🚀 Spring Boot Simplicity: Leverage Spring's dependency injection and configuration management
  • 📈 Enhanced AI Capabilities: Give AI models access to your organization's real-time data and services

Requirements

  • Java 17+
  • Maven
  • MCP Inspector (optional for testing)

Configuration for e.g. Claude Desktop

{
  "mcpServers": {
    "sample-mcp-server": {
      "command": "java",
      "args": [
        "-jar",
        "sample-mcp-server-0.0.1-SNAPSHOT.jar",
        "--port",
        "8080",
        "--host",
        "localhost"
      ],
      "env": {
        "JAVA_TOOL_OPTIONS": "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
      }
    }
  }
}

Note: The JAVA_TOOL_OPTIONS environment variable is used to set the JVM options for remote debugging. The address and port can be changed as needed.

💻 Development

Debugging

Install MCP Inspector

npm -g install @modelcontextprotocol/inspector

Run MCP Inspector for Testing

Build MCP Server
mvn clean package
Run MCP Inspector
npx @modelcontextprotocol/inspector \
    -e JAVA_TOOL_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 \
    java -jar target/sample-mcp-server-<version>-SNAPSHOT.jar \
    --port 8080 --host localhost

Note: The JAVA_TOOL_OPTIONS environment variable is used to set the JVM options for remote debugging. The address and port can be changed as needed. Now you can use the MCP Inspector to test and debug your Spring Boot MCP server. The inspector provides a user-friendly interface (Browser) to interact with the server and visualize the data being exchanged. The inspector can be used to send requests to the server, view the responses, and analyze the data flow between the client and server. To debug the server, you can set breakpoints in your code and use the debugger in your IDE to step through the code and inspect variables. Attach the debugger to the running server using the remote debugging options specified in the JAVA_TOOL_OPTIONS environment variable.

Spring AI extends the MCP Java SDK with productivity enhancements that make it straightforward to build MCP servers [1].

🔧 Using This Server with Claude Desktop

This sample server can be integrated with Claude Desktop or other AI assistants that support MCP. After configuring the server in your AI assistant:

  1. Start this Spring Boot MCP server
  2. Open Claude Desktop and enable the server in settings
  3. Ask Claude questions that require the tools provided by this server
  4. Watch as Claude seamlessly uses the server to access data and perform actions
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
ChatWiseThe second fastest AI chatbot™
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Amap Maps高德地图官方 MCP Server
Playwright McpPlaywright MCP server
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
DeepChatYour AI Partner on Desktop
CursorThe AI Code Editor
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Serper MCP ServerA Serper MCP Server
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
WindsurfThe new purpose-built IDE to harness magic
Tavily Mcp
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.