Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkgs/mcpx/docs/parity.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ carry instead is a description that says so and MCP annotations
| `tool_invoke` | `POST /v1/tools/{tool}` | `mcpx tool invoke` *generated* | `mcpx_tool_invoke` | `ops.toolInvoke()` | |
| `types` | `GET /v1/types` | `mcpx types` | `mcpx_types` | `ops.types()`, `types()` | |

## CLI commands (64)
## CLI commands (65)

Every command the binary dispatches, with the operations it reaches. A command
that reaches none says why: those are decisions, not gaps.
Expand Down Expand Up @@ -183,6 +183,7 @@ that reaches none says why: those are decisions, not gaps.
| `stats` | `stats_query` | |
| `status` | `status` | |
| `stop` | `shutdown` | |
| `supervise` | – | Runs in its own process as the re-exec target of the supervised transport; it serves no API. |
| `task` / `tasks` | `tasks_list`, `task_get`, `task_cancel`, `task_result` | Generated from the operation table. |
| `tool` | `tool_invoke` | Generated from the operation table. |
| `tools` | `tools` | Generated from the operation table. |
Expand Down
1 change: 1 addition & 0 deletions pkgs/mcpx/internal/cli/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (a *App) handWritten() map[string]Handler {
"logs": a.CmdLog,
"stats": a.CmdStats,
"daemon": a.CmdDaemon,
"supervise": a.CmdSupervise,
"config": a.CmdConfig,
"init": a.CmdInit,
"help": a.CmdHelp,
Expand Down
12 changes: 12 additions & 0 deletions pkgs/mcpx/internal/cli/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@ func handCommands() []Command {
Name: "stop", Group: "daemon",
Usage: "[--all]", Summary: "stop the daemon for this configuration, or all of them",
},
{
Name: "supervise", Group: "daemon",
Local: "Runs in its own process as the re-exec target of the supervised transport; it serves no API.",
Usage: "--socket <path> -- <command> [args...]",
Summary: "run one stdio server child under a supervisor (internal)",
Detail: "Phase 1 of the stdio supervisor design (#1384, #1385). The " +
"supervisor owns the child's pipes for the child's whole life and " +
"serves one attached daemon at a time over a unix socket, so the " +
"child survives a daemon restart. Spawned detached by the " +
"supervised transport when a server sets mcpx.supervised; not " +
"meant to be run by hand.",
},
{
Name: "daemon", Group: "daemon",
Local: "Starts a daemon, which a daemon's own API cannot do.",
Expand Down
47 changes: 47 additions & 0 deletions pkgs/mcpx/internal/cli/supervise.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cli

import (
"context"
"errors"
"fmt"

"github.com/dezren39/mcpx/internal/mcpclient"
)

// CmdSupervise runs one stdio MCP server child under a supervisor
// (#1385, Phase 1 of #1384). It is the re-exec target of the supervised
// transport: the daemon spawns it detached, it owns the child's pipes
// for the child's whole life, and daemons attach to its unix socket
// one at a time. The supervisor process's environment and working
// directory are the child's — the spawning transport sets them — so
// the child is spawned with InheritEnv and no extra env of its own.
//
// Usage: mcpx supervise --socket <path> -- <command> [args...]
func (a *App) CmdSupervise(ctx context.Context, args []string) error {
var socket string
var child []string
for i := 0; i < len(args); i++ {
switch {
case args[i] == "--socket" && i+1 < len(args):
socket = args[i+1]
i++
case args[i] == "--":
child = args[i+1:]
i = len(args)
default:
return fmt.Errorf("supervise: unexpected argument %q (want --socket <path> -- <command> [args...])", args[i])
}
}
if socket == "" {
return errors.New("supervise: --socket is required")
}
if len(child) == 0 {
return errors.New("supervise: no child command after --")
}
return mcpclient.RunSupervisor(mcpclient.SupervisorOptions{
SocketPath: socket,
Command: child[0],
Args: child[1:],
InheritEnv: true,
})
}
44 changes: 25 additions & 19 deletions pkgs/mcpx/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ type Extras struct {
Namespace string `json:"namespace,omitempty"`
// Disabled skips the server entirely.
Disabled bool `json:"disabled,omitempty"`
// Supervised runs a stdio server under a per-server supervisor
// process (#1385, Phase 1 of #1384): the supervisor owns the child's
// pipes for the child's whole life and daemons attach to it, so the
// child survives a daemon restart. Default false - the direct spawn
// path is unchanged.
Supervised bool `json:"supervised,omitempty"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include the supervised flag in pool identity

When mcpx.supervised is changed on configuration reload, Resolved.PoolID() remains unchanged because it does not include this field. Registry.Reload matches existing pools using ProcessID() and retains the original pool configuration, so enabling supervision continues using the direct transport, while disabling it continues using supervision. Servers otherwise identical except for this flag also incorrectly share a pool. Include the effective supervision setting in the process/pool identity so reload and alias deduplication respect the selected transport.

Useful? React with 👍 / 👎.

// Logging overrides the global settings for records about this server, so
// a single misbehaving server can be made verbose without drowning in the
// rest. Nested rather than flat, because "logging.level" reads as one
Expand Down Expand Up @@ -340,13 +346,13 @@ func pickLoggingLevel(vals ...*LoggingConfig) string {
// Resolved is a Server with all defaults folded in and durations parsed.
type Resolved struct {
*Server
Sharing Sharing
Scope Scope
Max int
Min int
IdleTimeout time.Duration
CallTimeout time.Duration
StartTimeout time.Duration
Sharing Sharing
Scope Scope
Max int
Min int
IdleTimeout time.Duration
CallTimeout time.Duration
StartTimeout time.Duration
Namespace string
Description string
Prelude string
Expand Down Expand Up @@ -627,18 +633,18 @@ func (c *Config) Resolve(name string) (*Resolved, error) {
name, ex.Namespace)
}
r := &Resolved{
Server: s,
Sharing: sharing,
Scope: scope,
Max: max,
Min: pick(ex.Min, d.Min, 0),
IdleTimeout: parseDur(pick(ex.IdleTimeout, d.IdleTimeout), DefaultIdleTimeout),
CallTimeout: parseDur(pick(ex.CallTimeout, d.CallTimeout), DefaultCallTimeout),
StartTimeout: parseDur(pick(ex.StartTimeout, d.StartTimeout), DefaultStartTimeout),
Namespace: pick(ex.Namespace, SanitizeNamespace(name)),
Description: ex.Description,
Prelude: pick(ex.Prelude, d.Prelude),
LogLevel: pickLoggingLevel(ex.Logging, d.Logging),
Server: s,
Sharing: sharing,
Scope: scope,
Max: max,
Min: pick(ex.Min, d.Min, 0),
IdleTimeout: parseDur(pick(ex.IdleTimeout, d.IdleTimeout), DefaultIdleTimeout),
CallTimeout: parseDur(pick(ex.CallTimeout, d.CallTimeout), DefaultCallTimeout),
StartTimeout: parseDur(pick(ex.StartTimeout, d.StartTimeout), DefaultStartTimeout),
Namespace: pick(ex.Namespace, SanitizeNamespace(name)),
Description: ex.Description,
Prelude: pick(ex.Prelude, d.Prelude),
LogLevel: pickLoggingLevel(ex.Logging, d.Logging),
Tools: allow,
ExcludeTools: deny,
Profiles: append(append([]string{}, d.Profiles...), ex.Profiles...),
Expand Down
Loading
Loading