---
id: w1/m18/t005
title: Thread rootDir through REST/GraphQL/MCP
worker: worker1
status: done
estimate: 45m
depends_on: [w1/m18/t001]
---

## Objective

Make `rootDir` settable and readable identically across bex-api's REST, GraphQL, and MCP adapters, following the same threading pattern already used for `Repo`/`Branch`.

## Context

- `lego/backend/internal/apps/service.go` — `CreateOpts`/`UpdateOpts` (and their mapping to the `App` CR, ~lines 290-480) carry `Repo`, `Branch`.
- `lego/backend/internal/apps/rest.go` — create/update request+response shapes (~lines 51-136) carry `Repo`, `Branch` as JSON fields.
- `lego/backend/internal/apps/graphql.go` — `repo`/`branch` argument configs and mutation resolvers (~lines 317-341).
- `lego/backend/internal/apps/mcp.go` — `Repo`/`Branch` fields with `jsonschema` doc tags on the deploy/create tool input structs (~lines 73-155).
- Every verb starts with `s.Authorize(ctx, core.Rel...)` per `internal/api/CLAUDE.md` — no change needed here since this only adds a field, not a new verb.

## Steps

1. Add `RootDir string` to `CreateOpts`/`UpdateOpts` in `service.go` and to the CR-mapping code (mirroring how `Repo`/`Branch` are copied to `dst.Repo`/`dst.Branch`).
2. Add `RootDir`/`rootDir` to the REST create/update request and response JSON shapes in `rest.go`.
3. Add a `rootDir` GraphQL argument + field to the relevant mutation/query in `graphql.go`.
4. Add `RootDir string` with a `jsonschema` doc tag to the relevant MCP tool input/output structs in `mcp.go`.
5. Confirm all three adapters round-trip the field identically (set via one, readable via all three).

## Files

- `lego/backend/internal/apps/service.go`
- `lego/backend/internal/apps/rest.go`
- `lego/backend/internal/apps/graphql.go`
- `lego/backend/internal/apps/mcp.go`

## Acceptance criteria

- [x] `rootDir` is settable on create and update via REST, GraphQL, and MCP
- [x] `rootDir` is readable on the corresponding get/list responses via all three adapters
- [x] Field semantics (optional, empty = repo root) match across all three
- [x] `go build ./...` and existing adapter tests in `lego/backend/` stay green

## Out of scope

- Dashboard UI for editing `rootDir` — separate follow-on milestone (`w5/m13`).
