Cover image
Test de printemps-ai-MCP
Public

Test de printemps-ai-MCP

Try Now
2025-03-18

Médique comment intégrer la prise en charge de Spring AI pour MCP (Protocole de contexte du modèle) dans les applications de démarrage Spring, couvrant les implémentations côté serveur et côté client.

3 years

Works with Finder

1

Github Watches

2

Github Forks

2

Github Stars

MCP Host Project

Description

This project showcases how to integrate Spring AI's support for MCP (Model Context Protocol) within Spring Boot applications, covering both server-side and client-side implementations.

MCP

MCP is a standard that streamlines the management of contextual interactions in AI models, enabling consistent integration with external data sources and tools.

Spring AI MCP extends the MCP Java SDK and provides dedicated Spring Boot starters for both clients and servers.

The MCP client handles communication and connection management with MCP servers.

In this project, we leverage Spring AI to build MCP servers, making their capabilities available to LLMs. Note that the use of a model supporting TOOLS is required; we are using Llama3.2 via Ollama.

Modules

This project consists of three main modules:

Geocoder Service

  • Port: 8081
  • Description: Provides latitude and longitude for a given city.
  • configuration
public interface Geocoder {
    GeoCodeResult geocode(String city) throws Exception;
}

public record GeoCodeResult(double latitude, double longitude) {}

Timezone Service

  • Port: 8082
  • Description: Provides timezone information for a given latitude and longitude.
  • configuration
public interface TimeZoneService {
    Optional<TimeZone> getTimeZoneFromLocation(double latitude, double longitude) throws Exception;
}
public record TimeZone(
        String id,
        String name,
        int rawOffset,
        int dstSavings
) {}

MCP Host

  • Description: Uses the Geocoder and Timezone services via MCP clients and provides a console interface to interact with an LLM.
  • configuration
@Bean
CommandLineRunner runner(final ChatClient.Builder chatClientBuilder, List<ToolCallback> toolCallbacks) {

   final ChatClient agent = chatClientBuilder.build();

   return args -> {
      try (Scanner scanner = new Scanner(System.in)) {
         while (true) {
            System.out.print("\n\nEnter city (or type 'exit' to quit): ");
            String city = scanner.nextLine();
            if ("exit".equalsIgnoreCase(city)) {
               break;
            }

            String queryTemplate = """
                    Please use the available tools to find the latitude and longitude for the city `{city}`. Once you have this information, 
                    use the tools to determine and provide all the timezone details for that location in the same language.
                    """;

            String systemTemplate = """
                    You are an AI assistant specialized in providing geographical information. Your task is to use the provided tools to gather and deliver accurate data.
                    """;

            String llmResponse = agent
                    .prompt()
                    .advisors(new SimpleLoggerAdvisor())
                    .system(systemSpec -> systemSpec.text(systemTemplate))
                    .user(userSpec -> userSpec.text(queryTemplate).param("city", city))
                    .tools(toolCallbacks)
                    .call()
                    .content();

            log.info("\n\n{}", llmResponse);
         }
      }
   };
}

Running the Project

  1. Start Geocoder Service:

    cd geocoder
    mvn spring-boot:run
    
  2. Start Timezone Service:

    cd timezone
    mvn spring-boot:run
    
  3. Start MCP Host:

    cd mcp-host
    mvn spring-boot:run
    

Usage

  1. Interact with MCP Host:
    • Run the MCP Host application.
    • Enter city names in the console.
    • The system will provide latitude, longitude, and timezone information for the entered city.

Insertamos image

image

相关推荐

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

  • 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.

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

  • Khalid kalib
  • Write professional emails

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

  • INFOLAB OPERATIONS 2
  • A medical specialist offering assistance grounded in clinical guidelines. Disclaimer: This is intended for research and is NOT safe for clinical use!

  • Yasir Eryilmaz
  • AI scriptwriting assistant for short, engaging video content.

  • J. DE HARO OLLE
  • Especialista en juegos de palabras en varios idiomas.

  • apappascs
  • Découvrez la collection la plus complète et la plus à jour de serveurs MCP sur le marché. Ce référentiel sert de centre centralisé, offrant un vaste catalogue de serveurs MCP open-source et propriétaires, avec des fonctionnalités, des liens de documentation et des contributeurs.

  • ShrimpingIt
  • Manipulation basée sur Micropython I2C de l'exposition GPIO de la série MCP, dérivée d'Adafruit_MCP230XX

  • OffchainLabs
  • Aller la mise en œuvre de la preuve de la participation Ethereum

  • huahuayu
  • Une passerelle API unifiée pour intégrer plusieurs API d'explorateur de blockchain de type étherscan avec la prise en charge du protocole de contexte modèle (MCP) pour les assistants d'IA.

  • deemkeen
  • Contrôlez votre MBOT2 avec un combo d'alimentation: MQTT + MCP + LLM

  • zhaoyunxing92
  • 本项目是一个钉钉 MCP (Protocole de connecteur de message) 服务 , 提供了与钉钉企业应用交互的 API 接口。项目基于 Go 语言开发 , 支持员工信息查询和消息发送等功能。

  • pontusab
  • La communauté du curseur et de la planche à voile, recherchez des règles et des MCP

    Reviews

    1 (1)
    Avatar
    user_BTxSuGqt
    2025-04-18

    I recently started using the spring-ai-mcp-test by oalles, and I must say, it has exceeded my expectations. The repository is well-organized, and the code is clean and easy to follow. This tool seamlessly integrates AI capabilities with Spring applications, making development efficient and enjoyable. Highly recommended for developers looking to streamline AI integration!