@@ -16,10 +16,16 @@ MCP (Model Context Protocol) server for App Store Connect API integration, desig
1616# Build the project
1717swift build
1818
19- # Run the MCP server (requires environment variables)
19+ # Run all unit tests (345 tests)
20+ swift test
21+
22+ # Run the MCP server (requires environment variables or companies.json)
2023./.build/debug/asc-mcp
2124
22- # Run tests/debug mode
25+ # Run with worker filtering (for clients with tool limits)
26+ ./.build/debug/asc-mcp --workers apps,builds,versions,reviews
27+
28+ # Run integration tests
2329./.build/debug/asc-mcp --test
2430
2531# Clean build
@@ -28,37 +34,52 @@ swift package clean
2834
2935## Environment Configuration
3036
31- Uses ` companies.json ` for multi-account configuration. Each company entry contains ` keyID ` , ` issuerID ` , and ` privateKeyPath ` .
37+ Three config methods (checked in priority order):
38+ 1 . ` --companies /path/to/companies.json ` (CLI argument)
39+ 2 . ` ASC_MCP_COMPANIES ` env var → path to JSON file
40+ 3 . Default JSON: ` ~/.config/asc-mcp/companies.json `
41+ 4 . ` ASC_COMPANY_1_KEY_ID ` , ` ASC_COMPANY_2_KEY_ID ` ... (multi-company env vars)
42+ 5 . ` ASC_KEY_ID ` + ` ASC_ISSUER_ID ` + ` ASC_PRIVATE_KEY_PATH ` (single company env vars)
43+
44+ Each company needs: ` keyID ` , ` issuerID ` , ` privateKeyPath ` (path to ` .p8 ` file).
3245
3346## Architecture
3447
3548### Core Components
3649
3750** WorkerManager** (` Workers/MainWorker/WorkerManager.swift ` ) — central registry, routes tool calls by prefix.
3851
39- ** Workers** (17 workers, ~ 109 tools):
52+ ** Workers** (25 workers, ~ 188 tools):
4053
4154| Worker | Prefix | Tools | Domain |
4255| --------| --------| -------| --------|
4356| CompaniesWorker | ` company_ ` | 3 | Multi-account management |
4457| AuthWorker | ` auth_ ` | 4 | JWT tokens |
45- | AppsWorker | ` apps_ ` | 9 | App listing, metadata, localizations, create/delete localization |
58+ | AppsWorker | ` apps_ ` | 9 | App listing, metadata, localizations |
4659| BuildsWorker | ` builds_ ` | 4 | Build management |
47- | BuildBetaDetailsWorker | ` builds_*_beta_ ` | 9 | TestFlight localizations, notifications, beta groups |
48- | BuildProcessingWorker | ` builds_*_processing_ ` | 5 | Build states, encryption |
60+ | BuildBetaDetailsWorker | ` builds_*_beta_ ` | 8 | TestFlight localizations, notifications, beta groups |
61+ | BuildProcessingWorker | ` builds_*_processing_ ` | 4 | Build states, encryption |
4962| AppLifecycleWorker | ` app_versions_ ` | 12 | Versions, submit, release, phased rollout |
50- | ReviewsWorker | ` reviews_ ` | 8 | Customer reviews and responses |
63+ | ReviewsWorker | ` reviews_ ` | 7 | Customer reviews and responses |
5164| BetaGroupsWorker | ` beta_groups_ ` | 9 | TestFlight groups CRUD, testers, builds |
52- | InAppPurchasesWorker | ` iap_ ` | 12 | IAP, subscriptions, localizations CRUD, submit |
65+ | InAppPurchasesWorker | ` iap_ ` | 17 | IAP, subscriptions, localizations, prices, screenshots |
5366| ProvisioningWorker | ` provisioning_ ` | 17 | Bundle IDs, devices, certificates, profiles, capabilities |
5467| BetaTestersWorker | ` beta_testers_ ` | 6 | Tester management, search, invite |
5568| AppInfoWorker | ` app_info_ ` | 6 | App info, categories, localizations |
5669| PricingWorker | ` pricing_ ` | 6 | Territories, availability, price points/schedule |
57- | UsersWorker | ` users_ ` | 6 | Team members, roles, invitations |
58- | AppEventsWorker | ` app_events_ ` | 6 | In-app events CRUD, localizations |
59- | AnalyticsWorker | ` analytics_ ` | 4 | Sales/financial reports, analytics requests |
60-
61- ** Services** : HTTPClient (actor, GET/POST/PATCH/PUT/DELETE + retry with 429), JWTService (ES256)
70+ | UsersWorker | ` users_ ` | 7 | Team members, roles, invitations |
71+ | AppEventsWorker | ` app_events_ ` | 9 | In-app events CRUD, localizations |
72+ | AnalyticsWorker | ` analytics_ ` | 11 | Sales/financial reports, app summary, analytics reports/instances/segments, snapshot status |
73+ | SubscriptionsWorker | ` subscriptions_ ` | 15 | Subscription CRUD, groups, localizations, prices, submit |
74+ | OfferCodesWorker | ` offer_codes_ ` | 7 | Subscription offer codes, one-time codes |
75+ | WinBackOffersWorker | ` winback_ ` | 5 | Win-back offers for subscriptions |
76+ | ScreenshotsWorker | ` screenshots_ ` | 12 | Screenshots, previews, sets, reorder |
77+ | CustomProductPagesWorker | ` custom_pages_ ` | 10 | Custom product pages, versions, localizations |
78+ | ProductPageOptimizationWorker | ` ppo_ ` | 9 | A/B test experiments, treatments |
79+ | PromotedPurchasesWorker | ` promoted_ ` | 6 | Promoted in-app purchases, images |
80+ | MetricsWorker | ` metrics_ ` | 5 | Performance/power metrics, diagnostics |
81+
82+ ** Services** : HTTPClient (actor, GET/POST/PATCH/PUT/DELETE + retry with 429), JWTService (ES256), CompaniesManager
6283
6384### Key Implementation Details
6485
@@ -79,20 +100,52 @@ Uses `companies.json` for multi-account configuration. Each company entry contai
79100
80101## Testing
81102
82- Test mode (` --test ` flag) performs:
83- 1 . Lists app versions to find editable one
84- 2 . If found, updates What's New field
85- 3 . Verifies the update succeeded
103+ ### Unit Tests (Swift Testing)
104+
105+ ``` bash
106+ swift test # Run all 345 tests across 28 suites
107+ ```
108+
109+ Test categories:
110+ - ** Worker tests** (` Tests/ASCMCPTests/Workers/ ` ):
111+ - ` WorkerToolDefinitionsTests ` — tool count and name correctness per worker
112+ - ` WorkerRoutingTests ` — unknown tool throws ` MCPError.methodNotFound `
113+ - ` ParameterValidationTests ` — missing required params returns ` isError `
114+ - ** Model tests** (` Tests/ASCMCPTests/Models/ ` ) — decode, roundtrip, edge cases
115+ - ** Service tests** (` Tests/ASCMCPTests/Services/ ` ) — JWT generation
116+ - ** Helper tests** (` Tests/ASCMCPTests/HelperTests/ ` ) — JSON formatting, pagination
117+ - ** Core tests** (` Tests/ASCMCPTests/Core/ ` ) — ASCError, config models
118+
119+ Test infrastructure: ` TestFactory ` (` Tests/ASCMCPTests/Helpers/TestHelpers.swift ` ) — creates mock HTTPClient, JWTService, loads fixtures.
120+
121+ ### Integration Test Mode
122+
123+ ``` bash
124+ ./.build/debug/asc-mcp --test # Test company switching
125+ ./.build/debug/asc-mcp --test-metadata # Test metadata update
126+ ```
86127
87128## Common Tasks
88129
89- ### Adding New Tool
130+ ### Adding New Tool to Existing Worker
131+
132+ 1 . Implement handler in ` Worker+Handlers.swift `
133+ 2 . Add tool definition in ` Worker+ToolDefinitions.swift `
134+ 3 . Register in worker's ` getTools() ` array
135+ 4 . Add case to worker's ` handleTool() ` switch
136+ 5 . No changes needed in WorkerManager — it automatically routes by prefix
137+
138+ ### Adding New Worker
90139
91- 1 . Implement method in appropriate Worker (e.g., ` AppsWorker+Handlers.swift ` )
92- 2 . Add tool definition method in Worker's tool definitions file (e.g., ` AppsWorker+ToolDefinitions.swift ` )
93- 3 . Register the tool in Worker's ` getTools() ` method
94- 4 . Add case to Worker's ` handleTool() ` switch
95- 5 . No changes needed in WorkerManager - it automatically routes by prefix
140+ 1 . Create directory ` Workers/MyWorker/ ` with 3 files:
141+ - ` MyWorker.swift ` — class, ` getTools() ` , ` handleTool() ` switch
142+ - ` MyWorker+ToolDefinitions.swift ` — tool schemas
143+ - ` MyWorker+Handlers.swift ` — handler implementations
144+ 2 . Create models in ` Models/MyDomain/MyModels.swift `
145+ 3 . Register in ` WorkerManager.swift ` : property, init, ` registerWorkers() ` (ListTools + CallTool), ` reinitializeWorkers() ` , getter method
146+ 4 . Add worker name to ` EntryPoint.swift ` → ` validWorkers ` set
147+ 5 . Add prefix description to ` Application.swift ` → server instructions
148+ 6 . Update tests: ` WorkerToolDefinitionsTests ` , ` WorkerRoutingTests ` , ` ParameterValidationTests `
96149
97150### Debugging API Issues
98151
@@ -103,10 +156,20 @@ Test mode (`--test` flag) performs:
103156
104157## Important Files
105158
106- - ` main.swift ` : Entry point with test mode
159+ - ` EntryPoint.swift ` : Entry point with ` --workers ` filtering and test modes
160+ - ` Core/Application.swift ` : MCP server setup and initialization
107161- ` Workers/MainWorker/WorkerManager.swift ` : Tool registry and routing
108- - ` Models/ ` : API response/request models (AppStoreConnect, Builds, InAppPurchases, Provisioning)
162+ - ` Models/ ` : API response/request models organized by domain:
163+ - ` AppStoreConnect/ ` , ` Builds/ ` , ` AppLifecycle/ ` — apps, versions, builds
164+ - ` InAppPurchases/ ` , ` Subscriptions/ ` — IAP, subscriptions, offer codes, win-back
165+ - ` Marketing/ ` — screenshots, custom pages, PPO experiments, promoted purchases
166+ - ` Metrics/ ` , ` Analytics/ ` , ` AppEvents/ ` — performance, reports, events
167+ - ` Provisioning/ ` , ` Pricing/ ` , ` Users/ ` , ` AppInfo/ ` — provisioning, pricing, users
168+ - ` Shared/ ` — shared types (upload operations, image assets)
109169- ` Services/HTTPClient.swift ` : HTTP actor with JWT auth and retry logic
170+ - ` Services/CompaniesManager.swift ` : Multi-account management
171+ - ` Services/JWTService.swift ` : ES256 JWT token generation
172+ - ` Helpers/ ` : JSONFormatter, SafeJSONHelpers, PaginationHelper, StderrWriter
110173
111174## Development Workflow Rules
112175
0 commit comments