mcp_server_spring_example

litao163email/mcp_server_spring_example

3.2

If you are the rightful owner of mcp_server_spring_example and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

This is a Spring AI-based Model Context Protocol (MCP) server example project, demonstrating how to build an MCP server using Spring Boot and provide tool services via HTTP/SSE.

Tools
4
Resources
0
Prompts
0

MCP Server Spring Example

这是一个基于 Spring AI 的 MCP (Model Context Protocol) 服务器示例项目,展示了如何使用 Spring Boot 构建 MCP 服务器,并通过 HTTP/SSE 方式提供工具服务。

项目简介

本项目演示了如何创建一个 MCP 服务器,提供以下功能:

  • 天气查询工具:根据经纬度查询天气信息
  • BI 业务查询工具:根据客户名称或合同号查询项目信息
  • 文本处理工具:文本转大写

快速开始

构建项目

./mvnw clean install -DskipTests

运行服务器

java -jar target/mcp-weather-starter-webmvc-server-0.0.1-SNAPSHOT.jar

服务器启动后,默认运行在 http://localhost:8080,SSE 消息端点:/mcp/message

配置说明

主要配置在 application.properties 文件中:

# 服务器名称和版本
spring.ai.mcp.server.name=my-weather-server
spring.ai.mcp.server.version=0.0.1

# 服务器类型(同步模式)
spring.ai.mcp.server.type=SYNC

# SSE 消息端点
spring.ai.mcp.server.sse-message-endpoint=/mcp/message

可用工具

1. 天气查询

  • 工具名getWeatherForecastByLocation
  • 功能:根据经纬度查询天气 forecast
  • 参数
    • latitude:纬度(double)
    • longitude:经度(double)

2. BI 业务查询

  • 工具名getProjectInfoByCustomerName

  • 功能:根据客户名称查询项目信息

  • 参数customerName:客户名称(String)

  • 工具名getProjectInfoByContractNum

  • 功能:根据合同号查询项目信息

  • 参数contractNum:合同编号(String)

3. 文本处理

  • 工具名toUpperCase
  • 功能:将文本转换为大写
  • 参数input:输入文本(String)

技术栈

  • Spring Boot 3.4.5
  • Spring AI MCP Server WebMVC Starter
  • Java

相关资源