Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions youtrack_mcp/api/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,55 @@ def get_issue(self, issue_id: str) -> Issue:
# Create minimal issue to avoid breaking calls
return Issue(id=issue_id, summary=f"Error: {str(e)[:100]}...")

def resolve_tag_ids(self, names: List[str]) -> List[Dict[str, str]]:
"""
Resolve tag names to YouTrack tag objects, creating missing tags.

YouTrack attaches tags by id, not by name, and does not create tags
implicitly. Returns a list of {"id": ...} ready to be sent as the
issue "tags" field.

Args:
names: Tag names to resolve

Returns:
List of tag references
"""
if not names:
return []

existing = {}
skip = 0
while True:
batch = self.client.get(
"issueTags", params={"fields": "id,name", "$top": 300, "$skip": skip}
)
if not isinstance(batch, list) or not batch:
break
for tag in batch:
name = (tag.get("name") or "").strip()
if name:
existing.setdefault(name.casefold(), tag.get("id"))
if len(batch) < 300:
break
skip += 300

refs = []
for name in names:
key = name.strip().casefold()
tag_id = existing.get(key)
if tag_id is None:
logger.info(f"Tag not found, creating: {name}")
created = self.client.post("issueTags", data={"name": name.strip()})
tag_id = created.get("id") if isinstance(created, dict) else None
if tag_id:
existing[key] = tag_id
if tag_id:
refs.append({"id": tag_id})
else:
logger.warning(f"Could not resolve or create tag: {name}")
return refs

def create_issue(
self,
project_id: str,
Expand Down
3 changes: 2 additions & 1 deletion youtrack_mcp/tools/issues/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ def create_issue(
summary: str,
description: Optional[str] = None,
custom_fields: Optional[Any] = None,
tags: Optional[List[str]] = None,
) -> str:
"""Create a new issue in the specified project."""
return self.basic_operations.create_issue(
project, summary, description, custom_fields
project, summary, description, custom_fields, tags
)

def update_issue(self, issue_id: str, summary: Optional[str] = None, description: Optional[str] = None, uses_markdown: Optional[bool] = None, additional_fields: Optional[Dict[str, Any]] = None) -> str:
Expand Down
15 changes: 13 additions & 2 deletions youtrack_mcp/tools/issues/basic_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import json
import logging
from typing import Any, Dict, Optional
from typing import Any, Dict, Optional, List

from youtrack_mcp.mcp_wrappers import sync_wrapper
from youtrack_mcp.utils import format_json_response
Expand Down Expand Up @@ -126,18 +126,20 @@ def create_issue(
summary: str,
description: Optional[str] = None,
custom_fields: Optional[Any] = None,
tags: Optional[List[str]] = None,
) -> str:
"""
Create a new issue in YouTrack.

FORMAT: create_issue(project="DEMO", summary="Bug in login", description="Users cannot log in", custom_fields={"Assignee": "admin", "Type": "Bug"})
FORMAT: create_issue(project="DEMO", summary="Bug in login", description="Users cannot log in", custom_fields={"Assignee": "admin", "Type": "Bug"}, tags=["Generated by AI"])

Args:
project: The project identifier (e.g., "DEMO", "PROJECT")
summary: The issue title/summary
description: Optional detailed description of the issue
custom_fields: Optional dict or JSON object of custom fields
(e.g. Assignee, Type, State, Priority, Sprints)
tags: Optional list of tag names to attach; missing tags are created

Returns:
JSON string with the created issue information
Expand Down Expand Up @@ -200,6 +202,14 @@ def create_issue(

# Call the API client to create the issue
try:
if tags:
tag_refs = self.issues_api.resolve_tag_ids(tags)
if tag_refs:
additional_fields = {
**(additional_fields or {}),
"tags": tag_refs,
}

if additional_fields:
issue = self.issues_api.create_issue(
project_id, summary, description, additional_fields
Expand Down Expand Up @@ -340,6 +350,7 @@ def get_tool_definitions(self) -> Dict[str, Dict[str, Any]]:
"project": "Project identifier (short name like 'DEMO' or ID like '0-1')",
"summary": "Issue title/summary (required)",
"description": "Detailed description of the issue (optional)",
"tags": "Optional list of tag names to attach; missing tags are created",
"custom_fields": "Optional dictionary of custom fields, e.g. {\"Assignee\": \"admin\", \"Type\": \"Bug\", \"Priority\": \"Normal\"}",
}
},
Expand Down
1 change: 1 addition & 0 deletions youtrack_mcp/tools/issues/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def get_tool_definitions_legacy(self) -> Dict[str, Dict[str, Any]]:
"summary": "Title/summary for the new issue",
"description": "Optional detailed description of the issue",
"custom_fields": "Optional dictionary of custom fields such as Assignee, Type, State, Priority",
"tags": "Optional list of tag names to attach; missing tags are created",
},
},
"update_issue": {
Expand Down