Skip to content

src/search-jira.ts

31 lines · 917 B · TypeScript
Raw
import { atlassianMcpSetupMessage, callAtlassianMcp, firstArray } from './mcp.ts'

type Input = { jql?: string; maxResults?: number }

/**
 * Search Jira issues through the connected Atlassian MCP server.
 * @param input - Optional helper arguments (query, limit, filters).
 * @returns Structured helper result for agents.
 * @example
 * import searchJira from 'kody:@kody/atlassian-mcp/search-jira'
 * const result = await searchJira()
 * // => { ... }
 */
export default async function searchJira(input: Input = {}) {
	const mcp = await callAtlassianMcp(
		[
  "searchJiraIssuesUsingJql",
  "search_jira_issues_using_jql",
  "search"
],
		{ jql: input.jql?.trim() || 'assignee = currentUser() ORDER BY updated DESC', maxResults: input.maxResults ?? 10 },
	)
	if (!mcp) {
		throw new Error(atlassianMcpSetupMessage())
	}
	return {
		via: 'mcp',
		tool: mcp.tool,
		issues: firstArray(mcp.result) ?? mcp.result,
	}
}