arcade-mcp/toolkits/jira/arcade_jira/tools/labels.py
Renato Byrro 30739dc44a
Support for multiple Atlassian Clouds in the Jira Toolkit (#506)
Adds `Jira.GetAvailableAtlassianClouds` tool, which provides a list of
clouds available (checking which Clouds were actually authorized by the
current auth token).

Refactors the interface of every tool to accept an `atlassian_cloud_id`
argument (when not provided, try to get a unique cloud ID - if multiple
are available, raises a Retryable error with the list of Clouds
available instructing to select one).

Gets rid of all caching. Now storing the global semaphore to the context
object. The global semaphore is important because some tools depend on
others, and each tool instantiates its own Jira HTTP client. Storing the
semaphore in the context object ensures that all HTTP clients will
respect the concurrency limit.

Removes from tool responses the Atlassian URLs linking to objects in the
Jira GUI (users, projects, issues, etc. We do not keep track of the
cloud name anymore, which is required to build the objects' URLs.

Extends/refactors unit tests accordingly.

Evals checking LLM behavior when:

- a cloud ID is explicitly mentioned in the prompt;
- no cloud ID is mentioned;
- a "multiple clouds available" error is raised and the user is prompted
to pick one;
- user request triggers another tool call after having previously picked
a cloud ID (in the same chat context);
2025-07-23 18:09:54 -03:00

40 lines
1.5 KiB
Python

from typing import Annotated, Any
from arcade_tdk import ToolContext, tool
from arcade_tdk.auth import Atlassian
from arcade_jira.client import JiraClient
from arcade_jira.utils import add_pagination_to_response, resolve_cloud_id
@tool(requires_auth=Atlassian(scopes=["read:jira-work"]))
async def list_labels(
context: ToolContext,
limit: Annotated[
int, "The maximum number of labels to return. Min of 1, Max of 200. Defaults to 200."
] = 200,
offset: Annotated[
int, "The number of labels to skip. Defaults to 0 (starts from the first label)"
] = 0,
atlassian_cloud_id: Annotated[
str | None,
"The ID of the Atlassian Cloud to use (defaults to None). If not provided and the user has "
"a single cloud authorized, the tool will use that. Otherwise, an error will be raised.",
] = None,
) -> Annotated[dict[str, Any], "The existing labels (tags) in the user's Jira instance"]:
"""Get the existing labels (tags) in the user's Jira instance."""
limit = max(min(limit, 200), 1)
atlassian_cloud_id = await resolve_cloud_id(context, atlassian_cloud_id)
client = JiraClient(context=context, cloud_id=atlassian_cloud_id)
api_response = await client.get(
"/label",
params={
"maxResults": limit,
"startAt": offset,
},
)
response = {
"labels": api_response["values"],
"total": api_response["total"],
}
return add_pagination_to_response(response, api_response["values"], limit, offset)