MCP cover image
See in Github
2025-04-04

Ejemplo básico del servidor MCP con Spring AI

1

Github Watches

0

Github Forks

0

Github Stars

Cars MCP Server

This is an MCP (Model Context Protocol) server built using Spring AI. The project demonstrates the use of Spring AI's ToolCallback API to expose tools for interacting with a list of cars, which represents Amarpreet's wishlist.

Demo

Demo Video

Project Structure

The project is organized as follows:

  • src/main/java/com/amarpreet/carsmcpserver/

    • CarsmcpserverApplication.java: The main entry point of the Spring Boot application. It initializes the application and registers the ToolCallback beans using the CarService class.
    • Car.java: A simple record class representing a car with two fields: modelName and buildYear.
    • CarService.java: A service class that provides methods to interact with the list of cars. These methods are exposed as tools using the ToolCallback API.
  • src/main/resources/application.properties: Contains configuration properties for the Spring Boot application.

  • src/test/java/com/amarpreet/carsmcpserver/

    • CarsmcpserverApplicationTests.java: Contains a basic test to ensure the application context loads correctly.

ToolCallback API

The ToolCallback API is used to expose methods from the CarService class as tools. These tools can be invoked programmatically or through an AI-driven interface. The CarsmcpserverApplication class registers these tools using the ToolCallbacks.from() method.

Tool Registration

In CarsmcpserverApplication.java:

@Bean
public List<ToolCallback> amarpreetTools(CarService carService) {
    return List.of(ToolCallbacks.from(carService));
}

This registers all methods annotated with @Tool in the CarService class as ToolCallback instances.

CarService

The CarService class is the core of this application. It manages a list of cars and provides the following methods:

Methods in CarService

getCars()

  • Tool Name: get_cars
  • Description: Retrieves the list of cars in Amarpreet's wishlist.
  • Return Type: List<Car>

getCar(String name)

  • Tool Name: get_car_by_name
  • Description: Finds a car by its model name.
  • Parameters:
    • name - The model name to search for.
  • Return Type: Car (or null if not found)

getCarByYear(Integer year)

  • Tool Name: get_car_by_years
  • Description: Finds a car by its build year.
  • Parameters:
    • year - The build year to search for.
  • Return Type: Car (or null if not found)

Initialization

The CarService class initializes a list of cars during application startup using the @PostConstruct annotation:

public void init() {
    log.info("Initializing cars MCP server...");
    cars.addAll(List.of(
        new Car("BMW Neue Klasse", 2025),
        new Car("Ferrari EV", 2025),
        new Car("Mercedes AMG 4dr EV", 2025),
        new Car("Porsche 718 Boxster", 2025)
    ));
}

How to Run

Build the project using Maven:

mvn clean install

Run the application:

java -jar target/carsmcpserver-0.0.1-SNAPSHOT.jar

Configuration

The application can be configured using the application.properties file located in src/main/resources. Key properties include:

  • spring.application.name: The name of the application.
  • spring.main.web-application-type: Set to none for a non-web application.
  • spring.ai.mcp.server: The name of the MCP server.
  • spring.ai.mcp.version: The version of the MCP server.

相关推荐

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

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

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

  • Contraband Interactive
  • Emulating Dr. Jordan B. Peterson's style in providing life advice and insights.

  • rustassistant.com
  • Your go-to expert in the Rust ecosystem, specializing in precise code interpretation, up-to-date crate version checking, and in-depth source code analysis. I offer accurate, context-aware insights for all your Rust programming questions.

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

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

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • apappascs
  • Descubra la colección más completa y actualizada de servidores MCP en el mercado. Este repositorio sirve como un centro centralizado, que ofrece un extenso catálogo de servidores MCP de código abierto y propietarios, completos con características, enlaces de documentación y colaboradores.

  • ShrimpingIt
  • Manipulación basada en Micrypthon I2C del expansor GPIO de la serie MCP, derivada de AdaFruit_MCP230xx

  • modelcontextprotocol
  • Servidores de protocolo de contexto modelo

  • Mintplex-Labs
  • La aplicación AI de escritorio todo en uno y Docker con trapo incorporado, agentes de IA, creador de agentes sin código, compatibilidad de MCP y más.

  • n8n-io
  • Plataforma de automatización de flujo de trabajo de código justo con capacidades de IA nativas. Combine el edificio visual con código personalizado, auto-anfitrión o nube, más de 400 integraciones.

  • ravitemer
  • Un poderoso complemento Neovim para administrar servidores MCP (protocolo de contexto del modelo)

  • WangRongsheng
  • 🧑‍🚀 全世界最好的 llM 资料总结(数据处理、模型训练、模型部署、 O1 模型、 MCP 、小语言模型、视觉语言模型) | Resumen de los mejores recursos del mundo.

  • jae-jae
  • Servidor MCP para obtener contenido de la página web con el navegador sin cabeza de dramaturgo.

  • patruff
  • Puente entre los servidores Ollama y MCP, lo que permite a LLM locales utilizar herramientas de protocolo de contexto del modelo

    Reviews

    5 (1)
    Avatar
    user_XQ2FRpQn
    2025-04-17

    Carsmcpserver is an outstanding application for car management. Amarpreetbhatia did a fantastic job developing it. The server runs smoothly, and it’s incredibly user-friendly. I highly recommend checking it out on GitHub at https://github.com/amarpreetbhatia/carsmcpserver. This tool will significantly streamline car management tasks. Great job!