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請求獲取當前系統時間,適用於需要精確時間戳的各種應用場景。

Markdownify MCP
Markdownify是一個多功能文件轉換服務,支持將PDF、圖片、音頻等多種格式及網頁內容轉換為Markdown格式。
TypeScript
43.2K
5分

Baidu Map
已認證
百度地圖MCP Server是國內首個兼容MCP協議的地圖服務,提供地理編碼、路線規劃等10個標準化API接口,支持Python和Typescript快速接入,賦能智能體實現地圖相關功能。
Python
53.7K
4.5分

Firecrawl MCP Server
Firecrawl MCP Server是一個集成Firecrawl網頁抓取能力的模型上下文協議服務器,提供豐富的網頁抓取、搜索和內容提取功能。
TypeScript
160.7K
5分

Sequential Thinking MCP Server
一個基於MCP協議的結構化思維服務器,通過定義思考階段幫助分解複雜問題並生成總結
Python
37.6K
4.5分

Notion Api MCP
已認證
一個基於Python的MCP服務器,通過Notion API提供高級待辦事項管理和內容組織功能,實現AI模型與Notion的無縫集成。
Python
27.1K
4.5分

Magic MCP
Magic Component Platform (MCP) 是一個AI驅動的UI組件生成工具,通過自然語言描述幫助開發者快速創建現代化UI組件,支持多種IDE集成。
JavaScript
25.2K
5分

Edgeone Pages MCP Server
EdgeOne Pages MCP是一個通過MCP協議快速部署HTML內容到EdgeOne Pages並獲取公開URL的服務
TypeScript
33.4K
4.8分

Context7
Context7 MCP是一個為AI編程助手提供即時、版本特定文檔和代碼示例的服務,通過Model Context Protocol直接集成到提示中,解決LLM使用過時信息的問題。
TypeScript
106.2K
4.7分
VIP會員




