@rashidazarang/aptly-mcp
Version:
Model Context Protocol server for Aptly package repository management - enables AI assistants to manage Debian repositories
86 lines • 3.32 kB
JavaScript
import { createSnapshotSchema, formatValidationError } from '../utils/validation.js';
import { z } from 'zod';
export function createSnapshotTools(client) {
return [
{
name: 'aptly_list_snapshots',
description: 'List all snapshots',
inputSchema: {
type: 'object',
properties: {},
required: []
}
},
{
name: 'aptly_create_snapshot',
description: 'Create a snapshot from a repository',
inputSchema: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'Name for the new snapshot'
},
repoName: {
type: 'string',
description: 'Name of the repository to create snapshot from'
},
description: {
type: 'string',
description: 'Optional description for the snapshot'
}
},
required: ['name', 'repoName']
}
}
];
}
export async function handleSnapshotTool(client, name, arguments_) {
try {
switch (name) {
case 'aptly_list_snapshots': {
const snapshots = await client.listSnapshots();
if (snapshots.length === 0) {
return {
content: [{
type: 'text',
text: 'No snapshots found.'
}]
};
}
const snapshotList = snapshots.map(snapshot => {
const createdDate = new Date(snapshot.CreatedAt).toLocaleString();
return `• ${snapshot.Name} - ${snapshot.Description} (created: ${createdDate})`;
}).join('\n');
return {
content: [{
type: 'text',
text: `Found ${snapshots.length} snapshot(s):\n\n${snapshotList}`
}]
};
}
case 'aptly_create_snapshot': {
const args = createSnapshotSchema.parse(arguments_);
const snapshot = await client.createSnapshot(args.name, args.repoName, args.description);
const createdDate = new Date(snapshot.CreatedAt).toLocaleString();
return {
content: [{
type: 'text',
text: `Snapshot '${snapshot.Name}' created successfully from repository '${args.repoName}'.\n` +
`Description: ${snapshot.Description}\n` +
`Created: ${createdDate}`
}]
};
}
default:
throw new Error(`Unknown snapshot tool: ${name}`);
}
}
catch (error) {
if (error instanceof z.ZodError) {
throw new Error(`Validation error: ${formatValidationError(error)}`);
}
throw error;
}
}
//# sourceMappingURL=snapshot-tools.js.map