feat: include active alert count in MCP server instructions

Add InstructionsFunc callback to ServerConfig, called during each
initialize handshake to generate dynamic instructions. The lab-monitoring
server uses this to query Alertmanager and include a count of active
non-silenced alerts, so the LLM can proactively inform the user.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-04 23:16:52 +01:00
parent 1755364bba
commit 2a08cdaf2e
3 changed files with 61 additions and 2 deletions

View File

@@ -30,6 +30,9 @@ type ServerConfig struct {
Version string
// Instructions are the server instructions sent to clients.
Instructions string
// InstructionsFunc, if set, is called during initialization to generate
// dynamic instructions. Its return value is appended to Instructions.
InstructionsFunc func() string
// DefaultChannel is the default channel to use when no revision is specified.
DefaultChannel string
// SourceName is the name of the source repository (e.g., "nixpkgs", "home-manager").
@@ -244,6 +247,13 @@ func (s *Server) handleInitialize(req *Request) *Response {
s.logger.Printf("Client: %s %s, protocol: %s",
params.ClientInfo.Name, params.ClientInfo.Version, params.ProtocolVersion)
instructions := s.config.Instructions
if s.config.InstructionsFunc != nil {
if extra := s.config.InstructionsFunc(); extra != "" {
instructions += "\n\n" + extra
}
}
result := InitializeResult{
ProtocolVersion: ProtocolVersion,
Capabilities: Capabilities{
@@ -255,7 +265,7 @@ func (s *Server) handleInitialize(req *Request) *Response {
Name: s.config.Name,
Version: s.config.Version,
},
Instructions: s.config.Instructions,
Instructions: instructions,
}
return &Response{