add_issue_note
Add notes and track time spent on Redmine issues using issue ID, notes, and optional details like hours, activity, and date for precise project management.
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
| Name | Required | Description | Default |
|---|---|---|---|
| activity_id | No | ||
| activity_name | No | ||
| issue_id | Yes | ||
| notes | Yes | ||
| private | No | ||
| spent_hours | No | ||
| spent_on | No |
Implementation Reference
- src/redmine_mcp/server.py:647-739 (handler)The primary handler function for the 'add_issue_note' tool. It is decorated with @mcp.tool(), which handles both registration with the MCP server and automatic schema generation from the type hints and docstring. The function adds a note to a Redmine issue, optionally creating a time entry.@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)}"