// Copyright 2026. Licensed under Apache-2.0. See LICENSE.
// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.

package mcp

import (
	"context"

	mcplib "github.com/mark3labs/mcp-go/mcp"
	"github.com/mark3labs/mcp-go/server"

	"ble-temperature-sensor-pp-cli/internal/cli"
	"ble-temperature-sensor-pp-cli/internal/device"
	"ble-temperature-sensor-pp-cli/internal/mcp/bound"
	"ble-temperature-sensor-pp-cli/internal/mcp/cobratree"
)

// RegisterTools registers the device's MCP tool surface: a read-only context
// tool returning the device's capability + safety metadata, plus every
// user-facing CLI command mirrored by the cobratree walker. The walker honors
// each command's mcp:read-only and mcp:hidden annotations, so commands a device
// cannot safely expose to an agent (for example controls that need a held BLE
// connection) are hidden by the CLI, not here.
func RegisterTools(s *server.MCPServer) {
	s.AddTool(
		mcplib.NewTool("context",
			mcplib.WithDescription("Get device context: protocol, telemetry fields, and callable vs withheld commands with their safety classes. Call this first."),
			mcplib.WithReadOnlyHintAnnotation(true),
		),
		handleContext,
	)
	cobratree.RegisterAll(s, cli.RootCmd(), cobratree.SiblingCLIPath)
}

func handleContext(_ context.Context, _ mcplib.CallToolRequest) (*mcplib.CallToolResult, error) {
	text, err := bound.JSON(device.Capabilities())
	if err != nil {
		return mcplib.NewToolResultError(err.Error()), nil
	}
	return mcplib.NewToolResultText(text), nil
}
