Cover image
Try Now
2025-03-25

春季AI示例。 MCP服务器,代理AI。

3 years

Works with Finder

1

Github Watches

1

Github Forks

0

Github Stars

Spring AI Example

Project Overview

This project demonstrates various implementation patterns and best practices for using Spring AI tools. It consists of two main modules:

  • mcp-server: Implements the Model Context Protocol (MCP) server with both WebFlux and WebMvc SSE support
  • proposal-agent: Implements the MCP client for making AI-powered proposals

Project Structure

.
├── mcp-server/           # MCP Server implementation
│   ├── src/             # Server source code
│   └── README.md        # Server documentation
├── proposal-agent/      # MCP Client implementation
│   ├── src/             # Client source code
│   └── README.md        # Client documentation
└── src/                 # Common source code

Tools Implementation Patterns

Methods as Tools

Spring AI supports using methods as tools by annotating them with @Tool. Example from DateTimeTools:

@Tool(name = "getCurrentDateTime", description = "Get the current date and time")
public String getCurrentDateTime() {
    return LocalDateTime.now().atZone(LocaleContextHolder.getTimeZone().toZoneId()).toString();
}

Tool Result Converter

Custom result converters can be implemented to control how tool results are formatted. Example from CustomToolCallResultConverter:

@Tool(name = "getCustomer",
      description = "Retrieve customer information",
      resultConverter = CustomToolCallResultConverter.class)
public Customer getCustomer(String name, ToolContext context) {
    return new Customer(name, "example@email.com");
}

Tool Context

Spring AI provides a ToolContext parameter that can be injected into tool methods to access contextual information:

public Customer getCustomerByEmail(String email, ToolContext context) {
    log.info("Context: {}", context);
    return new Customer("Demo", email);
}

Tool Parameters

Tool parameters can be annotated with @ToolParam to provide descriptions:

@Tool(name = "setAlarm")
public void setAlarm(@ToolParam(description = "Time in ISO-8601 format") String time) {
    // Implementation
}

Configuration

The project uses Spring Boot with the following key configurations:

  • Ollama AI model integration
  • Vector store with PGVector
  • H2 database for development
  • CORS configuration for web access
  • MCP Server implementation
  • MCP Client implementation
  • SSE implementation

SSE implementation

an implementation of SSE (Server-Sent Events) for real-time updates. This is achieved by using the SseEmitter class.

Technology Stack

  • Spring Boot
  • Spring AI
  • Ollama AI Model
  • PGVector Vector Store
  • H2 Database
  • CORS Configuration
  • SSE (Server-Sent Events) for real-time updates

相关推荐

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

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

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

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

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

  • Lists Tailwind CSS classes in monospaced font

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

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

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

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

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

    Reviews

    2 (1)
    Avatar
    user_VSpjISgI
    2025-04-16

    I am thoroughly impressed with the 'spring-ai-example' by lucasdengcn. The simplicity and efficiency of integrating AI with Spring framework is incredibly valuable. The comprehensive documentation and welcoming prompt streamline the setup process, making it accessible for both novices and experts. Highly recommended for anyone looking to enhance their Spring applications with AI capabilities. Fantastic work!