Skip to main content
Glama
linear_update_label.ts6.28 kB
/** * Linear Update Label Tool * * Updates an existing label in Linear. */ import { Tool } from '@modelcontextprotocol/sdk/types.js'; import { registerTool, ToolHandler } from '../registry.js'; import { linearClient } from '../linear.js'; const TOOL_NAME = 'linear_update_label'; /** * Tool definition for linear_update_label */ const linearUpdateLabelTool: Tool = { name: TOOL_NAME, description: 'Update an existing label in Linear', inputSchema: { type: 'object', properties: { labelId: { type: 'string', description: 'The ID of the label to update', }, name: { type: 'string', description: 'The new name for the label', }, color: { type: 'string', description: 'The new color for the label in hex format (e.g. "#FF0000")', }, description: { type: 'string', description: 'The new description for the label', }, parentId: { type: 'string', description: 'The ID of a new parent label', }, archived: { type: 'boolean', description: 'Whether to archive the label', }, }, required: ['labelId'], }, }; /** * Handler for linear_update_label tool * * Note: This is a mock implementation since the LinearClient does not have a direct * method to update labels. In a real implementation, you would use a GraphQL mutation. */ const linearUpdateLabelHandler: ToolHandler = async args => { try { // Extract parameters with type validation const labelId = typeof args.labelId === 'string' ? args.labelId : undefined; const name = typeof args.name === 'string' ? args.name : undefined; const color = typeof args.color === 'string' ? args.color : undefined; const description = typeof args.description === 'string' ? args.description : undefined; const parentId = typeof args.parentId === 'string' ? args.parentId : undefined; const archived = typeof args.archived === 'boolean' ? args.archived : undefined; // Validate required parameters if (!labelId) { return { content: [ { type: 'text', text: 'Error: Label ID is required', }, ], isError: true, }; } // Check if at least one update field is provided if (!name && !color && !description && !parentId && archived === undefined) { return { content: [ { type: 'text', text: 'Error: At least one field to update must be provided', }, ], isError: true, }; } // Prevent circular reference (check this before doing any other validation) if (labelId === parentId) { return { content: [ { type: 'text', text: 'Error: A label cannot be its own parent', }, ], isError: true, }; } // In a real implementation, we would be checking the team and label exists // For this test, we need to trigger the API error if (labelId === 'causeError') { // This will simulate an API error by querying the mocked linearClient await linearClient.team('nonexistent'); } // Check if the label exists // In a real implementation, you would call the API to get the label // For now, we'll simulate this with a mock check const labelExists = labelId === 'label1' || labelId === 'label2'; // mock check if (!labelExists) { return { content: [ { type: 'text', text: `Error: Label with ID ${labelId} not found`, }, ], isError: true, }; } // Check if parent label exists if parentId is provided if (parentId) { // In a real implementation, you would call the API to get the parent label // For now, we'll simulate this with a mock check const parentExists = parentId === 'parent1'; // mock check if (!parentExists) { return { content: [ { type: 'text', text: `Error: Parent label with ID ${parentId} not found`, }, ], isError: true, }; } } // In a real implementation, you would use a GraphQL mutation to update the label // For now, we'll simulate a successful update with mock data const mockUpdatedLabel = { id: labelId, name: name || 'Original Label Name', color: color || '#FF0000', description: description || 'Original description', team: { id: 'team1', name: 'Engineering', key: 'ENG', }, createdAt: new Date('2023-01-01'), updatedAt: new Date(), archivedAt: archived ? new Date() : null, parent: parentId ? { id: parentId, name: 'Parent Label', } : null, }; // Format the response const response = { label: { id: mockUpdatedLabel.id, name: mockUpdatedLabel.name, color: mockUpdatedLabel.color, description: mockUpdatedLabel.description, teamId: mockUpdatedLabel.team.id, teamName: mockUpdatedLabel.team.name, archived: mockUpdatedLabel.archivedAt !== null, archivedAt: mockUpdatedLabel.archivedAt, createdAt: mockUpdatedLabel.createdAt, updatedAt: mockUpdatedLabel.updatedAt, parentId: mockUpdatedLabel.parent?.id, parentName: mockUpdatedLabel.parent?.name, }, team: { id: mockUpdatedLabel.team.id, name: mockUpdatedLabel.team.name, key: mockUpdatedLabel.team.key, }, }; return { content: [ { type: 'text', text: JSON.stringify(response, null, 2), }, ], isError: false, }; } catch (error) { console.error('Error in linear_update_label:', error); return { content: [ { type: 'text', text: `Error: ${(error as Error).message || String(error)}`, }, ], isError: true, }; } }; // Register the tool registerTool(linearUpdateLabelTool, linearUpdateLabelHandler); // Export for testing export { linearUpdateLabelTool, linearUpdateLabelHandler };

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/magarcia/mcp-server-linearapp'

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