Skip to main content
Glama
snowild

Redmine MCP Server

by snowild

add_issue_note

Add notes to Redmine issues and optionally record time spent. Specify activity type and mark notes as private when needed.

Instructions

為議題新增備註,可同時記錄時間

Args:
    issue_id: 議題 ID
    notes: 備註內容
    private: 是否為私有備註(預設否)
    spent_hours: 耗用工時(小時)
    activity_name: 活動名稱(與 activity_id 二選一)
    activity_id: 活動 ID(與 activity_name 二選一)
    spent_on: 記錄日期 YYYY-MM-DD 格式(可選,預設今日)

Returns:
    新增結果訊息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
issue_idYes
notesYes
privateNo
spent_hoursNo
activity_nameNo
activity_idNo
spent_onNo

Implementation Reference

  • The add_issue_note tool handler function, decorated with @mcp.tool() for automatic registration and schema inference from type hints and docstring. Handles adding notes to Redmine issues, optionally with time tracking.
    @mcp.tool()
    def add_issue_note(issue_id: int, notes: str, private: bool = False, 
                       spent_hours: float = None, activity_name: str = None, 
                       activity_id: int = None, spent_on: str = None) -> str:
        """
        為議題新增備註,可同時記錄時間
        
        Args:
            issue_id: 議題 ID
            notes: 備註內容
            private: 是否為私有備註(預設否)
            spent_hours: 耗用工時(小時)
            activity_name: 活動名稱(與 activity_id 二選一)
            activity_id: 活動 ID(與 activity_name 二選一)
            spent_on: 記錄日期 YYYY-MM-DD 格式(可選,預設今日)
        
        Returns:
            新增結果訊息
        """
        try:
            if not notes.strip():
                return "錯誤: 備註內容不能為空"
            
            client = get_client()
            time_entry_id = None
            
            # 處理時間記錄
            if spent_hours is not None:
                if spent_hours <= 0:
                    return "錯誤: 耗用工時必須大於 0"
                
                # 處理活動參數
                final_activity_id = activity_id
                if activity_name:
                    final_activity_id = client.find_time_entry_activity_id_by_name(activity_name)
                    if not final_activity_id:
                        available_activities = client.get_available_time_entry_activities()
                        return f"找不到時間追蹤活動名稱:「{activity_name}」\n\n可用活動:\n" + "\n".join([f"- {name}" for name in available_activities.keys()])
                
                if not final_activity_id:
                    return "錯誤: 必須提供 activity_id 或 activity_name 參數"
                
                # 建立時間記錄
                try:
                    time_entry_id = client.create_time_entry(
                        issue_id=issue_id,
                        hours=spent_hours,
                        activity_id=final_activity_id,
                        comments=notes.strip(),
                        spent_on=spent_on
                    )
                except Exception as e:
                    return f"建立時間記錄失敗: {str(e)}"
            
            # 準備更新資料(新增備註)
            update_data = {'notes': notes.strip()}
            if private:
                update_data['private_notes'] = True
            
            # 執行更新
            client.update_issue(issue_id, **update_data)
            
            # 取得議題資訊
            issue = client.get_issue(issue_id)
            
            privacy_text = "私有" if private else "公開"
            result = f"""備註新增成功!
    
    議題: #{issue_id} - {issue.subject}
    備註類型: {privacy_text}
    備註內容:
    {notes.strip()}"""
    
            # 如果有建立時間記錄,添加相關資訊
            if time_entry_id:
                from datetime import date
                actual_date = spent_on if spent_on else date.today().strftime('%Y-%m-%d')
                activity_name_display = activity_name if activity_name else f"ID {final_activity_id}"
                result += f"""
    
    時間記錄新增成功!
    - 時間記錄 ID: {time_entry_id}
    - 耗用工時: {spent_hours} 小時
    - 活動: {activity_name_display}
    - 記錄日期: {actual_date}"""
    
            return result
            
        except RedmineAPIError as e:
            return f"新增議題備註失敗: {str(e)}"
        except Exception as e:
            return f"系統錯誤: {str(e)}"

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/snowild/redmine-mcp'

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