Skip to content

feat: run a pre-connect step before connecting to a server - #10

Merged
vrmiguel merged 1 commit into
mainfrom
tembo/pre-connect
Nov 16, 2026
Merged

vrmiguel merged 1 commit into
mainfrom
tembo/pre-connect

Conversation

@vrmiguel

Copy link
Copy Markdown
Contributor

A server can now name a pre-connect step: a command gate runs before every attempt to connect to it. It's for servers that need something set up first, and set up again later. Tembo's case is MCP servers on a customer's tailnet (tembo/monorepo#13140, with proxy from #9). The sandbox has to join the tailnet before connecting, and join again after its ephemeral node has been dropped, for example while a VM was hibernated.

{
  "preConnect": { "tailnet": { "command": "tembo", "args": ["tailscale", "join"], "stderr": "forward" } },
  "mcpServers": {
    "internal": { "url": "https://tools.example.ts.net/mcp", "proxy": "http://localhost:1056", "preConnect": "tailnet" }
  }
}
  • When it runs: before every connection attempt of a server that names it: the first connect, retries, reconnects after the server exits, and credential rotations. Attempts that overlap share one run, so concurrent servers start the command once; every later attempt runs it again, the way the TypeScript gateway's tembo tailscale join does.
  • Success is exit status 0. A failure fails that attempt, with the step named in the error, and gate's usual retries apply. Other servers are unaffected.
  • Output: there's no request on stdin, and stdout isn't read. With "stderr": "forward" both of the command's outputs go to gate's stderr, never its stdout, which carries MCP. Gate only waits for the command to exit, so a daemon it starts (tailscaled) can't hold the step open, and it outlives the step.
  • Config: steps take a hook's command, args, env, timeoutSeconds (default 120, since a first run may install or start things) and stderr. HTTP steps are rejected, as are references to unknown steps. Like other hooks, variables a step references are reserved for hooks.
  • Bumps the version to 0.1.1, which also ships feat: route an HTTP server's requests through a forward proxy #9's proxy.

Tests:

  • pre_connect_steps_run_before_every_attempt: while the step fails, only the server that names it fails (all three attempts run the step, and the error names it), and another server connects. Once the step succeeds, the next attempt runs it again and connects. It fails if gate doesn't run the step.
  • Overlapping runs share one execution and later runs execute again. This fails without the sharing.
  • The runner: exit status decides, a daemon left running neither holds the step nor dies with it, and a timeout kills the command.
  • Config validation.

Want tembo to make any changes? Add a comment with @tembo and i'll get back to work!

View on Tembo  Review in Tembo  View Agent Settings

Co-authored-by: tembo[bot] <208362400+tembo-io[bot]@users.noreply.github.com>
@tembo tembo Bot added the tembo Pull request created by Tembo label Nov 16, 2026
@vrmiguel
vrmiguel merged commit d4e8929 into main Nov 16, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tembo Pull request created by Tembo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant