6aa84002b3
MCP clients see tools namespaced by the server's local name already
(mcp__<server>__<tool>), so the fable_ prefix on every tool name was
redundant and ate tokens in the model's tool list.
Tools renamed (34 total):
fable_search → search
fable_list_notes / get_note / create_note / update_note / delete_note → list_notes / ...
fable_list_tasks / get_task / create_task / update_task / add_task_log → list_tasks / ...
fable_list_projects / get_project / create_project / update_project → list_projects / ...
fable_list_milestones / create_milestone / update_milestone → list_milestones / ...
fable_list_events / create_event / get_event / update_event / delete_event → list_events / ...
fable_list_tags → list_tags
fable_get_recent → get_recent
fable_list_persons / create_person / update_person → list_persons / ...
fable_list_places / create_place / update_place → list_places / ...
fable_list_lists / create_list / update_list → list_lists / ...
Also rebranded in MCP scope:
FastMCP("fable", ...) → FastMCP("scribe", ...)
auth realm "fable-mcp" → "scribe-mcp"
ASGI scope key fable_user_id → scribe_user_id
ContextVar label fable_mcp_user_id → scribe_mcp_user_id
Tool docstrings "in Fable" / "Fable task" → "in Scribe" / "Scribe task"
Server _INSTRUCTIONS prose
Deliberately kept:
- The internal Python package name `fabledassistant` (per project naming
convention — internal stays).
- "Fabled Scribe" as the official product/brand name (page footer,
smtp_from_name default).
- References to the legacy `fable-mcp/` standalone package in docstrings
explaining what we ported from — accurate until that directory is
deleted in Phase 10.
Client impact: existing MCP registrations need
claude mcp remove <name> && claude mcp add ...
once with a freshly-copied snippet from Settings → MCP Access. Claude
Code then re-discovers tools on connect — old conversations that
referenced fable_* tool names will see "tool not found" on those calls
until updated.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
159 lines
5.3 KiB
Python
159 lines
5.3 KiB
Python
"""Tests for fable_*_event tools."""
|
|
from datetime import datetime
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from fabledassistant.mcp._context import _user_id_ctx
|
|
from fabledassistant.mcp.tools.events import (
|
|
list_events, create_event, get_event,
|
|
update_event, delete_event,
|
|
)
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _bind_user():
|
|
token = _user_id_ctx.set(7)
|
|
yield
|
|
_user_id_ctx.reset(token)
|
|
|
|
|
|
def _fake_event(**overrides) -> MagicMock:
|
|
e = MagicMock()
|
|
base = {
|
|
"id": 1, "title": "ev", "start_dt": "2026-06-01T10:00:00",
|
|
"duration_minutes": 30, "all_day": False,
|
|
"location": "", "description": "",
|
|
}
|
|
base.update(overrides)
|
|
e.to_dict.return_value = base
|
|
return e
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_events_passes_datetime_range():
|
|
mock = AsyncMock(return_value=[
|
|
{"id": 1, "title": "morning standup"},
|
|
])
|
|
with patch("fabledassistant.mcp.tools.events.events_svc.list_events", mock):
|
|
out = await list_events(date_from="2026-06-01", date_to="2026-06-08")
|
|
args, _ = mock.call_args
|
|
assert args[0] == 7 # user_id
|
|
assert args[1] == datetime(2026, 6, 1)
|
|
assert args[2] == datetime(2026, 6, 8)
|
|
assert out["total"] == 1
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_event_combines_date_and_time():
|
|
e = _fake_event()
|
|
mock = AsyncMock(return_value=e)
|
|
with patch("fabledassistant.mcp.tools.events.events_svc.create_event", mock):
|
|
await create_event(
|
|
title="standup", start_date="2026-06-01", start_time="09:30",
|
|
duration_minutes=15,
|
|
)
|
|
kwargs = mock.call_args.kwargs
|
|
assert kwargs["start_dt"] == datetime(2026, 6, 1, 9, 30)
|
|
assert kwargs["duration_minutes"] == 15
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_event_zero_duration_means_point_event():
|
|
"""duration_minutes=0 must map to None at the service layer (NULL = point)."""
|
|
e = _fake_event()
|
|
mock = AsyncMock(return_value=e)
|
|
with patch("fabledassistant.mcp.tools.events.events_svc.create_event", mock):
|
|
await create_event(title="x", start_date="2026-06-01")
|
|
assert mock.call_args.kwargs["duration_minutes"] is None
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_event_raises_when_not_found():
|
|
with patch(
|
|
"fabledassistant.mcp.tools.events.events_svc.get_event",
|
|
AsyncMock(return_value=None),
|
|
):
|
|
with pytest.raises(ValueError, match="event 999 not found"):
|
|
await get_event(event_id=999)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_event_only_sends_non_default_fields():
|
|
e = _fake_event()
|
|
mock = AsyncMock(return_value=e)
|
|
with patch("fabledassistant.mcp.tools.events.events_svc.update_event", mock):
|
|
await update_event(event_id=1, title="new title")
|
|
args, kwargs = mock.call_args
|
|
assert args == (7, 1)
|
|
assert kwargs == {"title": "new title"}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_event_duration_minus_one_means_unchanged():
|
|
e = _fake_event()
|
|
mock = AsyncMock(return_value=e)
|
|
with patch("fabledassistant.mcp.tools.events.events_svc.update_event", mock):
|
|
await update_event(event_id=1, duration_minutes=-1)
|
|
assert "duration_minutes" not in mock.call_args.kwargs
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_event_duration_zero_clears_to_point():
|
|
"""duration_minutes=0 means "set to point event" (NULL)."""
|
|
e = _fake_event()
|
|
mock = AsyncMock(return_value=e)
|
|
with patch("fabledassistant.mcp.tools.events.events_svc.update_event", mock):
|
|
await update_event(event_id=1, duration_minutes=0)
|
|
assert mock.call_args.kwargs["duration_minutes"] is None
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_event_requires_both_date_and_time_to_move():
|
|
e = _fake_event()
|
|
mock = AsyncMock(return_value=e)
|
|
with patch("fabledassistant.mcp.tools.events.events_svc.update_event", mock):
|
|
await update_event(event_id=1, start_date="2026-06-02")
|
|
# Only start_date, no start_time → start_dt NOT in fields
|
|
assert "start_dt" not in mock.call_args.kwargs
|
|
|
|
mock.reset_mock()
|
|
await update_event(
|
|
event_id=1, start_date="2026-06-02", start_time="11:00",
|
|
)
|
|
assert mock.call_args.kwargs["start_dt"] == datetime(2026, 6, 2, 11)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_event_raises_when_not_found():
|
|
with patch(
|
|
"fabledassistant.mcp.tools.events.events_svc.update_event",
|
|
AsyncMock(return_value=None),
|
|
):
|
|
with pytest.raises(ValueError, match="event 999 not found"):
|
|
await update_event(event_id=999, title="x")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delete_event_checks_existence_then_returns_confirmation():
|
|
fake = _fake_event()
|
|
with patch(
|
|
"fabledassistant.mcp.tools.events.events_svc.get_event",
|
|
AsyncMock(return_value=fake),
|
|
), patch(
|
|
"fabledassistant.mcp.tools.events.events_svc.delete_event",
|
|
AsyncMock(return_value=None),
|
|
):
|
|
result = await delete_event(event_id=7)
|
|
assert result == "Event 7 deleted."
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delete_event_raises_when_not_found():
|
|
with patch(
|
|
"fabledassistant.mcp.tools.events.events_svc.get_event",
|
|
AsyncMock(return_value=None),
|
|
):
|
|
with pytest.raises(ValueError, match="event 999 not found"):
|
|
await delete_event(event_id=999)
|