Skip to content

Commit 5fa466f

Browse files
committed
Add XCODEBUILDMCP_ENABLED_WORKFLOWS environment variable for selective workflow loading
- Added registerSelectedWorkflows() function to load only specified workflows - Modified main server initialization to check for XCODEBUILDMCP_ENABLED_WORKFLOWS in static mode - Updated documentation with usage examples and available workflows - Allows clients without MCP sampling to reduce context window usage
1 parent 25d637b commit 5fa466f

File tree

4 files changed

+96
-4
lines changed

4 files changed

+96
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [Unreleased]
4+
### Added
5+
- **Selective Workflow Loading**: New `XCODEBUILDMCP_ENABLED_WORKFLOWS` environment variable allows loading only specific workflow groups in static mode, reducing context window usage for clients that don't support MCP sampling
6+
37
## [v1.11.2] - 2025-08-08
48
- Fixed "registerTools is not a function" errors during package upgrades
59

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,44 @@ Example MCP client configuration:
261261
}
262262
```
263263

264+
### Selective Workflow Loading (Static Mode)
265+
266+
For clients that don't support MCP Sampling but still want to reduce context window usage, you can selectively load only specific workflows using the `XCODEBUILDMCP_ENABLED_WORKFLOWS` environment variable:
267+
268+
```json
269+
{
270+
"mcpServers": {
271+
"XcodeBuildMCP": {
272+
"command": "npx",
273+
"args": [
274+
"-y",
275+
"xcodebuildmcp@latest"
276+
],
277+
"env": {
278+
"XCODEBUILDMCP_ENABLED_WORKFLOWS": "simulator,device,project-discovery"
279+
}
280+
}
281+
}
282+
}
283+
```
284+
285+
**Available Workflows:**
286+
- `device` (14 tools) - iOS Device Development
287+
- `simulator` (18 tools) - iOS Simulator Development
288+
- `simulator-management` (7 tools) - Simulator Management
289+
- `swift-package` (6 tools) - Swift Package Manager
290+
- `project-discovery` (5 tools) - Project Discovery
291+
- `macos` (11 tools) - macOS Development
292+
- `ui-testing` (11 tools) - UI Testing & Automation
293+
- `logging` (4 tools) - Log Capture & Management
294+
- `project-scaffolding` (2 tools) - Project Scaffolding
295+
- `utilities` (1 tool) - Project Utilities
296+
- `doctor` (1 tool) - System Doctor
297+
- `discovery` (1 tool) - Dynamic Tool Discovery
298+
299+
> [!NOTE]
300+
> The `XCODEBUILDMCP_ENABLED_WORKFLOWS` setting only works in Static Mode. If `XCODEBUILDMCP_DYNAMIC_TOOLS=true` is set, the selective workflow setting will be ignored.
301+
264302
### Usage Example
265303

266304
Once enabled, AI agents automatically discover and load relevant tools based on context. For example, when you mention working on an iOS app or the agent detects iOS development tasks in your workspace, it will automatically use the `discover_tools` tool to load the appropriate simulator and project tools needed for your workflow.

src/index.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ import process from 'node:process';
3434

3535
// Import resource management
3636
import { registerResources } from './core/resources.js';
37-
import { registerDiscoveryTools, registerAllToolsStatic } from './utils/tool-registry.js';
37+
import {
38+
registerDiscoveryTools,
39+
registerAllToolsStatic,
40+
registerSelectedWorkflows,
41+
} from './utils/tool-registry.js';
3842

3943
/**
4044
* Main function to start the server
@@ -72,9 +76,17 @@ async function main(): Promise<void> {
7276
await registerDiscoveryTools(server);
7377
log('info', '💡 Use discover_tools to enable additional workflows based on your task.');
7478
} else {
75-
// EXPLICIT STATIC MODE: Load all tools immediately
76-
log('info', '🚀 Initializing server in static tools mode...');
77-
await registerAllToolsStatic(server);
79+
// STATIC MODE: Check for selective workflows
80+
const enabledWorkflows = process.env.XCODEBUILDMCP_ENABLED_WORKFLOWS;
81+
82+
if (enabledWorkflows) {
83+
const workflowNames = enabledWorkflows.split(',');
84+
log('info', `🚀 Initializing server with selected workflows: ${workflowNames.join(', ')}`);
85+
await registerSelectedWorkflows(server, workflowNames);
86+
} else {
87+
log('info', '🚀 Initializing server in static tools mode...');
88+
await registerAllToolsStatic(server);
89+
}
7890
}
7991

8092
await registerResources(server);

src/utils/tool-registry.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,44 @@ export async function registerDiscoveryTools(server: McpServer): Promise<void> {
145145
log('info', `✅ Registered ${registeredCount} discovery tools in dynamic mode.`);
146146
}
147147

148+
/**
149+
* Register selected workflows based on environment variable
150+
*/
151+
export async function registerSelectedWorkflows(
152+
server: McpServer,
153+
workflowNames: string[],
154+
): Promise<void> {
155+
const { loadWorkflowGroups } = await import('../core/plugin-registry.js');
156+
const workflowGroups = await loadWorkflowGroups();
157+
const selectedTools = [];
158+
159+
for (const workflowName of workflowNames) {
160+
const workflow = workflowGroups.get(workflowName.trim());
161+
if (workflow) {
162+
for (const tool of workflow.tools) {
163+
selectedTools.push({
164+
name: tool.name,
165+
config: {
166+
description: tool.description ?? '',
167+
inputSchema: tool.schema,
168+
},
169+
callback: (args: unknown): Promise<ToolResponse> =>
170+
tool.handler(args as Record<string, unknown>),
171+
});
172+
}
173+
}
174+
}
175+
176+
if (selectedTools.length > 0) {
177+
server.registerTools(selectedTools);
178+
}
179+
180+
log(
181+
'info',
182+
`✅ Registered ${selectedTools.length} tools from workflows: ${workflowNames.join(', ')}`,
183+
);
184+
}
185+
148186
/**
149187
* Register all tools (static mode) - no tracking needed since these won't be removed
150188
*/

0 commit comments

Comments
 (0)