359cb24d9a
- client.py: async httpx wrapper, FableAPIError, stream_get() SSE generator, singleton init_client()/get_client() and _reset_client() for tests - tools/: notes, tasks, projects, milestones, search, chat — thin async functions that accept FableClient and call Fable REST endpoints - server.py: FastMCP entry point with 20 tools registered via @mcp.tool(), each opening a fresh FableClient context per call; validates env vars at startup - tests: 34 tests covering client HTTP behaviour, error handling, singleton, SSE streaming, and all tool modules Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
"""MCP tools for Fable projects."""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from fable_mcp.client import FableClient
|
|
|
|
|
|
async def list_projects(client: FableClient) -> dict[str, Any]:
|
|
"""List all projects for the authenticated user."""
|
|
return await client.get("/api/projects")
|
|
|
|
|
|
async def get_project(client: FableClient, *, project_id: int) -> dict[str, Any]:
|
|
"""Fetch a project by ID (includes milestone summary)."""
|
|
return await client.get(f"/api/projects/{project_id}")
|
|
|
|
|
|
async def create_project(
|
|
client: FableClient,
|
|
*,
|
|
title: str,
|
|
description: str = "",
|
|
goal: str | None = None,
|
|
status: str = "active",
|
|
color: str | None = None,
|
|
) -> dict[str, Any]:
|
|
"""Create a new project."""
|
|
payload: dict[str, Any] = {"title": title, "description": description, "status": status}
|
|
if goal is not None:
|
|
payload["goal"] = goal
|
|
if color is not None:
|
|
payload["color"] = color
|
|
return await client.post("/api/projects", json=payload)
|
|
|
|
|
|
async def update_project(
|
|
client: FableClient,
|
|
*,
|
|
project_id: int,
|
|
title: str | None = None,
|
|
description: str | None = None,
|
|
goal: str | None = None,
|
|
status: str | None = None,
|
|
color: str | None = None,
|
|
) -> dict[str, Any]:
|
|
"""Update an existing project."""
|
|
payload: dict[str, Any] = {}
|
|
if title is not None:
|
|
payload["title"] = title
|
|
if description is not None:
|
|
payload["description"] = description
|
|
if goal is not None:
|
|
payload["goal"] = goal
|
|
if status is not None:
|
|
payload["status"] = status
|
|
if color is not None:
|
|
payload["color"] = color
|
|
return await client.patch(f"/api/projects/{project_id}", json=payload)
|