# mcp-sample **Repository Path**: xshuai/mcp-sample ## Basic Information - **Project Name**: mcp-sample - **Description**: 基于SpringAI 版本 2.0.0-M1 搭建MCP Server 目前提供了和风天气Tool示例 智能体使用MaxKb搭建 - **Primary Language**: Java - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2026-01-22 - **Last Updated**: 2026-09-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 项目简介 MCP、Agent、Milvus、LangChain4J学习示例整理 * 后端采用Spring Boot、SpringAI * 阿里AgentScope 通用文本向量(Embedding)模型 BGE(bge-base-zh-v1.5) http://192.168.0.118:8089/statics/bge.zip (链接是转好的onnx文件) 技术架构: ----------------------------------- #### 开发环境 - 语言:Java 17+ (大于等于17) - IDE(JAVA): IDEA (必须安装lombok插件 ) - IDE(前端): Vscode、WebStorm、IDEA - 依赖管理:Maven - 引擎:内嵌Tomcat #### 后端 - 基础框架:Spring Boot 4.0.0 - AI框架: Spring AI 2.0.0-M2 - AgentScope框架:AgentScope 1.0.53 - Milvus-Plus:2.2.5 - Milvus:2.6.0 - 其他:fastjson, lombok(简化代码)等。 ## 系统模块 ~~~ mcp-agent ├── src/main/java/cn/ydxiaoshuai/mcp/ │ ├── MCPApplication.java // Spring Boot 启动入口 │ │ │ ├── agent/ // AgentScope 智能体实现 │ │ │ ├── advisor/ // AI Advisor 拦截链 │ │ └── LoggingChatMemoryAdvisor // 对话记忆日志记录(流式/非流式) │ │ │ ├── component/ // Spring 组件 │ │ └── KeywordRouter // 关键词意图路由(补贴/附近农机/播放音乐) │ │ │ ├── config/ // 配置类 │ │ ├── AgentChatClientConfig // ChatClient 配置 │ │ ├── AgentChatClientSkillsConfig // ChatClient(集成 Skills + Tools) │ │ ├── AgentConfiguration // AgentScope ReActAgent 注册配置 │ │ ├── DeepSeekConfig // DeepSeek 模型配置 │ │ ├── LangChainConfig // LangChain4j 模型配置 │ │ ├── MiaoDaConfig // 妙哒 API 配置(图片生成) │ │ ├── QWeatherConfig // 和风天气 API 配置 │ │ ├── TencentOssUtil // 腾讯云 COS 对象存储工具 │ │ ├── ToolConfig // MCP Tool 工具类统一注册 │ │ ├── VectorStoreConfig // Milvus 向量存储配置 │ │ ├── WebConfig // Web MVC 跨域配置 │ │ ├── vector/ │ │ │ ├── BgeEmbeddingModel // BGE 文本向量模型(ONNX Runtime + DJL) │ │ │ ├── intent/ │ │ │ │ └── IntentInitializer // 意图识别向量库初始化 │ │ │ ├── knowledge/ │ │ │ │ └── KnowledgeInitializer // 知识库向量化初始化 │ │ │ └── parser/ │ │ │ └── PDFDocumentParser // PDF 文档解析器(Apache PDFBox + iText) │ │ │ ├── constant/ // 常量定义 │ │ └── CommonConstant // 通用常量(提示词模板、配置键等) │ │ │ ├── controller/ // REST 控制器层 │ │ ├── AgentChatController // Agent 对话接口(非流式) │ │ ├── AgentChatSkillsController // Agent Skills 对话接口(流式 SSE) │ │ ├── IntentController // 意图识别接口 │ │ ├── MilvusController // Milvus 向量库管理接口 │ │ └── RagChatController // RAG 对话接口(保单知识库问答) │ │ │ ├── dto/ // 数据传输对象 │ │ ├── entity/MilvusFace // Milvus 人脸向量实体 │ │ ├── BaseBean // 统一响应体 │ │ ├── CurrentWeatherVo // 当前天气 VO │ │ ├── GenerateContentRequest/Response // 多模态内容生成请求/响应 │ │ ├── MilvusDocumentRequest // 文档入库请求 │ │ ├── PDFChatResponse // PDF 对话响应 │ │ ├── PdfUploadBean // PDF 上传 Bean │ │ ├── QueryRequest // 通用查询请求 │ │ ├── QWeatherGeoResponse // 和风天气地理信息响应 │ │ ├── QWeatherNowResponse // 和风天气实时数据响应 │ │ └── TencentPutObjectResult // 腾讯云 COS 上传结果 │ │ │ ├── filter/ // 过滤器与拦截器 │ │ ├── GlobalExceptionHandler // 全局异常处理器 │ │ ├── GlobalRequestInterceptor // 全局请求拦截器 │ │ ├── HttpRequestPrinter // HTTP 请求日志打印 │ │ └── RequestLoggingFilter // 请求日志过滤器 │ │ │ ├── initrunner/ // 启动初始化 │ │ └── PDFInitRunner // PDF 目录初始化(应用启动时执行) │ │ │ ├── tools/ // MCP Tool 工具实现 │ │ ├── BaiduSearchTool // 百度搜索 Tool │ │ ├── LangChainCalculatorTool // LangChain 计算器 Tool │ │ ├── MCPImageTools // 随机图片 Tool │ │ ├── MCPNanoBananaProTools // 多模态内容生成 Tool │ │ ├── MCPPdfMergeTools // PDF 合并 Tool │ │ ├── MCPQWeatherTools // 实时天气查询 Tool │ │ └── MCPTimeTools // 当前时间 Tool │ │ │ ├── service/ // 业务服务层 │ │ ├── AgentChatService // Agent 对话服务 │ │ ├── GeoCodeService // 地理编码服务 │ │ ├── LangChainAgent // LangChain4j Agent 服务 │ │ ├── LangChainAgentService // LangChain 对话服务 │ │ ├── MCPInitializeComponent // MCP 组件初始化(Milvus 集合管理) │ │ ├── MilvusFaceService // Milvus 人脸向量服务 │ │ ├── NanoBananaProService // 多模态内容生成服务 │ │ ├── PdfMergeService // PDF 合并服务 │ │ ├── PDFQAService // PDF 问答服务 │ │ ├── QWeatherService // 和风天气服务 │ │ └── RagService // RAG 检索增强生成服务 │ │ │ ├── utils/ // 工具类 │ │ ├── PDFFontInfo / PDFMergeConts / PDFParams / PDFType // PDF 相关工具 │ │ ├── PDFMergeUtil // PDF 合并工具类 │ │ ├── PDFToImage // PDF 转图片 │ │ └── PDFUtils // PDF 通用工具 │ │ │ └── sample/ // AgentScope 框架学习示例 │ ├── AgentScopeSample // AgentScope 基础示例 │ ├── AgentScopeErnieSample // AgentScope + 文心一言示例 │ ├── ModelConts // 模型常量 │ └── tools/ │ ├── GetTimeTool // 获取时间 Tool 示例 │ └── QWeatherTools // 和风天气 Tool 示例 │ ├── src/main/resources/ │ ├── application.yml // 主配置文件 │ └── skills/ // AI Skills 技能包 │ ├── greeter/ // 测试 Skill │ └── policy/ // 保单 Skill │ ├── LICENSE ├── pom.xml // Maven 依赖管理 └── README.md // 项目说明文档 ~~~ ## API 接口文档 默认服务地址:`http://127.0.0.1:18888` --- ### 1. 保单知识库 RAG 接口 (`/rag`) 基于向量检索 + LLM 的保单知识问答。 #### 保单问答 > POST `/rag/pdf/chat` ~~~ curl -X POST http://127.0.0.1:18888/rag/pdf/chat \ -H "Content-Type: application/json" \ -d '{ "question": "东方红LX1504 第三者责任险赔多少" }' ~~~