import { MCPTool } from './index.js';
import { ChangerawrClient } from '../client/changerawr-client.js';
import { validateAndNormalizeArgs } from '../utils/validation.js';
export const listProjectsTool: MCPTool = {
name: 'list_projects',
description: 'List all projects in Changerawr',
inputSchema: {
type: 'object',
properties: {},
required: [],
},
async execute(args: {}, client: ChangerawrClient) {
try {
const validatedArgs = validateAndNormalizeArgs(args, this.inputSchema);
const projects = await client.listProjects();
return {
success: true,
data: projects,
message: `Found ${projects.length} projects`,
};
} catch (error) {
console.error('listProjectsTool error:', error);
throw error;
}
},
};
export const getProjectTool: MCPTool = {
name: 'get_project',
description: 'Get details of a specific project',
inputSchema: {
type: 'object',
properties: {
projectId: {
type: 'string',
description: 'The ID of the project to retrieve',
},
},
required: ['projectId'],
},
async execute(args: { projectId: string }, client: ChangerawrClient) {
const project = await client.getProject(args.projectId);
return {
success: true,
data: project,
message: `Retrieved project: ${project.name}`,
};
},
};
export const createProjectTool: MCPTool = {
name: 'create_project',
description: 'Create a new project in Changerawr',
inputSchema: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'The name of the project',
},
isPublic: {
type: 'boolean',
description: 'Whether the project is publicly visible',
default: false,
},
allowAutoPublish: {
type: 'boolean',
description: 'Whether entries can be auto-published',
default: false,
},
requireApproval: {
type: 'boolean',
description: 'Whether changes require admin approval',
default: true,
},
defaultTags: {
type: 'array',
items: { type: 'string' },
description: 'Default tags for this project',
default: [],
},
},
required: ['name'],
},
async execute(args: {
name: string;
isPublic?: boolean;
allowAutoPublish?: boolean;
requireApproval?: boolean;
defaultTags?: string[];
}, client: ChangerawrClient) {
const project = await client.createProject(args);
return {
success: true,
data: project,
message: `Created project: ${project.name} (ID: ${project.id})`,
};
},
};
export const updateProjectTool: MCPTool = {
name: 'update_project',
description: 'Update an existing project',
inputSchema: {
type: 'object',
properties: {
projectId: {
type: 'string',
description: 'The ID of the project to update',
},
name: {
type: 'string',
description: 'The new name of the project',
},
isPublic: {
type: 'boolean',
description: 'Whether the project is publicly visible',
},
allowAutoPublish: {
type: 'boolean',
description: 'Whether entries can be auto-published',
},
requireApproval: {
type: 'boolean',
description: 'Whether changes require admin approval',
},
defaultTags: {
type: 'array',
items: { type: 'string' },
description: 'Default tags for this project',
},
},
required: ['projectId'],
},
async execute(args: {
projectId: string;
name?: string;
isPublic?: boolean;
allowAutoPublish?: boolean;
requireApproval?: boolean;
defaultTags?: string[];
}, client: ChangerawrClient) {
const { projectId, ...updateData } = args;
const project = await client.updateProject(projectId, updateData);
return {
success: true,
data: project,
message: `Updated project: ${project.name}`,
};
},
};
export const deleteProjectTool: MCPTool = {
name: 'delete_project',
description: 'Delete a project permanently (admin access)',
inputSchema: {
type: 'object',
properties: {
projectId: {
type: 'string',
description: 'The ID of the project to delete',
},
},
required: ['projectId'],
},
async execute(args: { projectId: string }, client: ChangerawrClient) {
await client.deleteProject(args.projectId);
return {
success: true,
message: `Project deleted permanently (admin access)`,
};
},
};