package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/mark3labs/mcp-go/mcp"
	"github.com/mark3labs/mcp-go/server"
)

func main() {
	s := server.NewMCPServer(
		"Time Service",
		"1.0.0",
		server.WithResourceCapabilities(true, true),
		server.WithLogging(),
	)

	tool_time := mcp.NewTool("get_current_time",
		mcp.WithDescription("获取当前系统时间,返回格式：yyyy-MM-dd HH:mm:ss"),
	)
	s.AddTool(tool_time, currentTimeHandler)

	tool_date := mcp.NewTool("get_current_date",
		mcp.WithDescription("get current date，output format:yyyy-MM-dd"),
	)
	s.AddTool(tool_date, currentDateHandler)

	if err := server.ServeStdio(s); err != nil {
		fmt.Printf("Server start fail: %v\n", err)
	} else {
		log.Println("Time MCP start")
	}
}

func currentTimeHandler(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
	currentTime := time.Now().Format("2006-01-02 15:04:05")
	return mcp.NewToolResultText(fmt.Sprintf("%s", currentTime)), nil
}

func currentDateHandler(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
	currentTime := time.Now().Format("2006-01-02")
	return mcp.NewToolResultText(fmt.Sprintf("%s", currentTime)), nil
}
