azdextutil

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package azdextutil provides shared utilities for building azd extensions that integrate with the Azure Developer CLI extension framework.

It reduces boilerplate for common patterns like metadata generation, listen command creation, MCP server setup, and distributed tracing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetArgsMap

func GetArgsMap(request mcp.CallToolRequest) map[string]interface{}

GetArgsMap extracts the arguments map from an MCP tool call request. Returns an empty map if arguments are nil or not a map.

func GetProjectDir

func GetProjectDir(envVar string) (string, error)

GetProjectDir returns the project directory from the specified environment variable, falling back to the current working directory. Validates the path is safe.

func GetStringParam

func GetStringParam(args map[string]interface{}, key string) (string, bool)

GetStringParam extracts a string parameter from the arguments map. Returns the value and whether it was found and is a string.

func MarshalToolResult

func MarshalToolResult(data interface{}) (*mcp.CallToolResult, error)

MarshalToolResult marshals any value to JSON and returns it as an MCP tool result.

func NewMetadataCommand deprecated

func NewMetadataCommand(extensionID string, rootCmdProvider func() *cobra.Command) *cobra.Command

Deprecated: Use azdext.NewMetadataCommand() from github.com/azure/azure-dev/cli/azd/pkg/azdext instead. The azdext version produces the correct framework schema (extensions.ExtensionCommandMetadata).

NewMetadataCommand creates a standard hidden metadata command that outputs extension metadata as JSON to stdout.

func SetupTracingFromEnv deprecated

func SetupTracingFromEnv(ctx context.Context) context.Context

Deprecated: Use azdext.NewContext() from github.com/azure/azure-dev/cli/azd/pkg/azdext instead. azdext.NewContext() provides proper OpenTelemetry W3C trace context propagation.

SetupTracingFromEnv reads TRACEPARENT and TRACESTATE from the environment and stores them in the context. Extensions can retrieve these values to propagate trace context to downstream calls.

func ValidatePath deprecated

func ValidatePath(path string, allowedBases ...string) (string, error)

Deprecated: Use security.ValidatePathWithinBases() from github.com/jongio/azd-core/security instead. It provides the same base directory containment check with better error types.

WARNING: This function silently falls back to the unresolved path on ALL symlink errors, not just os.IsNotExist. This may allow access to paths that should fail validation. The replacement ValidatePathWithinBases correctly distinguishes error types.

ValidatePath ensures a path is safe to access:

  • Resolves to absolute path
  • No path traversal (..)
  • Must be within allowed base directories

Returns the cleaned absolute path or an error.

func ValidateShellName

func ValidateShellName(shell string) error

ValidateShellName validates that a shell name is one of the known safe values.

Types

type ArgMetadata deprecated

type ArgMetadata struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Required    bool     `json:"required,omitempty"`
	Variadic    bool     `json:"variadic,omitempty"`
	ValidValues []string `json:"validValues,omitempty"`
}

ArgMetadata describes a positional argument for a command.

Deprecated: Use azdext.GenerateExtensionMetadata() from github.com/azure/azure-dev/cli/azd/pkg/azdext instead.

type CommandMetadata deprecated

type CommandMetadata struct {
	Name        []string          `json:"name"`
	Short       string            `json:"short"`
	Long        string            `json:"long,omitempty"`
	Usage       string            `json:"usage,omitempty"`
	Examples    []ExampleMetadata `json:"examples,omitempty"`
	Args        []ArgMetadata     `json:"args,omitempty"`
	Flags       []FlagMetadata    `json:"flags,omitempty"`
	Subcommands []CommandMetadata `json:"subcommands,omitempty"`
	Hidden      bool              `json:"hidden,omitempty"`
	Aliases     []string          `json:"aliases,omitempty"`
	Deprecated  string            `json:"deprecated,omitempty"`
}

CommandMetadata describes a single command in the extension.

Deprecated: Use azdext.GenerateExtensionMetadata() from github.com/azure/azure-dev/cli/azd/pkg/azdext instead.

type ConfigMetadata deprecated

type ConfigMetadata struct {
	EnvironmentVariables []EnvVarMetadata `json:"environmentVariables,omitempty"`
}

ConfigMetadata describes configuration for the extension.

Deprecated: Use azdext.GenerateExtensionMetadata() from github.com/azure/azure-dev/cli/azd/pkg/azdext instead.

type EnvVarMetadata deprecated

type EnvVarMetadata struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Default     string `json:"default,omitempty"`
	Example     string `json:"example,omitempty"`
}

EnvVarMetadata describes an environment variable used by the extension.

Deprecated: Use azdext.GenerateExtensionMetadata() from github.com/azure/azure-dev/cli/azd/pkg/azdext instead.

type ExampleMetadata deprecated

type ExampleMetadata struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Command     string `json:"command,omitempty"`
	Usage       string `json:"usage,omitempty"`
}

ExampleMetadata describes a usage example for a command.

Deprecated: Use azdext.GenerateExtensionMetadata() from github.com/azure/azure-dev/cli/azd/pkg/azdext instead.

type ExtensionMetadata deprecated

type ExtensionMetadata struct {
	SchemaVersion string            `json:"schemaVersion"`
	ID            string            `json:"id"`
	Commands      []CommandMetadata `json:"commands"`
	Configuration *ConfigMetadata   `json:"configuration,omitempty"`
}

ExtensionMetadata represents the metadata output for an azd extension.

Deprecated: Use azdext.GenerateExtensionMetadata() from github.com/azure/azure-dev/cli/azd/pkg/azdext instead. The azdext version produces the correct framework schema (extensions.ExtensionCommandMetadata).

func GenerateMetadataFromCobra deprecated

func GenerateMetadataFromCobra(schemaVersion, extensionID string, rootCmd *cobra.Command) *ExtensionMetadata

Deprecated: Use azdext.GenerateExtensionMetadata() from github.com/azure/azure-dev/cli/azd/pkg/azdext instead. The azdext version produces the correct framework schema (extensions.ExtensionCommandMetadata).

GenerateMetadataFromCobra generates ExtensionMetadata by introspecting a Cobra command tree. This is a lightweight alternative to azdext.GenerateExtensionMetadata that doesn't require the azure-dev/cli/azd dependency.

type FlagMetadata deprecated

type FlagMetadata struct {
	Name        string `json:"name"`
	Shorthand   string `json:"shorthand,omitempty"`
	Description string `json:"description"`
	Type        string `json:"type"`
	Default     string `json:"default,omitempty"`
	Required    bool   `json:"required,omitempty"`
	Hidden      bool   `json:"hidden,omitempty"`
	Deprecated  string `json:"deprecated,omitempty"`
}

FlagMetadata describes a flag for a command.

Deprecated: Use azdext.GenerateExtensionMetadata() from github.com/azure/azure-dev/cli/azd/pkg/azdext instead.

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter implements a token bucket rate limiter for MCP tool calls.

func NewRateLimiter

func NewRateLimiter(maxTokens float64, refillRate float64) *RateLimiter

NewRateLimiter creates a rate limiter with the specified max tokens and refill rate. For example, NewRateLimiter(10, 1.0) allows 10 burst calls and refills 1 token/second.

func (*RateLimiter) Allow

func (r *RateLimiter) Allow() bool

Allow returns true if a request is allowed, consuming one token.

func (*RateLimiter) CheckRateLimit

func (r *RateLimiter) CheckRateLimit(toolName string) error

CheckRateLimit checks the rate limiter and returns an error if the limit is exceeded.

type TraceContext

type TraceContext struct {
	TraceParent string
	TraceState  string
}

TraceContext holds W3C distributed trace context propagated from azd.

func GetTraceContext deprecated

func GetTraceContext(ctx context.Context) *TraceContext

Deprecated: Use azdext.NewContext() from github.com/azure/azure-dev/cli/azd/pkg/azdext instead. azdext.NewContext() provides proper OpenTelemetry W3C trace context propagation.

GetTraceContext retrieves the TraceContext from the context, if present.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL