get_issue_attachment
Retrieve specific attachments from JIRA issues by providing the issue key and attachment ID, enabling streamlined access to relevant files within the Personal JIRA MCP server.
Instructions
获取JIRA问题附件
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| attachment_id | Yes | ||
| issue_key | Yes |
Implementation Reference
- src/jira_mcp/server.py:156-232 (handler)Handler function for the get_issue_attachment MCP tool. It retrieves a specific attachment by ID from a JIRA issue, downloads the content, encodes it appropriately (base64 for non-text, text for text files), and returns metadata along with the content. The @mcp.tool decorator registers it as an MCP tool.@mcp.tool( description="获取JIRA问题附件", ) def get_issue_attachment( issue_key: str, attachment_id: str, ) -> Dict[str, Any]: """获取JIRA问题附件内容. Args: issue_key: JIRA问题键 attachment_id: 附件ID Returns: Dict[str, Any]: 附件内容 """ logger.info(f"获取问题附件: issue={issue_key}, attachment_id={attachment_id}") try: client = get_jira_client() issue = client.issue(issue_key) # 查找指定ID的附件 attachment = None # 检查attachments字段 attachments = [] if hasattr(issue.fields, "attachments") and issue.fields.attachments: attachments = issue.fields.attachments elif hasattr(issue.fields, "attachment") and issue.fields.attachment: attachments = issue.fields.attachment for att in attachments: if att.id == attachment_id: attachment = att break if not attachment: return {"error": f"未找到ID为 {attachment_id} 的附件"} # 获取附件内容 content = attachment.get() # 确定返回类型:对于图片类型,返回Base64编码;对于文本类型,返回文本内容 mime_type = attachment.mimeType filename = attachment.filename result = { "id": attachment.id, "filename": filename, "size": attachment.size, "content_type": mime_type, "created": attachment.created, } # 处理不同的内容类型 if mime_type.startswith("image/"): # 对于图片,返回Base64编码 result["content"] = base64.b64encode(content).decode('utf-8') result["encoding"] = "base64" elif mime_type.startswith("text/"): # 对于文本文件,直接返回文本内容 try: result["content"] = content.decode('utf-8') result["encoding"] = "text" except UnicodeDecodeError: # 如果解码失败,回退到Base64 result["content"] = base64.b64encode(content).decode('utf-8') result["encoding"] = "base64" else: # 对于其他类型,返回Base64编码 result["content"] = base64.b64encode(content).decode('utf-8') result["encoding"] = "base64" return result except Exception as e: logger.error(f"获取问题 {issue_key} 的附件 {attachment_id} 失败: {str(e)}") return {"error": str(e)}
- src/jira_mcp/server.py:156-158 (registration)MCP tool registration decorator for get_issue_attachment, specifying the tool description.@mcp.tool( description="获取JIRA问题附件", )