ratelimit

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package ratelimit provides token-bucket rate limiting for MCP servers.

The public API consists of the Limiter interface, Decision result type, and NewLimiter constructor. The token bucket implementation is internal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decision

type Decision struct {
	// Allowed is true when the request may proceed.
	Allowed bool

	// RetryAfter is populated when Allowed is false.
	// It indicates the minimum wait before the next request may succeed.
	RetryAfter time.Duration
}

Decision holds the result of a rate limit check.

type Limiter

type Limiter interface {
	// Allow checks whether a request is permitted.
	// toolName is the MCP tool being called (empty for non-tool requests).
	// userID is the authenticated user (reserved for #4550, currently no-op).
	Allow(ctx context.Context, toolName, userID string) (*Decision, error)
}

Limiter checks rate limits for an MCP server.

func NewLimiter

func NewLimiter(client redis.Cmdable, namespace, name string, crd *v1alpha1.RateLimitConfig) (Limiter, error)

NewLimiter constructs a Limiter from CRD configuration. Returns a no-op limiter (always allows) when crd is nil. namespace and name identify the MCP server for Redis key derivation.

Directories

Path Synopsis
internal
bucket
Package bucket implements the token bucket algorithm backed by Redis.
Package bucket implements the token bucket algorithm backed by Redis.

Jump to

Keyboard shortcuts

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