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

+33
View File
@@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"errors"
"path"
"strings"
"time"
)
@@ -130,6 +131,10 @@ type Limits struct {
BudgetPeriod Period
// AllowedModels nil means every model.
AllowedModels []string
// AllowedTools are the company MCP servers' tools this scope may call,
// as patterns: jira.*, db.query, *. Unlike models, nil says nothing
// here, and a tool no level grants is not granted.
AllowedTools []string
}
// Period is how often a budget resets.
@@ -165,6 +170,10 @@ type Effective struct {
BudgetPeriod Period
// AllowedModels is the intersection along the chain. nil means every model.
AllowedModels []string
// ToolGrants are AllowedTools of every level that set them, widest
// first: a tool is the caller's when each of them grants it, and at
// least one level said something.
ToolGrants [][]string
// ExcludedLicences are the licences the caller's person has said not to
// use, as LicenceKey gives them; none for a key without a person.
ExcludedLicences []string
@@ -228,6 +237,30 @@ func (e Effective) Allows(model string) bool {
return false
}
// AllowsTool reports whether a company MCP server's tool, server.tool, may
// be called with this key: granted somewhere along the chain, and by every
// level that names any.
func (e Effective) AllowsTool(name string) bool {
if len(e.ToolGrants) == 0 {
return false
}
for _, grants := range e.ToolGrants {
if !matchesTool(grants, name) {
return false
}
}
return true
}
func matchesTool(patterns []string, name string) bool {
for _, p := range patterns {
if ok, err := path.Match(p, name); err == nil && ok {
return true
}
}
return false
}
// Usage is one request's accounting record.
type Usage struct {
At time.Time