util

package
v1.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package util provides utilities for the gomcp library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ProcessGroupManager

type ProcessGroupManager struct {
	// contains filtered or unexported fields
}

ProcessGroupManager provides enhanced process cleanup capabilities that work in conjunction with the MCP ServerRegistry to prevent orphan processes.

func NewProcessGroupManager

func NewProcessGroupManager() *ProcessGroupManager

NewProcessGroupManager creates a new process group manager.

func (*ProcessGroupManager) CleanupAllProcessGroups

func (pgm *ProcessGroupManager) CleanupAllProcessGroups(timeout time.Duration) error

CleanupAllProcessGroups forcefully terminates all tracked process groups. This is a nuclear option for application shutdown.

func (*ProcessGroupManager) GetTrackedProcessGroups

func (pgm *ProcessGroupManager) GetTrackedProcessGroups() int

GetTrackedProcessGroups returns the number of currently tracked process groups.

func (*ProcessGroupManager) PrepareCommand

func (pgm *ProcessGroupManager) PrepareCommand(cmd *exec.Cmd) error

PrepareCommand configures a command to run in its own process group for enhanced cleanup capabilities. This should be called before cmd.Start().

func (*ProcessGroupManager) RegisterProcessGroup

func (pgm *ProcessGroupManager) RegisterProcessGroup(cmd *exec.Cmd) error

RegisterProcessGroup registers a process group for cleanup tracking. Call this after cmd.Start() succeeds.

func (*ProcessGroupManager) TerminateProcessGroup

func (pgm *ProcessGroupManager) TerminateProcessGroup(cmd *exec.Cmd, timeout time.Duration) error

TerminateProcessGroup terminates a process group more aggressively than the standard ServerRegistry termination. This kills the entire process tree.

type ProcessMonitor added in v1.6.2

type ProcessMonitor struct {
	// contains filtered or unexported fields
}

ProcessMonitor monitors the parent process and stdin for unexpected termination. This prevents orphaned MCP server processes when the parent (e.g., Cursor) exits unexpectedly.

func NewProcessMonitor added in v1.6.2

func NewProcessMonitor(logger *slog.Logger, shutdownFunc func()) *ProcessMonitor

NewProcessMonitor creates a new process monitor. shutdownFunc will be called when the parent process exits or stdin closes.

func (*ProcessMonitor) SetExitFunc added in v1.6.2

func (pm *ProcessMonitor) SetExitFunc(exitFunc func(int))

SetExitFunc sets a custom exit function (useful for testing). If set to nil, no exit will be performed.

func (*ProcessMonitor) Start added in v1.6.2

func (pm *ProcessMonitor) Start()

Start begins monitoring the parent process and stdin. This should be called once when the server starts.

func (*ProcessMonitor) Stop added in v1.6.2

func (pm *ProcessMonitor) Stop()

Stop stops the process monitor.

Directories

Path Synopsis
Package conversion provides utilities for converting between types.
Package conversion provides utilities for converting between types.
Package schema provides utilities for generating JSON Schema from Go structs.
Package schema provides utilities for generating JSON Schema from Go structs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL