# MCPService.serve(_:write:)

- **Module:** MCPService
- **Package:** LibTmuxMCP
- **Language:** Swift
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-swift/blob/254f8b2be7eb60cacc3ffcb3ea8e456784f582df/Sources/LibTmuxMCP/Serve.swift#L40
- **Page:** https://libtmux.org/en/swift/latest/mcp/reference/mcpservice-serve(_-write-)/

```
MCPService.serve(_:write:)(lines: AsyncStream<String>, write: @escaping (String) async -> Void) -> ()
```

Reads requests from `lines` and writes each answer through `write`.

Returns once `lines` has ended *and* every request it carried has been
answered. The end of input means no more requests, not abandon the ones
in hand: a client that sent a batch and closed its end is still owed the
replies, and cancelling them would drop answers that were already
computed.
Cancelling this call cancels active requests and queued output. The
`write` closure must return cooperatively when its task is cancelled.
`AsyncStream` concretely, rather than any non-throwing `AsyncSequence`:
naming the failure type is what makes a sequence non-throwing, and that
spelling needs macOS 15 where this package supports 13. Package-only
transports share the generic request loop below.
