upload_image
Add images to the DevHub CMS media gallery by uploading base64-encoded files in webp, jpeg, or png formats with specified filenames.
Instructions
Upload an image to the DevHub media gallery
Supports webp, jpeg and png images
Args:
base64_image_content: Base 64 encoded content of the image file
filename: Filename including the extension
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| base64_image_content | Yes | ||
| filename | Yes |
Implementation Reference
- src/devhub_cms_mcp/server.py:181-208 (handler)The upload_image tool handler: uploads a base64-encoded image to the DevHub CMS media gallery using the API, returns image ID and path.@mcp.tool() def upload_image(base64_image_content: str, filename: str) -> str: """Upload an image to the DevHub media gallery Supports webp, jpeg and png images Args: base64_image_content: Base 64 encoded content of the image file filename: Filename including the extension """ client, base_url = get_client() payload = { 'type': 'image', 'upload': { 'file': base64_image_content, 'filename': filename, } } r = client.post( '{}images/'.format(base_url), json=payload, ) image = r.json() return f""" Image ID: {image['id']} Image Path (for use in HTML src attributes): {image['absolute_path']} """
- src/devhub_cms_mcp/server.py:181-181 (registration)Registration of the upload_image tool via the @mcp.tool() decorator on the FastMCP server instance.@mcp.tool()
- src/devhub_cms_mcp/server.py:182-190 (schema)Input schema defined by function parameters (base64_image_content: str, filename: str) and docstring describing usage and supported formats.def upload_image(base64_image_content: str, filename: str) -> str: """Upload an image to the DevHub media gallery Supports webp, jpeg and png images Args: base64_image_content: Base 64 encoded content of the image file filename: Filename including the extension """
- src/devhub_cms_mcp/server.py:15-21 (helper)Helper function get_client() used by upload_image to obtain OAuth client and base URL for DevHub API calls.def get_client(): """Get DevHub API client and base_url.""" client = OAuth1Session( os.environ['DEVHUB_API_KEY'], client_secret=os.environ['DEVHUB_API_SECRET']) base_url = '{}/api/v2/'.format(os.environ['DEVHUB_BASE_URL']) return client, base_url