HTTP discovery probes keep hitting the Phoenix app after stdio is ready
Thanks for pi-elixir. The embedded stdio bridge has been solid for us, so this is a small rough edge rather than a blocker.
We run a Phoenix app on localhost:4000 with PI_MCP_URL unset. While pi is running, the Phoenix dev log fills with GET /config entries, each a Phoenix.Router.NoRouteError and a full debugger stacktrace. It keeps happening after stdio is connected, at roughly 15 to 30 second spacing once things settle, plus bursts during startup.
What we saw in v0.8.5:
resolveUrlinconnection/resolver.tscallsdiscoverExternalMCP(cwd)wheneverignoreExternalis not set andPI_MCP_URLis not set. That covers everyelixir_*tool throughresolveUrlWithStartupGrace, plus the tool hooks, session snapshots, executable skills, and session start.- Failed discovery is never cached. Only a found HTTP URL or a ready stdio URL is cached, and that entry expires after
CACHE_TTL = 30_000. On the next resolve after 30 seconds, discovery runs again beforeisEmbeddedReadyis ever checked. - A 404 is enough for the probe to give up (
fetchConfigrewrites/mcpto/configand treats non-OK as a miss), but Phoenix still logs the request and the dev router raises. Ports come fromPROBE_PORTS.
We could not find a switch for this. ignoreExternal exists but only bridge/plugin-commands.ts passes it, and only for quack commands. PI_DISABLE_EMBEDDED=1 disables stdio rather than discovery, and PI_MCP_URL forces HTTP. The README documents the resolution order but does not mention any way to keep stdio and skip the scan. If we missed an existing env, I would rather use it than add another.
Suggested fixes, either would solve our case:
- Add an env such as
PI_DISABLE_EXTERNAL_MCP=1that makesresolveUrlskipdiscoverExternalMCPfor all callers, matching theignoreExternaleffect. - Prefer an already-ready embedded connection. If
isEmbeddedReady(cwd)is true, return it before probing HTTP, so stdio users stop generatingGET /config.
The second is the behavior I would expect. Once the bundled bridge is up there is little reason to keep knocking on 4000. Both together would be ideal.
Happy to open a PR for either if that is useful. Also fine if you would rather take it in a different direction.