The store keeps the company's MCP servers, and which tools a scope may call

mcp_servers holds each server: its address, headers, and secret
references for the headers that carry credentials. limits gains
allowed_tools, patterns such as jira.* resolved down the tenancy tree;
unlike models, a tool no level grants is not granted.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-20 10:36:08 +02:00
1 parent 8ffde2b80c
commit 6dfdfbf2fe
8 files changed
+277 -10

No files matched your search

+17 -7
View File
@@ -267,29 +267,33 @@ func (s *DB) PutLimits(ctx context.Context, l Limits) error {
if err != nil {
return err
}
tools, err := encodeModels(l.AllowedTools)
if err != nil {
return err
}
_, err = s.db.ExecContext(ctx,
`INSERT INTO limits (scope_type, scope_id, rpm, tpm, budget_micros, budget_period, allowed_models)
VALUES (?, ?, ?, ?, ?, ?, ?)
`INSERT INTO limits (scope_type, scope_id, rpm, tpm, budget_micros, budget_period, allowed_models, allowed_tools)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (scope_type, scope_id) DO UPDATE SET
rpm = excluded.rpm, tpm = excluded.tpm,
budget_micros = excluded.budget_micros, budget_period = excluded.budget_period,
allowed_models = excluded.allowed_models`,
allowed_models = excluded.allowed_models, allowed_tools = excluded.allowed_tools`,
string(l.Scope), l.ScopeID, nullInt(l.RPM), nullInt(l.TPM),
nullInt64(l.Budget), nullString(string(l.BudgetPeriod)), models)
nullInt64(l.Budget), nullString(string(l.BudgetPeriod)), models, tools)
return err
}
// LimitsFor reads the limits set at one scope, without inheritance.
func (s *DB) LimitsFor(ctx context.Context, scope Scope, id string) (Limits, error) {
row := s.db.QueryRowContext(ctx,
`SELECT rpm, tpm, budget_micros, budget_period, allowed_models
`SELECT rpm, tpm, budget_micros, budget_period, allowed_models, allowed_tools
FROM limits WHERE scope_type = ? AND scope_id = ?`, string(scope), id)
l := Limits{Scope: scope, ScopeID: id}
var rpm, tpm sql.NullInt64
var budget sql.NullInt64
var period, models sql.NullString
if err := row.Scan(&rpm, &tpm, &budget, &period, &models); err != nil {
var period, models, tools sql.NullString
if err := row.Scan(&rpm, &tpm, &budget, &period, &models, &tools); err != nil {
if errors.Is(err, sql.ErrNoRows) {
return Limits{}, ErrNotFound
}
@@ -312,6 +316,9 @@ func (s *DB) LimitsFor(ctx context.Context, scope Scope, id string) (Limits, err
if l.AllowedModels, err = decodeModels(models); err != nil {
return Limits{}, err
}
if l.AllowedTools, err = decodeModels(tools); err != nil {
return Limits{}, err
}
return l, nil
}
@@ -409,6 +416,9 @@ func (e *Effective) tighten(l Limits) {
e.BudgetPeriod = l.BudgetPeriod
e.BudgetOwner = owner
}
if l.AllowedTools != nil {
e.ToolGrants = append(e.ToolGrants, slices.Clone(l.AllowedTools))
}
if l.AllowedModels != nil {
if e.AllowedModels == nil {
e.AllowedModels = slices.Clone(l.AllowedModels)