feat: add argent server start for long-lived tool-server#182
Open
filip131311 wants to merge 1 commit intomainfrom
Open
feat: add argent server start for long-lived tool-server#182filip131311 wants to merge 1 commit intomainfrom
argent server start for long-lived tool-server#182filip131311 wants to merge 1 commit intomainfrom
Conversation
Adds a CLI command to spawn a tool-server that does not auto-shutdown on idle, with configurable port and bind host. Lays the groundwork for remote tool-server connections (consumer side already honors ARGENT_TOOLS_URL). - tool-server: read HOST env var (default 127.0.0.1), bind to it, surface bind errors (EADDRINUSE / EACCES) cleanly. - tools-client: broaden readiness regex to any host; extend buildToolsServerEnv with host/idleTimeoutMinutes; add `host` to the state file; export spawn/state/health helpers for CLI reuse. - argent-cli: implement `server start [--port|-p] [--host] [--idle-timeout] [--detach|-d] [--force]`. Foreground by default for process supervisors; --detach reuses the daemon spawn path. Refuses to start when a healthy server is already running unless --force. Warns when binding to a non-loopback host. - dispatcher: thread BUNDLED_RUNTIME_PATHS through to `server`.
pFornagiel
reviewed
May 4, 2026
Comment on lines
+65
to
+67
| // HOST defaults to loopback so the local auto-spawn path stays safe. | ||
| // `argent server start --host 0.0.0.0` is the opt-in for remote exposure. | ||
| const HOST = process.env.HOST ?? "127.0.0.1"; |
Collaborator
There was a problem hiding this comment.
I would change both the PORT and HOST env varibales in all the code references to ARGENT_HOST and ARGENT_PORT. There is a chance someone will have defined HOST env variable in their shell and this will cause hard-to-reproduce problems.
pFornagiel
reviewed
May 4, 2026
Comment on lines
+112
to
+114
| process.stdout.write(`Tools server listening on http://${HOST}:${boundPort}\n`); | ||
| process.stderr.write(` GET http://${HOST}:${boundPort}/tools\n`); | ||
| process.stderr.write(` POST http://${HOST}:${boundPort}/tools/:name\n`); |
Collaborator
There was a problem hiding this comment.
Tiny NIT, because it is only user-facing, but if host is ipv6 the authority part should be written in square brackets like this:
http://[::1]:3001
pFornagiel
reviewed
May 4, 2026
Comment on lines
+368
to
+371
| if (stateWritten) { | ||
| clearToolsServerState().catch(() => { | ||
| /* non-fatal */ | ||
| }); |
Collaborator
There was a problem hiding this comment.
The writeToolServerState is asynchronous, so there could be a situation when:
- parent spawns child tool-server
- parent starts async
writeToolsServerState, which is not awaited - child may exit quickly (bind fail for example)
- exit handler runs and only clears state if
stateWritten === true - if write resolves after exit handler, stale state file remains, which can cause agent confusion as the data will be referencing a server that has failed at startup
or it may be fine, hard to tell, but this seems like a real edge-case
Collaborator
|
Taking it from here |
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.
Human summary:
This adds
argent server startcommand to enable us to spawn tools server in arbitrary location. we want this to enable using remote tools-server via our mcp not only local ones.Summary
argent server startto spawn a tool-server that does not auto-shutdown on idle, with configurable bind port and host — the missing piece for running tool-server on a remote/dedicated host.--detachkeeps the existing daemon-spawn behavior. Refuses to clobber a healthy running server unless--force.--tools-urlflag pointing the MCP / CLI at a remote tool-server) is now a one-flag change away —tools-client.tsandmcp-server.tsalready honorARGENT_TOOLS_URL. Out of scope for this PR.What changed
tool-server— readHOSTenv var (default127.0.0.1so the existing auto-spawn path is unaffected), bind to it, attach anerrorlistener onapp.listensoEADDRINUSE/EACCESexit cleanly instead of routing throughuncaughtException.argent-tools-client— broaden the readiness regex to match any host; extendbuildToolsServerEnvwith optional{ host, idleTimeoutMinutes }; recordhostin~/.argent/tool-server.json(backward-compat: missing field defaults to127.0.0.1); exportspawnToolsServer,findFreePort,isToolsServerHealthy,isToolsServerProcessAlive, the state read/write/clear helpers, andformatToolsServerUrlso the CLI can reuse them.argent-cli— newserver start [flags]:--port/-p(default 3001,0= pick free),--host(default127.0.0.1),--idle-timeout(default0= never),--detach/-d,--force,--help. Warns when host is non-loopback. Foreground mode forwardsSIGINT/SIGTERMto the child and writes the state file so localargent run/argent mcpcan attach.argentdispatcher — passBUNDLED_RUNTIME_PATHStoserver()so the new subcommand can find the bundled tool-server.Test plan
argent server --helplists the newstartsubcommandargent server start --helpshows full flag referenceargent server start --detach --port 0→ status alive/healthy,/toolsreachable, state file populated withhostfieldargent server start --detachrefuses (exit 1) with helpful messageargent server start --detach --forcekills the old PID and starts a new oneargent server start --port 0runs with inherited stdio; child PID is the actual tool-server (not the wrapper);argent server stopfrom a sibling shell tears down bothargent tools) still works — verifies the regex broadening + default-host change is backward-compatibletool-server(444 tests) +argent-tools-client(1) +argentdispatcher (1) suites pass--host 0.0.0.0— could not exercise locally (sandbox declined the public-interface bind); the warning + bind path is identical to loopback besides the listen address