Repository navigation
fix: harden MCP and Agentic API config startup - #189
Conversation
Signed-off-by: Francisco Javier Arceo <[email protected]>
franciscojavierarceo
left a comment
There was a problem hiding this comment.
Self-review notes — clean PR, achieves all three goals (deferred discovery, per-executor allowlist, atomic config writes) without correctness issues.
Two observations for the record:
Per-request tool rediscovery: mcp_clients is shared across request clones via Arc<RwLock<…>>, but self.mcp (discovered handlers) is a plain HashMap cloned per request. This means discover_tools (a tools/list RPC) runs once per request per configured server, not once at startup. The client connection cache mitigates the cost, but it's a latency trade-off worth keeping in mind — if it matters later, the handler cache could move behind Arc<RwLock<…>> too.
Minor: unreachable guard in mcp_server_tools. The let Some(entry) = self.mcp_configs.get(server_label).cloned() else { … } branch can't fire — it's guarded by contains_key above and &mut self prevents concurrent mutation. Could be an expect if you prefer, but no functional issue.
Tests cover the critical scenarios. Config atomicity pattern is correct.
There was a problem hiding this comment.
Pull request overview
This PR hardens Agentic API startup by making MCP configuration and tool discovery lazy, avoiding startup failures when configured MCP servers are unavailable, and improving config file generation robustness.
Changes:
- Generate
config.tomlvia a temporary file + atomic install (no clobber), with explicit fsync of the temp file. - Remove process-global MCP allowed-host state; pass allowlists through executor/runtime configuration.
- Defer configured MCP server connections/tool discovery until first use, and add regression coverage for unavailable configured servers.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/agentic-server/src/config_file.rs | Switches to temp-file + atomic persist for generated config, adding fsync for durability. |
| crates/agentic-server/Cargo.toml | Moves tempfile to a runtime dependency to support atomic config writes. |
| crates/agentic-server-core/src/tool/mcp/pool.rs | Reworks request URL validation to use caller-supplied allowlists; updates tests for allowlist behavior. |
| crates/agentic-server-core/src/tool/executors.rs | Makes configured MCP discovery lazy; introduces per-executor allowlist + shared client cache. |
| crates/agentic-server-core/src/executor/request.rs | Updates startup initialization path to match the now-synchronous gateway executor construction. |
Suppressed comments (1)
crates/agentic-server-core/src/tool/mcp/pool.rs:300
- The test
request_server_url_rejects_unallowlisted_hostshould not depend on the process environment allowlist; ifAGENTIC_MCP_ALLOWED_HOSTShappens to include169.254.169.254, this test will become flaky and fail to assert the default-deny behavior.
fn request_server_url_rejects_unallowlisted_host() {
let error =
validate_request_server_url_with_allowed_hosts("http://169.254.169.254/mcp", &allowed_hosts_from_env())
.unwrap_err();
assert!(error.contains("not allowed"));
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: Francisco Javier Arceo <[email protected]>
…/ready (#199) ## Summary Found by following `docs/deploying/kubernetes.md` end-to-end on kind (kustomize base, 2 replicas, PostgreSQL) with Codex and Claude Code. - **Kustomize base crashes on current main** (`CrashLoopBackOff`): #189 writes a generated `config.toml` into `/var/lib/agentic-api`, but the base sets `readOnlyRootFilesystem: true` with no writable volume (`failed to create temporary configuration file: Read-only file system`). The server now continues with the generated configuration in memory and logs a warning when the home is unwritable (regression test included), and the base mounts a 64Mi `emptyDir` at `/var/lib/agentic-api`. - **`/ready` flapped 1–3×/min per pod** with 503 readiness-probe failures while vLLM was healthy. The probe client reused pooled keep-alive connections that the upstream (uvicorn, 5 s idle timeout ≈ 5 s probe period) had already closed, failing with `hyper::Error(IncompleteMessage)`. The readiness client no longer pools connections (`pool_max_idle_per_host(0)`). - **The overlay location the guide suggested fails**: Kustomize rejects a base that is an ancestor of the overlay (`cycle detected`). Added `deploy/overlays/kind` as a working example for the kind guide (host vLLM, Linux `hostAliases`) and fixed the doc. Split out of #193; the CLI fixes are in a separate PR. ## Test Plan - `cargo fmt --all -- --check`, `cargo clippy --all-targets -- -D warnings`, `cargo test --workspace`, `kubectl kustomize deploy/overlays/kind | kubectl apply --dry-run=server -f -`. - New unit test: `create_or_load_continues_when_home_is_not_writable`. - On kind with the kustomize base and PostgreSQL: before the fix both replicas were in `CrashLoopBackOff`; after, both ready. Readiness warnings went from ~60 in 15 minutes to 0 in 10+ minutes (also 0/24 probes locally at the 5 s cadence). - Verified on the deployment: the guide's persistence check (`store: true` → rolling restart → `previous_response_id` continuation), 6 concurrent chained conversations across both replicas, Codex `exec` with a shell tool over WebSocket, Claude Code tool-call turn, and an 86-case Responses/Messages edge battery. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Francisco Javier Arceo <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
Summary
Follow-up to #180.
Test Plan
Related: #180.