Skip to main content
Glama
KS-GEN-AI

Jira MCP Server

by KS-GEN-AI

add_attachment_from_confluence

Add attachments from Confluence pages to Jira tickets using page ID and attachment name to link documentation and files.

Instructions

Add an attachment to a ticket on Jira from a Confluence page by its name on the api /rest/api/3/issue/{issueIdOrKey}/attachments. Do not use markdown in your query.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
issueIdOrKeyYesThe issue id or key
pageIdYesThe page id
attachmentNameYesThe name of the attachment

Implementation Reference

  • The main handler function that retrieves an attachment from a Confluence page by pageId and attachmentName, downloads it, and attaches it to a Jira issue.
    async function addAttachmentFromConfluence(
      issueIdOrKey: string,
      pageId: string,
      attachmentName: string,
    ): Promise<any> {
      try {
        // Récupérer l'attachement depuis Confluence
        const response = await axios.get(
          `${JIRA_URL}/wiki/rest/api/content/${pageId}/child/attachment`,
          {
            headers: getAuthHeaders().headers,
          },
        );
    
        // Trouver l'attachement spécifique
        const attachment = response.data.results.find(
          (attachment: any) => attachment.title === attachmentName,
        );
    
        if (!attachment) {
          return {
            error: 'Attachment not found',
          };
        }
    
        // Télécharger l'attachement
        const attachmentResponse = await axios.get(
          `${JIRA_URL}/wiki${attachment._links.download}`,
          {
            headers: getAuthHeaders().headers,
            responseType: 'arraybuffer',
          },
        );
    
        // Créer un FormData et ajouter le fichier
        const formData = new FormData();
        const blob = new Blob([attachmentResponse.data], {
          type: attachment.mediaType,
        });
        formData.append('file', blob, attachmentName);
    
        // Headers spéciaux pour l'upload de fichiers
        const headers = {
          ...getAuthHeaders().headers,
          'X-Atlassian-Token': 'no-check',
          'Content-Type': 'multipart/form-data',
        };
    
        // Uploader l'attachement sur le ticket Jira
        const uploadResponse = await axios.post(
          `${JIRA_URL}/rest/api/3/issue/${issueIdOrKey}/attachments`,
          formData,
          { headers },
        );
    
        return uploadResponse.data;
      } catch (error: any) {
        return {
          error: error.response?.data || error.message,
        };
      }
    }
  • src/index.ts:262-284 (registration)
    Tool registration in the list of available tools, including description and input schema definition.
    {
      name: 'add_attachment_from_confluence',
      description:
        'Add an attachment to a ticket on Jira from a Confluence page by its name on the api /rest/api/3/issue/{issueIdOrKey}/attachments. Do not use markdown in your query.',
      inputSchema: {
        type: 'object',
        properties: {
          issueIdOrKey: {
            type: 'string',
            description: 'The issue id or key',
          },
          pageId: {
            type: 'string',
            description: 'The page id',
          },
          attachmentName: {
            type: 'string',
            description: 'The name of the attachment',
          },
        },
        required: ['issueIdOrKey', 'pageId', 'attachmentName'],
      },
    },
  • Input schema definition for the tool parameters.
    inputSchema: {
      type: 'object',
      properties: {
        issueIdOrKey: {
          type: 'string',
          description: 'The issue id or key',
        },
        pageId: {
          type: 'string',
          description: 'The page id',
        },
        attachmentName: {
          type: 'string',
          description: 'The name of the attachment',
        },
      },
      required: ['issueIdOrKey', 'pageId', 'attachmentName'],
  • Dispatcher case in the CallToolRequestSchema handler that validates arguments and calls the addAttachmentFromConfluence handler.
    case 'add_attachment_from_confluence': {
      const issueIdOrKey: any = request.params.arguments?.issueIdOrKey;
      const pageId: any = request.params.arguments?.pageId;
      const attachmentName: any = request.params.arguments?.attachmentName;
    
      if (!issueIdOrKey || !pageId || !attachmentName) {
        throw new Error(
          'Issue id or key, page id and attachment name are required',
        );
      }
    
      const response = await addAttachmentFromConfluence(
        issueIdOrKey,
        pageId,
        attachmentName,
      );
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(response, null, 2),
          },
        ],
      };
    }

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/KS-GEN-AI/jira-mcp-server'

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