|
1 | 1 | import { z } from 'zod'; |
2 | 2 | import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; |
3 | 3 | import type { AppStoreConnectClient } from '../api/client.js'; |
| 4 | +import type { |
| 5 | + CiMacOsVersion, |
| 6 | + CiWorkflowAction, |
| 7 | + CiXcodeVersion, |
| 8 | + ScmRepository, |
| 9 | + WorkflowIncludedResource, |
| 10 | +} from '../api/types.js'; |
4 | 11 | import { parseIdentifier } from '../utils/identifiers.js'; |
5 | 12 | import { errorResponse, jsonResponse } from '../utils/tool-response.js'; |
6 | 13 |
|
@@ -70,4 +77,131 @@ export function registerDiscoveryTools( |
70 | 77 | } |
71 | 78 | }, |
72 | 79 | ); |
| 80 | + |
| 81 | + server.registerTool( |
| 82 | + 'get_workflow_details', |
| 83 | + { |
| 84 | + description: |
| 85 | + 'Retrieve detailed Xcode Cloud workflow configuration, including environment, start conditions, actions, and enabled state.', |
| 86 | + inputSchema: { |
| 87 | + workflowId: z.string(), |
| 88 | + }, |
| 89 | + }, |
| 90 | + async ({ workflowId }: { workflowId: string }) => { |
| 91 | + try { |
| 92 | + const workflowIdentifier = parseIdentifier(workflowId, 'workflow'); |
| 93 | + const { workflow, included } = await client.workflows.getById(workflowIdentifier); |
| 94 | + const repository = findIncludedResource<ScmRepository>( |
| 95 | + included, |
| 96 | + workflow.relationships?.repository?.data?.id, |
| 97 | + 'scmRepositories', |
| 98 | + ); |
| 99 | + const xcodeVersion = findIncludedResource<CiXcodeVersion>( |
| 100 | + included, |
| 101 | + workflow.relationships?.xcodeVersion?.data?.id, |
| 102 | + 'ciXcodeVersions', |
| 103 | + ); |
| 104 | + const macOsVersion = findIncludedResource<CiMacOsVersion>( |
| 105 | + included, |
| 106 | + workflow.relationships?.macOsVersion?.data?.id, |
| 107 | + 'ciMacOsVersions', |
| 108 | + ); |
| 109 | + const actions = workflow.attributes.actions ?? []; |
| 110 | + |
| 111 | + return jsonResponse({ |
| 112 | + workflow: { |
| 113 | + id: workflow.id, |
| 114 | + general: { |
| 115 | + name: workflow.attributes.name, |
| 116 | + description: workflow.attributes.description ?? null, |
| 117 | + isEnabled: workflow.attributes.isEnabled, |
| 118 | + isLockedForEditing: workflow.attributes.isLockedForEditing ?? null, |
| 119 | + clean: workflow.attributes.clean, |
| 120 | + containerFilePath: workflow.attributes.containerFilePath, |
| 121 | + lastModifiedDate: workflow.attributes.lastModifiedDate, |
| 122 | + }, |
| 123 | + environment: { |
| 124 | + repository: repository |
| 125 | + ? { |
| 126 | + id: repository.id, |
| 127 | + ownerName: repository.attributes.ownerName ?? null, |
| 128 | + repositoryName: repository.attributes.repositoryName ?? null, |
| 129 | + scmProvider: repository.attributes.scmProvider ?? null, |
| 130 | + defaultBranch: repository.attributes.defaultBranch ?? null, |
| 131 | + httpCloneUrl: repository.attributes.httpCloneUrl ?? null, |
| 132 | + sshCloneUrl: repository.attributes.sshCloneUrl ?? null, |
| 133 | + } |
| 134 | + : null, |
| 135 | + xcodeVersion: xcodeVersion |
| 136 | + ? { |
| 137 | + id: xcodeVersion.id, |
| 138 | + name: xcodeVersion.attributes.name ?? null, |
| 139 | + version: xcodeVersion.attributes.version ?? null, |
| 140 | + supportedTestDestinations: |
| 141 | + xcodeVersion.attributes.testDestinations?.length ?? 0, |
| 142 | + } |
| 143 | + : null, |
| 144 | + macOsVersion: macOsVersion |
| 145 | + ? { |
| 146 | + id: macOsVersion.id, |
| 147 | + name: macOsVersion.attributes.name ?? null, |
| 148 | + version: macOsVersion.attributes.version ?? null, |
| 149 | + } |
| 150 | + : null, |
| 151 | + }, |
| 152 | + startConditions: { |
| 153 | + branch: workflow.attributes.branchStartCondition ?? null, |
| 154 | + manualBranch: workflow.attributes.manualBranchStartCondition ?? null, |
| 155 | + pullRequest: workflow.attributes.pullRequestStartCondition ?? null, |
| 156 | + manualPullRequest: |
| 157 | + workflow.attributes.manualPullRequestStartCondition ?? null, |
| 158 | + scheduled: workflow.attributes.scheduledStartCondition ?? null, |
| 159 | + tag: workflow.attributes.tagStartCondition ?? null, |
| 160 | + manualTag: workflow.attributes.manualTagStartCondition ?? null, |
| 161 | + }, |
| 162 | + actions: actions.map(formatWorkflowAction), |
| 163 | + postActions: [], |
| 164 | + postActionsNote: |
| 165 | + 'The App Store Connect workflow payload did not expose separate post-actions, so this field is empty unless Apple adds that data.', |
| 166 | + }, |
| 167 | + }); |
| 168 | + } catch (error) { |
| 169 | + return errorResponse(error); |
| 170 | + } |
| 171 | + }, |
| 172 | + ); |
| 173 | +} |
| 174 | + |
| 175 | +function findIncludedResource<TResource extends WorkflowIncludedResource>( |
| 176 | + resources: WorkflowIncludedResource[], |
| 177 | + identifier: string | undefined, |
| 178 | + type: TResource['type'], |
| 179 | +): TResource | undefined { |
| 180 | + if (!identifier) { |
| 181 | + return undefined; |
| 182 | + } |
| 183 | + |
| 184 | + return resources.find( |
| 185 | + (resource): resource is TResource => |
| 186 | + resource.id === identifier && resource.type === type, |
| 187 | + ); |
| 188 | +} |
| 189 | + |
| 190 | +function formatWorkflowAction(action: CiWorkflowAction) { |
| 191 | + return { |
| 192 | + name: action.name, |
| 193 | + actionType: action.actionType, |
| 194 | + platform: action.platform ?? null, |
| 195 | + scheme: action.scheme ?? null, |
| 196 | + destination: action.destination ?? null, |
| 197 | + buildDistributionAudience: action.buildDistributionAudience ?? null, |
| 198 | + isRequiredToPass: action.isRequiredToPass ?? null, |
| 199 | + testConfiguration: action.testConfiguration |
| 200 | + ? { |
| 201 | + kind: action.testConfiguration.kind ?? null, |
| 202 | + testPlanName: action.testConfiguration.testPlanName ?? null, |
| 203 | + testDestinations: action.testConfiguration.testDestinations ?? [], |
| 204 | + } |
| 205 | + : null, |
| 206 | + }; |
73 | 207 | } |
0 commit comments