pi-elixir icon indicating copy to clipboard operation
pi-elixir copied to clipboard

HTTP discovery probes keep hitting the Phoenix app after stdio is ready

Open basilenouvellet opened this issue 2 months ago • 0 comments

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:

  • resolveUrl in connection/resolver.ts calls discoverExternalMCP(cwd) whenever ignoreExternal is not set and PI_MCP_URL is not set. That covers every elixir_* tool through resolveUrlWithStartupGrace, 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 before isEmbeddedReady is ever checked.
  • A 404 is enough for the probe to give up (fetchConfig rewrites /mcp to /config and treats non-OK as a miss), but Phoenix still logs the request and the dev router raises. Ports come from PROBE_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:

  1. Add an env such as PI_DISABLE_EXTERNAL_MCP=1 that makes resolveUrl skip discoverExternalMCP for all callers, matching the ignoreExternal effect.
  2. Prefer an already-ready embedded connection. If isEmbeddedReady(cwd) is true, return it before probing HTTP, so stdio users stop generating GET /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.

basilenouvellet avatar Sep 15 '26 09:09 basilenouvellet