Skip to main content
Glama
yuezheng2006

Personal JIRA MCP

by yuezheng2006

get_attachment_by_filename

Retrieve JIRA attachments by specifying an issue key and filename to access specific files from your project management system.

Instructions

根据问题ID和文件名获取JIRA附件

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
issue_keyYes
filenameYes
save_to_diskNo

Implementation Reference

  • The primary MCP tool handler for 'get_attachment_by_filename'. It is decorated with @mcp.tool, defines the input parameters with type hints (serving as schema), and implements the full logic to retrieve, download, process (base64 encode if needed), and optionally save JIRA attachments by issue key and filename.
    @mcp.tool(
        description="根据问题ID和文件名获取JIRA附件",
    )
    def get_attachment_by_filename(
        issue_key: str,
        filename: str,
        save_to_disk: bool = True,
    ) -> Dict[str, Any]:
        """根据问题ID和文件名获取JIRA附件.
        
        Args:
            issue_key: JIRA问题键
            filename: 附件文件名
            save_to_disk: 是否保存到本地磁盘
        
        Returns:
            Dict[str, Any]: 附件内容
        """
        logger.info(f"根据文件名获取附件: issue={issue_key}, filename={filename}")
        try:
            # 使用JIRA REST API直接获取问题附件
            client = get_jira_client()
            
            # 获取问题详情
            issue_url = f"{jira_settings.server_url}/rest/api/2/issue/{issue_key}"
            response = client._session.get(issue_url)
            if response.status_code != 200:
                return {"error": f"获取问题失败: {response.text}"}
                
            issue_data = response.json()
            
            # 检查附件
            attachments = issue_data.get("fields", {}).get("attachment", [])
            if not attachments:
                return {"error": f"问题 {issue_key} 没有附件"}
                
            # 查找指定文件名的附件
            attachment = None
            for att in attachments:
                if att.get("filename") == filename:
                    attachment = att
                    break
                    
            if not attachment:
                return {"error": f"未找到名为 {filename} 的附件"}
                
            # 获取附件内容
            attachment_url = attachment.get("content")
            if not attachment_url:
                return {"error": "附件URL不存在"}
                
            # 下载附件
            response = client._session.get(attachment_url)
            if response.status_code != 200:
                return {"error": f"下载附件失败: {response.text}"}
                
            content = response.content
            mime_type = attachment.get("mimeType", "application/octet-stream")
            
            result = {
                "id": attachment.get("id"),
                "filename": filename,
                "size": len(content),
                "content_type": mime_type,
                "created": attachment.get("created"),
            }
            
            # 如果要保存到磁盘
            if save_to_disk:
                file_path = get_attachment_path(issue_key, filename)
                with open(file_path, "wb") as f:
                    f.write(content)
                result["local_path"] = file_path
            
            # 处理不同的内容类型
            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} 的附件 {filename} 失败: {str(e)}")
            return {"error": str(e)}
Behavior2/5

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

With no annotations, the description carries full burden but only states the basic action. It doesn't disclose behavioral traits such as whether this is a read-only operation, what happens if the file doesn't exist, authentication needs, rate limits, or output format (e.g., file download vs. metadata).

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. It's appropriately sized and front-loaded, with every word contributing to understanding.

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 (3 parameters, no annotations, no output schema), the description is incomplete. It lacks details on behavioral aspects, parameter usage beyond basics, and output handling, making it inadequate for a tool that likely involves file operations.

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?

Schema description coverage is 0%, so the description must compensate. It mentions '问题ID' (issue ID) and '文件名' (filename), which map to the required parameters 'issue_key' and 'filename', adding meaning beyond the schema. However, it doesn't explain the optional 'save_to_disk' parameter or provide format details, leaving gaps.

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 ('获取' meaning 'get') and resource ('JIRA附件' meaning 'JIRA attachment'), specifying it retrieves an attachment based on issue ID and filename. It distinguishes from siblings like 'get_issue_attachment' or 'download_all_attachments' by focusing on filename-based retrieval, though not explicitly named.

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?

No guidance is provided on when to use this tool versus alternatives like 'get_issue_attachment' or 'download_all_attachments'. The description implies usage for retrieving a specific attachment by filename, but lacks explicit when/when-not instructions or prerequisites.

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