mcp-xcode
Version:
MCP server that wraps Xcode command-line tools for iOS/macOS development workflows
48 lines • 1.77 kB
JavaScript
import { validateProjectPath } from '../../utils/validation.js';
import { executeCommand, buildXcodebuildCommand } from '../../utils/command.js';
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
export async function xcodebuildListTool(args) {
const { projectPath, outputFormat = 'json' } = args;
try {
// Validate inputs
await validateProjectPath(projectPath);
// Build command
const command = buildXcodebuildCommand('-list', projectPath, {
json: outputFormat === 'json',
});
// Execute command
const result = await executeCommand(command);
if (result.code !== 0) {
throw new McpError(ErrorCode.InternalError, `Failed to list project information: ${result.stderr}`);
}
let responseText;
if (outputFormat === 'json') {
try {
// Parse and format JSON response
const projectInfo = JSON.parse(result.stdout);
responseText = JSON.stringify(projectInfo, null, 2);
}
catch (parseError) {
throw new McpError(ErrorCode.InternalError, `Failed to parse xcodebuild output: ${parseError}`);
}
}
else {
responseText = result.stdout;
}
return {
content: [
{
type: 'text',
text: responseText,
},
],
};
}
catch (error) {
if (error instanceof McpError) {
throw error;
}
throw new McpError(ErrorCode.InternalError, `xcodebuild-list failed: ${error instanceof Error ? error.message : String(error)}`);
}
}
//# sourceMappingURL=list.js.map