Skip to main content
Glama
yuezheng2006

Personal JIRA MCP

by yuezheng2006

get_issue_attachments

Retrieve all attachments from a JIRA issue to access supporting files and documents. Specify the issue key to fetch attachments, with an option to download them directly.

Instructions

获取JIRA问题的所有附件

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
issue_keyYes
downloadNo

Implementation Reference

  • The main handler and registration for the get_issue_attachments MCP tool. Lists all attachments for a JIRA issue, checks local existence, and optionally downloads via download_all_attachments.
    @mcp.tool(
        description="获取JIRA问题的所有附件",
    )
    def get_issue_attachments(
        issue_key: str,
        download: bool = False
    ) -> Dict[str, Any]:
        """获取JIRA问题的所有附件信息.
        
        Args:
            issue_key: JIRA问题键
            download: 是否下载附件到本地
        
        Returns:
            Dict[str, Any]: 附件列表
        """
        logger.info(f"获取问题附件列表: {issue_key}, download={download}")
        
        if download:
            return download_all_attachments(issue_key)
        
        try:
            client = get_jira_client()
            issue = client.issue(issue_key)
            
            attachments = []
            if hasattr(issue.fields, "attachment") and issue.fields.attachment:
                for attachment in issue.fields.attachment:
                    # 检查附件是否已存在于本地
                    local_path = get_attachment_path(issue_key, attachment.filename)
                    exists_locally = os.path.exists(local_path)
                    
                    attachments.append({
                        "id": attachment.id,
                        "filename": attachment.filename,
                        "size": attachment.size,
                        "content_type": attachment.mimeType,
                        "created": str(attachment.created),  # 确保日期是字符串
                        "url": str(attachment.content),  # 确保URL是字符串
                        "local_path": local_path if exists_locally else None,
                        "exists_locally": exists_locally
                    })
            
            return {
                "issue_key": issue_key,
                "attachments": attachments,
                "total": len(attachments),
                "attachments_dir": os.path.join(ATTACHMENTS_DIR, issue_key)
            }
        except Exception as e:
            logger.error(f"获取问题 {issue_key} 附件列表失败: {str(e)}")
            return {"error": str(e)}
  • Helper utility to determine the local filesystem path for storing attachments of a specific JIRA issue.
    def get_attachment_path(issue_key: str, filename: str) -> str:
        """获取附件在本地文件系统中的保存路径."""
        # 创建问题专属目录
        issue_dir = os.path.join(ATTACHMENTS_DIR, issue_key)
        os.makedirs(issue_dir, exist_ok=True)
        return os.path.join(issue_dir, filename)
  • Supporting tool/helper invoked by get_issue_attachments when download parameter is True. Downloads all attachments to local directory and returns download results.
    @mcp.tool(
        description="下载JIRA问题的所有附件到本地",
    )
    def download_all_attachments(
        issue_key: str,
    ) -> Dict[str, Any]:
        """下载JIRA问题的所有附件到本地.
        
        Args:
            issue_key: JIRA问题键
        
        Returns:
            Dict[str, Any]: 下载结果
        """
        logger.info(f"下载问题所有附件: {issue_key}")
        try:
            client = get_jira_client()
            issue = client.issue(issue_key)
            
            downloads = []
            failed = []
            
            # 获取附件列表
            attachments = []
            if hasattr(issue.fields, "attachment") and issue.fields.attachment:
                attachments = issue.fields.attachment
            
            if not attachments:
                return {
                    "issue_key": issue_key,
                    "message": "此问题没有附件",
                    "total": 0,
                    "downloads": []
                }
            
            # 为此问题创建目录
            issue_dir = os.path.join(ATTACHMENTS_DIR, issue_key)
            os.makedirs(issue_dir, exist_ok=True)
            
            # 下载每个附件
            for attachment in attachments:
                try:
                    file_path = os.path.join(issue_dir, attachment.filename)
                    
                    # 下载内容
                    content = attachment.get()
                    
                    # 保存到文件
                    with open(file_path, "wb") as f:
                        f.write(content)
                    
                    downloads.append({
                        "id": attachment.id,
                        "filename": attachment.filename,
                        "size": os.path.getsize(file_path),
                        "content_type": attachment.mimeType,
                        "local_path": file_path
                    })
                except Exception as e:
                    logger.error(f"下载附件 {attachment.filename} 失败: {str(e)}")
                    failed.append({
                        "filename": attachment.filename,
                        "error": str(e)
                    })
            
            return {
                "issue_key": issue_key,
                "total": len(attachments),
                "success": len(downloads),
                "failed": len(failed),
                "download_dir": issue_dir,
                "downloads": downloads,
                "failures": failed if failed else None
            }
        except Exception as e:
            logger.error(f"下载问题 {issue_key} 的所有附件失败: {str(e)}")
            return {"error": str(e)}
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't describe how it behaves: for example, whether it returns metadata or file content, if there are rate limits, authentication requirements, or pagination for large attachment sets. This is a significant gap for a tool with potential complexity in handling attachments.

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 in Chinese that directly states the tool's purpose without any fluff or redundancy. It's appropriately sized and front-loaded, making it easy to parse quickly.

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 complexity of handling attachments (which could involve metadata, file downloads, or pagination), no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., list of attachment objects, file contents, or download links), leaving critical gaps for an agent to use it effectively.

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 0%, so the description must compensate, but it doesn't mention any parameters. It implies 'issue_key' is needed by referring to 'JIRA问题' (JIRA issue), but doesn't explain the 'download' parameter or its boolean nature. The baseline is 3 because the schema fully documents the parameters, though the description adds no value beyond what's in the schema.

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 verb ('获取' meaning 'get') and resource ('JIRA问题的所有附件' meaning 'all attachments of a JIRA issue'), making the purpose immediately understandable. It doesn't explicitly distinguish from sibling tools like 'get_attachment_by_filename' or 'download_all_attachments', which would require more specificity to earn a 5.

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 'get_attachment_by_filename' (for specific attachments) or 'download_all_attachments' (which may have different behavior). There's no mention of prerequisites, context, or exclusions, leaving the agent to infer usage from 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/yuezheng2006/mcp-server-jira'

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