mcp_key_set.cpp¶
src/mcp/mcp_key_set.cpp
@file mcp_key_set.cpp @brief MCPKeySet implementation.
Owners: @tvanfossen
find_best_match
MCPAccessLevel entropic::MCPKeySet::find_best_match(const std::string &tool_name) const
Find the best matching access level for a tool name.
src/mcp/mcp_key_set.cpp:198
Source · 18 lines
MCPAccessLevel MCPKeySet::find_best_match(
const std::string& tool_name) const {
auto result = MCPAccessLevel::NONE;
// 1. Exact match (most specific)
auto it = keys_.find(tool_name);
if (it != keys_.end()) {
result = it->second;
} else if (auto wc = server_wildcard(tool_name);
!wc.empty() &&
(it = keys_.find(wc)) != keys_.end()) {
// 2. Server wildcard (e.g., "filesystem.*")
result = it->second;
} else if ((it = keys_.find("*")) != keys_.end()) {
// 3. Full wildcard
result = it->second;
}
return result;
}Activity · 11 steps
Requirements
has_access
bool entropic::MCPKeySet::has_access(const std::string &tool_name, MCPAccessLevel required) const
Check if a specific tool is authorized at the required level.
src/mcp/mcp_key_set.cpp:66
Source · 7 lines
bool MCPKeySet::has_access(const std::string& tool_name,
MCPAccessLevel required) const {
std::lock_guard<std::mutex> lock(key_mutex_);
auto granted = find_best_match(tool_name);
return static_cast<uint8_t>(granted) >=
static_cast<uint8_t>(required);
}Activity · 3 steps
Requirements
server_wildcard
std::string entropic::MCPKeySet::server_wildcard(const std::string &tool_name)
Extract server prefix from a fully-qualified tool name.
src/mcp/mcp_key_set.cpp:176
Source · 8 lines
std::string MCPKeySet::server_wildcard(
const std::string& tool_name) {
auto dot = tool_name.find('.');
if (dot == std::string::npos) {
return "";
}
return tool_name.substr(0, dot) + ".*";
}