Files
mopac-glpi-go/cmd/mglpi-mcp/main.go
T

48 lines
1.4 KiB
Go

// Command mglpi-mcp is the GLPI MCP server (stdio JSON-RPC, stdlib
// only). Connection settings come from MGLPI_URL / MGLPI_APP_TOKEN /
// MGLPI_USER_TOKEN env vars (plus optional MGLPI_PROFILE_ID for agent
// mode) or a 0600 --config env file — the same discipline as mglpi.
package main
import (
"context"
"flag"
"fmt"
"os"
"git.knownelement.com/ukrrs/mopac-glpi-go/glpi"
"git.knownelement.com/ukrrs/mopac-glpi-go/internal/config"
"git.knownelement.com/ukrrs/mopac-glpi-go/internal/mcp"
)
func main() {
cfgPath := flag.String("config", "", "env file with MGLPI_URL/MGLPI_APP_TOKEN/MGLPI_USER_TOKEN (must be 0600)")
profile := flag.Int("profile", 0, "agent profile id to switch to after InitSession (overrides MGLPI_PROFILE_ID)")
flag.Parse()
if *cfgPath == "" {
*cfgPath = os.Getenv("MGLPI_CONFIG")
}
cfg, _, err := config.Load(*cfgPath)
if err != nil {
fmt.Fprintf(os.Stderr, "mglpi-mcp: %v\n", err)
os.Exit(1)
}
if *profile == 0 {
*profile = cfg.ProfileID
}
c := glpi.New(glpi.Config{
BaseURL: cfg.BaseURL,
AppToken: cfg.AppToken,
UserToken: cfg.UserToken,
})
if err := mcp.New(c, *profile).Serve(os.Stdin, os.Stdout); err != nil {
fmt.Fprintf(os.Stderr, "mglpi-mcp: %v\n", err)
os.Exit(1)
}
// Graceful close: release the session when the peer hangs up.
if err := c.KillSession(context.Background()); err != nil {
fmt.Fprintf(os.Stderr, "mglpi-mcp: killSession: %v\n", err)
}
}