TUI and MCP interfaces
fnox provides two interactive access surfaces for secrets: a terminal user interface (TUI) for a person and a Model Context Protocol (MCP) server for an AI agent. Both start from the active configuration and profile, use the shared resolution context, and keep their own rules for how resolved values are shown or passed to another process. See Background and interactive runtime for the wider runtime model.
Terminal user interface
The TUI is a live dashboard for inspecting the active profile and working with secret values during one terminal session. It combines a provider view, a secret view, status messages, and temporary dialogs while background resolution keeps the screen responsive.
Dashboard lifecycle
The fnox tui command prepares a terminal session, loads the selected profile, starts secret resolution, and then owns the session until the user quits. It marks provider work as non-interactive so prompts do not interrupt the screen. home/…/tui.rs• L24-57
The main loop draws the current state before it waits for the next event. A terminal guard and panic hook restore the user's terminal even when the command exits through an error or panic. home/…/tui.rs• L14-23, home/…/terminal.rs• L14-36
The diagram shows how the dashboard turns terminal and resolution events into updated screen state.
flowchart LR
A[fnox tui] --> B[Active config and profile]
B --> C[Dashboard state]
C --> D[Initial secret resolution]
D --> E[Resolution message]
E --> C
F[Keyboard or mouse event] --> C
C --> G[Rendered dashboard]
G --> F
C --> H[Quit]
References: home/…/tui.rs• L28-79 home/…/terminal.rs• L14-36
Dashboard state
The dashboard state is the single source for focus, selection, profile, search, popup, loading, and display status. It also holds the resolved values that the renderer can show or copy. home/…/app.rs• L69-147
User actions change this state rather than writing the configuration. Profile changes rebuild the visible provider and secret sets before starting a new resolution. Editing or setting a secret changes the in-memory view only, so durable changes must use a normal write command such as fnox set. home/…/app.rs• L805-841, home/…/app.rs• L623-738
The TUI ignores a result from an older resolution after a refresh or profile change. This prevents a slow earlier request from replacing the values for the current profile. home/…/app.rs• L247-318
References: home/…/app.rs• L69-147 home/…/app.rs• L247-318 home/…/app.rs• L623-738 home/…/app.rs• L805-841
Event loop
The event handler combines user input, periodic ticks, terminal resize events, and messages from background work into one channel. Keyboard and mouse input update the dashboard state. Resolution messages update loaded values or show an error. home/…/event.rs• L12-23, home/…/tui.rs• L58-75
The loop uses a periodic tick as a redraw opportunity even when the user does not press a key. A resize also sends a tick. The current tick branch has no separate animation or timer behavior, but it keeps the event model open for later screen updates. home/…/event.rs• L31-79
The dashboard supports two input styles. The keyboard path includes navigation, search, profile selection, refresh, detail views, copy, and temporary value changes. The mouse path selects panels and rows and moves through the lists with the wheel. home/…/app.rs• L320-569
References: home/…/event.rs• L12-79 home/…/tui.rs• L58-75 home/…/app.rs• L320-569
Rendered dashboard
The renderer turns dashboard state into a fixed screen layout with a profile header, provider panel, secret panel, status bar, and key hints. It then places the active help, profile, detail, edit, set, confirmation, or error dialog above the main view. home/…/ui.rs• L70-102
The secret panel presents each key with its provider and value state. Values remain hidden by default, while explicit detail and copy actions expose a resolved value to the user. Search filters the secret list by name without changing the underlying profile data. home/…/ui.rs• L172-253, home/…/app.rs• L228-245
The screen uses the terminal's color capability when available and falls back to plain terminal styles when color is disabled. The layout also records panel bounds and scroll offsets so mouse input maps back to the visible row. home/…/ui.rs• L13-68, home/…/ui.rs• L118-170
References: home/…/ui.rs• L13-102 home/…/ui.rs• L118-253 home/…/app.rs• L228-245
Interface components
The TUI has a small set of user-facing component roles: provider navigation, secret navigation, status feedback, key guidance, and modal dialogs. These roles are rendered together from the shared dashboard state, so a selection or load change can update more than one part of the screen.
The public components module is reserved for reusable pieces as the interface grows. The current component roles remain grouped in the main renderer rather than being separate component modules. home/…/mod.rs• L1-13, home/…/ui.rs• L104-316
References: home/…/mod.rs• L1-13 home/…/ui.rs• L104-316 home/…/ui.rs• L318-803
Model Context Protocol server
The MCP server exposes fnox as a session-scoped secret broker for an AI agent. It communicates over standard input and output using MCP's JSON-RPC transport, advertises only enabled tools, and keeps resolved values in memory until the session ends. When it runs under fnox proxy run, it changes from a value broker into a placeholder broker so real values stay with the proxy.
MCP command integration
The fnox mcp command loads the active configuration and profile before it creates the server. It applies the MCP secret allowlist, warns about unknown or incomplete entries, rejects an invalid zero execution timeout, and starts the server on stdio. home/…/mcp.rs• L30-107
MCP always runs in non-interactive mode. Provider prompts must not write to the protocol stream, so the server depends on cached or otherwise non-prompting provider authentication. The command passes the selected profile and shared resolution context into the session. home/…/mcp.rs• L30-35, home/…/mcp.rs• L89-102
The CLI registers mcp as a config-backed command. The common command dispatcher therefore loads configuration before the MCP command runs, while global CLI options provide the config path, profile overlays, missing-value policy, and daemon choice. home/…/mod.rs• L40-89, home/…/mod.rs• L216-242
References: home/…/mcp.rs• L30-107 home/…/mod.rs• L40-89 home/…/mod.rs• L216-242
MCP session
The server creates one cache for the life of the process. On the first tool call it resolves secrets that are allowed for command execution in one batch. Secrets that are not meant for execution remain unresolved until a direct request needs them. Both present and absent results are cached so repeated calls do not repeat provider work. home/…/server.rs• L108-128, home/…/tools.rs• L84-145
The session ends when the MCP client closes the stdio connection. Because the cache is process memory, the server does not provide durable secret storage. A daemon may reduce provider work for the resolution path, but it does not change the MCP allowlist or tool policy. For the shared daemon boundary, see Daemon and proxy runtime.
References: home/…/server.rs• L13-26 home/…/server.rs• L108-128 home/…/tools.rs• L84-145
MCP tool surface
The configured tool list controls both what the server advertises through tools/list and what it accepts at call time. Tool discovery is private and has no useful cache lifetime, so a client must treat the list as session-specific. A proxy session removes exec because the proxy itself owns command traffic. home/…/server.rs• L65-106, home/…/server.rs• L188-217
| Tool | Purpose | Value boundary |
|---|---|---|
get_secret | Return one named resolved secret | Returns the raw value unless the secret is marked for file-only use; under the proxy it returns usage details and a placeholder |
exec | Run one command with allowed secrets supplied to the child | Returns bounded command output rather than giving the agent direct process access; unavailable under the proxy |
request_secret | Ask the user to enter a missing or replacement secret | Stores the value without returning it to the agent; under the proxy it also gives the value to the proxy |
get_secret resolves execution-ready values from the session cache and resolves non-injected values on demand. It rejects names outside the configured profile and rejects file-only secrets because those secrets are intended to be consumed through exec. home/…/tools.rs• L64-145, home/…/server.rs• L79-90
References: home/…/server.rs• L65-106 home/…/server.rs• L188-217 home/…/tools.rs• L64-145 home/…/request_secret.rs• L33-63
MCP secret boundary
The MCP allowlist defines the set of secret names visible to this server. If it is absent, the active profile's secrets are available. If it is present, unlisted secrets are neither resolved nor injected into commands. home/…/mcp.rs• L38-81, home/…/config.rs• L335-359
Secret environment mode adds a second boundary inside that set. Execution-ready secrets can enter child commands, while secrets marked as non-injected remain available only through an explicit get_secret request. A secret marked as_file enters a child as a short-lived file path instead of its raw value. home/…/tools.rs• L167-227, home/…/config.rs• L236-247
These controls limit the MCP channel, not every capability of an agent running as the same user. In particular, exec gives the agent control of the command and therefore provides an auditable command boundary rather than a complete secret sandbox.
References: home/…/mcp.rs• L38-81 home/…/tools.rs• L167-227 home/…/server.rs• L79-90 home/…/config.rs• L236-247 home/…/config.rs• L335-359
MCP command execution
The exec tool starts the requested program without a shell. The child receives only the allowed execution secrets, and file-only secrets become temporary paths. Standard input is closed so child output cannot corrupt the MCP stream. home/…/tools.rs• L148-227
The child also loses the ambient fnox age identity. This prevents it from using inherited decryption credentials to access other configuration values. home/…/tools.rs• L21-25, home/…/tools.rs• L195-227
The server reads standard output and standard error at the same time. It applies a time limit and a total output budget, then returns the output with the exit result. Sensitive secret values are redacted by default before the result reaches the agent, while explicitly non-sensitive values remain readable. Short or empty values are not used as redaction patterns. home/…/tools.rs• L244-361, home/…/tools.rs• L374-406
Temporary files remain alive only for the command call and use restricted owner-only permissions on Unix. The command result can still contain transformed or encoded secret data because redaction matches literal secret text. home/…/temp_file_secrets.rs• L10-57, home/…/tools.rs• L183-213, home/…/tools.rs• L319-396
References: home/…/tools.rs• L21-25 home/…/tools.rs• L148-227 home/…/tools.rs• L244-361 home/…/tools.rs• L364-406 home/…/temp_file_secrets.rs• L10-57
Secret request flow
The request_secret tool adds a user-controlled path for a missing or replacement value. It validates the name and allowlist, checks that the configured provider can store the value securely, and then asks the MCP client to open a one-time local page through URL-mode elicitation. home/…/request_secret.rs• L33-117
The local page binds only to loopback and uses a random one-time path. It accepts requests only for its expected host and path, rejects cross-site form submissions, escapes agent-provided text, and applies browser controls that prevent caching and framing. It also limits request size, read time, and concurrent connections. The user sees the secret name, provider, target profile, and an optional reason from the agent. The value goes from the browser to fnox, not through the agent or its model. home/…/page.rs• L19-39, home/…/page.rs• L125-167, home/…/page.rs• L220-247, home/…/page.rs• L316-355, home/…/page.rs• L418-459
The page claims the first valid save or decline before it sends the choice to fnox. While storage is in progress it shows a waiting state. After completion it keeps only the result page available for a short period, so a browser redirect can show success or failure after request_secret returns. A later submission cannot replace the first one. home/…/page.rs• L52-73, home/…/page.rs• L92-121, home/…/page.rs• L240-303
After the user submits, fnox rechecks the current configuration, provider, value shape, and proxy use before storing the value. It then reloads the session and reports only the storage result and how the agent can use the secret. A client without URL elicitation support receives a terminal fnox set fallback instead. That fallback marks the name for reload so a later request does not keep using an old session or daemon value. home/…/request_secret.rs• L122-211, home/…/request_secret.rs• L269-403
The opening request and page submission share one deadline. A client decline, client cancellation, client timeout, and user decline remain distinct outcomes; a client decline does not prove that the user saw or rejected the page. fnox does not reopen the page automatically or ask the agent to collect the value in chat. An expired or abandoned page reports that the request is no longer active. home/…/request_secret.rs• L14-15, home/…/request_secret.rs• L215-256, home/…/page.rs• L220-313
The diagram shows how a secret request crosses from the agent to the user and back to fnox without exposing the value to the agent.
sequenceDiagram
participant A as MCP agent
participant F as fnox MCP server
participant C as MCP client
participant B as Local browser page
participant P as Secret provider
A->>F: request_secret(name, reason)
F->>C: URL-mode elicitation
C->>B: Open one-time loopback URL
B->>F: Submit value or decline
F->>P: Securely store value
F-->>B: Saved or failed confirmation
F-->>A: Status only
References: home/…/request_secret.rs• L33-117 home/…/request_secret.rs• L122-211 home/…/request_secret.rs• L215-256 home/…/page.rs• L125-167 home/…/page.rs• L220-303
Proxy MCP integration
When fnox mcp runs inside fnox proxy run, it acts as an authenticated stdio relay to the proxy rather than loading a separate local configuration. The relay reads the proxy URL and credentials, opens the MCP connection with a bounded wait, and forwards MCP input and output until the proxy closes the session. home/…/relay.rs• L17-20, home/…/relay.rs• L74-181
The proxy owns the served configuration and profile in this mode. The relay rejects local flags that would silently select a different config, profile, write target, or default-secret policy. Those choices must be made on the outer fnox proxy run command. home/…/relay.rs• L22-71
Inside the proxy, get_secret returns a placeholder, its environment name, and the domains where the proxy can inject the real value. request_secret stores a new value and hands it to the proxy. exec is not offered because commands run outside the sandbox through the proxy's normal request path. home/…/server.rs• L38-72, home/…/proxied.rs• L10-79
The proxy model keeps the real secret out of the agent's MCP result. The agent sends the placeholder to the target request, and the proxy replaces it only for matching protected traffic. home/…/proxied.rs• L61-78
References: home/…/relay.rs• L17-71 home/…/relay.rs• L102-181 home/…/server.rs• L38-72 home/…/proxied.rs• L10-79
Interface relationship
The TUI and MCP server use the same configuration, profile selection, and secret resolution purpose, but they expose different actors and output paths. The TUI gives a person direct visual control over a session. MCP gives an agent named tools and either a child-command path or a proxy placeholder path with explicit limits.
| Interface | Primary actor | Main result | Session boundary |
|---|---|---|---|
| TUI | Human operator | Screen state, detail views, clipboard actions, and temporary edits | Open terminal process |
| MCP | AI agent | Named secret results, bounded command output, or proxy placeholders | MCP server or proxy process |
The daemon can support resolution for either interface when the shared runtime allows it. It only improves reuse of resolved values. It does not widen the TUI's display behavior or the MCP server's tool, allowlist, and proxy rules. See Background and interactive runtime, Daemon and proxy runtime, and Daemon client protocol for those broader relationships.
Change checklist
When these files or sections are changed, remember to consider these:
- When TUI events or dashboard state change, check keyboard handling, mouse row mapping, popup behavior, and the renderer's saved panel offsets together.
- When TUI edits or profile changes change, check whether the action remains in memory or must use the persistent configuration write path.
- When MCP tool names or configuration defaults change, check tool advertisement, tool lookup, and call-time rejection as one contract.
- When
request_secretor URL elicitation changes, check the allowlist, secure-provider check, one-time page, page request checks, client outcome handling, terminal fallback, and agent-facing status together. - When the secret page changes, check the loopback host and token path, cross-site request checks, first-submission claim, confirmation lifetime, and escaped agent text together.
- When proxy MCP behavior changes, check relay flag ownership, proxy authentication and connection lifetime, placeholder descriptions, value handoff, and the removal of
exectogether. - When secret environment modes or the MCP allowlist change, check both
get_secretvisibility and the environment passed toexec. - When MCP subprocess output or lifetime rules change, check stdio isolation, timeout cleanup, output limits, redaction, and temporary file lifetime together.
- When shared resolution context changes, check both TUI and MCP callers and their non-interactive behavior.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A slow TUI resolution completes after a profile switch or refresh | Old values can replace the current profile's view | Associate results with the current resolution and discard stale messages |
| A user treats a TUI edit or new secret as a config write | The change disappears when the dashboard exits | Use the normal persistent write commands for durable changes |
| Provider authentication needs a prompt during TUI or MCP work | A prompt can block the dashboard or corrupt the MCP stdio stream | Run both surfaces in non-interactive mode and provide usable provider auth in advance |
| MCP tool listing and call checks use different enabled-tool rules | An agent can see a tool that calls will reject, or call an undisclosed tool | Apply the same configured tool list to advertisement and dispatch |
| An MCP client caches a tool list from another session | The agent can use stale descriptions or assume a tool is available | Treat the private, zero-TTL tool list as session-specific |
| An allowlist omits a provider dependency | The allowed secret may fail to authenticate even though its name is listed | Include required dependent secrets or review the startup warning |
| A secret page request uses another host, path, or site origin | The page rejects the request instead of accepting an unintended submission | Require the expected loopback host and token path and reject cross-site form metadata |
A client returns decline while the page was never shown | The agent may wrongly tell the user that they refused the request | Report the client action separately and do not ask for the value in chat |
A client cannot open the request_secret URL | The agent cannot obtain a missing value through the secure page | Use the terminal fallback and call request_secret again after fnox set |
| A terminal fallback leaves an old session or daemon value cached | A later request can report that the secret is still present or absent incorrectly | Mark the name for reload and evict or reload it before the next check |
| Configuration or provider rules change while the page is open | The submitted value can be saved under rules different from those shown to the user | Recheck the current config, provider, value shape, and proxy rules before storing |
| A user or agent retries a completed secret page | A second value can overwrite the first request or create confusion | Claim the page once and keep only the confirmation response available |
An exec child prints an injected secret | Sensitive content can be sent back in command output | Keep redaction enabled and limit the allowlist; do not treat exec as a sandbox |
| An MCP command hangs or emits unbounded output | The server can wait too long or consume excessive memory | Use the execution timeout, concurrent bounded reads, and output caps |
A relay receives local config or profile flags under fnox proxy run | The agent may believe it uses one config while the proxy serves another | Reject conflicting flags and pass them to the outer proxy command |
| The relay cannot authenticate or the proxy does not answer its MCP connection | The MCP client loses the server or can wait without a useful protocol response | Require the fnox proxy URL, bound the connection response, and close both stream directions with the proxy |
Key files
| File | Why to read it |
|---|---|
| src/…/mod.rs | Shows how the CLI loads configuration and routes to tui and mcp. |
| src/…/tui.rs | Shows terminal setup, initial resolution, and the TUI event loop. |
| src/…/app.rs | Defines dashboard state, user actions, profile changes, and resolution messages. |
| src/…/event.rs | Defines the combined keyboard, mouse, tick, and background event stream. |
| src/…/ui.rs | Shows the main dashboard layout, panels, status view, and dialogs. |
| src/…/terminal.rs | Shows terminal setup, cleanup, and panic recovery. |
| src/…/mod.rs | States the current boundary for future reusable TUI components. |
| src/…/mcp.rs | Shows MCP startup, profile and allowlist preparation, and stdio service setup. |
| src/…/server.rs | Defines the MCP session policy, tool discovery, tool dispatch, and proxy mode. |
| src/…/tools.rs | Defines direct secret access, command execution, output controls, and redaction. |
| src/…/request_secret.rs | Defines the user-mediated secret request flow, client outcomes, recheck, and terminal fallback. |
| src/…/page.rs | Defines the one-time local page, request checks, and post-submit confirmation. |
| src/…/relay.rs | Defines the authenticated stdio relay used when MCP runs under the proxy. |
| src/…/proxied.rs | Defines placeholder results and value handoff to the proxy. |
| crates/…/config.rs | Defines MCP tools, allowlists, execution settings, and secret environment modes. |
| crates/…/temp_file_secrets.rs | Defines the short-lived file boundary for file-based secret injection. |