Fix block content param type: str -> dict|str with JSON parsing #27

Merged
forgejo_admin merged 1 commit from 26-fix-create-block-and-update-block-conten into main 2026-03-09 03:39:53 +00:00

Summary

The create_block and update_block MCP tools typed content as str, but the pal-e-docs REST API expects a JSON dict. This caused a catch-22 where dict input was rejected by Pydantic validation and string input was rejected by the API. Fixed by changing the type to dict | str | None with automatic JSON parsing for string inputs.

Changes

  • src/pal_e_docs_mcp/tools/blocks.py — Changed content param type from str | None to dict | str | None in both create_block and update_block. Added _parse_content helper that normalises content (dict pass-through, JSON string auto-parse, None pass-through). Updated field descriptions with content shapes per block type (heading, paragraph, list, table, code).
  • tests/conftest.py — Added blocks_mod to mock_sdk fixture so block tool tests can use the shared mock.
  • tests/test_param_alignment.py — Added 14 new tests: 6 for _parse_content unit tests (None, dict, valid JSON string, invalid JSON, JSON array, JSON scalar), 4 for create_block content handling, 4 for update_block content handling.

Test Plan

  • All 39 tests pass (25 existing + 14 new)
  • uv run pytest tests/ -v — full pass
  • uv run ruff check src/ tests/ — clean
  • uv run ruff format --check src/ tests/ — clean

Review Checklist

  • content param type changed from str | None to dict | str | None in both tools
  • _parse_content helper handles dict, JSON string, None, and error cases
  • Field descriptions document content shapes for all block types
  • conftest patches get_sdk for blocks module
  • 14 new tests cover all paths (dict, string, None, invalid input)
  • Existing 25 tests still pass
  • Ruff lint and format clean
  • Plan: todo-mcp-block-content-type
  • Forgejo issue: #26
## Summary The `create_block` and `update_block` MCP tools typed `content` as `str`, but the pal-e-docs REST API expects a JSON dict. This caused a catch-22 where dict input was rejected by Pydantic validation and string input was rejected by the API. Fixed by changing the type to `dict | str | None` with automatic JSON parsing for string inputs. ## Changes - `src/pal_e_docs_mcp/tools/blocks.py` — Changed `content` param type from `str | None` to `dict | str | None` in both `create_block` and `update_block`. Added `_parse_content` helper that normalises content (dict pass-through, JSON string auto-parse, None pass-through). Updated field descriptions with content shapes per block type (heading, paragraph, list, table, code). - `tests/conftest.py` — Added `blocks_mod` to `mock_sdk` fixture so block tool tests can use the shared mock. - `tests/test_param_alignment.py` — Added 14 new tests: 6 for `_parse_content` unit tests (None, dict, valid JSON string, invalid JSON, JSON array, JSON scalar), 4 for `create_block` content handling, 4 for `update_block` content handling. ## Test Plan - All 39 tests pass (25 existing + 14 new) - `uv run pytest tests/ -v` — full pass - `uv run ruff check src/ tests/` — clean - `uv run ruff format --check src/ tests/` — clean ## Review Checklist - [x] `content` param type changed from `str | None` to `dict | str | None` in both tools - [x] `_parse_content` helper handles dict, JSON string, None, and error cases - [x] Field descriptions document content shapes for all block types - [x] conftest patches `get_sdk` for blocks module - [x] 14 new tests cover all paths (dict, string, None, invalid input) - [x] Existing 25 tests still pass - [x] Ruff lint and format clean ## Related - Plan: `todo-mcp-block-content-type` - Forgejo issue: #26
Fix block content param type: str -> dict|str with JSON parsing
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
d30ff65ea6
The create_block and update_block MCP tools typed `content` as `str`,
but the pal-e-docs REST API expects a JSON dict. This caused a catch-22
where dict input was rejected by Pydantic and string input was rejected
by the API.

Changes:
- content parameter type: `str | None` -> `dict | str | None`
- Add _parse_content helper: dict pass-through, JSON string auto-parse
- Update field descriptions with content shapes per block type
- Patch get_sdk for blocks module in test conftest
- Add 14 tests covering dict, string, None, and error paths

Closes #26

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
forgejo_admin deleted branch 26-fix-create-block-and-update-block-conten 2026-03-09 03:39:53 +00:00
Sign in to join this conversation.
No description provided.