devboy-mcp 0.28.1

MCP (Model Context Protocol) server for devboy-tools — JSON-RPC 2.0 over stdio, exposing every devboy provider as MCP tools to AI agents.
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
//! Integration tests for MCP tool filtering based on provider configuration.
//!
//! These tests verify that the MCP server correctly filters tools based on
//! which providers are configured:
//! - No providers: only context management tools available
//! - Issue-only providers (ClickUp, Jira): issue tools + context tools
//! - Git providers (GitHub, GitLab): issue tools + MR tools + context tools

use std::sync::Arc;

use async_trait::async_trait;
use devboy_core::{
    Comment, CreateCommentInput, CreateIssueInput, Discussion, FileDiff, Issue, IssueFilter,
    IssueProvider, MergeRequest, MergeRequestProvider, MrFilter, Provider, Result,
    UpdateIssueInput, User,
};
use devboy_mcp::McpServer;

// =============================================================================
// Test Providers
// =============================================================================

/// ClickUp-like provider that only supports issues, not merge requests.
struct ClickUpTestProvider;

#[async_trait]
impl IssueProvider for ClickUpTestProvider {
    async fn get_issues(&self, _filter: IssueFilter) -> Result<devboy_core::ProviderResult<Issue>> {
        Ok(vec![Issue {
            key: "CU-123".to_string(),
            title: "Test Issue".to_string(),
            description: None,
            state: "open".to_string(),
            source: "clickup".to_string(),
            labels: vec![],
            assignees: vec![],
            author: None,
            priority: None,
            url: None,
            created_at: None,
            updated_at: None,
            attachments_count: None,
            parent: None,
            subtasks: vec![],
            custom_fields: std::collections::HashMap::new(),
        }]
        .into())
    }

    async fn get_issue(&self, _key: &str) -> Result<Issue> {
        Err(devboy_core::Error::NotFound("not implemented".into()))
    }

    async fn create_issue(&self, _input: CreateIssueInput) -> Result<Issue> {
        Err(devboy_core::Error::NotFound("not implemented".into()))
    }

    async fn update_issue(&self, _key: &str, _input: UpdateIssueInput) -> Result<Issue> {
        Err(devboy_core::Error::NotFound("not implemented".into()))
    }

    async fn get_comments(&self, _issue_key: &str) -> Result<devboy_core::ProviderResult<Comment>> {
        Ok(vec![].into())
    }

    async fn add_comment(&self, _issue_key: &str, _body: &str) -> Result<Comment> {
        Err(devboy_core::Error::NotFound("not implemented".into()))
    }

    fn provider_name(&self) -> &'static str {
        "clickup"
    }
}

#[async_trait]
impl MergeRequestProvider for ClickUpTestProvider {
    fn provider_name(&self) -> &'static str {
        "clickup"
    }
    // Default implementations return ProviderUnsupported
}

#[async_trait]
impl devboy_core::PipelineProvider for ClickUpTestProvider {
    fn provider_name(&self) -> &'static str {
        "test"
    }
}

#[async_trait]
impl Provider for ClickUpTestProvider {
    async fn get_current_user(&self) -> Result<User> {
        Ok(User {
            id: "1".to_string(),
            username: "clickup-user".to_string(),
            name: None,
            email: None,
            avatar_url: None,
        })
    }
}

/// GitLab-like provider that supports both issues and merge requests.
struct GitLabTestProvider;

#[async_trait]
impl IssueProvider for GitLabTestProvider {
    async fn get_issues(&self, _filter: IssueFilter) -> Result<devboy_core::ProviderResult<Issue>> {
        Ok(vec![Issue {
            key: "gitlab#123".to_string(),
            title: "Test Issue".to_string(),
            description: None,
            state: "opened".to_string(),
            source: "gitlab".to_string(),
            labels: vec![],
            assignees: vec![],
            author: None,
            priority: None,
            url: None,
            created_at: None,
            updated_at: None,
            attachments_count: None,
            parent: None,
            subtasks: vec![],
            custom_fields: std::collections::HashMap::new(),
        }]
        .into())
    }

    async fn get_issue(&self, _key: &str) -> Result<Issue> {
        Err(devboy_core::Error::NotFound("not implemented".into()))
    }

    async fn create_issue(&self, _input: CreateIssueInput) -> Result<Issue> {
        Err(devboy_core::Error::NotFound("not implemented".into()))
    }

    async fn update_issue(&self, _key: &str, _input: UpdateIssueInput) -> Result<Issue> {
        Err(devboy_core::Error::NotFound("not implemented".into()))
    }

    async fn get_comments(&self, _issue_key: &str) -> Result<devboy_core::ProviderResult<Comment>> {
        Ok(vec![].into())
    }

    async fn add_comment(&self, _issue_key: &str, _body: &str) -> Result<Comment> {
        Err(devboy_core::Error::NotFound("not implemented".into()))
    }

    fn provider_name(&self) -> &'static str {
        "gitlab"
    }
}

#[async_trait]
impl MergeRequestProvider for GitLabTestProvider {
    async fn get_merge_requests(
        &self,
        _filter: MrFilter,
    ) -> Result<devboy_core::ProviderResult<MergeRequest>> {
        Ok(vec![MergeRequest {
            key: "mr#123".to_string(),
            title: "Test MR".to_string(),
            description: None,
            state: "opened".to_string(),
            source: "gitlab".to_string(),
            source_branch: "feature".to_string(),
            target_branch: "main".to_string(),
            author: None,
            assignees: vec![],
            reviewers: vec![],
            labels: vec![],
            draft: false,
            url: None,
            created_at: None,
            updated_at: None,
        }]
        .into())
    }

    async fn get_merge_request(&self, _key: &str) -> Result<MergeRequest> {
        Err(devboy_core::Error::NotFound("not implemented".into()))
    }

    async fn get_discussions(
        &self,
        _mr_key: &str,
    ) -> Result<devboy_core::ProviderResult<Discussion>> {
        Ok(vec![].into())
    }

    async fn get_diffs(&self, _mr_key: &str) -> Result<devboy_core::ProviderResult<FileDiff>> {
        Ok(vec![].into())
    }

    async fn add_comment(&self, _mr_key: &str, _input: CreateCommentInput) -> Result<Comment> {
        Err(devboy_core::Error::NotFound("not implemented".into()))
    }

    fn provider_name(&self) -> &'static str {
        "gitlab"
    }
}

#[async_trait]
impl devboy_core::PipelineProvider for GitLabTestProvider {
    fn provider_name(&self) -> &'static str {
        "test"
    }
}

#[async_trait]
impl Provider for GitLabTestProvider {
    async fn get_current_user(&self) -> Result<User> {
        Ok(User {
            id: "1".to_string(),
            username: "gitlab-user".to_string(),
            name: None,
            email: None,
            avatar_url: None,
        })
    }
}

// =============================================================================
// Integration Tests
// =============================================================================

/// Context management tools that should always be available.
const CONTEXT_TOOLS: &[&str] = &["list_contexts", "use_context", "get_current_context"];

/// Issue-related tools.
const ISSUE_TOOLS: &[&str] = &[
    "get_issues",
    "get_issue",
    "create_issue",
    "update_issue",
    "get_issue_comments",
    "get_issue_relations",
    "add_issue_comment",
];

const MR_TOOLS: &[&str] = &[
    "get_merge_requests",
    "get_merge_request",
    "get_merge_request_discussions",
    "get_merge_request_diffs",
    "create_merge_request_comment",
];

/// Helper to get tool names from server.
fn get_tool_names(server: &McpServer) -> Vec<String> {
    use devboy_mcp::RequestId;
    use devboy_mcp::protocol::ToolsListResult;

    let resp = server.handle_tools_list(RequestId::Number(1));
    let result: ToolsListResult = serde_json::from_value(resp.result.unwrap()).unwrap();
    result.tools.into_iter().map(|t| t.name).collect()
}

#[test]
fn test_no_providers_only_context_tools() {
    let server = McpServer::new();
    let tools = get_tool_names(&server);

    // Context tools should be available
    for tool in CONTEXT_TOOLS {
        assert!(
            tools.contains(&tool.to_string()),
            "Expected context tool '{}' to be available",
            tool
        );
    }

    // Issue tools should NOT be available
    for tool in ISSUE_TOOLS {
        assert!(
            !tools.contains(&tool.to_string()),
            "Issue tool '{}' should not be available without providers",
            tool
        );
    }

    // MR tools should NOT be available
    for tool in MR_TOOLS {
        assert!(
            !tools.contains(&tool.to_string()),
            "MR tool '{}' should not be available without providers",
            tool
        );
    }
}

#[test]
fn test_clickup_provider_has_issue_tools_but_no_mr_tools() {
    let mut server = McpServer::new();
    server.add_provider(Arc::new(ClickUpTestProvider));
    let tools = get_tool_names(&server);

    // Context tools should be available
    for tool in CONTEXT_TOOLS {
        assert!(
            tools.contains(&tool.to_string()),
            "Expected context tool '{}' to be available",
            tool
        );
    }

    // Issue tools should be available
    for tool in ISSUE_TOOLS {
        assert!(
            tools.contains(&tool.to_string()),
            "Expected issue tool '{}' to be available with ClickUp provider",
            tool
        );
    }

    // MR tools should NOT be available (ClickUp doesn't support MRs)
    for tool in MR_TOOLS {
        assert!(
            !tools.contains(&tool.to_string()),
            "MR tool '{}' should not be available with ClickUp-only provider",
            tool
        );
    }
}

#[test]
fn test_gitlab_provider_has_all_tools() {
    let mut server = McpServer::new();
    server.add_provider(Arc::new(GitLabTestProvider));
    let tools = get_tool_names(&server);

    // Context tools should be available
    for tool in CONTEXT_TOOLS {
        assert!(
            tools.contains(&tool.to_string()),
            "Expected context tool '{}' to be available",
            tool
        );
    }

    // Issue tools should be available
    for tool in ISSUE_TOOLS {
        assert!(
            tools.contains(&tool.to_string()),
            "Expected issue tool '{}' to be available with GitLab provider",
            tool
        );
    }

    // MR tools should be available (GitLab supports MRs)
    for tool in MR_TOOLS {
        assert!(
            tools.contains(&tool.to_string()),
            "Expected MR tool '{}' to be available with GitLab provider",
            tool
        );
    }
}

#[test]
fn test_mixed_providers_clickup_and_gitlab() {
    let mut server = McpServer::new();
    server.add_provider(Arc::new(ClickUpTestProvider));
    server.add_provider(Arc::new(GitLabTestProvider));
    let tools = get_tool_names(&server);

    // All tools should be available when at least one Git provider is configured
    for tool in CONTEXT_TOOLS {
        assert!(
            tools.contains(&tool.to_string()),
            "Expected context tool '{}' to be available",
            tool
        );
    }

    for tool in ISSUE_TOOLS {
        assert!(
            tools.contains(&tool.to_string()),
            "Expected issue tool '{}' to be available",
            tool
        );
    }

    for tool in MR_TOOLS {
        assert!(
            tools.contains(&tool.to_string()),
            "Expected MR tool '{}' to be available with GitLab in mix",
            tool
        );
    }
}

#[test]
fn test_context_switching_affects_tool_availability() {
    let mut server = McpServer::new();

    // Default context has no providers
    server.ensure_context("clickup-only");
    server.add_provider_to_context("clickup-only", Arc::new(ClickUpTestProvider));

    server.ensure_context("gitlab-context");
    server.add_provider_to_context("gitlab-context", Arc::new(GitLabTestProvider));

    // Default context (no providers) - only context tools
    let tools = get_tool_names(&server);
    assert!(!tools.contains(&"get_issues".to_string()));
    assert!(!tools.contains(&"get_merge_requests".to_string()));

    // Switch to ClickUp context - issue tools available, no MR tools
    server.set_active_context("clickup-only").unwrap();
    let tools = get_tool_names(&server);
    assert!(tools.contains(&"get_issues".to_string()));
    assert!(!tools.contains(&"get_merge_requests".to_string()));

    // Switch to GitLab context - all tools available
    server.set_active_context("gitlab-context").unwrap();
    let tools = get_tool_names(&server);
    assert!(tools.contains(&"get_issues".to_string()));
    assert!(tools.contains(&"get_merge_requests".to_string()));
}