Add create_note_from_template MCP tool #31

Merged
forgejo_admin merged 1 commit from 28-add-create-note-from-template-tool into main 2026-03-09 17:30:22 +00:00

Summary

Adds a create_note_from_template MCP tool that wraps the SDK's create_note_from_template() method, allowing agents to create notes from Jinja2 templates by passing structured data (as a JSON string) instead of raw HTML.

Changes

  • src/pal_e_docs_mcp/tools/notes.py — Added import json and the create_note_from_template tool function. Follows the same @mcp.tool() / Annotated[..., Field()] / _ok() / _error_response() pattern as create_note. Parses data from JSON string to dict via json.loads(), validates it is a dict, splits comma-separated tags to a list, and forwards all params to the SDK.
  • tests/test_param_alignment.py — Added TestCreateNoteFromTemplate class with 10 unit tests covering: valid JSON data, invalid JSON error, non-object JSON error, tags CSV splitting, tags None sends empty list, trailing comma handling, optional metadata forwarding, SDK error handling, empty object data, and scalar JSON error.
  • uv.lock — Lockfile specifier updated to match pyproject.toml's >=0.2.0 SDK floor (was stale at >=0.1.0).

Test Plan

  • All 53 tests pass: cd ~/pal-e-docs-mcp && PALDOCS_BASE_URL=https://paldocs.tail5b443a.ts.net .venv/bin/pytest tests/ -v
  • ruff lint and format checks pass
  • 10 new tests specifically cover the create_note_from_template tool

Review Checklist

  • Tool follows existing pattern in tools/notes.py (decorator, Annotated params, try/except)
  • data param is JSON string at MCP layer, parsed to dict before SDK call
  • Invalid JSON returns 422-style error, not a crash
  • Tags splitting matches create_note behavior (comma-separated, strip whitespace, filter empty)
  • Tool description documents expected data keys for plan templates
  • No changes to __init__.py or server.py
  • ruff lint and format clean
  • Plan: plan-2026-03-09-template-rendering
  • Forgejo issue: #28

Closes #28

## Summary Adds a `create_note_from_template` MCP tool that wraps the SDK's `create_note_from_template()` method, allowing agents to create notes from Jinja2 templates by passing structured data (as a JSON string) instead of raw HTML. ## Changes - `src/pal_e_docs_mcp/tools/notes.py` — Added `import json` and the `create_note_from_template` tool function. Follows the same `@mcp.tool()` / `Annotated[..., Field()]` / `_ok()` / `_error_response()` pattern as `create_note`. Parses `data` from JSON string to dict via `json.loads()`, validates it is a dict, splits comma-separated `tags` to a list, and forwards all params to the SDK. - `tests/test_param_alignment.py` — Added `TestCreateNoteFromTemplate` class with 10 unit tests covering: valid JSON data, invalid JSON error, non-object JSON error, tags CSV splitting, tags None sends empty list, trailing comma handling, optional metadata forwarding, SDK error handling, empty object data, and scalar JSON error. - `uv.lock` — Lockfile specifier updated to match pyproject.toml's `>=0.2.0` SDK floor (was stale at `>=0.1.0`). ## Test Plan - All 53 tests pass: `cd ~/pal-e-docs-mcp && PALDOCS_BASE_URL=https://paldocs.tail5b443a.ts.net .venv/bin/pytest tests/ -v` - ruff lint and format checks pass - 10 new tests specifically cover the `create_note_from_template` tool ## Review Checklist - [x] Tool follows existing pattern in `tools/notes.py` (decorator, Annotated params, try/except) - [x] `data` param is JSON string at MCP layer, parsed to dict before SDK call - [x] Invalid JSON returns 422-style error, not a crash - [x] Tags splitting matches `create_note` behavior (comma-separated, strip whitespace, filter empty) - [x] Tool description documents expected data keys for plan templates - [x] No changes to `__init__.py` or `server.py` - [x] ruff lint and format clean ## Related - Plan: `plan-2026-03-09-template-rendering` - Forgejo issue: #28 Closes #28
Add create_note_from_template MCP tool
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
b96cde8e37
Wraps the SDK's create_note_from_template() method so agents can create
notes from Jinja2 templates by passing structured data instead of raw HTML.
The data parameter is a JSON string at the MCP layer, parsed to a dict
before forwarding to the SDK. Invalid JSON returns a 422-style error.

Includes 10 unit tests covering JSON parsing, tag splitting, metadata
forwarding, and error handling.

Closes #28

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
forgejo_admin deleted branch 28-add-create-note-from-template-tool 2026-03-09 17:30:23 +00:00
Sign in to join this conversation.
No description provided.