@toolprint/hypertool-mcp
Version:
HyperTool MCP proxy server for routing requests between clients and multiple underlying MCP servers
76 lines • 2.58 kB
JavaScript
/**
* Migration utility to add missing type fields to MCP server configurations
*/
/**
* Add missing type fields to server configurations
* @param config The MCP configuration to migrate
* @returns Updated configuration with type fields added
*/
export function addMissingTypeFields(config) {
if (!config.mcpServers) {
return config;
}
let modified = false;
const updatedServers = {};
for (const [name, server] of Object.entries(config.mcpServers)) {
if (!server || typeof server !== "object") {
updatedServers[name] = server;
continue;
}
if (!server.type) {
// Determine type based on configuration
if (server.command) {
// Has command field, must be stdio type
updatedServers[name] = {
...server,
type: "stdio",
};
modified = true;
console.log(`Added type "stdio" to server "${name}"`);
}
else if (server.url) {
// Has url field, determine if http or sse based on other indicators
// Default to http unless there are SSE-specific indicators
const inferredType = server.url.includes("sse") || server.events ? "sse" : "http";
updatedServers[name] = {
...server,
type: inferredType,
};
modified = true;
console.log(`Added type "${inferredType}" to server "${name}"`);
}
else {
// Unknown configuration, skip
console.warn(`Server "${name}" has no recognizable fields (command or url), skipping type migration`);
updatedServers[name] = server;
}
}
else {
updatedServers[name] = server;
}
}
if (modified) {
console.info("Added missing type fields to MCP server configurations");
}
return {
...config,
mcpServers: updatedServers,
};
}
/**
* Check if a configuration needs type migration
* @param config The MCP configuration to check
* @returns True if migration is needed
*/
export function needsTypeMigration(config) {
if (!config.mcpServers) {
return false;
}
for (const server of Object.values(config.mcpServers)) {
if (server && typeof server === "object" && !server.type) {
return true;
}
}
return false;
}
//# sourceMappingURL=type-migration.js.map