Repository navigation
Configure the operational-files directory via McpConfig - #138
Merged
aterga merged 2 commits intoAug 18, 2026
Merged
Conversation
imcp2's only persistent operational file — the dynamic-client-registration
store — was located by reading `OAUTH_CLIENTS_FILE` deep inside the auth
module (`clients_file()`), a process-global env lookup the library
performed for itself. That is the wrong layer: the embedding application,
not a global env var, should decide where imcp2 writes its state.
Introduce `McpConfig.state_dir: PathBuf` — the directory imcp2 creates its
operational files in — and thread it through:
* `SharedClients::load(state_dir)` loads/persists
`{state_dir}/oauth-clients.json`; `ClientStore` now owns its resolved
file path, so the coalesced writer needs no global lookup.
* `McpServer` stores `state_dir` and exposes `state_dir()`, so an
embedder can place its own operational files under the same home and
future imcp2 state has one configured location (not scattered files).
* The library no longer reads any path from the environment. The `imcp2`
binary reads the directory from `IMCP2_STATE_DIR` (default: the working
directory, preserving the old `./oauth-clients.json` default) and the
systemd unit points it at `StateDirectory` (`/var/lib/imcp2`), so the
store still lands at the same `/var/lib/imcp2/oauth-clients.json`.
`persist_clients_to`/`load_clients_from` take `&Path` (non-UTF-8 safe) and
the atomic-replace temp path is derived on `OsString`. The e2e handshake
test and router tests inject a throwaway directory instead of overriding a
process-global env. README, the module docs, the directory-submission doc,
and the unit file are updated to the directory model.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
Configures imcp2 operational storage through McpConfig.state_dir, removing library-level environment lookup.
Changes:
- Persists OAuth clients under
<state_dir>/oauth-clients.json. - Exposes the configured state directory through
McpServer. - Updates deployment configuration, tests, and documentation.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/auth.rs |
Makes client persistence path-based. |
src/lib.rs |
Adds and exposes state_dir. |
src/main.rs |
Reads IMCP2_STATE_DIR. |
src/e2e_handshake.rs |
Uses an isolated state directory. |
src/metrics.rs |
Supplies state configuration in tests. |
tests/routers.rs |
Migrates router tests to directory storage. |
README.md |
Documents state-directory configuration. |
docs/anthropic-directory-submission.md |
Updates storage disclosure. |
deploy/native/imcp2.service |
Points state storage at systemd’s directory. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Addresses the PR review:
* `state_dir` and `clients` were two independent fields that could
disagree — a caller could load `clients` from directory A while setting
`state_dir` to B, and `McpServer::state_dir()` would then report B while
files went to A. Fixed by making the client store the single source of
truth: `ClientStore` now owns the operational DIRECTORY (not a file
path), `SharedClients::state_dir()` surfaces it, and
`McpServer::state_dir()` reports it straight from the store. Construction
asserts `config.clients` was loaded from `config.state_dir`, so a
mismatch fails loudly instead of letting the getter lie. New tests cover
both the happy path and the panic.
* Reworded the `IMCP2_STATE_DIR` default comment: the default is the
process's current working directory, not necessarily the executable's
directory ("beside the binary" was inaccurate).
* Fixed the indentation of the edited client-store test seam. (The tree is
formatted with a different rustfmt line width than this toolchain's
default, so `cargo fmt --all` would rewrite unrelated files; hand-matched
the surrounding style instead. CI does not gate `cargo fmt --check`.)
Co-Authored-By: Claude Opus 4.8 <[email protected]>
MRmarioruci
approved these changes
Aug 18, 2026
9 of 11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
imcp2's only persistent operational file — the dynamic-client-registration store — was located by reading
OAUTH_CLIENTS_FILEdeep inside the auth module (clients_file()), a process-global env lookup the library did for itself. Wrong layer: the embedding application should decide where imcp2 writes its state, the way it already injects theAgent.This adds
McpConfig.state_dir: PathBuf— the directory imcp2 creates its operational files in — and threads it through so the location has one configured home (and future operational state isn't scattered).Changes
SharedClients::load(state_dir)loads/persists{state_dir}/oauth-clients.json.ClientStorenow owns its resolved file path, so the coalesced write-through needs no global/env lookup.McpServerstoresstate_dirand exposesstate_dir(), so an embedder can place its own operational files under the same home.imcp2binary reads the directory fromIMCP2_STATE_DIR(default: the working directory, preserving the old./oauth-clients.jsondefault). The systemd unit points it atStateDirectory— so the store still lands at exactly/var/lib/imcp2/oauth-clients.json(no data migration).persist_clients_to/load_clients_fromtake&Path(non-UTF-8 safe); the atomic-replace temp path is derived onOsString.Behavior / compatibility
/var/lib/imcp2/oauth-clients.json).OAUTH_CLIENTS_FILE(full file path) →IMCP2_STATE_DIR(directory); the unit file is updated in the same change, and a bare local run still defaults to./oauth-clients.json.Tests
176 lib + router + integration tests pass;
--features e2ecompiles; clippy clean on the changed files.Note on base
Stacked on #137 (
security/dcr-limits-atomic-store) because it builds directly on that PR's atomic, path-taking persistence helpers — basing onmainwould duplicate and conflict with them. Retarget tomainonce #137 merges. Happy to make it independent instead if you'd prefer.🤖 Generated with Claude Code