Enforce an explicit read-only tool allowlist
Remove every tool that is not explicitly approved for the private Buzz agent. This keeps future mutating tools closed by default instead of relying on a denylist that must be updated manually. Co-authored-by: fredamn76 <fredrik.fallman@gmail.com> Signed-off-by: fredamn76 <fredrik.fallman@gmail.com>
This commit is contained in:
+15
-12
@@ -1,6 +1,7 @@
|
||||
"""Small, confirmation-friendly MCP facade over the Mealie API."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import html
|
||||
import json
|
||||
import os
|
||||
@@ -38,16 +39,17 @@ RESOURCE_DIR = Path(__file__).parent / "resources"
|
||||
|
||||
mcp = MCPServer("mealie", version="0.1.0")
|
||||
|
||||
WRITE_TOOL_NAMES = frozenset(
|
||||
READ_ONLY_TOOL_NAMES = frozenset(
|
||||
{
|
||||
"import_recipe_url",
|
||||
"import_recipe_text",
|
||||
"import_recipe_image",
|
||||
"patch_recipe",
|
||||
"delete_recipe",
|
||||
"parse_ingredients",
|
||||
"set_cover_image",
|
||||
"shopping_list_add",
|
||||
"check_auth",
|
||||
"find_by_source_url",
|
||||
"get_recipe",
|
||||
"list_organizers",
|
||||
"resolve_foods",
|
||||
"scale_ingredients",
|
||||
"search_recipes",
|
||||
"suggest_recipes",
|
||||
"verify_recipe",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -762,10 +764,11 @@ def main() -> None:
|
||||
|
||||
def _configure_read_only(
|
||||
server: MCPServer,
|
||||
write_tool_names: frozenset[str] = WRITE_TOOL_NAMES,
|
||||
allowed_tool_names: frozenset[str] = READ_ONLY_TOOL_NAMES,
|
||||
) -> None:
|
||||
"""Remove mutating tools before exposing the server to a read-only client."""
|
||||
for name in sorted(write_tool_names):
|
||||
"""Expose only explicitly approved tools to a read-only client."""
|
||||
registered_tool_names = {tool.name for tool in asyncio.run(server.list_tools())}
|
||||
for name in sorted(registered_tool_names - allowed_tool_names):
|
||||
server.remove_tool(name)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user