| 1 | using AgentForge.Abstractions; |
| 2 | using AgentForge.Mcp.Core; |
| 3 | |
| 4 | namespace AgentForge.Plugin.MergeRequest; |
| 5 | |
| 6 | internal static class ForgeMergeRequestMcpTools |
| 7 | { |
| 8 | internal static void Register(ForgeMcpToolRegistry registry) |
| 9 | { |
| 10 | ForgeMcpHttpTools.Add(registry, MergeRequestCreateDescriptor, (client, args, ct) => |
| 11 | client.CreateMergeRequestAsync( |
| 12 | ForgeMcpArgParser.RequireString(args, "repo"), |
| 13 | ForgeMcpArgParser.ParseCreateMergeRequest(args), |
| 14 | ct)); |
| 15 | ForgeMcpHttpTools.Add(registry, MergeRequestOpenDescriptor, (client, args, ct) => |
| 16 | client.GetMergeRequestAsync( |
| 17 | ForgeMcpArgParser.RequireString(args, "repo"), |
| 18 | ForgeMcpArgParser.RequireInt(args, "number"), |
| 19 | ct)); |
| 20 | ForgeMcpHttpTools.Add(registry, MergeRequestListDescriptor, (client, args, ct) => |
| 21 | client.ListMergeRequestsAsync(ForgeMcpArgParser.RequireString(args, "repo"), ct)); |
| 22 | ForgeMcpHttpTools.Add(registry, MergeRequestCiDescriptor, (client, args, ct) => |
| 23 | client.GetCiStatusAsync( |
| 24 | ForgeMcpArgParser.RequireString(args, "repo"), |
| 25 | ForgeMcpArgParser.RequireInt(args, "number"), |
| 26 | ct)); |
| 27 | ForgeMcpHttpTools.Add(registry, MergeRequestDiffDescriptor, (client, args, ct) => |
| 28 | client.GetMergeRequestDiffAsync( |
| 29 | ForgeMcpArgParser.RequireString(args, "repo"), |
| 30 | ForgeMcpArgParser.RequireInt(args, "number"), |
| 31 | ct)); |
| 32 | ForgeMcpHttpTools.Add(registry, MergeRequestAcceptDescriptor, (client, args, ct) => |
| 33 | client.AcceptMergeRequestAsync( |
| 34 | ForgeMcpArgParser.RequireString(args, "repo"), |
| 35 | ForgeMcpArgParser.RequireInt(args, "number"), |
| 36 | ct)); |
| 37 | ForgeMcpHttpTools.Add(registry, MergeRequestRejectDescriptor, (client, args, ct) => |
| 38 | client.RejectMergeRequestAsync( |
| 39 | ForgeMcpArgParser.RequireString(args, "repo"), |
| 40 | ForgeMcpArgParser.RequireInt(args, "number"), |
| 41 | ct)); |
| 42 | ForgeMcpHttpTools.Add(registry, MergeRequestCommentDescriptor, (client, args, ct) => |
| 43 | client.AddMergeRequestCommentAsync( |
| 44 | ForgeMcpArgParser.RequireString(args, "repo"), |
| 45 | ForgeMcpArgParser.RequireInt(args, "number"), |
| 46 | ForgeMcpArgParser.ParseAddComment(args), |
| 47 | ct)); |
| 48 | ForgeMcpHttpTools.Add(registry, HandoffRelayDescriptor, (client, args, ct) => |
| 49 | client.HandoffMergeRequestAsync( |
| 50 | ForgeMcpArgParser.RequireString(args, "repo"), |
| 51 | ForgeMcpArgParser.RequireInt(args, "number"), |
| 52 | ForgeMcpArgParser.RequireString(args, "target_repo"), |
| 53 | ct)); |
| 54 | } |
| 55 | |
| 56 | private static readonly ForgeMcpToolDescriptor MergeRequestCreateDescriptor = new() |
| 57 | { |
| 58 | Name = ForgeMcpToolNames.MergeRequestCreate, |
| 59 | Description = "Создать merge request; git push — отдельно.", |
| 60 | InputSchema = ForgeMcpSchemas.Object(new |
| 61 | { |
| 62 | type = "object", |
| 63 | properties = new |
| 64 | { |
| 65 | repo = new { type = "string" }, |
| 66 | title = new { type = "string" }, |
| 67 | source_branch = new { type = "string" }, |
| 68 | target_branch = new { type = "string", description = "По умолчанию main." }, |
| 69 | anchors = ForgeMcpSchemas.Anchors, |
| 70 | author = new { type = "string", description = "oar:LineName; иначе FORGE_ACTOR." }, |
| 71 | }, |
| 72 | required = new[] { "repo", "title", "source_branch" }, |
| 73 | }), |
| 74 | }; |
| 75 | |
| 76 | private static readonly ForgeMcpToolDescriptor MergeRequestOpenDescriptor = new() |
| 77 | { |
| 78 | Name = ForgeMcpToolNames.MergeRequestOpen, |
| 79 | Description = "MR по номеру: ветки, status, mrUrl, anchors.", |
| 80 | InputSchema = ForgeMcpSchemas.Object(new |
| 81 | { |
| 82 | type = "object", |
| 83 | properties = new |
| 84 | { |
| 85 | repo = new { type = "string" }, |
| 86 | number = new { type = "integer" }, |
| 87 | }, |
| 88 | required = new[] { "repo", "number" }, |
| 89 | }), |
| 90 | }; |
| 91 | |
| 92 | private static readonly ForgeMcpToolDescriptor MergeRequestListDescriptor = new() |
| 93 | { |
| 94 | Name = ForgeMcpToolNames.MergeRequestList, |
| 95 | Description = "Список merge requests репозитория.", |
| 96 | InputSchema = ForgeMcpSchemas.Object(new |
| 97 | { |
| 98 | type = "object", |
| 99 | properties = new { repo = new { type = "string" } }, |
| 100 | required = new[] { "repo" }, |
| 101 | }), |
| 102 | }; |
| 103 | |
| 104 | private static readonly ForgeMcpToolDescriptor MergeRequestCiDescriptor = new() |
| 105 | { |
| 106 | Name = ForgeMcpToolNames.MergeRequestCi, |
| 107 | Description = "Последний CI status для MR (pending|success|failure|cancelled|unknown).", |
| 108 | InputSchema = ForgeMcpSchemas.Object(new |
| 109 | { |
| 110 | type = "object", |
| 111 | properties = new |
| 112 | { |
| 113 | repo = new { type = "string" }, |
| 114 | number = new { type = "integer", description = "Номер MR." }, |
| 115 | }, |
| 116 | required = new[] { "repo", "number" }, |
| 117 | }), |
| 118 | }; |
| 119 | |
| 120 | private static readonly ForgeMcpToolDescriptor MergeRequestDiffDescriptor = new() |
| 121 | { |
| 122 | Name = ForgeMcpToolNames.MergeRequestDiff, |
| 123 | Description = "Structured MR diff (files[], stats, per-file patch) — как GitHub/GitLab, не сырой git diff.", |
| 124 | InputSchema = ForgeMcpSchemas.Object(new |
| 125 | { |
| 126 | type = "object", |
| 127 | properties = new |
| 128 | { |
| 129 | repo = new { type = "string" }, |
| 130 | number = new { type = "integer" }, |
| 131 | }, |
| 132 | required = new[] { "repo", "number" }, |
| 133 | }), |
| 134 | }; |
| 135 | |
| 136 | private static readonly ForgeMcpToolDescriptor MergeRequestAcceptDescriptor = new() |
| 137 | { |
| 138 | Name = ForgeMcpToolNames.MergeRequestAccept, |
| 139 | Description = "Принять MR: merge в git и status=merged.", |
| 140 | InputSchema = ForgeMcpSchemas.Object(new |
| 141 | { |
| 142 | type = "object", |
| 143 | properties = new |
| 144 | { |
| 145 | repo = new { type = "string" }, |
| 146 | number = new { type = "integer" }, |
| 147 | }, |
| 148 | required = new[] { "repo", "number" }, |
| 149 | }), |
| 150 | }; |
| 151 | |
| 152 | private static readonly ForgeMcpToolDescriptor MergeRequestRejectDescriptor = new() |
| 153 | { |
| 154 | Name = ForgeMcpToolNames.MergeRequestReject, |
| 155 | Description = "Отклонить MR (status=rejected, без merge).", |
| 156 | InputSchema = ForgeMcpSchemas.Object(new |
| 157 | { |
| 158 | type = "object", |
| 159 | properties = new |
| 160 | { |
| 161 | repo = new { type = "string" }, |
| 162 | number = new { type = "integer" }, |
| 163 | }, |
| 164 | required = new[] { "repo", "number" }, |
| 165 | }), |
| 166 | }; |
| 167 | |
| 168 | private static readonly ForgeMcpToolDescriptor MergeRequestCommentDescriptor = new() |
| 169 | { |
| 170 | Name = ForgeMcpToolNames.MergeRequestComment, |
| 171 | Description = "IOP-комментарий к MR; author или X-Forge-Actor.", |
| 172 | InputSchema = ForgeMcpSchemas.Object(new |
| 173 | { |
| 174 | type = "object", |
| 175 | properties = new |
| 176 | { |
| 177 | repo = new { type = "string" }, |
| 178 | number = new { type = "integer" }, |
| 179 | body = new { type = "string" }, |
| 180 | author = new { type = "string", description = "oar:LineName (или заголовок X-Forge-Actor)." }, |
| 181 | }, |
| 182 | required = new[] { "repo", "number", "body" }, |
| 183 | }), |
| 184 | }; |
| 185 | |
| 186 | private static readonly ForgeMcpToolDescriptor HandoffRelayDescriptor = new() |
| 187 | { |
| 188 | Name = ForgeMcpToolNames.HandoffRelay, |
| 189 | Description = "Relay MR: создать MR в target repo из ветки agent-source MR (source repo must be agent-driven).", |
| 190 | InputSchema = ForgeMcpSchemas.Object(new |
| 191 | { |
| 192 | type = "object", |
| 193 | properties = new |
| 194 | { |
| 195 | repo = new { type = "string", description = "Agent-driven source repo." }, |
| 196 | number = new { type = "integer", description = "Source MR number." }, |
| 197 | target_repo = new { type = "string", description = "Target repo slug (agent- or human-driven)." }, |
| 198 | }, |
| 199 | required = new[] { "repo", "number", "target_repo" }, |
| 200 | }), |
| 201 | }; |
| 202 | } |
| 203 | |