From bfb6c713798f695884e993b2efd68c7ce59cca1b Mon Sep 17 00:00:00 2001 From: josedario87 Date: Thu, 16 Oct 2025 17:05:34 -0600 Subject: [PATCH] Agregar herramienta para gestionar transferencias de repos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Nueva herramienta gitea_transfer_manage con 3 acciones: - status: Ver estado de transferencias pendientes - accept: Aceptar transferencia como destinatario - reject: Rechazar/cancelar transferencia como owner actual - Notificaciones claras para cada acción - Manejo de errores mejorado --- mcp-gitea-server/src/index.ts | 84 +++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/mcp-gitea-server/src/index.ts b/mcp-gitea-server/src/index.ts index cc30832..42a8107 100644 --- a/mcp-gitea-server/src/index.ts +++ b/mcp-gitea-server/src/index.ts @@ -481,6 +481,90 @@ server.registerTool( } ); +// ==================== HERRAMIENTA 7: gitea_transfer_manage ==================== +server.registerTool( + 'gitea_transfer_manage', + { + title: 'Gestionar Transferencias de Repositorios Gitea', + description: 'Gestiona transferencias: status (ver estado), accept (aceptar como recipient), reject (rechazar como owner). Requiere owner y repo.', + inputSchema: { + action: z.enum(['status', 'accept', 'reject']).describe('Acción a realizar'), + owner: z.string().describe('Propietario actual del repo'), + repo: z.string().describe('Nombre del repo'), + }, + outputSchema: { + result: z.any().describe('Resultado de la operación') + } + }, + async ({ action, owner, repo }) => { + try { + let result; + let notification = ''; + + switch (action) { + case 'status': + // Obtener información del repo incluyendo estado de transferencia + const repoData: any = await giteaRequest(`/repos/${owner}/${repo}`); + const transferStatus = repoData.repo_transfer; + + if (transferStatus) { + notification = `⚠️ Hay una transferencia pendiente: ${transferStatus.doer.login} → ${transferStatus.recipient.login}`; + result = { + has_pending_transfer: true, + transfer: transferStatus, + _notification: notification + }; + } else { + notification = '✓ No hay transferencias pendientes'; + result = { + has_pending_transfer: false, + _notification: notification + }; + } + break; + + case 'accept': + // Aceptar transferencia (como recipient) + result = await giteaRequest(`/repos/${owner}/${repo}/transfer/accept`, { + method: 'POST', + }); + notification = `✓ Transferencia aceptada exitosamente para '${owner}/${repo}'`; + result = typeof result === 'object' && result !== null + ? { ...result, _notification: notification } + : { success: true, _notification: notification }; + break; + + case 'reject': + // Rechazar/cancelar transferencia (como owner) + result = await giteaRequest(`/repos/${owner}/${repo}/transfer`, { + method: 'DELETE', + }); + notification = `✓ Transferencia rechazada/cancelada exitosamente para '${owner}/${repo}'`; + result = typeof result === 'object' && result !== null + ? { ...result, _notification: notification } + : { success: true, _notification: notification }; + break; + } + + return { + content: [{ + type: 'text', + text: JSON.stringify(result, null, 2) + }], + structuredContent: { + result + } + }; + } catch (error) { + const errorMsg = error instanceof Error ? error.message : 'Error desconocido'; + return { + content: [{ type: 'text', text: `Error: ${errorMsg}` }], + isError: true + }; + } + } +); + // ==================== SERVIDOR EXPRESS ==================== const app = express(); app.use(express.json());