linear-tools 0.5.1

Linear issue tools via CLI + MCP
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
//! Tool wrappers for linear_tools using agentic-tools-core.
//!
//! Each tool delegates to the corresponding method on [`LinearTools`].

use crate::LinearTools;
use crate::models::ArchiveIssueResult;
use crate::models::CommentResult;
use crate::models::CreateIssueResult;
use crate::models::GetMetadataResult;
use crate::models::IssueDetails;
use crate::models::IssueResult;
use crate::models::SearchResult;
use crate::models::SetRelationResult;
use agentic_tools_core::Tool;
use agentic_tools_core::ToolContext;
use agentic_tools_core::ToolError;
use agentic_tools_core::ToolRegistry;
use futures::future::BoxFuture;
use schemars::JsonSchema;
use serde::Deserialize;
use std::sync::Arc;

// ============================================================================
// SearchIssues Tool
// ============================================================================

/// Input for search_issues tool.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct SearchIssuesInput {
    /// Full-text search term (searches title, description, and optionally comments)
    #[serde(default)]
    pub query: Option<String>,
    /// Include comments in full-text search (default: true, only applies when query is provided)
    #[serde(default)]
    pub include_comments: Option<bool>,
    /// Filter by priority (0=None, 1=Urgent, 2=High, 3=Normal, 4=Low)
    #[serde(default)]
    pub priority: Option<i32>,
    /// Workflow state ID (UUID)
    #[serde(default)]
    pub state_id: Option<String>,
    /// Assignee user ID (UUID)
    #[serde(default)]
    pub assignee_id: Option<String>,
    /// Creator user ID (UUID)
    #[serde(default)]
    pub creator_id: Option<String>,
    /// Team ID (UUID)
    #[serde(default)]
    pub team_id: Option<String>,
    /// Project ID (UUID)
    #[serde(default)]
    pub project_id: Option<String>,
    /// Only issues created after this ISO 8601 date
    #[serde(default)]
    pub created_after: Option<String>,
    /// Only issues created before this ISO 8601 date
    #[serde(default)]
    pub created_before: Option<String>,
    /// Only issues updated after this ISO 8601 date
    #[serde(default)]
    pub updated_after: Option<String>,
    /// Only issues updated before this ISO 8601 date
    #[serde(default)]
    pub updated_before: Option<String>,
    /// Page size (default 50, max 100)
    #[serde(default)]
    pub first: Option<i32>,
    /// Pagination cursor
    #[serde(default)]
    pub after: Option<String>,
}

/// Tool for searching Linear issues.
#[derive(Clone)]
pub struct SearchIssuesTool {
    linear: Arc<LinearTools>,
}

impl SearchIssuesTool {
    pub fn new(linear: Arc<LinearTools>) -> Self {
        Self { linear }
    }
}

impl Tool for SearchIssuesTool {
    type Input = SearchIssuesInput;
    type Output = SearchResult;
    const NAME: &'static str = "linear_search_issues";
    const DESCRIPTION: &'static str = "Search Linear issues using full-text search and/or filters";

    fn call(
        &self,
        input: Self::Input,
        _ctx: &ToolContext,
    ) -> BoxFuture<'static, Result<Self::Output, ToolError>> {
        let linear = self.linear.clone();
        Box::pin(async move {
            linear
                .search_issues(
                    input.query,
                    input.include_comments,
                    input.priority,
                    input.state_id,
                    input.assignee_id,
                    input.creator_id,
                    input.team_id,
                    input.project_id,
                    input.created_after,
                    input.created_before,
                    input.updated_after,
                    input.updated_before,
                    input.first,
                    input.after,
                )
                .await
                .map_err(map_anyhow_to_tool_error)
        })
    }
}

// ============================================================================
// ReadIssue Tool
// ============================================================================

/// Input for read_issue tool.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct ReadIssueInput {
    /// Issue ID, identifier (e.g., ENG-245), or URL
    pub issue: String,
}

/// Tool for reading a single Linear issue.
#[derive(Clone)]
pub struct ReadIssueTool {
    linear: Arc<LinearTools>,
}

impl ReadIssueTool {
    pub fn new(linear: Arc<LinearTools>) -> Self {
        Self { linear }
    }
}

impl Tool for ReadIssueTool {
    type Input = ReadIssueInput;
    type Output = IssueDetails;
    const NAME: &'static str = "linear_read_issue";
    const DESCRIPTION: &'static str =
        "Read a Linear issue by ID, identifier (e.g., ENG-245), or URL";

    fn call(
        &self,
        input: Self::Input,
        _ctx: &ToolContext,
    ) -> BoxFuture<'static, Result<Self::Output, ToolError>> {
        let linear = self.linear.clone();
        Box::pin(async move {
            linear
                .read_issue(input.issue)
                .await
                .map_err(map_anyhow_to_tool_error)
        })
    }
}

// ============================================================================
// CreateIssue Tool
// ============================================================================

/// Input for create_issue tool.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct CreateIssueInput {
    /// Team ID (UUID) to create the issue in
    pub team_id: String,
    /// Issue title
    pub title: String,
    /// Issue description (markdown supported)
    #[serde(default)]
    pub description: Option<String>,
    /// Priority (0=None, 1=Urgent, 2=High, 3=Normal, 4=Low)
    #[serde(default)]
    pub priority: Option<i32>,
    /// Assignee user ID (UUID)
    #[serde(default)]
    pub assignee_id: Option<String>,
    /// Project ID (UUID)
    #[serde(default)]
    pub project_id: Option<String>,
    /// Workflow state ID (UUID)
    #[serde(default)]
    pub state_id: Option<String>,
    /// Parent issue ID (UUID) for sub-issues
    #[serde(default)]
    pub parent_id: Option<String>,
    /// Label IDs (UUIDs)
    #[serde(default)]
    pub label_ids: Vec<String>,
}

/// Tool for creating a new Linear issue.
#[derive(Clone)]
pub struct CreateIssueTool {
    linear: Arc<LinearTools>,
}

impl CreateIssueTool {
    pub fn new(linear: Arc<LinearTools>) -> Self {
        Self { linear }
    }
}

impl Tool for CreateIssueTool {
    type Input = CreateIssueInput;
    type Output = CreateIssueResult;
    const NAME: &'static str = "linear_create_issue";
    const DESCRIPTION: &'static str = "Create a new Linear issue in a team";

    fn call(
        &self,
        input: Self::Input,
        _ctx: &ToolContext,
    ) -> BoxFuture<'static, Result<Self::Output, ToolError>> {
        let linear = self.linear.clone();
        Box::pin(async move {
            linear
                .create_issue(
                    input.team_id,
                    input.title,
                    input.description,
                    input.priority,
                    input.assignee_id,
                    input.project_id,
                    input.state_id,
                    input.parent_id,
                    input.label_ids,
                )
                .await
                .map_err(map_anyhow_to_tool_error)
        })
    }
}

// ============================================================================
// AddComment Tool
// ============================================================================

/// Input for add_comment tool.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct AddCommentInput {
    /// Issue ID, identifier (e.g., ENG-245), or URL
    pub issue: String,
    /// Comment body (markdown supported)
    pub body: String,
    /// Parent comment ID for replies (UUID)
    #[serde(default)]
    pub parent_id: Option<String>,
}

/// Tool for adding a comment to a Linear issue.
#[derive(Clone)]
pub struct AddCommentTool {
    linear: Arc<LinearTools>,
}

impl AddCommentTool {
    pub fn new(linear: Arc<LinearTools>) -> Self {
        Self { linear }
    }
}

impl Tool for AddCommentTool {
    type Input = AddCommentInput;
    type Output = CommentResult;
    const NAME: &'static str = "linear_add_comment";
    const DESCRIPTION: &'static str = "Add a comment to a Linear issue";

    fn call(
        &self,
        input: Self::Input,
        _ctx: &ToolContext,
    ) -> BoxFuture<'static, Result<Self::Output, ToolError>> {
        let linear = self.linear.clone();
        Box::pin(async move {
            linear
                .add_comment(input.issue, input.body, input.parent_id)
                .await
                .map_err(map_anyhow_to_tool_error)
        })
    }
}

// ============================================================================
// GetIssueComments Tool
// ============================================================================

/// Input for get_issue_comments tool.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct GetIssueCommentsInput {
    /// Issue ID, identifier (e.g., ENG-245), or URL
    pub issue: String,
}

/// Tool for fetching comments on a Linear issue with implicit pagination.
#[derive(Clone)]
pub struct GetIssueCommentsTool {
    linear: Arc<LinearTools>,
}

impl GetIssueCommentsTool {
    pub fn new(linear: Arc<LinearTools>) -> Self {
        Self { linear }
    }
}

impl Tool for GetIssueCommentsTool {
    type Input = GetIssueCommentsInput;
    type Output = crate::models::CommentsResult;
    const NAME: &'static str = "linear_get_issue_comments";
    const DESCRIPTION: &'static str = "Get comments on a Linear issue. Returns 10 comments per call with implicit pagination - call again with the same issue to get more comments.";

    fn call(
        &self,
        input: Self::Input,
        _ctx: &ToolContext,
    ) -> BoxFuture<'static, Result<Self::Output, ToolError>> {
        let linear = self.linear.clone();
        Box::pin(async move {
            linear
                .get_issue_comments(input.issue)
                .await
                .map_err(map_anyhow_to_tool_error)
        })
    }
}

// ============================================================================
// ArchiveIssue Tool
// ============================================================================

/// Input for archive_issue tool.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct ArchiveIssueInput {
    /// Issue ID, identifier (e.g., ENG-245), or URL
    pub issue: String,
}

/// Tool for archiving a Linear issue.
#[derive(Clone)]
pub struct ArchiveIssueTool {
    linear: Arc<LinearTools>,
}

impl ArchiveIssueTool {
    pub fn new(linear: Arc<LinearTools>) -> Self {
        Self { linear }
    }
}

impl Tool for ArchiveIssueTool {
    type Input = ArchiveIssueInput;
    type Output = ArchiveIssueResult;
    const NAME: &'static str = "linear_archive_issue";
    const DESCRIPTION: &'static str =
        "Archive a Linear issue by ID, identifier (e.g., ENG-245), or URL";

    fn call(
        &self,
        input: Self::Input,
        _ctx: &ToolContext,
    ) -> BoxFuture<'static, Result<Self::Output, ToolError>> {
        let linear = self.linear.clone();
        Box::pin(async move {
            linear
                .archive_issue(input.issue)
                .await
                .map_err(map_anyhow_to_tool_error)
        })
    }
}

// ============================================================================
// UpdateIssue Tool
// ============================================================================

/// Input for updating an existing Linear issue
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct UpdateIssueInput {
    /// Issue identifier (UUID, key like ENG-245, or Linear URL)
    pub issue: String,
    /// New title for the issue
    #[serde(default)]
    pub title: Option<String>,
    /// New description (markdown supported)
    #[serde(default)]
    pub description: Option<String>,
    /// Priority: 0=None, 1=Urgent, 2=High, 3=Medium, 4=Low
    #[serde(default)]
    pub priority: Option<i32>,
    /// Assignee user ID (UUID)
    #[serde(default)]
    pub assignee_id: Option<String>,
    /// Workflow state ID (UUID)
    #[serde(default)]
    pub state_id: Option<String>,
    /// Project ID (UUID)
    #[serde(default)]
    pub project_id: Option<String>,
    /// Parent issue ID (UUID) for sub-issues
    #[serde(default)]
    pub parent_id: Option<String>,
    /// Replace all labels with these IDs (overrides existing)
    #[serde(default)]
    pub label_ids: Option<Vec<String>>,
    /// Add these label IDs (incremental)
    #[serde(default)]
    pub added_label_ids: Option<Vec<String>>,
    /// Remove these label IDs (incremental)
    #[serde(default)]
    pub removed_label_ids: Option<Vec<String>>,
    /// Due date in ISO 8601 format (YYYY-MM-DD)
    #[serde(default)]
    pub due_date: Option<String>,
}

/// Tool for updating an existing Linear issue.
#[derive(Clone)]
pub struct UpdateIssueTool {
    linear: Arc<LinearTools>,
}

impl UpdateIssueTool {
    pub fn new(linear: Arc<LinearTools>) -> Self {
        Self { linear }
    }
}

impl Tool for UpdateIssueTool {
    type Input = UpdateIssueInput;
    type Output = IssueResult;
    const NAME: &'static str = "linear_update_issue";
    const DESCRIPTION: &'static str = "Update an existing Linear issue. Use linear_get_metadata to look up user IDs, state IDs, project IDs, and label IDs.";

    fn call(
        &self,
        input: Self::Input,
        _ctx: &ToolContext,
    ) -> BoxFuture<'static, Result<Self::Output, ToolError>> {
        let linear = self.linear.clone();
        Box::pin(async move {
            linear
                .update_issue(
                    input.issue,
                    input.title,
                    input.description,
                    input.priority,
                    input.assignee_id,
                    input.state_id,
                    input.project_id,
                    input.parent_id,
                    input.label_ids,
                    input.added_label_ids,
                    input.removed_label_ids,
                    input.due_date,
                )
                .await
                .map_err(map_anyhow_to_tool_error)
        })
    }
}

// ============================================================================
// SetRelation Tool
// ============================================================================

/// Input for setting or removing an issue relation
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct SetRelationInput {
    /// Source issue identifier (UUID, key like ENG-245, or URL)
    pub issue: String,
    /// Related issue identifier (UUID, key like ENG-245, or URL)
    pub related_issue: String,
    /// Relation type: "blocks", "duplicate", "related". Null/omitted to remove relation.
    #[serde(default)]
    pub relation_type: Option<String>,
}

/// Tool for setting or removing issue relations.
#[derive(Clone)]
pub struct SetRelationTool {
    linear: Arc<LinearTools>,
}

impl SetRelationTool {
    pub fn new(linear: Arc<LinearTools>) -> Self {
        Self { linear }
    }
}

impl Tool for SetRelationTool {
    type Input = SetRelationInput;
    type Output = SetRelationResult;
    const NAME: &'static str = "linear_set_relation";
    const DESCRIPTION: &'static str = "Set or remove a relation between two issues. Provide relation_type to create (blocks/duplicate/related), or omit/null to remove any existing relation.";

    fn call(
        &self,
        input: Self::Input,
        _ctx: &ToolContext,
    ) -> BoxFuture<'static, Result<Self::Output, ToolError>> {
        let linear = self.linear.clone();
        Box::pin(async move {
            linear
                .set_relation(input.issue, input.related_issue, input.relation_type)
                .await
                .map_err(map_anyhow_to_tool_error)
        })
    }
}

// ============================================================================
// GetMetadata Tool
// ============================================================================

/// Input for get_metadata tool.
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct GetMetadataInput {
    /// Kind of metadata to retrieve
    pub kind: crate::models::MetadataKind,
    /// Optional search string (case-insensitive name match)
    #[serde(default)]
    pub search: Option<String>,
    /// Optional team ID to filter by (relevant for workflow_states and labels)
    #[serde(default)]
    pub team_id: Option<String>,
    /// Maximum number of results (default: 50)
    #[serde(default)]
    pub first: Option<i32>,
    /// Pagination cursor for next page
    #[serde(default)]
    pub after: Option<String>,
}

/// Tool for looking up Linear metadata (users, teams, projects, workflow states, labels).
#[derive(Clone)]
pub struct GetMetadataTool {
    linear: Arc<LinearTools>,
}

impl GetMetadataTool {
    pub fn new(linear: Arc<LinearTools>) -> Self {
        Self { linear }
    }
}

impl Tool for GetMetadataTool {
    type Input = GetMetadataInput;
    type Output = GetMetadataResult;
    const NAME: &'static str = "linear_get_metadata";
    const DESCRIPTION: &'static str = "Look up Linear metadata: users, teams, projects, workflow states, or labels. Use this to discover IDs for filtering and updating issues.";

    fn call(
        &self,
        input: Self::Input,
        _ctx: &ToolContext,
    ) -> BoxFuture<'static, Result<Self::Output, ToolError>> {
        let linear = self.linear.clone();
        Box::pin(async move {
            linear
                .get_metadata(
                    input.kind,
                    input.search,
                    input.team_id,
                    input.first,
                    input.after,
                )
                .await
                .map_err(map_anyhow_to_tool_error)
        })
    }
}

// ============================================================================
// Registry Builder
// ============================================================================

/// Build a ToolRegistry containing all linear_tools tools.
pub fn build_registry(linear: Arc<LinearTools>) -> ToolRegistry {
    ToolRegistry::builder()
        .register::<SearchIssuesTool, ()>(SearchIssuesTool::new(linear.clone()))
        .register::<ReadIssueTool, ()>(ReadIssueTool::new(linear.clone()))
        .register::<CreateIssueTool, ()>(CreateIssueTool::new(linear.clone()))
        .register::<AddCommentTool, ()>(AddCommentTool::new(linear.clone()))
        .register::<GetIssueCommentsTool, ()>(GetIssueCommentsTool::new(linear.clone()))
        .register::<ArchiveIssueTool, ()>(ArchiveIssueTool::new(linear.clone()))
        .register::<UpdateIssueTool, ()>(UpdateIssueTool::new(linear.clone()))
        .register::<SetRelationTool, ()>(SetRelationTool::new(linear.clone()))
        .register::<GetMetadataTool, ()>(GetMetadataTool::new(linear))
        .finish()
}

// ============================================================================
// Error Conversion
// ============================================================================

/// Map anyhow::Error to agentic_tools_core::ToolError based on error message patterns.
fn map_anyhow_to_tool_error(e: anyhow::Error) -> ToolError {
    let msg = e.to_string();
    let lc = msg.to_lowercase();
    if lc.contains("permission") || lc.contains("401") || lc.contains("403") {
        ToolError::Permission(msg)
    } else if lc.contains("not found") || lc.contains("404") {
        ToolError::NotFound(msg)
    } else if lc.contains("invalid") || lc.contains("bad request") {
        ToolError::InvalidInput(msg)
    } else if lc.contains("timeout") || lc.contains("network") || lc.contains("rate limit") {
        ToolError::External(msg)
    } else {
        ToolError::Internal(msg)
    }
}