Navigation
MCP Host Project: Seamless Server/Client AI Workflows - MCP Implementation

MCP Host Project: Seamless Server/Client AI Workflows

MCP Host Project showcases Spring AI's Model Context Protocol integration in Spring Boot apps, enabling seamless server/client implementations for AI-driven workflows.

Developer Tools
4.1(26 reviews)
39 saves
18 comments

Ranked in the top 5% of all AI tools in its category

About MCP Host Project

What is MCP Host Project: Seamless Server/Client AI Workflows?

The MCP Host Project is an advanced framework demonstrating seamless integration of AI tools via the Model Context Protocol (MCP). By embedding MCP into Spring Boot ecosystems, it enables bidirectional communication between server-side geospatial services and client-driven conversational agents. This modular architecture allows Large Language Models (LLMs) like Llama3.2 to dynamically leverage external APIs for real-time data enrichment.

How to Use MCP Host Project: Seamless Server/Client AI Workflows?

Follow this streamlined workflow:
1. Deploy geocoder (port 8081) and timezone (8082) microservices
2. Launch the MCP Host interface via Spring Boot
3. Engage the CLI prompt to query cities - responses automatically chain geolocation lookup with timezone analysis. Input validation and error handling are managed through Spring AI's tool callback mechanisms.

MCP Host Project Features

Key Features of MCP Host Project: Seamless Server/Client AI Workflows?

  • Contextual Orchestration: LLMs autonomously route requests through MCP's standardized tool interfaces
  • Modular Scalability: Independent services communicate via RESTful MCP clients for easy expansion
  • Human-in-the-Loop: CLI interface provides direct access to AI reasoning processes through logging advisors

Use Cases of MCP Host Project: Seamless Server/Client AI Workflows?

Enterprise applications include:
• Travel planning systems requiring real-time timezone conversions
• Logistics platforms optimizing delivery routes based on geospatial data
• Multilingual customer service bots needing localized time references
The modular design allows rapid adaptation to domain-specific APIs while maintaining MCP's standardized interaction patterns.

MCP Host Project FAQ

FAQ from MCP Host Project: Seamless Server/Client AI Workflows?

Why Llama3.2? Its advanced tool calling capabilities align perfectly with MCP's structured workflows.
Can I add custom tools? Absolutely - just implement the MCP client interface and register in Spring configuration.
How does error handling work? Built-in advisors log failures, while optional retry mechanisms can be configured via Spring AI's builder pattern.

Content

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 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 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
  1. Start Timezone Service :

    cd timezone

mvn spring-boot:run
  1. 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

Related MCP Servers & Clients