UNPKG

@rashidazarang/aptly-mcp

Version:

Model Context Protocol server for Aptly package repository management - enables AI assistants to manage Debian repositories

134 lines 5.79 kB
import { publishRepoSchema, formatValidationError } from '../utils/validation.js'; import { z } from 'zod'; export function createPublishTools(client) { return [ { name: 'aptly_list_published', description: 'List all published repositories', inputSchema: { type: 'object', properties: {}, required: [] } }, { name: 'aptly_publish_repo', description: 'Publish a repository to make it available for apt', inputSchema: { type: 'object', properties: { repoName: { type: 'string', description: 'Name of the repository to publish' }, distribution: { type: 'string', description: 'Distribution name for the publication (e.g., stable, testing, unstable)' }, prefix: { type: 'string', description: 'Optional prefix for the publication endpoint' } }, required: ['repoName', 'distribution'] } }, { name: 'aptly_publish_snapshot', description: 'Publish a snapshot to make it available for apt', inputSchema: { type: 'object', properties: { snapshotName: { type: 'string', description: 'Name of the snapshot to publish' }, distribution: { type: 'string', description: 'Distribution name for the publication (e.g., stable, testing, unstable)' }, prefix: { type: 'string', description: 'Optional prefix for the publication endpoint' } }, required: ['snapshotName', 'distribution'] } } ]; } export async function handlePublishTool(client, name, arguments_) { try { switch (name) { case 'aptly_list_published': { const published = await client.listPublishedRepositories(); if (published.length === 0) { return { content: [{ type: 'text', text: 'No published repositories found.' }] }; } const publishList = published.map(pub => { const prefix = pub.Prefix || '(no prefix)'; const sources = pub.Sources.map(s => `${s.Component}:${s.Name}`).join(', '); return `• ${prefix}/${pub.Distribution} (${pub.SourceKind}) - Sources: ${sources}`; }).join('\n'); return { content: [{ type: 'text', text: `Found ${published.length} published repository(ies):\n\n${publishList}` }] }; } case 'aptly_publish_repo': { const args = publishRepoSchema.parse(arguments_); const result = await client.publishRepository(args.repoName, args.distribution, args.prefix); const prefix = result.Prefix || '(no prefix)'; const endpoint = prefix === '' ? result.Distribution : `${prefix}/${result.Distribution}`; return { content: [{ type: 'text', text: `Repository '${args.repoName}' published successfully!\n` + `Distribution: ${result.Distribution}\n` + `Prefix: ${prefix}\n` + `Endpoint: ${endpoint}\n` + `Architectures: ${result.Architectures.join(', ')}\n` + `Source Kind: ${result.SourceKind}` }] }; } case 'aptly_publish_snapshot': { const args = z.object({ snapshotName: z.string(), distribution: z.string(), prefix: z.string().optional() }).parse(arguments_); const result = await client.publishSnapshot(args.snapshotName, args.distribution, args.prefix); const prefix = result.Prefix || '(no prefix)'; const endpoint = prefix === '' ? result.Distribution : `${prefix}/${result.Distribution}`; return { content: [{ type: 'text', text: `Snapshot '${args.snapshotName}' published successfully!\n` + `Distribution: ${result.Distribution}\n` + `Prefix: ${prefix}\n` + `Endpoint: ${endpoint}\n` + `Architectures: ${result.Architectures.join(', ')}\n` + `Source Kind: ${result.SourceKind}` }] }; } default: throw new Error(`Unknown publish tool: ${name}`); } } catch (error) { if (error instanceof z.ZodError) { throw new Error(`Validation error: ${formatValidationError(error)}`); } throw error; } } //# sourceMappingURL=publish-tools.js.map