Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ alter that request's response contract.
Each Xcode installation has at most one owned headless host process, shared by
every MCP session.
A host connection owns its process: it starts it on first use, sends one
`initialize`, assigns upstream request IDs, returns progress to the requesting
`initialize`, assigns host request IDs, returns progress to the requesting
session, and sends `notifications/cancelled` when a request is cancelled or
times out. A timeout fails only that request.

Expand All @@ -67,7 +67,7 @@ in the result's `_meta`. The broker records that report for the session and
removes it from the client's result.

When a process exits or violates the protocol, its in-flight requests fail with
`upstream unavailable`, handles created by that process expire, and the next
`host unavailable`, handles created by that process expire, and the next
request starts a new process. Delivery-unknown mutations are not replayed.
Closing an MCP session releases its handles. A headless host for a non-default
installation stops after `NativeHostBroker.idleHostGracePeriod`
Expand All @@ -94,12 +94,12 @@ startup; write failure unwinds acquired resources.

## Streamable HTTP contract

- Every request is checked by one Host and Origin policy before route resolution, session creation, debug reset, or upstream I/O. This includes `/health`, `/debug/*`, MCP routes, and unknown routes.
- Every request is checked by one Host and Origin policy before route resolution, session creation, debug reset, or host I/O. This includes `/health`, `/debug/*`, MCP routes, and unknown routes.
- A `Host` header must name an IP address, `localhost`, or the configured listen host, with any port, since a port forward delivers the client's port; multiple or other values return `403`. A page that rebinds its own domain to the listener therefore cannot reach it. A missing `Host` is allowed.
- A missing `Origin` header is allowed for non-browser clients. When `Origin` is present it must be one valid HTTP(S) origin whose host and port match the actual listener policy; empty, multiple, `null`, malformed, and cross-origin values return `403`.
- `/debug/upstreams` and `/debug/reset` return `404` unless the server enables debug endpoints (`--debug-endpoints`) and listens on loopback.
- `/debug/hosts` and `/debug/reset` return `404` unless the server enables debug endpoints (`--debug-endpoints`) and listens on loopback.
- `POST /mcp` requires `Content-Type: application/json`. A client whose `Accept` omits `text/event-stream` gets every reply as JSON and no progress.
- A POST that carries a request is answered with one JSON-RPC response; a client notification or response gets `202`. When the request reports progress before its reply, or its reply takes longer than 15 seconds, the POST response becomes an event stream (`text/event-stream`) that carries the progress notifications and keepalive comments every 15 seconds, and ends with the response; otherwise the response is JSON. Clients give up on a response that does not start within a minute, and on a stream that stays silent for a few minutes. `initialize` is never streamed. When a host's response is not valid JSON-RPC for its request, the client receives error `-32603` (`invalid upstream response`) for that request.
- A POST that carries a request is answered with one JSON-RPC response; a client notification or response gets `202`. When the request reports progress before its reply, or its reply takes longer than 15 seconds, the POST response becomes an event stream (`text/event-stream`) that carries the progress notifications and keepalive comments every 15 seconds, and ends with the response; otherwise the response is JSON. Clients give up on a response that does not start within a minute, and on a stream that stays silent for a few minutes. `initialize` is never streamed. When a host's response is not valid JSON-RPC for its request, the client receives error `-32603` (`invalid host response`) for that request.
- HTTP owns MCP sessions. It generates `MCP-Session-Id` on `initialize`, ignoring caller-provided ids, and ends the runtime's side of a session when the session is deleted, expires, or the server stops. An `initialize` that arrives while the server is stopping returns `503`.
- After initialize, `POST`, `GET`, and `DELETE` require `MCP-Session-Id`. An explicit `MCP-Protocol-Version` must be valid, supported, and match the negotiated version.
- When `MCP-Protocol-Version` is omitted, the server uses the session's negotiated version. If no negotiated version exists, it evaluates the protocol-defined fallback `2025-03-26` and returns `400` when that version is unsupported.
Expand All @@ -109,7 +109,7 @@ startup; write failure unwinds acquired resources.
- A GET stream carries a keepalive comment every 15 seconds.
- A session with no in-flight HTTP request and no open SSE stream is retained for five minutes after its last client activity so that an interrupted SSE connection can reconnect. A one-minute sweep then terminates stale sessions and their buffered notifications; outbound server notifications do not extend this lifetime.
- HTTP connection, SSE connection, request, and response access events are debug telemetry, including expected protocol-level `4xx` responses. The response remains the client-visible error contract.
- Empty, singleton, and mixed JSON-RPC arrays return `400`; the internal executor and response router operate on typed single messages. An array response from an upstream is a protocol violation.
- Empty, singleton, and mixed JSON-RPC arrays return `400`; the internal executor and response router operate on typed single messages. An array response from a host is a protocol violation.
- Host `notifications/progress` is delivered only on the POST response stream of the request that carries that progress token, never to another session, another request, or a GET stream. It is dropped when the request has finished, and while a client that falls behind has not read the earlier ones. Other host notifications fan out to the GET streams of the sessions using that host.
- HTTP owns each session's bounded SSE notification buffer. On overflow it drops the oldest notification and emits at most one warning per 30 seconds per session. `dropped_notifications` is cumulative for that session, while the warning also reports the dropped delta and sanitized methods of the notifications actually evicted; notification payloads are never logged. Unhandled server notifications remain debug-level events.

Expand Down
2 changes: 1 addition & 1 deletion Docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Use `xcode-mcp-proxy-server --help` for CLI usage.
| `--max-body-bytes bytes` | Maximum accepted HTTP request body size. |
| `--share-compilation-cache` | Enable shared compilation caching and Swift/Clang prefix mapping in native hosts. Off by default; see [compilation caching](#compilation-caching). |
| `--auto-approve` | Automatically allow MCP connection dialogs for agents connecting directly to GUI Xcode. Off by default; requires macOS Accessibility access. |
| `--debug-endpoints` | Serve `/debug/upstreams` and `/debug/reset` when the listener is loopback. Off by default. |
| `--debug-endpoints` | Serve `/debug/hosts` and `/debug/reset` when the listener is loopback. Off by default. |
| `--force-restart` | Terminate an existing `xcode-mcp-proxy-server` on the listen port before starting. |
| `--dry-run` | Print the resolved server command without starting it. |

Expand Down
2 changes: 1 addition & 1 deletion Docs/maintainer-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ three GUI tools, including `XcodeListWindows`, from installed Xcode schemas
without executing their actions. Standalone native-host transports omit this
flag and advertise only executable tools. The broker keeps
their native tab selectors and results, and lazily starts Apple's `mcpbridge`
through the existing upstream connection transport. That connection shares
through the existing host connection transport. That connection shares
request-ID/progress mapping, cancellation, restart, and shutdown handling with
headless connections. Bridge failures never enter Organizer collection.
Stopping the bridge terminates only the owned bridge process, leaving Xcode
Expand Down
5 changes: 5 additions & 0 deletions Docs/migrations/native-backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,8 @@ after initialize and send individual JSON-RPC messages instead of batch arrays.
An explicit `MCP-Protocol-Version` must match negotiation. The SDK handles
these details. See the [HTTP contract](../architecture.md#streamable-http-contract)
for expiry, recovery, and header errors.

The debug snapshot moved from `/debug/upstreams` to `/debug/hosts`. Host error
messages say `host` instead of `upstream`: `host unavailable`, `host overloaded`,
`host timeout`, and `invalid host response`. The JSON-RPC error codes are
unchanged.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package enum MCPBridgeRuntimeError: Error, Equatable, Sendable {
package enum MCPRuntimeError: Error, Equatable, Sendable {
case closed
case invalidRequest(String)
case invalidResponse(String)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/// Raw invocation of a configured MCP process.
package struct MCPBridgeInvocation: Equatable, Sendable {
/// Raw process command used to launch the bridge.
package struct MCPProcessInvocation: Equatable, Sendable {
/// Raw process command used to launch the process.
package let command: String

/// Raw process arguments passed to the bridge command.
/// Raw process arguments passed to the command.
package let arguments: [String]

/// Creates a raw bridge process invocation.
/// Creates a raw process invocation.
package init(command: String, arguments: [String]) {
self.command = command
self.arguments = arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ package enum NativeHostInvocation {
environment: [String: String] = ProcessInfo.processInfo.environment,
executableURL: URL? = Bundle.main.executableURL,
fileSystem: FileSystemClient = .liveValue
) throws -> MCPBridgeInvocation {
) throws -> MCPProcessInvocation {
let executable: URL
if let bundleURL {
executable = try resolveExecutable(in: bundleURL, fileSystem: fileSystem)
Expand All @@ -35,21 +35,21 @@ package enum NativeHostInvocation {
guard let bundle = candidates.first(where: {
fileSystem.isExecutableFile($0.appendingPathComponent("Contents/MacOS/\(executableName)").path)
}) else {
throw MCPBridgeRuntimeError.transportUnavailable("Cannot find \(bundleName). Install XcodeMCPKit or supply nativeHostBundleURL / XCODE_MCP_NATIVE_HOST_BUNDLE.")
throw MCPRuntimeError.transportUnavailable("Cannot find \(bundleName). Install XcodeMCPKit or supply nativeHostBundleURL / XCODE_MCP_NATIVE_HOST_BUNDLE.")
}
executable = try resolveExecutable(in: bundle, fileSystem: fileSystem)
}
var arguments: [String] = []
if let developerDirectoryURL { arguments += ["--developer-dir", developerDirectoryURL.path] }
if sharesCompilationCache { arguments.append("--share-compilation-cache") }
return MCPBridgeInvocation(command: executable.path, arguments: arguments)
return MCPProcessInvocation(command: executable.path, arguments: arguments)
}

private static func resolveExecutable(in bundleURL: URL, fileSystem: FileSystemClient) throws -> URL {
let executable = bundleURL.standardizedFileURL.resolvingSymlinksInPath()
.appendingPathComponent("Contents/MacOS/\(executableName)")
guard fileSystem.isExecutableFile(executable.path) else {
throw MCPBridgeRuntimeError.transportUnavailable("Native helper executable is unavailable: \(executable.path)")
throw MCPRuntimeError.transportUnavailable("Native helper executable is unavailable: \(executable.path)")
}
return executable
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

extension Upstream {
extension MCPProcess {
/// Where an owned process session reports conditions that it handles itself, such as a
/// dropped stdout line or a failed signal.
package struct Diagnostics: Sendable {
Expand Down
Loading