@rashidazarang/aptly-mcp
Version:
Model Context Protocol server for Aptly package repository management - enables AI assistants to manage Debian repositories
165 lines • 7.12 kB
JavaScript
import { createMirrorSchema, formatValidationError } from '../utils/validation.js';
import { z } from 'zod';
export function createMirrorTools(client) {
return [
{
name: 'aptly_list_mirrors',
description: 'List all configured mirrors',
inputSchema: {
type: 'object',
properties: {},
required: []
}
},
{
name: 'aptly_create_mirror',
description: 'Create a mirror of a remote repository',
inputSchema: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'Name for the mirror'
},
archiveURL: {
type: 'string',
description: 'URL of the remote archive (e.g., http://archive.ubuntu.com/ubuntu/)'
},
distribution: {
type: 'string',
description: 'Distribution name (e.g., focal, jammy, bookworm)'
},
components: {
type: 'array',
items: { type: 'string' },
description: 'Optional list of components to mirror (e.g., main, contrib, non-free)'
},
architectures: {
type: 'array',
items: { type: 'string' },
description: 'Optional list of architectures to mirror (e.g., amd64, arm64, i386)'
}
},
required: ['name', 'archiveURL', 'distribution']
}
},
{
name: 'aptly_update_mirror',
description: 'Update a mirror to fetch the latest packages from the remote repository',
inputSchema: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'Name of the mirror to update'
}
},
required: ['name']
}
},
{
name: 'aptly_get_mirror',
description: 'Get detailed information about a specific mirror',
inputSchema: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'Name of the mirror to retrieve'
}
},
required: ['name']
}
}
];
}
export async function handleMirrorTool(client, name, arguments_) {
try {
switch (name) {
case 'aptly_list_mirrors': {
const mirrors = await client.listMirrors();
if (mirrors.length === 0) {
return {
content: [{
type: 'text',
text: 'No mirrors configured.'
}]
};
}
const mirrorList = mirrors.map(mirror => {
const lastUpdate = mirror.LastDownloadDate
? new Date(mirror.LastDownloadDate).toLocaleString()
: 'Never updated';
return `• ${mirror.Name}\n` +
` Archive: ${mirror.ArchiveRoot}\n` +
` Distribution: ${mirror.Distribution}\n` +
` Components: ${mirror.Components.join(', ')}\n` +
` Architectures: ${mirror.Architectures.join(', ')}\n` +
` Last Update: ${lastUpdate}`;
}).join('\n\n');
return {
content: [{
type: 'text',
text: `Found ${mirrors.length} mirror(s):\n\n${mirrorList}`
}]
};
}
case 'aptly_create_mirror': {
const args = createMirrorSchema.parse(arguments_);
const mirror = await client.createMirror(args.name, args.archiveURL, args.distribution, args.components, args.architectures);
return {
content: [{
type: 'text',
text: `Mirror '${mirror.Name}' created successfully!\n` +
`Archive: ${mirror.ArchiveRoot}\n` +
`Distribution: ${mirror.Distribution}\n` +
`Components: ${mirror.Components.join(', ')}\n` +
`Architectures: ${mirror.Architectures.join(', ')}\n\n` +
`To download packages, run: aptly_update_mirror with name '${mirror.Name}'`
}]
};
}
case 'aptly_update_mirror': {
const args = z.object({ name: z.string() }).parse(arguments_);
// Mirror updates can take a long time, so we'll initiate and return immediately
await client.updateMirror(args.name);
return {
content: [{
type: 'text',
text: `Mirror '${args.name}' update initiated successfully.\n` +
`This operation may take several minutes to complete depending on the repository size.\n` +
`Use 'aptly_get_mirror' to check the update status.`
}]
};
}
case 'aptly_get_mirror': {
const args = z.object({ name: z.string() }).parse(arguments_);
const mirror = await client.getMirror(args.name);
const lastUpdate = mirror.LastDownloadDate
? new Date(mirror.LastDownloadDate).toLocaleString()
: 'Never updated';
return {
content: [{
type: 'text',
text: `Mirror Details:\n` +
`Name: ${mirror.Name}\n` +
`Archive: ${mirror.ArchiveRoot}\n` +
`Distribution: ${mirror.Distribution}\n` +
`Components: ${mirror.Components.join(', ')}\n` +
`Architectures: ${mirror.Architectures.join(', ')}\n` +
`Last Update: ${lastUpdate}`
}]
};
}
default:
throw new Error(`Unknown mirror tool: ${name}`);
}
}
catch (error) {
if (error instanceof z.ZodError) {
throw new Error(`Validation error: ${formatValidationError(error)}`);
}
throw error;
}
}
//# sourceMappingURL=mirror-tools.js.map