raps-cli 4.15.0

RAPS (rapeseed) - Rust Autodesk Platform Services CLI
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
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024-2025 Dmytro Yemelianov

//! ACC (Issues, RFIs, Assets, Submittals, Checklists) tool implementations for the MCP server.

use raps_acc::{
    CreateAssetRequest, CreateChecklistRequest, CreateIssueRequest, CreateRfiRequest,
    CreateSubmittalRequest, UpdateAssetRequest, UpdateChecklistRequest, UpdateIssueRequest,
    UpdateRfiRequest, UpdateSubmittalRequest,
};

use super::server::RapsServer;

impl RapsServer {
    // ========================================================================
    // Issues Tools
    // ========================================================================

    pub(crate) async fn issue_list(&self, project_id: String, filter: Option<String>) -> String {
        let client = self.get_issues_client().await;

        match client.list_issues(&project_id, filter.as_deref()).await {
            Ok(issues) => {
                if issues.is_empty() {
                    return "No issues found.".to_string();
                }

                let mut output = format!("Found {} issue(s):\n\n", issues.len());
                for issue in &issues {
                    let display_id = issue
                        .display_id
                        .map(|d| d.to_string())
                        .unwrap_or_else(|| "-".to_string());
                    output.push_str(&format!(
                        "* #{} {} [{}]\n  ID: {}\n",
                        display_id, issue.title, issue.status, issue.id
                    ));
                }
                output
            }
            Err(e) => format!("Failed to list issues: {}", e),
        }
    }

    pub(crate) async fn issue_get(&self, project_id: String, issue_id: String) -> String {
        let client = self.get_issues_client().await;

        match client.get_issue(&project_id, &issue_id).await {
            Ok(issue) => {
                let mut output = format!(
                    "Issue Details:\n\n* Title: {}\n* Status: {}\n* ID: {}",
                    issue.title, issue.status, issue.id
                );
                if let Some(ref desc) = issue.description {
                    output.push_str(&format!("\n* Description: {}", desc));
                }
                if let Some(ref assigned) = issue.assigned_to {
                    output.push_str(&format!("\n* Assigned to: {}", assigned));
                }
                if let Some(ref due) = issue.due_date {
                    output.push_str(&format!("\n* Due date: {}", due));
                }
                output
            }
            Err(e) => format!("Failed to get issue: {}", e),
        }
    }

    pub(crate) async fn issue_create(
        &self,
        project_id: String,
        title: String,
        description: Option<String>,
        status: Option<String>,
    ) -> String {
        let client = self.get_issues_client().await;

        let request = CreateIssueRequest {
            title,
            description,
            status: status.unwrap_or_else(|| "open".to_string()),
            issue_type_id: None,
            issue_subtype_id: None,
            assigned_to: None,
            assigned_to_type: None,
            due_date: None,
        };

        match client.create_issue(&project_id, request).await {
            Ok(issue) => format!(
                "Issue created successfully:\n* Title: {}\n* ID: {}\n* Status: {}",
                issue.title, issue.id, issue.status
            ),
            Err(e) => format!("Failed to create issue: {}", e),
        }
    }

    pub(crate) async fn issue_update(
        &self,
        project_id: String,
        issue_id: String,
        title: Option<String>,
        description: Option<String>,
        status: Option<String>,
    ) -> String {
        let client = self.get_issues_client().await;

        let request = UpdateIssueRequest {
            title,
            description,
            status,
            assigned_to: None,
            due_date: None,
        };

        match client.update_issue(&project_id, &issue_id, request).await {
            Ok(issue) => format!(
                "Issue updated successfully:\n* Title: {}\n* Status: {}",
                issue.title, issue.status
            ),
            Err(e) => format!("Failed to update issue: {}", e),
        }
    }

    // ========================================================================
    // Issue Comment Tools
    // ========================================================================

    pub(crate) async fn issue_comments_list(&self, project_id: String, issue_id: String) -> String {
        let client = self.get_issues_client().await;

        match client.list_comments(&project_id, &issue_id).await {
            Ok(comments) => {
                if comments.is_empty() {
                    return "No comments found.".to_string();
                }

                let mut output = format!("Found {} comment(s):\n\n", comments.len());
                for comment in &comments {
                    let author = comment.created_by.as_deref().unwrap_or("-");
                    let created = comment.created_at.as_deref().unwrap_or("-");
                    output.push_str(&format!(
                        "* [{}] by {} ({})\n  {}\n",
                        comment.id, author, created, comment.body
                    ));
                }
                output
            }
            Err(e) => format!("Failed to list issue comments: {}", e),
        }
    }

    pub(crate) async fn issue_comment_add(
        &self,
        project_id: String,
        issue_id: String,
        body: String,
    ) -> String {
        let client = self.get_issues_client().await;

        match client.add_comment(&project_id, &issue_id, &body).await {
            Ok(comment) => format!(
                "Comment added successfully:\n* ID: {}\n* Body: {}",
                comment.id, comment.body
            ),
            Err(e) => format!("Failed to add issue comment: {}", e),
        }
    }

    pub(crate) async fn issue_comment_delete(
        &self,
        project_id: String,
        issue_id: String,
        comment_id: String,
    ) -> String {
        let client = self.get_issues_client().await;

        match client
            .delete_comment(&project_id, &issue_id, &comment_id)
            .await
        {
            Ok(()) => format!("Comment {} deleted successfully.", comment_id),
            Err(e) => format!("Failed to delete issue comment: {}", e),
        }
    }

    // ========================================================================
    // RFI Tools
    // ========================================================================

    pub(crate) async fn rfi_list(&self, project_id: String) -> String {
        let client = self.get_rfi_client().await;

        match client.list_rfis(&project_id).await {
            Ok(rfis) => {
                if rfis.is_empty() {
                    return "No RFIs found.".to_string();
                }

                let mut output = format!("Found {} RFI(s):\n\n", rfis.len());
                for rfi in &rfis {
                    let number = rfi.number.as_deref().unwrap_or("-");
                    output.push_str(&format!(
                        "* #{} {} [{}]\n  ID: {}\n",
                        number, rfi.title, rfi.status, rfi.id
                    ));
                }
                output
            }
            Err(e) => format!("Failed to list RFIs: {}", e),
        }
    }

    pub(crate) async fn rfi_get(&self, project_id: String, rfi_id: String) -> String {
        let client = self.get_rfi_client().await;

        match client.get_rfi(&project_id, &rfi_id).await {
            Ok(rfi) => {
                let mut output = format!(
                    "RFI Details:\n\n* Title: {}\n* Status: {}\n* ID: {}",
                    rfi.title, rfi.status, rfi.id
                );
                if let Some(ref question) = rfi.question {
                    output.push_str(&format!("\n* Question: {}", question));
                }
                if let Some(ref answer) = rfi.answer {
                    output.push_str(&format!("\n* Answer: {}", answer));
                }
                if let Some(ref priority) = rfi.priority {
                    output.push_str(&format!("\n* Priority: {}", priority));
                }
                output
            }
            Err(e) => format!("Failed to get RFI: {}", e),
        }
    }

    #[allow(clippy::too_many_arguments)]
    pub(crate) async fn rfi_create(
        &self,
        project_id: String,
        title: String,
        question: Option<String>,
        priority: Option<String>,
        due_date: Option<String>,
        assigned_to: Option<String>,
        location: Option<String>,
    ) -> String {
        let client = self.get_rfi_client().await;

        let request = CreateRfiRequest {
            title,
            question,
            priority,
            due_date,
            assigned_to,
            location,
            discipline: None,
        };

        match client.create_rfi(&project_id, request).await {
            Ok(rfi) => {
                format!(
                    "RFI created successfully:\n\n* ID: {}\n* Title: {}\n* Status: {}",
                    rfi.id, rfi.title, rfi.status
                )
            }
            Err(e) => format!("Failed to create RFI: {}", e),
        }
    }

    #[allow(clippy::too_many_arguments)]
    pub(crate) async fn rfi_update(
        &self,
        project_id: String,
        rfi_id: String,
        title: Option<String>,
        question: Option<String>,
        answer: Option<String>,
        status: Option<String>,
        priority: Option<String>,
    ) -> String {
        let client = self.get_rfi_client().await;

        let request = UpdateRfiRequest {
            title,
            question,
            answer,
            status,
            priority,
            due_date: None,
            assigned_to: None,
            location: None,
        };

        match client.update_rfi(&project_id, &rfi_id, request).await {
            Ok(rfi) => {
                format!(
                    "RFI updated successfully:\n\n* ID: {}\n* Title: {}\n* Status: {}",
                    rfi.id, rfi.title, rfi.status
                )
            }
            Err(e) => format!("Failed to update RFI: {}", e),
        }
    }

    // ========================================================================
    // ACC Extended Tools (Assets, Submittals, Checklists)
    // ========================================================================

    pub(crate) async fn acc_assets_list(&self, project_id: String) -> String {
        let client = self.get_acc_client().await;

        match client.list_assets(&project_id).await {
            Ok(assets) => {
                if assets.is_empty() {
                    return "No assets found.".to_string();
                }

                let mut output = format!("Found {} asset(s):\n\n", assets.len());
                for asset in &assets {
                    let desc = asset.description.as_deref().unwrap_or("-");
                    output.push_str(&format!("* {} - {}\n", asset.id, desc));
                }
                output
            }
            Err(e) => format!("Failed to list assets: {}", e),
        }
    }

    pub(crate) async fn asset_create(
        &self,
        project_id: String,
        category_id: Option<String>,
        description: Option<String>,
        barcode: Option<String>,
        client_asset_id: Option<String>,
    ) -> String {
        let client = self.get_acc_client().await;

        let request = CreateAssetRequest {
            category_id,
            description,
            barcode,
            client_asset_id,
        };

        match client.create_asset(&project_id, request).await {
            Ok(asset) => {
                format!(
                    "Asset created successfully:\n\n* ID: {}\n* Description: {}",
                    asset.id,
                    asset.description.as_deref().unwrap_or("-")
                )
            }
            Err(e) => format!("Failed to create asset: {}", e),
        }
    }

    pub(crate) async fn asset_update(
        &self,
        project_id: String,
        asset_id: String,
        category_id: Option<String>,
        status_id: Option<String>,
        description: Option<String>,
        barcode: Option<String>,
    ) -> String {
        let client = self.get_acc_client().await;

        let request = UpdateAssetRequest {
            category_id,
            status_id,
            description,
            barcode,
        };

        match client.update_asset(&project_id, &asset_id, request).await {
            Ok(asset) => {
                format!(
                    "Asset updated successfully:\n\n* ID: {}\n* Description: {}",
                    asset.id,
                    asset.description.as_deref().unwrap_or("-")
                )
            }
            Err(e) => format!("Failed to update asset: {}", e),
        }
    }

    pub(crate) async fn asset_delete(&self, project_id: String, asset_id: String) -> String {
        let client = self.get_acc_client().await;

        match client.delete_asset(&project_id, &asset_id).await {
            Ok(()) => format!("Asset {} deleted successfully", asset_id),
            Err(e) => format!("Failed to delete asset: {}", e),
        }
    }

    pub(crate) async fn asset_get(&self, project_id: String, asset_id: String) -> String {
        let client = self.get_acc_client().await;

        match client.get_asset(&project_id, &asset_id).await {
            Ok(asset) => {
                let mut output = format!("Asset details:\n\n* ID: {}\n", asset.id);
                if let Some(ref desc) = asset.description {
                    output.push_str(&format!("* Description: {}\n", desc));
                }
                if let Some(ref status_id) = asset.status_id {
                    output.push_str(&format!("* Status ID: {}\n", status_id));
                }
                if let Some(ref category_id) = asset.category_id {
                    output.push_str(&format!("* Category ID: {}\n", category_id));
                }
                if let Some(ref barcode) = asset.barcode {
                    output.push_str(&format!("* Barcode: {}\n", barcode));
                }
                if let Some(ref created_at) = asset.created_at {
                    output.push_str(&format!("* Created: {}\n", created_at));
                }
                if let Some(ref updated_at) = asset.updated_at {
                    output.push_str(&format!("* Updated: {}\n", updated_at));
                }
                output
            }
            Err(e) => format!("Failed to get asset: {}", e),
        }
    }

    pub(crate) async fn acc_submittals_list(&self, project_id: String) -> String {
        let client = self.get_acc_client().await;

        match client.list_submittals(&project_id).await {
            Ok(submittals) => {
                if submittals.is_empty() {
                    return "No submittals found.".to_string();
                }

                let mut output = format!("Found {} submittal(s):\n\n", submittals.len());
                for sub in &submittals {
                    let number = sub.number.as_deref().unwrap_or("-");
                    output.push_str(&format!(
                        "* #{} {} [{}]\n  ID: {}\n",
                        number, sub.title, sub.status, sub.id
                    ));
                }
                output
            }
            Err(e) => format!("Failed to list submittals: {}", e),
        }
    }

    pub(crate) async fn submittal_create(
        &self,
        project_id: String,
        title: String,
        spec_section: Option<String>,
        due_date: Option<String>,
    ) -> String {
        let client = self.get_acc_client().await;

        let request = CreateSubmittalRequest {
            title,
            spec_section,
            due_date,
        };

        match client.create_submittal(&project_id, request).await {
            Ok(submittal) => {
                format!(
                    "Submittal created successfully:\n\n* ID: {}\n* Title: {}\n* Status: {}",
                    submittal.id, submittal.title, submittal.status
                )
            }
            Err(e) => format!("Failed to create submittal: {}", e),
        }
    }

    pub(crate) async fn submittal_update(
        &self,
        project_id: String,
        submittal_id: String,
        title: Option<String>,
        status: Option<String>,
        due_date: Option<String>,
    ) -> String {
        let client = self.get_acc_client().await;

        let request = UpdateSubmittalRequest {
            title,
            status,
            due_date,
        };

        match client
            .update_submittal(&project_id, &submittal_id, request)
            .await
        {
            Ok(submittal) => {
                format!(
                    "Submittal updated successfully:\n\n* ID: {}\n* Title: {}\n* Status: {}",
                    submittal.id, submittal.title, submittal.status
                )
            }
            Err(e) => format!("Failed to update submittal: {}", e),
        }
    }

    pub(crate) async fn acc_checklists_list(&self, project_id: String) -> String {
        let client = self.get_acc_client().await;

        match client.list_checklists(&project_id).await {
            Ok(checklists) => {
                if checklists.is_empty() {
                    return "No checklists found.".to_string();
                }

                let mut output = format!("Found {} checklist(s):\n\n", checklists.len());
                for checklist in &checklists {
                    output.push_str(&format!(
                        "* {} [{}]\n  ID: {}\n",
                        checklist.title, checklist.status, checklist.id
                    ));
                }
                output
            }
            Err(e) => format!("Failed to list checklists: {}", e),
        }
    }

    pub(crate) async fn checklist_templates_list(&self, project_id: String) -> String {
        let client = self.get_acc_client().await;

        match client.list_checklist_templates(&project_id).await {
            Ok(templates) => {
                if templates.is_empty() {
                    return "No checklist templates found.".to_string();
                }

                let mut output = format!("Found {} checklist template(s):\n\n", templates.len());
                for template in &templates {
                    let desc = template.description.as_deref().unwrap_or("-");
                    let created = template.created_at.as_deref().unwrap_or("-");
                    output.push_str(&format!(
                        "* {} (id: {}, created: {})\n  Description: {}\n",
                        template.title, template.id, created, desc
                    ));
                }
                output
            }
            Err(e) => format!("Failed to list checklist templates: {}", e),
        }
    }

    pub(crate) async fn checklist_create(
        &self,
        project_id: String,
        title: String,
        template_id: Option<String>,
        location: Option<String>,
        due_date: Option<String>,
        assignee_id: Option<String>,
    ) -> String {
        let client = self.get_acc_client().await;

        let request = CreateChecklistRequest {
            title,
            template_id,
            location,
            due_date,
            assignee_id,
        };

        match client.create_checklist(&project_id, request).await {
            Ok(checklist) => {
                format!(
                    "Checklist created successfully:\n\n* ID: {}\n* Title: {}\n* Status: {}",
                    checklist.id, checklist.title, checklist.status
                )
            }
            Err(e) => format!("Failed to create checklist: {}", e),
        }
    }

    #[allow(clippy::too_many_arguments)]
    pub(crate) async fn checklist_update(
        &self,
        project_id: String,
        checklist_id: String,
        title: Option<String>,
        status: Option<String>,
        location: Option<String>,
        due_date: Option<String>,
        assignee_id: Option<String>,
    ) -> String {
        let client = self.get_acc_client().await;

        let request = UpdateChecklistRequest {
            title,
            status,
            location,
            due_date,
            assignee_id,
        };

        match client
            .update_checklist(&project_id, &checklist_id, request)
            .await
        {
            Ok(checklist) => {
                format!(
                    "Checklist updated successfully:\n\n* ID: {}\n* Title: {}\n* Status: {}",
                    checklist.id, checklist.title, checklist.status
                )
            }
            Err(e) => format!("Failed to update checklist: {}", e),
        }
    }
}