H

Hello MCP Server Current Time

基于Spring AI的MCP服务示例,实现获取当前时间功能
2 points
30
Installation
Copy the following command to your Client for configuration
Note: Your key is sensitive information, do not share it with anyone.

🚀 基于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请求获取当前系统时间,适用于需要精确时间戳的各种应用场景。

N
Notte Browser
Certified
Notte是一个开源的全栈网络AI代理框架,提供浏览器会话、自动化LLM驱动的代理、网页观察与操作、凭证管理等功能,旨在将互联网转化为代理友好的环境,并通过自然语言描述网站结构,降低LLM的认知负担。
861
4.5 points
S
Search1api
Search1API MCP Server是一个基于Model Context Protocol (MCP)的服务器,提供搜索和爬取功能,支持多种搜索服务和工具。
TypeScript
528
4 points
D
Duckduckgo MCP Server
Certified
DuckDuckGo搜索MCP服务器,为Claude等LLM提供网页搜索和内容抓取服务
Python
1.3K
4.3 points
B
Bing Search MCP
一个用于集成微软Bing搜索API的MCP服务器,支持网页、新闻和图片搜索功能,为AI助手提供网络搜索能力。
Python
430
4 points
M
MCP Alchemy
Certified
MCP Alchemy是一个连接Claude Desktop与多种数据库的工具,支持SQL查询、数据库结构分析和数据报告生成。
Python
506
4.2 points
P
Postgresql MCP
一个基于FastMCP库的PostgreSQL数据库MCP服务,提供对指定表的CRUD操作、模式检查和自定义SQL查询功能。
Python
206
4 points
A
Agentic Radar
Agentic Radar是一个用于分析和评估代理系统的安全扫描工具,帮助开发者、研究人员和安全专家理解代理系统的工作流程并识别潜在漏洞。
Python
640
5 points
M
MCP Scan
MCP-Scan是一款针对MCP服务器的安全扫描工具,用于检测提示注入、工具污染和跨域升级等常见安全漏洞。
Python
695
5 points
Featured MCP Services
F
Figma Context MCP
Framelink Figma MCP Server是一个为AI编程工具(如Cursor)提供Figma设计数据访问的服务器,通过简化Figma API响应,帮助AI更准确地实现设计到代码的一键转换。
TypeScript
7.1K
4.5 points
D
Duckduckgo MCP Server
Certified
DuckDuckGo搜索MCP服务器,为Claude等LLM提供网页搜索和内容抓取服务
Python
1.3K
4.3 points
F
Firecrawl MCP Server
Firecrawl MCP Server是一个集成Firecrawl网页抓取能力的模型上下文协议服务器,提供丰富的网页抓取、搜索和内容提取功能。
TypeScript
4.5K
5 points
E
Edgeone Pages MCP Server
EdgeOne Pages MCP是一个通过MCP协议快速部署HTML内容到EdgeOne Pages并获取公开URL的服务
TypeScript
472
4.8 points
M
Minimax MCP Server
MiniMax Model Context Protocol (MCP) 是一个官方服务器,支持与强大的文本转语音、视频/图像生成API交互,适用于多种客户端工具如Claude Desktop、Cursor等。
Python
1.1K
4.8 points
E
Exa Web Search
Certified
Exa MCP Server是一个为AI助手(如Claude)提供网络搜索功能的服务器,通过Exa AI搜索API实现实时、安全的网络信息获取。
TypeScript
2.1K
5 points
C
Context7
Context7 MCP是一个为AI编程助手提供实时、版本特定文档和代码示例的服务,通过Model Context Protocol直接集成到提示中,解决LLM使用过时信息的问题。
TypeScript
5.8K
4.7 points
B
Baidu Map
Certified
百度地图MCP Server是国内首个兼容MCP协议的地图服务,提供地理编码、路线规划等10个标准化API接口,支持Python和Typescript快速接入,赋能智能体实现地图相关功能。
Python
1.1K
4.5 points
AIbase
Zhiqi Future, Your AI Solution Think Tank
© 2025AIbase