Cover image
Try Now
2025-03-20

使用Spring Boot Java的MCP服务器

3 years

Works with Finder

2

Github Watches

1

Github Forks

2

Github Stars

MCP Server using Spring Boot Java

A Model Context Protocol (MCP) server implementation built with Spring Boot and Java 21. This project demonstrates how to create an MCP server that provides user management tools for AI assistants.

Features

  • Implements MCP server functionality using Spring AI
  • Exposes user management tools via MCP
  • Synchronous communication mode
  • Support for Standard I/O and Server-Sent Events transports
  • Integrates with DummyJSON external API for user data

Technologies

  • Java 21
  • Spring Boot 3.4.3
  • Spring AI (Model Context Protocol)
  • Project Lombok
  • Maven

Getting Started

Prerequisites

  • Java 21 or higher
  • Maven

Installation

  1. Clone the repository
git clone https://github.com/yourusername/mcp-spring-java.git
cd mcp-spring-java
  1. Build the project
mvn clean package
  1. Run the application
java -jar target/mcp-spring-java-0.0.1-SNAPSHOT.jar

Configuration

The MCP server is configured in application.yml:

  • Server runs on port 8090
  • Server name: my-dummy-users-server
  • Synchronous communication mode
  • Supports STDIO transport for terminal-based communication
  • Exposes /mcp/message endpoint for SSE communication

Available Tools

The server exposes the following user management tools:

  • getAllUsers - Get all users with pagination
  • getAllUsersDefault - Get all users with default pagination
  • getUserById - Get a single user by ID
  • searchUsers - Search for users by query
  • addUser - Add a new user
  • updateUser - Update a user
  • deleteUser - Delete a user

Testing with Postman

You can use Postman to test the MCP server endpoints:

  1. Start the MCP server

  2. Open Postman and create a new request:

  3. For the request body, use the following JSON format to invoke any of the available tools:

{
  "message": {
    "toolCalls": [
      {
        "id": "call-123",
        "name": "[TOOL_NAME]",
        "parameters": {
          "[PARAMETER_NAME]": "[PARAMETER_VALUE]"
        }
      }
    ]
  }
}

Example Requests

Get All Users (Default Pagination)

{
  "message": {
    "toolCalls": [
      {
        "id": "call-123",
        "name": "getAllUsersDefault",
        "parameters": {}
      }
    ]
  }
}

Get User by ID

{
  "message": {
    "toolCalls": [
      {
        "id": "call-123",
        "name": "getUserById",
        "parameters": {
          "id": 1
        }
      }
    ]
  }
}

Search Users

{
  "message": {
    "toolCalls": [
      {
        "id": "call-123",
        "name": "searchUsers",
        "parameters": {
          "query": "John"
        }
      }
    ]
  }
}

The response will contain a JSON object with the results from the tool execution.

Usage with MCP Clients

You can configure this server in MCP client applications using the following configuration:

{
  "mcpServers": {
    "dummy-user-server": {
      "command": "java",
      "args": [
        "-Dspring.ai.mcp.server.stdio=true",
        "-Dspring.main.web-application-type=none",
        "-Dlogging.pattern.console=",
        "-jar",
        "path/to/mcp-spring-java-0.0.1-SNAPSHOT.jar"
      ]
    }
  }
}

License

This project is licensed under the terms provided in the LICENSE file.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Callycode Limited
  • A geek-themed horoscope generator blending Bitcoin prices, tech jargon, and astrological whimsy.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Khalid kalib
  • Write professional emails

  • Beniyam Berhanu
  • Therapist adept at identifying core issues and offering practical advice with images.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • OffchainLabs
  • 进行以太坊的实施

  • huahuayu
  • 统一的API网关,用于将多个Etherscan样区块链Explorer API与对AI助手的模型上下文协议(MCP)支持。

  • deemkeen
  • 用电源组合控制您的MBOT2:MQTT+MCP+LLM

    Reviews

    5 (1)
    Avatar
    user_beEAZkb8
    2025-04-15

    Heart-mcp-server is a game-changer for any MCP application enthusiast! Developed by atuinturtle, it streamlines the management and deployment process, making it exceptionally user-friendly and efficient. The seamless integration and robust performance of this server have significantly enhanced my project's productivity. Highly recommend for anyone looking to optimize their MCP server experience! Check it out at https://mcp.so/server/heart-mcp-server/atuinturtle