Provides date and time utilities including current date/time, date calculations, and formatting
Gets current date and time in various formats
Calculates the difference between two dates
Adds or subtracts time from a date
#:package [email protected]
#:package [email protected]
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Server;
using System.ComponentModel;
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddConsole(consoleLogOptions =>
{
// Configure all logs to go to stderr
consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace;
});
// Register the MCP server
builder.Services
.AddMcpServer()
.WithStdioServerTransport()
.WithToolsFromAssembly();
// Build and run the MCP Server Application
await builder.Build().RunAsync();
//====== TOOLS ======
public record CurrentDateTimeResult(string FormattedDateTime);
public record DateDifferenceResult(int Days, int Hours, int Minutes);
public record AddTimeResult(DateTime ResultDate);
[McpServerToolType]
public static class DateTimeTools
{
[McpServerTool, Description("Gets current date and time in various formats")]
public static CurrentDateTimeResult GetCurrentDateTime(
[Description("Date format string (default: yyyy-MM-dd HH:mm:ss)")] string format = "yyyy-MM-dd HH:mm:ss")
{
return new CurrentDateTimeResult(DateTime.Now.ToString(format));
}
[McpServerTool, Description("Calculates the difference between two dates")]
public static DateDifferenceResult DateDifference(
[Description("Start date")] DateTime startDate,
[Description("End date")] DateTime endDate)
{
var diff = endDate - startDate;
return new DateDifferenceResult(diff.Days, diff.Hours, diff.Minutes);
}
[McpServerTool, Description("Adds or subtracts time from a date")]
public static AddTimeResult AddTime(
[Description("Base date")] DateTime date,
[Description("Days to add")] int days = 0,
[Description("Hours to add")] int hours = 0,
[Description("Minutes to add")] int minutes = 0)
{
return new AddTimeResult(date.AddDays(days).AddHours(hours).AddMinutes(minutes));
}
}
Copy the code above and save it as date-times-mcp.cs
Add this configuration to your .mcp.json
file:
Note: This example is for Visual Studio and similar clients. For Claude Code, use mcpServers
instead of servers
.
{
"servers": {
"date-times-mcp": {
"type": "stdio",
"command": "dotnet",
"args": ["run", "C:\\path\\to\\date-times-mcp.cs"]
}
}
}
Configure any required environment variables (see sidebar)
Restart Claude Desktop, Continue, or your preferred MCP client
XAKPC Dev Labs
Maintained by the AnyMCP community