feat: v0 — glpi-go client, mglpi CLI, mglpi-mcp, fake-GLPI test suite [#767]
https://projects.knownelement.com/issues/767#note-4191
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Command mglpi is the GLPI/CMDB CLI over the mopac-glpi-go library.
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"git.knownelement.com/ukrrs/mopac-glpi-go/internal/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
os.Exit(cli.Run(os.Args[1:], os.Stdout, os.Stderr))
|
||||
}
|
||||
Reference in New Issue
Block a user