feat(mcp): project + milestone CRUD tools
Seven tools matching existing fable-mcp contracts: - fable_list/get/create/update_project (no delete; archive via status) - fable_list/create/update_milestone (no get; no delete) LLM-era similarity-check / 'confirmed' guard for create_project is NOT replicated — Claude doesn't need it. The service's auto-summary regeneration side effect (services.projects.update_project) stays for now; gets removed in Phase 7 along with all other LLM code. Notable sentinels: - update_milestone: order_index=-1 means "leave unchanged" (0 is valid) - create_milestone: description="" becomes None at the service layer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,9 @@ Each tool module exposes a `register(mcp)` function that attaches its tools
|
||||
to a FastMCP instance. `register_all(mcp)` is the single entry point called
|
||||
from `mcp.server.build_mcp_server`.
|
||||
"""
|
||||
from fabledassistant.mcp.tools import notes, search, tasks
|
||||
from fabledassistant.mcp.tools import (
|
||||
milestones, notes, projects, search, tasks,
|
||||
)
|
||||
|
||||
|
||||
def register_all(mcp) -> None:
|
||||
@@ -12,3 +14,5 @@ def register_all(mcp) -> None:
|
||||
search.register(mcp)
|
||||
notes.register(mcp)
|
||||
tasks.register(mcp)
|
||||
projects.register(mcp)
|
||||
milestones.register(mcp)
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
"""Milestone CRUD MCP tools — thin wrappers over services/milestones.py.
|
||||
|
||||
Mirrors existing fable-mcp milestone tool contracts: list/create/update. The
|
||||
existing surface has no fable_get_milestone or fable_delete_milestone — kept
|
||||
that way for parity.
|
||||
|
||||
Sentinels:
|
||||
- title="" / description="" / status="" → "leave unchanged" on update
|
||||
- order_index=-1 → "leave unchanged" on update (0 is a valid order_index)
|
||||
- status="active" default on create
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from fabledassistant.mcp._context import current_user_id
|
||||
from fabledassistant.services import milestones as milestones_svc
|
||||
|
||||
|
||||
async def fable_list_milestones(project_id: int) -> dict:
|
||||
"""List milestones for a Fable project, ordered by order_index.
|
||||
|
||||
Returns id, title, description, status (active/done), order_index,
|
||||
and task counts.
|
||||
"""
|
||||
uid = current_user_id()
|
||||
rows = await milestones_svc.get_project_milestone_summary(uid, project_id)
|
||||
return {"milestones": rows}
|
||||
|
||||
|
||||
async def fable_create_milestone(
|
||||
project_id: int,
|
||||
title: str,
|
||||
description: str = "",
|
||||
status: str = "active",
|
||||
) -> dict:
|
||||
"""Create a milestone within a Fable project.
|
||||
|
||||
Args:
|
||||
project_id: The project this milestone belongs to (required).
|
||||
title: Milestone name (required).
|
||||
description: Optional description of what this milestone covers.
|
||||
status: active (default) or done.
|
||||
"""
|
||||
uid = current_user_id()
|
||||
milestone = await milestones_svc.create_milestone(
|
||||
uid,
|
||||
project_id=project_id,
|
||||
title=title,
|
||||
description=description or None,
|
||||
status=status,
|
||||
)
|
||||
return milestone.to_dict()
|
||||
|
||||
|
||||
async def fable_update_milestone(
|
||||
project_id: int,
|
||||
milestone_id: int,
|
||||
title: str = "",
|
||||
description: str = "",
|
||||
status: str = "",
|
||||
order_index: int = -1,
|
||||
) -> dict:
|
||||
"""Update a Fable milestone. Only explicitly provided fields are changed.
|
||||
|
||||
Args:
|
||||
project_id: Project the milestone belongs to (preserved for API parity;
|
||||
ownership scoping is enforced by user_id at the service layer).
|
||||
milestone_id: ID of the milestone to update.
|
||||
title: New title, or omit to leave unchanged.
|
||||
description: New description, or omit to leave unchanged.
|
||||
status: New status — active or done.
|
||||
order_index: New display position (0-based). Use -1 to leave unchanged.
|
||||
"""
|
||||
uid = current_user_id()
|
||||
fields: dict = {}
|
||||
if title:
|
||||
fields["title"] = title
|
||||
if description:
|
||||
fields["description"] = description
|
||||
if status:
|
||||
fields["status"] = status
|
||||
if order_index >= 0:
|
||||
fields["order_index"] = order_index
|
||||
milestone = await milestones_svc.update_milestone(uid, milestone_id, **fields)
|
||||
if milestone is None:
|
||||
raise ValueError(f"milestone {milestone_id} not found")
|
||||
return milestone.to_dict()
|
||||
|
||||
|
||||
def register(mcp) -> None:
|
||||
for fn in (
|
||||
fable_list_milestones,
|
||||
fable_create_milestone,
|
||||
fable_update_milestone,
|
||||
):
|
||||
mcp.tool(name=fn.__name__)(fn)
|
||||
@@ -0,0 +1,123 @@
|
||||
"""Project CRUD MCP tools — thin wrappers over services/projects.py.
|
||||
|
||||
Mirrors existing fable-mcp project tool contracts. Note: there is no
|
||||
fable_delete_project here (matches existing fable-mcp surface). To stop
|
||||
working on a project, update its status to 'archived'.
|
||||
|
||||
The LLM-era similarity-check / 'confirmed' guard from services/tools/projects.py
|
||||
is intentionally NOT replicated here — Claude is the client, not a weak local
|
||||
model that needs that guardrail. services.projects.create_project creates
|
||||
directly with no similarity warning.
|
||||
|
||||
The auto-summary regeneration that services.projects.update_project triggers
|
||||
async will be removed in Phase 7 (it's an LLM call). The wrapper makes no
|
||||
assumption either way; once the service-layer side effect is gone, this code
|
||||
keeps working.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from fabledassistant.mcp._context import current_user_id
|
||||
from fabledassistant.services import milestones as milestones_svc
|
||||
from fabledassistant.services import projects as projects_svc
|
||||
|
||||
|
||||
async def fable_list_projects() -> dict:
|
||||
"""List all Fable projects for the current user.
|
||||
|
||||
Returns id, title, description, goal, status (active/archived), color,
|
||||
and a short auto-generated summary for each project.
|
||||
"""
|
||||
uid = current_user_id()
|
||||
rows = await projects_svc.list_projects(uid)
|
||||
return {"projects": [p.to_dict() for p in rows]}
|
||||
|
||||
|
||||
async def fable_get_project(project_id: int) -> dict:
|
||||
"""Fetch a Fable project by ID, including its milestone summary.
|
||||
|
||||
Returns full project fields plus a milestone_summary list with each
|
||||
milestone's id, title, status, and task counts.
|
||||
"""
|
||||
uid = current_user_id()
|
||||
project = await projects_svc.get_project(uid, project_id)
|
||||
if project is None:
|
||||
raise ValueError(f"project {project_id} not found")
|
||||
data = project.to_dict()
|
||||
data["milestone_summary"] = await milestones_svc.get_project_milestone_summary(
|
||||
uid, project_id,
|
||||
)
|
||||
return data
|
||||
|
||||
|
||||
async def fable_create_project(
|
||||
title: str,
|
||||
description: str = "",
|
||||
goal: str = "",
|
||||
status: str = "active",
|
||||
color: str = "",
|
||||
) -> dict:
|
||||
"""Create a new project in Fable.
|
||||
|
||||
Args:
|
||||
title: Project name (required).
|
||||
description: Short summary of what the project is.
|
||||
goal: The desired outcome or definition of done for the project.
|
||||
status: active (default) or archived.
|
||||
color: Optional hex colour for the project card (e.g. "#6366f1").
|
||||
"""
|
||||
uid = current_user_id()
|
||||
project = await projects_svc.create_project(
|
||||
uid,
|
||||
title=title,
|
||||
description=description,
|
||||
goal=goal,
|
||||
status=status,
|
||||
color=color or None,
|
||||
)
|
||||
return project.to_dict()
|
||||
|
||||
|
||||
async def fable_update_project(
|
||||
project_id: int,
|
||||
title: str = "",
|
||||
description: str = "",
|
||||
goal: str = "",
|
||||
status: str = "",
|
||||
color: str = "",
|
||||
) -> dict:
|
||||
"""Update an existing Fable project. Only explicitly provided fields are changed.
|
||||
|
||||
Args:
|
||||
project_id: ID of the project to update.
|
||||
title: New title, or omit to leave unchanged.
|
||||
description: New description, or omit to leave unchanged.
|
||||
goal: New goal/definition-of-done, or omit to leave unchanged.
|
||||
status: New status — active or archived.
|
||||
color: New hex colour, or omit to leave unchanged.
|
||||
"""
|
||||
uid = current_user_id()
|
||||
fields: dict = {}
|
||||
if title:
|
||||
fields["title"] = title
|
||||
if description:
|
||||
fields["description"] = description
|
||||
if goal:
|
||||
fields["goal"] = goal
|
||||
if status:
|
||||
fields["status"] = status
|
||||
if color:
|
||||
fields["color"] = color
|
||||
project = await projects_svc.update_project(uid, project_id, **fields)
|
||||
if project is None:
|
||||
raise ValueError(f"project {project_id} not found")
|
||||
return project.to_dict()
|
||||
|
||||
|
||||
def register(mcp) -> None:
|
||||
for fn in (
|
||||
fable_list_projects,
|
||||
fable_get_project,
|
||||
fable_create_project,
|
||||
fable_update_project,
|
||||
):
|
||||
mcp.tool(name=fn.__name__)(fn)
|
||||
Reference in New Issue
Block a user