@aurracloud/mcp-cli
Version:
A command-line tool to install, manage, and setup MCP (Model Context Protocol) servers with Docker support
144 lines • 5.34 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAvailableCloudTools = getAvailableCloudTools;
exports.getCloudToolDetails = getCloudToolDetails;
exports.isCloudToolSlug = isCloudToolSlug;
exports.generateCloudToolSSEUrl = generateCloudToolSSEUrl;
exports.validateCloudAuth = validateCloudAuth;
exports.testCloudToolAccess = testCloudToolAccess;
const node_fetch_1 = __importDefault(require("node-fetch"));
const logger_1 = require("./logger");
const auth_1 = require("./auth");
const AURRA_REGISTRY = 'https://aurracloud.com';
const AURRA_MCP_BASE = 'https://mcp-v1.aurracloud.com/mcp';
/**
* Get list of all available cloud SSE tools
*/
async function getAvailableCloudTools() {
try {
logger_1.logger.verbose('Fetching available cloud tools from aurracloud.com');
const response = await (0, node_fetch_1.default)(`${AURRA_REGISTRY}/api/tools/hosted`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
throw new Error(`Failed to fetch cloud tools: ${response.status} ${response.statusText}`);
}
const tools = await response.json();
logger_1.logger.debug(`Found ${tools.length} available cloud tools`);
return tools;
}
catch (error) {
logger_1.logger.warn(`Failed to fetch cloud tools: ${error}`);
throw error;
}
}
/**
* Get details for a specific cloud tool by slug
*/
async function getCloudToolDetails(toolSlug) {
try {
logger_1.logger.verbose(`Fetching details for cloud tool: ${toolSlug}`);
const response = await (0, node_fetch_1.default)(`${AURRA_REGISTRY}/api/tools/hosted/${toolSlug}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
if (response.status === 404) {
logger_1.logger.debug(`Cloud tool not found: ${toolSlug}`);
return null;
}
throw new Error(`Failed to fetch tool details: ${response.status} ${response.statusText}`);
}
const toolDetails = await response.json();
logger_1.logger.debug(`Retrieved details for cloud tool: ${toolDetails.name}`);
return toolDetails;
}
catch (error) {
logger_1.logger.warn(`Failed to fetch tool details for ${toolSlug}: ${error}`);
throw error;
}
}
/**
* Check if a package name is a valid cloud tool slug
*/
async function isCloudToolSlug(packageName) {
try {
// First try to get the specific tool details
const toolDetails = await getCloudToolDetails(packageName);
if (toolDetails) {
return toolDetails;
}
// If that fails, check if it exists in the list of all tools
const allTools = await getAvailableCloudTools();
const tool = allTools.find(t => t.slug === packageName);
return tool || null;
}
catch (error) {
logger_1.logger.debug(`Error checking if ${packageName} is a cloud tool slug: ${error}`);
return null;
}
}
/**
* Generate the SSE URL for a cloud tool
*/
function generateCloudToolSSEUrl(toolSlug, apiKey) {
return `${AURRA_MCP_BASE}/${apiKey}/${toolSlug}/sse`;
}
/**
* Validate that the user has an API key for aurracloud.com
*/
function validateCloudAuth() {
const apiKey = (0, auth_1.getApiKey)(AURRA_REGISTRY);
if (!apiKey) {
throw new Error(`Not authenticated with ${AURRA_REGISTRY}. Please run "mcp login" first.`);
}
return apiKey;
}
/**
* Test if a cloud tool SSE endpoint is accessible
*/
async function testCloudToolAccess(toolSlug) {
try {
const apiKey = validateCloudAuth();
const sseUrl = generateCloudToolSSEUrl(toolSlug, apiKey);
logger_1.logger.verbose(`Testing access to cloud tool SSE: ${sseUrl}`);
// Create an AbortController for timeout
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout
try {
// Make a simple HEAD request to test accessibility
const response = await (0, node_fetch_1.default)(sseUrl, {
method: 'HEAD',
headers: {
'Accept': 'text/event-stream',
},
signal: controller.signal,
});
clearTimeout(timeoutId);
const accessible = response.ok;
logger_1.logger.debug(`Cloud tool ${toolSlug} accessibility test: ${accessible ? 'PASS' : 'FAIL'}`);
return accessible;
}
catch (fetchError) {
clearTimeout(timeoutId);
if (fetchError.name === 'AbortError') {
logger_1.logger.debug(`Cloud tool access test timed out for ${toolSlug}`);
return false;
}
throw fetchError;
}
}
catch (error) {
logger_1.logger.debug(`Cloud tool access test failed for ${toolSlug}: ${error}`);
return false;
}
}
//# sourceMappingURL=cloud-sse.js.map