# `OzMcp.Transport.Stdio.Console`
[🔗](https://github.com/oz-elixir/oz_mcp/blob/v0.9.0/lib/oz_mcp/transport/stdio/console.ex#L1)

Puts the standard input and output of the process in a shape the stdio
transport can use.

A server on stdio must write JSON-RPC messages to stdout and nothing
else: one log line or one stray `IO.puts/1` breaks the protocol of the
client. `open/0` returns the two functions the transport takes as its
`:read` and `:write` options and prepares the environment: the
encoding of the standard IO device becomes UTF-8, the default handler
of the `Logger` moves to stderr and the group leader of the calling
process moves to the standard error device, so every process that
starts later writes its stray output to stderr too.

Call it once, first thing, in the process that starts the transport.

# `open`

```elixir
@spec open() :: %{
  read: (-&gt; {:ok, binary()} | :eof | {:error, term()}),
  write: (iodata() -&gt; :ok | {:error, term()})
}
```

# `reader`

```elixir
@spec reader(device :: pid() | atom()) :: (-&gt; {:ok, binary()}
                                        | :eof
                                        | {:error, term()})
```

The function the transport takes as its `:read` option: one line of
stdin per call, as `{:ok, line}`, `:eof`, or `{:error, reason}`.

# `redirect_logger`

```elixir
@spec redirect_logger() :: :ok
```

Moves the default handler of the `Logger` to stderr and keeps its
level, formatter and filters. Does nothing when there is no default
handler.

# `writer`

```elixir
@spec writer(device :: pid() | atom()) :: (iodata() -&gt; :ok | {:error, term()})
```

The function the transport takes as its `:write` option: it writes the
message to stdout, `:ok`, or `{:error, reason}` when the write fails.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
