# MCP server

> Run bytepeel as a Model Context Protocol server so an AI agent can call it as a tool, and the peel and set tools it offers.

`bytepeel mcp` runs a [Model Context Protocol](https://modelcontextprotocol.io)
server on stdio, so an agent can call bytepeel as a tool. It is built into the
same binary. In Claude Code:

```sh
claude mcp add bytepeel -- npx -y bytepeel mcp     # or: -- bytepeel mcp, if installed
```

Other clients take the same command in their JSON config:

```json
{ "mcpServers": { "bytepeel": { "command": "npx", "args": ["-y", "bytepeel", "mcp"] } } }
```

It is listed in the [MCP Registry](https://registry.modelcontextprotocol.io) as
`io.github.Pinta365/bytepeel`, and on
[Glama](https://glama.ai/mcp/servers/Pinta365/bytepeel), where you can browse
its tools and try it in the [MCP Inspector](https://glama.ai/mcp/inspector)
before installing.

## Tools

- **`peel`** decodes `input` (text) or `file` (a path), with optional
  `get`, `format` (`json`, `tree`, or `raw`, which returns the whole
  payload as text, or as hex when it is binary) and the CLI's options (`in`,
  `as`, `depth`, `alts`, `max_items`).
- **`set`** applies `edits` (`[{"op":"set","path":"3.1","value":"300"}]`;
  `op` can also be `add` or `del`) and returns the re-encoded data. Text
  comes back as text and binary data as hex. Pass `output_file` to write the
  result instead; an existing file is replaced only with `overwrite: true`.

Pass binary data as a `file`; text data (hex, base64, PEM, a JWT) can go
inline as `input`.

## Protocol details

The CLI binary is also a Model Context Protocol server: `bytepeel mcp` reads
newline-delimited JSON-RPC 2.0 on stdin and writes responses on stdout. It
implements `initialize` (protocol versions 2024-11-05, 2025-03-26, 2025-06-18
and 2025-11-25; a client asking for another gets 2025-06-18), `ping`,
`tools/list` and `tools/call`. Notifications get no response. It has no
dependencies; requests are read by a strict JSON parser in the CLI crate.

| Tool | Arguments | Result text |
|---|---|---|
| `peel` | `input` (text) or `file` (path); `get`; `format`: `json` (default), `tree`, or `raw` (with `get`, that item's payload; without, the innermost layer's bytes, as in the CLI) | the CLI's output for the same options; for `raw`, the whole payload as `{"encoding":"text","data":..}` when it is printable UTF-8, else `{"encoding":"hex","data":..}` (lowercase hex) |
| `set` | `input` or `file`; `edits`: `[{op, path, value}]`, applied in order. `op` is `set` (default), `add` or `del`. `value` is a string in the CLI value syntax (`"42"`, `"true"`, `"null"`, `"\\"text\\""`, `"str:text"`, `"hex:0a0b"`, `"sint:-2"`; a JSON number, `true`/`false` or `null` is also accepted); `del` takes none | the same `encoding`/`data` object as `raw` |

Both tools also take the CLI options `in`, `as`, `depth`, `alts` and
`max_items`, and `output_file` (with `overwrite`). With `output_file` the
result (raw bytes for `format: raw` and for `set`) is written to that path
and the text is `{"written":PATH,"bytes":N}`. "Printable" means valid UTF-8 with no control characters other than tab, CR and LF, the rule used for text layers; anything else, such as a binary protobuf that happens to be valid UTF-8, comes back as hex. An existing file is replaced
only with `overwrite: true`; otherwise the call fails with `IO`.

A failed call is a tool result with `isError: true` whose text is the error
JSON (`{"error":{"code":..,"message":..,"offset":..}}`, the same codes as the
CLI). Unknown arguments are `USAGE`. A malformed message is a JSON-RPC error:
`-32700` (not JSON), `-32600` (not a request), `-32601` (unknown method) or
`-32602` (unknown tool, or `params`/`arguments` not an object).
