include/entropic/mcp/mcp_key_set.h

← API

include/entropic/mcp/mcp_key_set.h

entropic::MCPKeySet

Per-identity set of authorized MCP tool keys.

void entropic::MCPKeySet::grant(const std::string &pattern, MCPAccessLevel level)

Grant a tool key with an access level.

If the pattern already exists, the level is updated (not additive). Granting READ to a pattern that had WRITE downgrades it.

Parameters
  • pattern — Tool pattern string.
  • level — Access level to grant.

bool entropic::MCPKeySet::revoke(const std::string &pattern)

Revoke a tool key entirely.

Parameters
  • pattern — Tool pattern string to revoke.
Returns
true if pattern was found and removed.

bool entropic::MCPKeySet::has_access(const std::string &tool_name, MCPAccessLevel required) const

Check if a specific tool is authorized at the required level.

Resolution order (most specific wins): Exact match on tool_name Server wildcard (e.g., "filesystem.*" matches "filesystem.read_file") Full wildcard ("*") No match → denied Access level comparison: granted >= required means authorized. Levels are ordinal, so a key granting WRITE also satisfies a READ requirement but not the reverse — which is what makes ToolBase's WRITE default a genuine restriction on a READ-only key set.

Parameters
  • tool_name — Fully-qualified tool name (e.g., "filesystem.read_file").
  • required — Minimum access level needed.
  • tool_name — Fully-qualified tool name.
  • required — Minimum access level needed, as declared by the tool.
Returns
  • true if authorized.
  • true when the best-matching granted key's level is at least required; false otherwise, including when no key matches (which resolves to NONE).

std::vector< MCPKey > entropic::MCPKeySet::list() const

List all granted keys.

Returns
Vector of MCPKey entries.

size_t entropic::MCPKeySet::size() const

Number of granted keys.

Returns
Key count.

void entropic::MCPKeySet::clear()

Remove all granted keys.

std::string entropic::MCPKeySet::serialize() const

Serialize key set to JSON string.

Returns
  • JSON array: [{"pattern":"...", "level":"WRITE"}, ...]
  • JSON array of {pattern, level} objects.

bool entropic::MCPKeySet::deserialize(const std::string &json)

Deserialize key set from JSON string.

Replaces all current keys with the deserialized set. Invalid entries are logged as WARNING and skipped.

Parameters
  • json — JSON array string (same format as serialize output).
  • json — JSON array string.
Returns
true if parsed successfully.