mcp-datetime 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ from . import server
2
+
3
+
4
+ def main():
5
+ """Main entry point for the package."""
6
+ return server.main()
7
+
8
+
9
+ __all__ = ["main", "server"]
@@ -0,0 +1,6 @@
1
+ from .server import main
2
+
3
+ if __name__ == "__main__":
4
+ import asyncio
5
+
6
+ asyncio.run(main())
mcp_datetime/server.py ADDED
@@ -0,0 +1,130 @@
1
+ import asyncio
2
+ import logging
3
+ from collections.abc import Sequence
4
+ from datetime import datetime, timezone
5
+ from typing import Any
6
+
7
+ from mcp.server import Server
8
+ from mcp.server.stdio import stdio_server
9
+ from mcp.types import EmbeddedResource, ImageContent, TextContent, Tool
10
+
11
+ # Prepare logging
12
+ logging.basicConfig(level=logging.INFO)
13
+ logger = logging.getLogger("mcp-datetime")
14
+
15
+ # Prepare server
16
+ server = Server("mcp-datetime")
17
+
18
+
19
+ # Datetime formatting function
20
+ def format_datetime(format_type: str) -> str:
21
+ # Generate a new time object each time, considering timezone
22
+ current_time = datetime.now(timezone.utc).astimezone()
23
+ formats = {
24
+ # Basic date formats
25
+ "date": "%Y-%m-%d", # 2024-12-10
26
+ "date_slash": "%Y/%m/%d", # 2024/12/10
27
+ "date_jp": "%Y年%m月%d日", # 2024年12月10日
28
+ # Basic datetime formats
29
+ "datetime": "%Y-%m-%d %H:%M:%S", # 2024-12-10 00:54:01
30
+ "datetime_jp": "%Y年%m月%d日 %H時%M分%S秒", # 2024年12月10日 00時54分01秒
31
+ "datetime_t": "%Y-%m-%dT%H:%M:%S", # 2024-12-10T00:54:01
32
+ # Compact formats for filenames or IDs
33
+ "compact": "%Y%m%d%H%M%S", # 20241210005401
34
+ "compact_date": "%Y%m%d", # 20241210
35
+ "compact_time": "%H%M%S", # 005401
36
+ # Filename formats
37
+ "filename_md": "%Y%m%d%H%M%S.md", # 20241210005401.md
38
+ "filename_txt": "%Y%m%d%H%M%S.txt", # 20241210005401.txt
39
+ "filename_log": "%Y%m%d%H%M%S.log", # 20241210005401.log
40
+ # ISO 8601 formats
41
+ "iso": "%Y-%m-%dT%H:%M:%S%z", # 2024-12-10T00:54:01+0900
42
+ "iso_basic": "%Y%m%dT%H%M%S%z", # 20241210T005401+0900
43
+ # Log formats
44
+ "log": "%Y-%m-%d %H:%M:%S.%f", # 2024-12-10 00:54:01.123456
45
+ "log_compact": "%Y%m%d_%H%M%S", # 20241210_005401
46
+ # Time-only formats
47
+ "time": "%H:%M:%S", # 00:54:01
48
+ "time_jp": "%H時%M分%S秒", # 00時54分01秒
49
+ }
50
+
51
+ if format_type not in formats:
52
+ raise ValueError(f"Unknown format type: {format_type}")
53
+
54
+ try:
55
+ return current_time.strftime(formats[format_type])
56
+ except Exception as e:
57
+ logger.error("Format error: %s", str(e))
58
+ raise RuntimeError(f"Error formatting date: {str(e)}") from e
59
+
60
+
61
+ # Get list of available tools
62
+ @server.list_tools()
63
+ async def list_tools() -> list[Tool]:
64
+ return [
65
+ Tool(
66
+ name="get_datetime",
67
+ description="Get current date and time in various formats",
68
+ inputSchema={
69
+ "type": "object",
70
+ "properties": {
71
+ "format": {
72
+ "type": "string",
73
+ "description": """
74
+ Available formats:
75
+ - date: 2024-12-10
76
+ - date_slash: 2024/12/10
77
+ - date_jp: 2024年12月10日
78
+ - datetime: 2024-12-10 00:54:01
79
+ - datetime_jp: 2024年12月10日 00時54分01秒
80
+ - datetime_t: 2024-12-10T00:54:01
81
+ - compact: 20241210005401
82
+ - compact_date: 20241210
83
+ - compact_time: 005401
84
+ - filename_md: 20241210005401.md
85
+ - filename_txt: 20241210005401.txt
86
+ - filename_log: 20241210005401.log
87
+ - iso: 2024-12-10T00:54:01+0900
88
+ - iso_basic: 20241210T005401+0900
89
+ - log: 2024-12-10 00:54:01.123456
90
+ - log_compact: 20241210_005401
91
+ - time: 00:54:01
92
+ - time_jp: 00時54分01秒
93
+ """,
94
+ }
95
+ },
96
+ "required": ["format"],
97
+ },
98
+ )
99
+ ]
100
+
101
+
102
+ # Tool call handler
103
+ @server.call_tool()
104
+ async def call_tool(
105
+ name: str, arguments: Any
106
+ ) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
107
+ if name == "get_datetime":
108
+ try:
109
+ format_type = arguments.get("format")
110
+ if not format_type:
111
+ raise ValueError("Format type is required")
112
+ formatted_time = format_datetime(format_type)
113
+ return [TextContent(type="text", text=formatted_time)]
114
+ except ValueError as e:
115
+ logger.error("Format error: %s", str(e))
116
+ raise RuntimeError(str(e)) from e
117
+ else:
118
+ raise ValueError(f"Unknown tool: {name}")
119
+
120
+
121
+ # Main function
122
+ async def main():
123
+ async with stdio_server() as (read_stream, write_stream):
124
+ await server.run(
125
+ read_stream, write_stream, server.create_initialization_options()
126
+ )
127
+
128
+
129
+ if __name__ == "__main__":
130
+ asyncio.run(main())
@@ -0,0 +1,188 @@
1
+ Metadata-Version: 2.3
2
+ Name: mcp-datetime
3
+ Version: 0.1.0
4
+ Summary: A MCP server for datetime formatting and file name generation.
5
+ Project-URL: Repository, https://github.com/ZeparHyfar/mcp-datetime.git
6
+ Author-email: ZeparHyfar <zeparhyfar@gmail.com>
7
+ License: MIT
8
+ Keywords: claude,datetime,format,mcp,time,timezone
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Python: >=3.12
15
+ Requires-Dist: mcp>=1.1.1
16
+ Provides-Extra: dev
17
+ Requires-Dist: pylint>=3.0.3; extra == 'dev'
18
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
19
+ Description-Content-Type: text/markdown
20
+
21
+ # mcp-datetime
22
+
23
+ [![Python Version](https://img.shields.io/badge/python-3.12-blue.svg)](https://www.python.org/downloads/)
24
+ [![MCP Version](https://img.shields.io/badge/mcp-1.1.1-green.svg)](https://github.com/anaisbetts/mcp)
25
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
26
+
27
+ English | [日本語](README_ja.md)
28
+
29
+ A datetime formatting service implemented as an MCP server for the Claude Desktop Application. Supports generation of datetime strings in various formats.
30
+
31
+ ## Features
32
+
33
+ - ✨ Support for various datetime formats
34
+ - 🇯🇵 Japanese language support
35
+ - 📁 Optimized formats for filename generation
36
+ - 🌏 Accurate timezone handling
37
+ - 🔧 Seamless integration with Claude Desktop App
38
+
39
+ ## MCP Server Components
40
+
41
+ ### Tools
42
+
43
+ The server implements one tool:
44
+
45
+ - `get_datetime`: Get current date and time in various formats
46
+ - Takes "format" as a required string argument
47
+ - Returns formatted datetime string based on specified format
48
+ - Supports multiple format types including standard, Japanese, and ISO formats
49
+
50
+ ## Usage with Claude Desktop App
51
+
52
+ Add the following to your config file:
53
+
54
+ - Config file location:
55
+
56
+ - MacOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
57
+ - Windows: `%APPDATA%/Claude/claude_desktop_config.json`
58
+
59
+ ```json
60
+ {
61
+ "mcpServers": {
62
+ "mcp-datetime": {
63
+ "command": "uvx",
64
+ "args": ["mcp-datetime"]
65
+ }
66
+ }
67
+ }
68
+ ```
69
+
70
+ ## About Installation
71
+
72
+ No installation is required for normal use. You can use this package by simply adding the configuration to your Claude Desktop App config file. The uvx command will automatically download and execute the package as needed.
73
+
74
+ If you need to install the package directly (e.g., for development or source code inspection), you can use one of these methods:
75
+
76
+ - Install from PyPI
77
+
78
+ ```bash
79
+ pip install mcp-datetime
80
+ ```
81
+
82
+ - Install from GitHub Source
83
+
84
+ ```bash
85
+ git clone https://github.com/ZeparHyfar/mcp-datetime.git
86
+ cd mcp-datetime
87
+ pip install -e .
88
+ ```
89
+
90
+ - `claude_desktop_config.json` for manual installation
91
+
92
+ ```json
93
+ {
94
+ "mcpServers": {
95
+ "mcp-datetime": {
96
+ "command": "python",
97
+ "args": ["-m", "mcp_datetime"],
98
+ "env": {
99
+ "PYTHON": "/path/to/your/python"
100
+ }
101
+ }
102
+ }
103
+ }
104
+ ```
105
+
106
+ - Replace "/path/to/your/python" with your actual Python interpreter path.
107
+
108
+ - Examples:
109
+ - MacOS: "/usr/local/bin/python3" or "/Users/username/.pyenv/versions/3.12.0/bin/python3"
110
+ - Windows: "C:\Python312\python.exe"
111
+
112
+ ## Basic Examples
113
+
114
+ - Command format
115
+
116
+ ```
117
+ # Standard datetime format
118
+ call datetime-service.get_datetime {"format": "datetime"}
119
+ # Result: 2024-12-10 00:54:01
120
+
121
+ # Japanese format
122
+ call datetime-service.get_datetime {"format": "datetime_jp"}
123
+ # Result: 2024年12月10日 00時54分01秒
124
+
125
+ # Filename format
126
+ call datetime-service.get_datetime {"format": "filename_md"}
127
+ # Result: 20241210005401.md
128
+ ```
129
+
130
+ - Claude Desktop App prompt examples
131
+
132
+ - User
133
+
134
+ ```
135
+ Please tell me the current time in date_slash format
136
+ ```
137
+
138
+ - Claude
139
+
140
+ ```
141
+ I'll get the current date in date_slash format.
142
+
143
+ The current date is 2024/12/12
144
+ ```
145
+
146
+ ## Supported Formats
147
+
148
+ | Format Name | Example | Description |
149
+ | ------------ | --------------------------- | ------------------------ |
150
+ | date | 2024-12-10 | Standard date format |
151
+ | date_slash | 2024/12/10 | Date with slashes |
152
+ | date_jp | 2024年12月10日 | Japanese date format |
153
+ | datetime | 2024-12-10 00:54:01 | Standard datetime |
154
+ | datetime_jp | 2024年12月10日 00時54分01秒 | Japanese datetime |
155
+ | datetime_t | 2024-12-10T00:54:01 | DateTime with T separator|
156
+ | compact | 20241210005401 | Compact format for IDs |
157
+ | compact_date | 20241210 | Compact date only |
158
+ | compact_time | 005401 | Compact time only |
159
+ | filename_md | 20241210005401.md | Markdown filename |
160
+ | filename_txt | 20241210005401.txt | Text filename |
161
+ | filename_log | 20241210005401.log | Log filename |
162
+ | iso | 2024-12-10T00:54:01+0900 | ISO 8601 format |
163
+ | iso_basic | 20241210T005401+0900 | Basic ISO format |
164
+ | log | 2024-12-10 00:54:01.123456 | Log format with microseconds|
165
+ | log_compact | 20241210_005401 | Compact log format |
166
+ | time | 00:54:01 | Time only |
167
+ | time_jp | 00時54分01秒 | Japanese time format |
168
+
169
+ ## Debugging
170
+
171
+ Since MCP servers run over stdio, debugging can be challenging. We recommend using the [MCP Inspector](https://github.com/modelcontextprotocol/inspector):
172
+
173
+ - Using PyPI package
174
+
175
+ ```
176
+ npx @modelcontextprotocol/inspector uvx mcp-datetime
177
+ ```
178
+
179
+ - Using downloaded source code from GitHub
180
+
181
+ ```
182
+ git clone https://github.com/ZeparHyfar/mcp-datetime.git
183
+ npx @modelcontextprotocol/inspector uvx --directory ./mcp-datetime run mcp-datetime
184
+ ```
185
+
186
+ ## License
187
+
188
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,8 @@
1
+ mcp_datetime/__init__.py,sha256=IdxiQAPybMgY3UTm3GPIOb4WScKUFFf2YuO8K-O5mag,135
2
+ mcp_datetime/__main__.py,sha256=ALA29xcNZOjzwjX6U7xi90BiIRbsx10mAmSvxxWWiZo,97
3
+ mcp_datetime/server.py,sha256=SZfuW7tbHnL32YqjU24Zk0BNhf5qsNXRk_QwtHDJ_qM,4277
4
+ mcp_datetime-0.1.0.dist-info/METADATA,sha256=cmlXYi1kvnHtWQdmZzaDpYIzMdncq9BZe_W6GmUvSKg,5986
5
+ mcp_datetime-0.1.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
6
+ mcp_datetime-0.1.0.dist-info/entry_points.txt,sha256=rEPiYXeEl45bG10hEnozSfdJdrZ-J3HTYYPmiQdGXhk,51
7
+ mcp_datetime-0.1.0.dist-info/licenses/LICENSE,sha256=2w9RD7tqFXGd_kFE1kE9QxAZyhTouM-aMJ52Ba8MYO8,1067
8
+ mcp_datetime-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.26.3
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mcp-datetime = mcp_datetime:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ZeparHyfar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.