import { sentryMcpSetupMessage, callSentryMcp, firstArray } from './mcp.ts'
type Input = { limit?: number }
/**
* List Sentry organizations through the connected Sentry MCP server.
* @param input - Optional helper arguments (query, limit, filters).
* @returns Structured helper result for agents.
* @example
* import listOrganizations from 'kody:@kody/sentry-mcp/list-organizations'
* const result = await listOrganizations()
* // => { ... }
*/
export default async function listOrganizations(input: Input = {}) {
const mcp = await callSentryMcp(
[
"list_organizations",
"listOrganizations",
"find_organizations"
],
{ limit: input.limit ?? 10 },
)
if (!mcp) {
throw new Error(sentryMcpSetupMessage())
}
return {
via: 'mcp',
tool: mcp.tool,
organizations: firstArray(mcp.result) ?? mcp.result,
}
}