feat: add create_label write tool

Adds a create_label write-mode tool so labels can be created in a repository
through the MCP server (previously there was no way to define labels, which
blocked attaching labels to issues). Follows the full tool checklist:

- arguments.py: CreateLabelArgs (name, hex color, optional description/exclusive),
  with extra=forbid and a hex-color pattern.
- gitea_client.py: create_label() POSTing to /repos/{owner}/{repo}/labels with
  url-encoded path segments.
- write_tools.py: create_label_tool handler; normalizes the color to a leading
  '#', bounds text output, and lets auth/authz errors surface.
- mcp_protocol.py: register create_label (write_operation=True).
- server.py: wire create_label into TOOL_HANDLERS.
- docs/api-reference.md: document create_label.
- tests: success path, color normalization, and invalid-color rejection.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-14 20:24:33 +02:00
parent e873d0325b
commit f0db219ee8
7 changed files with 125 additions and 0 deletions
+27
View File
@@ -668,6 +668,33 @@ class GiteaClient:
)
return result if isinstance(result, dict) else {}
async def create_label(
self,
owner: str,
repo: str,
*,
name: str,
color: str,
description: str = "",
exclusive: bool = False,
) -> dict[str, Any]:
"""Create a repository label."""
payload: dict[str, Any] = {
"name": name,
"color": color,
"description": description,
"exclusive": exclusive,
}
result = await self._request(
"POST",
f"/api/v1/repos/{quote(owner, safe='')}/{quote(repo, safe='')}/labels",
json_body=payload,
correlation_id=str(
self.audit.log_tool_invocation(tool_name="create_label", result_status="pending")
),
)
return result if isinstance(result, dict) else {}
async def add_labels(
self,
owner: str,