mcp

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package mcp provides MCP handlers for time and date utilities. It enables AI assistants to perform time-related operations through standardized MCP tools.

Index

Constants

View Source
const (
	// TransportSTDIO uses standard input/output for communication.
	TransportSTDIO transport = iota
	// TransportStream uses an HTTP stream for communication.
	TransportStream
)

Variables

View Source
var TransportNames = map[transport]string{
	TransportSTDIO:  "stdio",
	TransportStream: "stream",
}

TransportNames maps transport types to their string representations.

Functions

func CompareTime

func CompareTime(ctx context.Context, request mcp.CallToolRequest) (r *mcp.CallToolResult, err error)

CompareTime is the handler for the 'compare_time' MCP tool. It compares two times and returns -1, 0, or 1.

func ConvertTime

func ConvertTime(ctx context.Context, request mcp.CallToolRequest) (r *mcp.CallToolResult, err error)

ConvertTime is the handler for the 'convert_timezone' MCP tool. It converts a time from one timezone to another.

func CurrentTime

func CurrentTime(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)

CurrentTime is the handler for the 'current_time' MCP tool. It returns the current time, optionally formatted and in a specific timezone.

func GetTransports

func GetTransports() []string

GetTransports returns a slice of available transport names.

func RegisterHandlers

func RegisterHandlers(s *server.MCPServer)

RegisterHandlers registers the time and date MCP tools with the provided MCP server.

Parameters:

  • s: The MCP server instance to register tools with.

Returns an error if tool registration fails (though current implementation always returns nil).

func RelativeTime

func RelativeTime(ctx context.Context, request mcp.CallToolRequest) (r *mcp.CallToolResult, err error)

RelativeTime is the handler for the 'relative_time' MCP tool. It parses a natural language time expression relative to a given time.

func TimeAdd

func TimeAdd(ctx context.Context, request mcp.CallToolRequest) (r *mcp.CallToolResult, err error)

TimeAdd is the handler for the 'add_time' MCP tool. It adds a duration to a given time.

Types

type Server

type Server struct {
	*server.MCPServer
}

Server wraps the core MCP server and registers the time-specific handlers.

func NewServer

func NewServer(name, version string) *Server

NewServer creates a new MCP server with the time tools registered. It initializes the underlying MCP server and registers all the tool handlers.

func (Server) StartStdio

func (s Server) StartStdio(ctx context.Context) error

StartStdio starts the server listening on standard input/output. It blocks until the context is canceled or an error occurs.

func (Server) StartStream

func (s Server) StartStream(ctx context.Context, address string) error

StartStream starts the server as an HTTP stream on the given address. It includes a graceful shutdown mechanism that is triggered by the context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL