getProject.ts•1.44 kB
import { z } from 'zod';
import { Backlog } from 'backlog-js';
import { buildToolSchema, ToolDefinition } from '../types/tool.js';
import { TranslationHelper } from '../createTranslationHelper.js';
import { ProjectSchema } from '../types/zod/backlogOutputDefinition.js';
import { resolveIdOrKey } from '../utils/resolveIdOrKey.js';
const getProjectSchema = buildToolSchema((t) => ({
projectId: z
.number()
.optional()
.describe(
t(
'TOOL_GET_PROJECT_PROJECT_ID',
'The numeric ID of the project (e.g., 12345)'
)
),
projectKey: z
.string()
.optional()
.describe(
t(
'TOOL_GET_PROJECT_PROJECT_KEY',
"The key of the project (e.g., 'PROJECT')"
)
),
}));
export const getProjectTool = (
backlog: Backlog,
{ t }: TranslationHelper
): ToolDefinition<
ReturnType<typeof getProjectSchema>,
(typeof ProjectSchema)['shape']
> => {
return {
name: 'get_project',
description: t(
'TOOL_GET_PROJECT_DESCRIPTION',
'Returns information about a specific project'
),
schema: z.object(getProjectSchema(t)),
outputSchema: ProjectSchema,
handler: async ({ projectId, projectKey }) => {
const result = resolveIdOrKey(
'project',
{ id: projectId, key: projectKey },
t
);
if (!result.ok) {
throw result.error;
}
return backlog.getProject(result.value);
},
};
};