UNPKG

@cnbcool/mcp-server

Version:

CNB MCP Server. A comprehensive MCP server that provides seamless integration to the CNB's API(https://cnb.cool), offering a wide range of tools for repository management, pipelines operations and collaboration features

47 lines (46 loc) 1.65 kB
import CnbApiClient from './client.js'; export async function listGroups(params) { const cnbInst = CnbApiClient.getInstance(); const url = new URL('/user/groups', cnbInst.baseUrl); if (params) { for (const [key, value] of Object.entries(params)) { if (value === undefined) continue; url.searchParams.set(key, value.toString()); } } return cnbInst.request('GET', `${url.pathname}${url.search}`); } export async function listSubGroups(group, params) { const cnbInst = CnbApiClient.getInstance(); const url = new URL(`/user/groups/${group}`, cnbInst.baseUrl); if (params) { for (const [key, value] of Object.entries(params)) { if (value === undefined) continue; url.searchParams.set(key, value.toString()); } } return cnbInst.request('GET', `${url.pathname}${url.search}`); } export async function getGroup(group) { const cnbInst = CnbApiClient.getInstance(); return cnbInst.request('GET', `/${group}`); } export async function createGroup(params) { const body = Object.entries(params).reduce((acc, [key, value]) => { if (value === undefined) return acc; Object.assign(acc, { [key]: value }); return acc; }, {}); const response = await CnbApiClient.getInstance().request('POST', '/groups', body, { header: { 'Content-Type': 'application/json' } }, 'raw'); if (response.status === 201) { return { message: 'Created' }; } else { return { status: response.status, message: response.statusText }; } }