import { LinearAPIClient } from '../linear-client.js';
import { CreateLabelSchema, ListLabelsSchema } from '../schemas/index.js';
/**
* Create a new label
*/
export async function createLabel(client: LinearAPIClient, args: unknown) {
const params = CreateLabelSchema.parse(args);
const label = await client.createLabel(params);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: true,
message: `Label created: ${label.name}`,
label: label,
},
null,
2
),
},
],
};
}
/**
* List all labels with optional team filter
*/
export async function listLabels(client: LinearAPIClient, args: unknown) {
const params = ListLabelsSchema.parse(args);
const labels = await client.listLabels(params.teamId);
const parentLabels = labels.filter((l) => l.isParent);
const regularLabels = labels.filter((l) => !l.isParent);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
count: labels.length,
regularLabelsCount: regularLabels.length,
parentLabelsCount: parentLabels.length,
note:
parentLabels.length > 0
? 'Parent labels (isParent: true) cannot be assigned to issues directly. Use their child labels instead.'
: undefined,
labels: labels,
},
null,
2
),
},
],
};
}