Skip to content

Commit a37bb73

Browse files
docs: add doc comments to internal registry and server components
1 parent 55e18d6 commit a37bb73

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

cmd/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type registryServerRunnable struct {
6969
mcpRegistry *registry.Registry
7070
}
7171

72+
// Start starts the MCP discovery HTTP server and listens until context cancellation.
7273
func (r *registryServerRunnable) Start(ctx context.Context) error {
7374
r.mcpRegistry.Start(ctx)
7475
srv := &http.Server{
@@ -92,6 +93,7 @@ func (r *registryServerRunnable) Start(ctx context.Context) error {
9293
return nil
9394
}
9495

96+
// NeedLeaderElection returns false so the registry server runs across all manager replicas.
9597
func (r *registryServerRunnable) NeedLeaderElection() bool {
9698
return false
9799
}

internal/registry/mcp_client.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ type mcpInitializeRequest struct {
6464
Params mcpInitializeParams `json:"params"`
6565
}
6666

67+
// mcpInitializeParams encapsulates the parameters passed to the MCP initialize RPC.
6768
type mcpInitializeParams struct {
6869
ProtocolVersion string `json:"protocolVersion"`
6970
ClientInfo mcpClientInfo `json:"clientInfo"`
7071
Capabilities map[string]interface{} `json:"capabilities"`
7172
}
7273

74+
// mcpClientInfo identifies the client implementation and version to the MCP server.
7375
type mcpClientInfo struct {
7476
Name string `json:"name"`
7577
Version string `json:"version"`
@@ -83,27 +85,32 @@ type mcpInitializeResponse struct {
8385
Error *mcpError `json:"error,omitempty"`
8486
}
8587

88+
// mcpError represents a JSON-RPC 2.0 error object.
8689
type mcpError struct {
8790
Code int `json:"code"`
8891
Message string `json:"message"`
8992
}
9093

94+
// mcpInitializeResult encapsulates the capability and tool declarations returned by an MCP server.
9195
type mcpInitializeResult struct {
9296
ProtocolVersion string `json:"protocolVersion"`
9397
Capabilities mcpCapabilities `json:"capabilities"`
9498
ServerInfo *mcpClientInfo `json:"serverInfo,omitempty"`
9599
Tools []mcpToolDefinition `json:"tools,omitempty"`
96100
}
97101

102+
// mcpCapabilities declares server-supported features such as tools or resources.
98103
type mcpCapabilities struct {
99104
Tools *mcpToolsCapability `json:"tools,omitempty"`
100105
}
101106

107+
// mcpToolsCapability specifies tool availability and listing support.
102108
type mcpToolsCapability struct {
103109
Available []string `json:"available,omitempty"`
104110
List bool `json:"list,omitempty"`
105111
}
106112

113+
// mcpToolDefinition describes an individual tool declared in the initialize result.
107114
type mcpToolDefinition struct {
108115
Name string `json:"name"`
109116
}

internal/registry/mcp_registrar.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func (r *Registrar) Heartbeat(ctx context.Context, ad *agentraxv1alpha1.AgentDep
152152
return hbErr
153153
}
154154

155+
// incrementFailures records a probe failure and returns the new consecutive failure count.
155156
func (r *Registrar) incrementFailures(namespace, name string) int {
156157
r.failuresMu.Lock()
157158
defer r.failuresMu.Unlock()
@@ -163,6 +164,7 @@ func (r *Registrar) incrementFailures(namespace, name string) int {
163164
return r.failures[k]
164165
}
165166

167+
// resetFailures clears the consecutive failure counter for the specified agent.
166168
func (r *Registrar) resetFailures(namespace, name string) {
167169
r.failuresMu.Lock()
168170
defer r.failuresMu.Unlock()

internal/registry/registry.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ func (r *Registry) Handler() http.Handler {
375375
return mux
376376
}
377377

378+
// handleRegister handles HTTP POST requests to register or update an agent entry.
378379
func (r *Registry) handleRegister(w http.ResponseWriter, req *http.Request) {
379380
var entry Entry
380381
if err := json.NewDecoder(req.Body).Decode(&entry); err != nil {
@@ -391,6 +392,7 @@ func (r *Registry) handleRegister(w http.ResponseWriter, req *http.Request) {
391392
_ = json.NewEncoder(w).Encode(map[string]string{"status": "registered"})
392393
}
393394

395+
// handleDeregisterAgentPath handles HTTP DELETE requests targeting /agents/{namespace}/{name}.
394396
func (r *Registry) handleDeregisterAgentPath(w http.ResponseWriter, req *http.Request) {
395397
namespace := req.PathValue("namespace")
396398
name := req.PathValue("name")
@@ -409,6 +411,7 @@ func (r *Registry) handleDeregisterAgentPath(w http.ResponseWriter, req *http.Re
409411
_ = json.NewEncoder(w).Encode(map[string]string{"status": "deregistered"})
410412
}
411413

414+
// handleDeregister handles legacy HTTP DELETE requests targeting /deregister.
412415
func (r *Registry) handleDeregister(w http.ResponseWriter, req *http.Request) {
413416
namespace := req.URL.Query().Get("namespace")
414417
name := req.URL.Query().Get("name")
@@ -439,13 +442,15 @@ func (r *Registry) handleDeregister(w http.ResponseWriter, req *http.Request) {
439442
_ = json.NewEncoder(w).Encode(map[string]string{"status": "deregistered"})
440443
}
441444

445+
// handleListAgents handles HTTP GET requests to list all active, non-expired registered agents.
442446
func (r *Registry) handleListAgents(w http.ResponseWriter, req *http.Request) {
443447
agents := r.List()
444448
w.Header().Set("Content-Type", "application/json")
445449
w.WriteHeader(http.StatusOK)
446450
_ = json.NewEncoder(w).Encode(agents)
447451
}
448452

453+
// handleGetAgent handles HTTP GET requests to fetch details of a specific agent.
449454
func (r *Registry) handleGetAgent(w http.ResponseWriter, req *http.Request) {
450455
namespace := req.PathValue("namespace")
451456
name := req.PathValue("name")

0 commit comments

Comments
 (0)