registry

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 6 Imported by: 0

README

kite-mcp-registry

Go Reference

Pre-registered Kite app credentials store (admin-managed) for the algo2go ecosystem. Backed by algo2go/kite-mcp-alerts shared SQLite DB. Lets admins onboard Kite developer apps centrally so end-users don't need to bring their own credentials.

Used by Sundeepg98/kite-mcp-server for admin-managed credential pool + per-user assignment via the admin dashboard.

Why a separate module?

Pre-registered credential storage is an admin-side primitive any algo2go consumer that runs a hosted MCP server may need. Hosting as a module:

  • Centralizes the credential schema + lookup contract
  • Pairs with algo2go/kite-mcp-alerts (shared DB)

Stability promise

v0.x — unstable. Pin v0.1.0 deliberately.

Install

go get github.com/algo2go/kite-mcp-registry@v0.1.0

Public API

  • Store — credential CRUD with *alerts.DB backend
  • Credential — DTO struct (Email, APIKey, APISecret, etc.)
  • NewStore(db *alerts.DB) *Store

Dependencies

  • github.com/algo2go/kite-mcp-alerts v0.1.0 — shared DB backend

All algo2go deps published; no upstream replace directives needed.

Reference consumer

Sundeepg98/kite-mcp-server — consumed across kc/credential_service.go, kc/store_registry.go, kc/manager_*, kc/ops/admin_edge_registry_test.go, kc/ops/handler.go.

License

MIT — see LICENSE.

Authors

Original design: Sundeepg98 (Zerodha Tech). Multi-module promotion (2026-05-10): algo2go contributors.

Documentation

Index

Constants

View Source
const (
	StatusActive   = "active"
	StatusDisabled = "disabled"
	StatusInvalid  = "invalid"  // Kite API rejected this key
	StatusReplaced = "replaced" // User re-authenticated with a different key

	SourceAdmin           = "admin"
	SourceSelfProvisioned = "self-provisioned"
	SourceMigrated        = "migrated"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppRegistration

type AppRegistration struct {
	ID           string     `json:"id"`
	APIKey       string     `json:"api_key"`       // Kite API key (= client_id for Kite apps)
	APISecret    string     `json:"api_secret"`    // Kite API secret (encrypted at rest)
	AssignedTo   string     `json:"assigned_to"`   // expected email (empty = unassigned / open)
	Label        string     `json:"label"`         // e.g. "Personal Trading", "Mom's Account"
	Status       string     `json:"status"`        // active, disabled, invalid, replaced
	RegisteredBy string     `json:"registered_by"` // admin email who registered it
	Source       string     `json:"source"`        // "admin", "self-provisioned", "migrated"
	LastUsedAt   *time.Time `json:"last_used_at"`  // last successful token exchange with this key
	CreatedAt    time.Time  `json:"created_at"`
	UpdatedAt    time.Time  `json:"updated_at"`
}

AppRegistration represents a pre-registered Kite app in the key registry. Admin registers these ahead of time; users are matched by email at login.

type AppRegistrationSummary

type AppRegistrationSummary struct {
	ID            string     `json:"id"`
	APIKey        string     `json:"api_key"`
	APISecretHint string     `json:"api_secret_hint"`
	AssignedTo    string     `json:"assigned_to"`
	Label         string     `json:"label"`
	Status        string     `json:"status"`
	RegisteredBy  string     `json:"registered_by"`
	Source        string     `json:"source"`
	LastUsedAt    *time.Time `json:"last_used_at"`
	CreatedAt     time.Time  `json:"created_at"`
	UpdatedAt     time.Time  `json:"updated_at"`
}

AppRegistrationSummary is a redacted view of a registration (API secret masked).

type Store

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

Store is a thread-safe in-memory key registry, optionally backed by SQLite.

func New

func New() *Store

New creates a new registry store.

func (*Store) Count

func (s *Store) Count() int

Count returns the number of registry entries.

func (*Store) Delete

func (s *Store) Delete(id string) error

Delete removes a registration by ID.

func (*Store) Get

func (s *Store) Get(id string) (*AppRegistration, bool)

Get retrieves a registration by ID.

func (*Store) GetByAPIKey

func (s *Store) GetByAPIKey(apiKey string) (*AppRegistration, bool)

GetByAPIKey finds a registration by its API key.

func (*Store) GetByAPIKeyAnyStatus

func (s *Store) GetByAPIKeyAnyStatus(apiKey string) (*AppRegistration, bool)

GetByAPIKeyAnyStatus finds a registration by its API key regardless of status.

func (*Store) GetByEmail

func (s *Store) GetByEmail(email string) (*AppRegistration, bool)

GetByEmail finds the most recently updated active app registration assigned to this email. If no assigned entry is found, returns nil.

func (*Store) HasEntries

func (s *Store) HasEntries() bool

HasEntries returns true if the registry has any entries.

func (*Store) List

func (s *Store) List() []AppRegistrationSummary

List returns a redacted summary of all registered apps.

func (*Store) LoadFromDB

func (s *Store) LoadFromDB() error

LoadFromDB populates the in-memory store from the database.

func (*Store) MarkStatus

func (s *Store) MarkStatus(apiKey, status string)

MarkStatus sets the status of a registration found by API key. Unlike Update(), this does not require an ID and accepts any valid status.

func (*Store) Register

func (s *Store) Register(reg *AppRegistration) error

Register adds a new app registration to the registry.

func (*Store) SetDB

func (s *Store) SetDB(db *alerts.DB)

SetDB enables write-through persistence to the given SQLite database.

func (*Store) SetLogger

func (s *Store) SetLogger(logger *slog.Logger)

SetLogger sets the logger for DB error reporting.

func (*Store) Update

func (s *Store) Update(id string, assignedTo, label, status string) error

Update modifies a registration's mutable fields (assigned_to, label, status).

func (*Store) UpdateLastUsedAt

func (s *Store) UpdateLastUsedAt(apiKey string)

UpdateLastUsedAt records the most recent successful token exchange for this API key.

Jump to

Keyboard shortcuts

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