@@ -36,7 +36,16 @@ func New() (*ClockworkServer, error) {
3636 }
3737
3838 // Create MCP server
39- mcpServer := server .NewMCPServer ("clockwork" , "1.0.0" )
39+ mcpServer := server .NewMCPServer (
40+ "clockwork" ,
41+ "1.0.0" ,
42+ server .WithInstructions (`Automatically track work time based on git commits of a project.
43+
44+ Examples:
45+ - "track 2h" - Create entry with 2 hours from recent git commits
46+ - "clockwork 1h" - Create entry with 1 hour from recent commits
47+ - "book 1h meeting with alex" - Manual entry without git commit aggregation` ),
48+ )
4049
4150 cs := & ClockworkServer {
4251 store : store ,
@@ -56,7 +65,11 @@ func (s *ClockworkServer) Close() error {
5665
5766// Helper function to get required string argument
5867func getRequiredString (request mcp.CallToolRequest , key string ) (string , error ) {
59- val , ok := request .Params .Arguments [key ]
68+ args , ok := request .Params .Arguments .(map [string ]interface {})
69+ if ! ok {
70+ return "" , fmt .Errorf ("invalid arguments type" )
71+ }
72+ val , ok := args [key ]
6073 if ! ok {
6174 return "" , fmt .Errorf ("missing required argument: %s" , key )
6275 }
@@ -127,7 +140,7 @@ func (s *ClockworkServer) registerUpdateProject() {
127140 if err != nil {
128141 return mcp .NewToolResultError (err .Error ()), nil
129142 }
130- args := request .Params .Arguments
143+ args , _ := request .Params .Arguments .( map [ string ] interface {})
131144
132145 name , _ := args ["name" ].(string )
133146 gitRepoPath , _ := args ["git_repo_path" ].(string )
@@ -194,7 +207,7 @@ func (s *ClockworkServer) registerCreateEntry() {
194207 if err != nil {
195208 return mcp .NewToolResultError (err .Error ()), nil
196209 }
197- args := request .Params .Arguments
210+ args , _ := request .Params .Arguments .( map [ string ] interface {})
198211
199212 customMessage , _ := args ["message" ].(string )
200213 invoiced , _ := args ["invoiced" ].(bool )
@@ -234,7 +247,15 @@ func (s *ClockworkServer) registerCreateEntry() {
234247 message = "Manual entry"
235248 }
236249
237- entry , err := s .store .CreateEntry (projectID , duration , message , "" , invoiced , createdAt )
250+ // For manual entries, always store current HEAD commit hash (even if duplicate)
251+ project , _ := s .store .GetProject (projectID )
252+ currentHash , err := git .GetLatestCommitHash (project .GitRepoPath )
253+ if err != nil {
254+ // If we can't get HEAD hash, just store empty string
255+ currentHash = ""
256+ }
257+
258+ entry , err := s .store .CreateEntry (projectID , duration , message , currentHash , invoiced , createdAt )
238259 if err != nil {
239260 return mcp .NewToolResultError (err .Error ()), nil
240261 }
@@ -257,7 +278,13 @@ func (s *ClockworkServer) registerCreateEntry() {
257278
258279 var sinceHash string
259280 if lastEntry != nil && lastEntry .CommitHash != "" {
260- sinceHash = lastEntry .CommitHash
281+ // Validate that the commit hash exists in the repository
282+ if git .ValidateCommitHash (project .GitRepoPath , lastEntry .CommitHash ) {
283+ sinceHash = lastEntry .CommitHash
284+ } else {
285+ // Invalid or not found - fall back to getting all commits from HEAD
286+ sinceHash = ""
287+ }
261288 }
262289
263290 // Get commits since last entry
@@ -325,7 +352,7 @@ func (s *ClockworkServer) registerUpdateEntry() {
325352 if err != nil {
326353 return mcp .NewToolResultError (err .Error ()), nil
327354 }
328- args := request .Params .Arguments
355+ args , _ := request .Params .Arguments .( map [ string ] interface {})
329356
330357 var duration * int64
331358 var message , commitHash * string
@@ -401,7 +428,7 @@ func (s *ClockworkServer) registerListEntries() {
401428 )
402429
403430 s .mcp .AddTool (tool , func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
404- args := request .Params .Arguments
431+ args , _ := request .Params .Arguments .( map [ string ] interface {})
405432
406433 projectID , _ := args ["project_id" ].(string )
407434 invoicedStr , _ := args ["invoiced" ].(string )
@@ -435,7 +462,7 @@ func (s *ClockworkServer) registerGetStatistics() {
435462 )
436463
437464 s .mcp .AddTool (tool , func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
438- args := request .Params .Arguments
465+ args , _ := request .Params .Arguments .( map [ string ] interface {})
439466
440467 projectID , _ := args ["project_id" ].(string )
441468 startDateStr , _ := args ["start_date" ].(string )
0 commit comments