Files
mcphub/plugins/n8n/handlers/credentials.py
airano-ir f203ca88de
Some checks failed
Release / Test before release (push) Has been cancelled
Release / Publish to PyPI (push) Has been cancelled
Release / Publish to Docker Hub (push) Has been cancelled
Release / Create GitHub Release (push) Has been cancelled
feat(v3.12.0): media pipeline, AI image generation, capability probe, companion v2.9.0
Three-month batch sync from internal repo (~80 commits) covering Tracks F.5a, F.7e, F.8, F.17, F.18, F.X.

WordPress media pipeline
- Pillow-based optimization, AI image generation (OpenAI / Stability / Replicate / Google Nano Banana / OpenRouter), chunked + resumable uploads, bulk delete/reassign, idempotent retries.

Capability discovery (F.7e)
- Per-site credential probe + adapters for WordPress / WooCommerce / Gitea, tier-fit unions granted ∪ roles, capability badge UI with HTMX partial re-check, install hint in every companion-unreachable error.

Companion plugin overhaul
- Renamed wordpress-plugin/airano-mcp-seo-bridge → wordpress-plugin/airano-mcp-bridge.
- Eight new endpoints: /capabilities, /bulk-meta, /export, /cache-purge, /transient-flush, /site-health, /audit-hook, /upload-and-attach.
- wp.org Plugin Check pass: i18n, WP_Filesystem, scheme allowlist on audit-hook URL.

Other
- Gitea ergonomics (F.17): batch files, tree, search, compare, releases, fork.
- Opportunistic bcrypt upgrade for legacy SHA-256 admin keys (F.8).
- n8n refactor: structured errors, capability probe, missing tools backfilled.
- Idempotency-Key dedup for AI media upload retries; WP client fast-fails on unreachable sites.

Docs
- README + CLAUDE.md drop the fixed "633 tools" claim. The total grows with each release; per-plugin approximations + dashboard-surfaced counts replace it.
- Tools/Tests badges removed in favour of "Plugins: 10".

Deployment
- PyPI mirror chain, optional BUILD_HTTP_PROXY, Alpine→Yandex apk mirror, Debian-slim Plan-B Dockerfile, mirror.gcr.io variant.

CI
- Black + Ruff clean on Python 3.12; pytest tests/ green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 16:25:58 +02:00

175 lines
6.0 KiB
Python

"""Credentials Handler - manages n8n credentials."""
import json
from typing import Any
from plugins.n8n.client import N8nApiError, N8nClient
def _error_json(exc: Exception) -> str:
if isinstance(exc, N8nApiError):
return json.dumps({"success": False, **exc.to_dict()}, indent=2)
return json.dumps({"success": False, "error": str(exc)}, indent=2)
def get_tool_specifications() -> list[dict[str, Any]]:
"""Return tool specifications for ToolGenerator"""
return [
{
"name": "get_credential",
"method_name": "get_credential",
"description": "Get credential metadata by ID. Note: Listing all credentials is not supported in n8n Public API.",
"schema": {
"type": "object",
"properties": {"credential_id": {"type": "string", "minLength": 1}},
"required": ["credential_id"],
},
"scope": "read",
},
{
"name": "create_credential",
"method_name": "create_credential",
"description": "Create a new credential. Use get_credential_schema to see required fields.",
"schema": {
"type": "object",
"properties": {
"name": {"type": "string", "minLength": 1, "description": "Credential name"},
"type": {
"type": "string",
"minLength": 1,
"description": "Credential type (e.g., 'githubApi')",
},
"data": {
"type": "object",
"description": "Credential data matching the type schema",
},
},
"required": ["name", "type", "data"],
},
"scope": "admin",
},
{
"name": "delete_credential",
"method_name": "delete_credential",
"description": "Delete a credential.",
"schema": {
"type": "object",
"properties": {"credential_id": {"type": "string", "minLength": 1}},
"required": ["credential_id"],
},
"scope": "admin",
},
{
"name": "get_credential_schema",
"method_name": "get_credential_schema",
"description": "Get the schema for a credential type. Shows required fields.",
"schema": {
"type": "object",
"properties": {
"credential_type": {
"type": "string",
"minLength": 1,
"description": "Credential type name",
}
},
"required": ["credential_type"],
},
"scope": "read",
},
{
"name": "transfer_credential",
"method_name": "transfer_credential",
"description": "[Enterprise] Transfer a credential to another project. Requires n8n Enterprise/Pro license.",
"schema": {
"type": "object",
"properties": {
"credential_id": {"type": "string", "minLength": 1},
"destination_project_id": {"type": "string", "minLength": 1},
},
"required": ["credential_id", "destination_project_id"],
},
"scope": "admin",
},
]
# === HANDLER FUNCTIONS ===
# Note: list_credentials is not supported in n8n Public API (GET /credentials returns 405)
async def get_credential(client: N8nClient, credential_id: str) -> str:
"""Get credential metadata"""
try:
cred = await client.get_credential(credential_id)
result = {
"success": True,
"credential": {
"id": cred.get("id"),
"name": cred.get("name"),
"type": cred.get("type"),
"created_at": cred.get("createdAt"),
"updated_at": cred.get("updatedAt"),
},
}
return json.dumps(result, indent=2)
except Exception as e:
return _error_json(e)
async def create_credential(client: N8nClient, name: str, type: str, data: dict[str, Any]) -> str:
"""Create a new credential"""
try:
cred_data = {"name": name, "type": type, "data": data}
cred = await client.create_credential(cred_data)
result = {
"success": True,
"message": f"Credential '{name}' created successfully",
"credential": {
"id": cred.get("id"),
"name": cred.get("name"),
"type": cred.get("type"),
},
}
return json.dumps(result, indent=2)
except Exception as e:
return _error_json(e)
async def delete_credential(client: N8nClient, credential_id: str) -> str:
"""Delete a credential"""
try:
await client.delete_credential(credential_id)
return json.dumps(
{"success": True, "message": f"Credential {credential_id} deleted"}, indent=2
)
except Exception as e:
return _error_json(e)
async def get_credential_schema(client: N8nClient, credential_type: str) -> str:
"""Get credential type schema"""
try:
schema = await client.get_credential_schema(credential_type)
return json.dumps(
{"success": True, "credential_type": credential_type, "schema": schema}, indent=2
)
except Exception as e:
return _error_json(e)
async def transfer_credential(
client: N8nClient, credential_id: str, destination_project_id: str
) -> str:
"""Transfer credential to another project"""
try:
await client.transfer_credential(credential_id, destination_project_id)
return json.dumps(
{
"success": True,
"message": f"Credential {credential_id} transferred to project {destination_project_id}",
},
indent=2,
)
except Exception as e:
return _error_json(e)