|
| 1 | +#!/usr/bin/env bash |
| 2 | +# serve-mcp.sh — Expose the MCP server over HTTP for Docker/remote clients. |
| 3 | +# |
| 4 | +# Wraps supergateway to bridge stdio MCP to Streamable HTTP, setting the |
| 5 | +# correct PATH and workflow config so homebrew-installed tools (xcodegen, |
| 6 | +# create-dmg, etc.) are reachable from the child process. |
| 7 | +# |
| 8 | +# Usage: |
| 9 | +# ./scripts/serve-mcp.sh # defaults: port 9090, all workflows |
| 10 | +# ./scripts/serve-mcp.sh --port 8080 # custom port |
| 11 | +# WORKFLOWS="build-tools,simulator" ./scripts/serve-mcp.sh # specific workflows |
| 12 | +# |
| 13 | +# Docker client config (.mcp.json inside container): |
| 14 | +# { |
| 15 | +# "mcpServers": { |
| 16 | +# "xcode": { |
| 17 | +# "type": "http", |
| 18 | +# "url": "http://host.docker.internal:<port>/mcp" |
| 19 | +# } |
| 20 | +# } |
| 21 | +# } |
| 22 | + |
| 23 | +set -euo pipefail |
| 24 | + |
| 25 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 26 | +PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 27 | + |
| 28 | +# --- PATH: include common tool locations --- |
| 29 | +# homebrew (Apple Silicon + Intel), MacPorts, user-local |
| 30 | +for dir in /opt/homebrew/bin /usr/local/bin /opt/local/bin "$HOME/.local/bin"; do |
| 31 | + [[ -d "$dir" ]] && [[ ":$PATH:" != *":$dir:"* ]] && PATH="$dir:$PATH" |
| 32 | +done |
| 33 | +export PATH |
| 34 | + |
| 35 | +# --- Workflows --- |
| 36 | +# Default: all workflows. Override with WORKFLOWS env var. |
| 37 | +if [[ -z "${XCODEBUILDMCP_ENABLED_WORKFLOWS:-}" ]]; then |
| 38 | + export XCODEBUILDMCP_ENABLED_WORKFLOWS="${WORKFLOWS:-build-tools,simulator,macos,device,doctor,workflow-discovery,project-discovery,utilities}" |
| 39 | +fi |
| 40 | + |
| 41 | +# --- Port --- |
| 42 | +PORT=9090 |
| 43 | +prev_arg="" |
| 44 | +for arg in "$@"; do |
| 45 | + if [[ "$prev_arg" == "--port" ]]; then |
| 46 | + PORT="$arg" |
| 47 | + fi |
| 48 | + prev_arg="$arg" |
| 49 | +done |
| 50 | + |
| 51 | +# --- Launch --- |
| 52 | +echo "MCP server: ${PROJECT_ROOT}/build/cli.js" |
| 53 | +echo "Endpoint: http://localhost:${PORT}/mcp" |
| 54 | +echo "Workflows: ${XCODEBUILDMCP_ENABLED_WORKFLOWS}" |
| 55 | +echo "PATH includes: $(which xcodegen 2>/dev/null || echo '(xcodegen not found)'), $(which codesign 2>/dev/null || echo '(codesign not found)')" |
| 56 | +echo "" |
| 57 | + |
| 58 | +exec npx supergateway \ |
| 59 | + --port "$PORT" \ |
| 60 | + --stdio "node ${PROJECT_ROOT}/build/cli.js mcp" \ |
| 61 | + --outputTransport streamableHttp \ |
| 62 | + --cors \ |
| 63 | + "$@" |
0 commit comments