Hello MCP Server Current Time
🚀 基于spring-ai-starter-mcp-server的自定义mcp server简单示例,获取当前时间
本项目是一个基于Spring AI Starter MCP Server的自定义MCP服务器示例,主要展示了如何运用MCP协议创建一个能返回当前系统时间的自定义时间服务,为需要精确时间戳的应用场景提供支持。
🚀 快速开始
运行项目
将项目打包并运行:
mvn spring-boot:run
验证服务
访问 /current-time
端点,查看当前时间:
curl http://localhost:8090/current-time
✨ 主要特性
- 基于Spring Boot框架搭建,具备Spring Boot的高效与便捷。
- 集成MCP通信协议,实现特定的通信功能。
- 提供获取当前时间的功能,适用于需要精确时间戳的场景。
📦 安装指南
本项目无需额外的安装步骤,直接使用以下命令运行即可:
mvn spring-boot:run
💻 使用示例
基础用法
通过以下命令启动项目:
mvn spring-boot:run
启动成功后,使用以下命令获取当前时间:
curl http://localhost:8090/current-time
📚 详细文档
项目结构
src/main/java/
com/example/mcptime/
McpTimeApplication.java
controller/
TimeController.java
config/
McpServerConfig.java
配置文件
# application.properties
server.port=8090
# MCP服务器配置
mcp.server.name=mcp-time-server
mcp.server.ip=127.0.0.1
mcp.server.port=5000
核心代码
TimeController.java
package com.example.mcptime.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
@RestController
public class TimeController {
@GetMapping("/current-time")
public String getCurrentTime() {
return new Date().toString();
}
}
McpServerConfig.java
package com.example.mcptime.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "mcp.server")
public class McpServerConfig {
private String name;
private String ip;
private int port;
// Getters and Setters omitted for brevity
}
McpTimeApplication.java
package com.example.mcptime;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter;
import org.springframework.remoting.mcp.McpServer;
@SpringBootApplication
@ComponentScan(basePackages = "com.example.mcptime")
public class McpTimeApplication {
public static void main(String[] args) {
SpringApplication.run(McpTimeApplication.class, args);
}
@Bean
public McpServer mcpServer() {
return new McpServer("tcp://127.0.0.1:5000");
}
}
🔧 技术细节
本项目基于Spring Boot框架搭建,利用Spring Boot的自动配置和依赖管理功能,快速搭建项目骨架。集成MCP通信协议,通过 McpServer
实现特定的通信功能。在 TimeController
中,使用 @GetMapping
注解处理HTTP GET请求,返回当前系统时间。配置文件通过 application.properties
进行配置,使用 @ConfigurationProperties
注解将配置文件中的属性注入到 McpServerConfig
类中。
📄 项目总结
通过本示例,展示了如何基于Spring Boot和MCP协议快速搭建一个自定义的时间服务。此服务可以通过简单的HTTP请求获取当前系统时间,适用于需要精确时间戳的各种应用场景。
Featured MCP Services

Figma Context MCP
Framelink Figma MCP Server是一个为AI编程工具(如Cursor)提供Figma设计数据访问的服务器,通过简化Figma API响应,帮助AI更准确地实现设计到代码的一键转换。
TypeScript
7.1K
4.5 points

Duckduckgo MCP Server
Certified
DuckDuckGo搜索MCP服务器,为Claude等LLM提供网页搜索和内容抓取服务
Python
1.3K
4.3 points

Firecrawl MCP Server
Firecrawl MCP Server是一个集成Firecrawl网页抓取能力的模型上下文协议服务器,提供丰富的网页抓取、搜索和内容提取功能。
TypeScript
4.5K
5 points

Edgeone Pages MCP Server
EdgeOne Pages MCP是一个通过MCP协议快速部署HTML内容到EdgeOne Pages并获取公开URL的服务
TypeScript
472
4.8 points

Minimax MCP Server
MiniMax Model Context Protocol (MCP) 是一个官方服务器,支持与强大的文本转语音、视频/图像生成API交互,适用于多种客户端工具如Claude Desktop、Cursor等。
Python
1.1K
4.8 points

Exa Web Search
Certified
Exa MCP Server是一个为AI助手(如Claude)提供网络搜索功能的服务器,通过Exa AI搜索API实现实时、安全的网络信息获取。
TypeScript
2.1K
5 points

Context7
Context7 MCP是一个为AI编程助手提供实时、版本特定文档和代码示例的服务,通过Model Context Protocol直接集成到提示中,解决LLM使用过时信息的问题。
TypeScript
5.8K
4.7 points

Baidu Map
Certified
百度地图MCP Server是国内首个兼容MCP协议的地图服务,提供地理编码、路线规划等10个标准化API接口,支持Python和Typescript快速接入,赋能智能体实现地图相关功能。
Python
1.1K
4.5 points