- Changed the formatting of the environment variable section in CLAUDE.md to use code block syntax for better readability. - Added a CloudFlare protection notice in README.md to inform users about potential API request blocks and provide steps for resolution.
3.6 KiB
3.6 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Penpot MCP Server is a Python-based Model Context Protocol (MCP) server that bridges AI language models with Penpot, an open-source design platform. It enables programmatic interaction with design files through a well-structured API.
Key Commands
Development Setup
# Install dependencies (recommended)
uv sync --extra dev
# Run the MCP server
uv run penpot-mcp
# Run tests
uv run pytest
uv run pytest --cov=penpot_mcp tests/ # with coverage
# Lint and fix code
uv run python lint.py # check issues
uv run python lint.py --autofix # auto-fix issues
Running the Server
# Default stdio mode (for Claude Desktop/Cursor)
make mcp-server
# SSE mode (for debugging with inspector)
make mcp-server-sse
# Launch MCP inspector (requires SSE mode)
make mcp-inspector
CLI Tools
# Generate tree visualization
penpot-tree path/to/penpot_file.json
# Validate Penpot file
penpot-validate path/to/penpot_file.json
Architecture Overview
Core Components
-
MCP Server (
penpot_mcp/server/mcp_server.py)- Built on FastMCP framework
- Implements resources and tools for Penpot interaction
- Memory cache with 10-minute TTL
- Supports stdio (default) and SSE modes
-
API Client (
penpot_mcp/api/penpot_api.py)- REST client for Penpot platform
- Transit+JSON format handling
- Cookie-based authentication with auto-refresh
- Lazy authentication pattern
-
Key Design Patterns
- Authentication: Cookie-based with automatic re-authentication on 401/403
- Caching: In-memory file cache to reduce API calls
- Resource/Tool Duality: Resources can be exposed as tools via RESOURCES_AS_TOOLS config
- Transit Format: Special handling for UUIDs (
~uprefix) and keywords (~:prefix)
Available Tools/Functions
list_projects: Get all Penpot projectsget_project_files: List files in a projectget_file: Retrieve and cache file datasearch_object: Search design objects by name (regex)get_object_tree: Get filtered object tree with screenshotexport_object: Export design objects as imagespenpot_tree_schema: Get schema for object tree fields
Environment Configuration
Create a .env file with:
PENPOT_API_URL=https://design.penpot.app/api
PENPOT_USERNAME=your_username
PENPOT_PASSWORD=your_password
ENABLE_HTTP_SERVER=true # for image serving
RESOURCES_AS_TOOLS=false # MCP resource mode
DEBUG=true # debug logging
Working with the Codebase
- Adding New Tools: Decorate functions with
@self.mcp.tool()in mcp_server.py - API Extensions: Add methods to PenpotAPI class following existing patterns
- Error Handling: Always check for
"error"keys in API responses - Testing: Use
test_mode=Truewhen creating server instances in tests - Transit Format: Remember to handle Transit+JSON when working with raw API
Common Workflow for Code Generation
- List projects → Find target project
- Get project files → Locate design file
- Search for component → Find specific element
- Get tree schema → Understand available fields
- Get object tree → Retrieve structure with screenshot
- Export if needed → Get rendered component image
Testing Patterns
- Mock fixtures in
tests/conftest.py - Test both stdio and SSE modes
- Verify Transit format conversions
- Check cache behavior and expiration
Memories
- Keep the current transport format for the current API requests