import { LinearAPIClient } from '../linear-client.js';
import {
ListTeamsSchema,
ListWorkflowStatesSchema,
GetTeamSchema,
CreateTeamSchema,
UpdateTeamSchema,
ArchiveTeamSchema,
UnarchiveTeamSchema,
} from '../schemas/index.js';
/**
* List all teams
*/
export async function listTeams(client: LinearAPIClient, args: unknown) {
const params = ListTeamsSchema.parse(args);
const teams = await client.listTeams(params.includeArchived);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
count: teams.length,
teams: teams,
},
null,
2
),
},
],
};
}
/**
* Get team details by ID
*/
export async function getTeam(client: LinearAPIClient, args: unknown) {
const params = GetTeamSchema.parse(args);
const team = await client.getTeam(params.teamId);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(team, null, 2),
},
],
};
}
/**
* Create a new team
*/
export async function createTeam(client: LinearAPIClient, args: unknown) {
const params = CreateTeamSchema.parse(args);
const team = await client.createTeam(params);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: true,
message: `Team created: ${team.key} - ${team.name}`,
team: team,
},
null,
2
),
},
],
};
}
/**
* Update an existing team
*/
export async function updateTeam(client: LinearAPIClient, args: unknown) {
const params = UpdateTeamSchema.parse(args);
const { teamId, ...updateData } = params;
const team = await client.updateTeam(teamId, updateData);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: true,
message: `Team updated: ${team.key} - ${team.name}`,
team: team,
},
null,
2
),
},
],
};
}
/**
* Archive a team
* Note: Not supported by Linear API - returns error message
*/
export async function archiveTeam(client: LinearAPIClient, args: unknown) {
const params = ArchiveTeamSchema.parse(args);
try {
const result = await client.archiveTeam(params.teamId);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(result, null, 2),
},
],
};
} catch (error) {
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: false,
error: error instanceof Error ? error.message : String(error),
},
null,
2
),
},
],
};
}
}
/**
* Unarchive a team
* Note: Not supported by Linear API - returns error message
*/
export async function unarchiveTeam(client: LinearAPIClient, args: unknown) {
const params = UnarchiveTeamSchema.parse(args);
try {
const result = await client.unarchiveTeam(params.teamId);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(result, null, 2),
},
],
};
} catch (error) {
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: false,
error: error instanceof Error ? error.message : String(error),
},
null,
2
),
},
],
};
}
}
/**
* List workflow states for a team
*/
export async function listWorkflowStates(client: LinearAPIClient, args: unknown) {
const params = ListWorkflowStatesSchema.parse(args);
const states = await client.listWorkflowStates(params.teamId);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
count: states.length,
states: states,
},
null,
2
),
},
],
};
}