Skip to main content
Glama
adrian-dotco

Harvest Natural Language Time Entry MCP Server

by adrian-dotco

log_time

Log time entries in Harvest using natural language commands to track work hours, projects, and tasks with automatic date parsing.

Instructions

Log time entry using natural language

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesNatural language time entry (e.g. "2 hours on Project X doing development work yesterday")

Implementation Reference

  • Handler for the 'log_time' tool. Parses natural language input to extract date, hours, project, and task, then creates a time entry in Harvest via API.
    case 'log_time': {
      const { text } = request.params.arguments as { text: string };
      
      try {
        // Parse time entry details
        const { spent_date, hours, isLeave, leaveType } = await this.parseTimeEntry(text);
        
        // Find matching project
        const project_id = await this.findProject(text, isLeave, leaveType);
        
        // Find matching task
        const task_id = await this.findTask(project_id, text, isLeave, leaveType);
        
        // Create time entry
        const response = await this.axiosInstance.post('/time_entries', {
          project_id,
          task_id,
          spent_date,
          hours,
          notes: text,
        });
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(response.data, null, 2),
            },
          ],
        };
      } catch (error) {
        if (error instanceof McpError) {
          throw error;
        }
        if (axios.isAxiosError(error)) {
          throw new McpError(
            ErrorCode.InternalError,
            `Harvest API error: ${error.response?.data?.message ?? error.message}`
          );
        }
        throw error;
      }
    }
  • src/index.ts:267-279 (registration)
    Registration of the 'log_time' tool in the ListTools response, including description and input schema definition.
      name: 'log_time',
      description: 'Log time entry using natural language',
      inputSchema: {
        type: 'object',
        properties: {
          text: {
            type: 'string',
            description: 'Natural language time entry (e.g. "2 hours on Project X doing development work yesterday")',
          },
        },
        required: ['text'],
      },
    },
  • Helper method that parses the natural language text input into structured time entry data: date, hours, and leave detection.
    private async parseTimeEntry(text: string) {
      const lowercaseText = text.toLowerCase();
      const now = new Date(new Date().toLocaleString('en-US', { timeZone: TIMEZONE }));
      
      // Check if this is a leave request
      const leaveCheck = this.isLeaveRequest(text);
      if (leaveCheck.isLeave && leaveCheck.type) {
        // For leave requests, use the full work day
        return {
          spent_date: now.toISOString().split('T')[0],
          hours: STANDARD_WORK_DAY_HOURS,
          isLeave: true,
          leaveType: leaveCheck.type
        };
      }
    
      // For regular time entries
      let date: Date;
      if (lowercaseText.includes('today')) {
        date = now;
      } else {
        const parsed = chrono.parseDate(text);
        if (!parsed) {
          throw new McpError(ErrorCode.InvalidParams, 'Could not parse date from input');
        }
        date = parsed;
      }
    
      // Extract hours/minutes
      const durationMatch = text.match(/(\d+)\s*(hour|hr|h|minute|min|m)s?/i);
      if (!durationMatch) {
        throw new McpError(ErrorCode.InvalidParams, 'Could not parse duration from input');
      }
    
      const amount = parseInt(durationMatch[1]);
      const unit = durationMatch[2].toLowerCase();
      const hours = unit.startsWith('h') ? amount : amount / 60;
    
      return {
        spent_date: date.toISOString().split('T')[0],
        hours,
        isLeave: false
      };
    }
  • Helper method to find the appropriate project ID by matching the input text or using predefined leave project.
    private async findProject(text: string, isLeave: boolean = false, leaveType?: keyof typeof LEAVE_PATTERNS): Promise<number> {
      const response = await this.axiosInstance.get('/projects');
      const projects = response.data.projects;
      
      if (isLeave && leaveType) {
        // For leave requests, look for the specific leave project
        const leaveProject = projects.find((p: { name: string; id: number }) => 
          p.name === LEAVE_PATTERNS[leaveType].project
        );
        if (leaveProject) {
          return leaveProject.id;
        }
      }
      
      // For regular entries or if leave project not found
      const projectMatch = projects.find((p: { name: string; id: number }) => 
        text.toLowerCase().includes(p.name.toLowerCase())
      );
    
      if (!projectMatch) {
        throw new McpError(ErrorCode.InvalidParams, 'Could not find matching project');
      }
    
      return projectMatch.id;
    }
  • Helper method to find the task ID for the given project by matching text or leave task.
    private async findTask(projectId: number, text: string, isLeave: boolean = false, leaveType?: keyof typeof LEAVE_PATTERNS): Promise<number> {
      const response = await this.axiosInstance.get(`/projects/${projectId}/task_assignments`);
      const tasks = response.data.task_assignments;
    
      if (isLeave && leaveType) {
        // For leave requests, look for the specific leave task
        const leaveTask = tasks.find((t: { task: { name: string; id: number } }) => 
          t.task.name === LEAVE_PATTERNS[leaveType].task
        );
        if (leaveTask) {
          return leaveTask.task.id;
        }
      }
    
      // For regular entries or if leave task not found
      const taskMatch = tasks.find((t: { task: { name: string; id: number } }) => 
        text.toLowerCase().includes(t.task.name.toLowerCase())
      );
    
      if (!taskMatch) {
        // Default to first task if no match found
        return tasks[0].task.id;
      }
    
      return taskMatch.task.id;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states the tool logs time but doesn't disclose behavioral traits such as whether this is a write operation (implied but not confirmed), if it requires authentication, what happens on success/failure, or any rate limits. This leaves significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It's front-loaded with the core purpose and method, making it easy to parse quickly. Every word earns its place without redundancy or unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity as a write operation with no annotations and no output schema, the description is incomplete. It doesn't explain what the tool returns, error conditions, or integration context, leaving the agent with insufficient information for reliable use. This is inadequate for a mutation tool without structured support.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with the parameter 'text' fully documented in the schema. The description adds minimal value by reiterating 'natural language' but doesn't provide additional semantics beyond what the schema already specifies (e.g., examples or formatting nuances). Baseline 3 is appropriate as the schema handles the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Log time entry') and the method ('using natural language'), which distinguishes it from sibling tools like 'get_time_report' or 'list_entries' that likely retrieve rather than create data. However, it doesn't specify the resource being logged (e.g., to a timesheet system), making it slightly less specific than a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'list_entries' for viewing logs or 'list_projects' for context. It implies usage for logging time but doesn't mention prerequisites, exclusions, or explicit alternatives, leaving the agent to infer based on tool names alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/adrian-dotco/harvest-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server