/**
* Utility functions for MCP Forge
*/
import fs from 'fs-extra';
import path from 'path';
import { createBasicTemplate } from './templates/basic.js';
import { createWebSearchTemplate } from './templates/web-search.js';
import { createDatabaseTemplate } from './templates/database.js';
/**
* Generate a new MCP server from a template
* @param {string} name - The name of the MCP server
* @param {string} template - The template to use (basic, web-search, database)
* @param {string} outputDir - The directory to output the generated server
* @returns {Promise<object>} - The result of the generation
*/
export async function generateMcpServer(name, template, outputDir) {
try {
// Create output directory if it doesn't exist
await fs.ensureDir(outputDir);
let templateFn;
switch (template) {
case "basic":
templateFn = createBasicTemplate;
break;
case "web-search":
templateFn = createWebSearchTemplate;
break;
case "database":
templateFn = createDatabaseTemplate;
break;
default:
templateFn = createBasicTemplate;
}
const files = templateFn(name);
// Write files
for (const [filePath, content] of Object.entries(files)) {
await fs.writeFile(path.join(outputDir, filePath), content);
}
return {
success: true,
message: `MCP server "${name}" has been generated in ${outputDir}`,
files: Object.keys(files)
};
} catch (error) {
return {
success: false,
error: error.message
};
}
}
/**
* Generate Cursor IDE integration code
* @param {string} packageName - The NPM package name
* @param {object} config - The configuration object
* @returns {object} - The integration code
*/
export function getCursorIntegration(packageName, config = {}) {
const configString = JSON.stringify(config).replace(/"/g, '\\"');
const cursorConfig = {
command: "npx",
args: [
"-y",
"@smithery/cli@latest",
"run",
packageName,
"--config",
`"${configString}"`
]
};
const mcpJson = {
mcpServers: {
[packageName.split('/').pop()]: cursorConfig
}
};
return {
mcpJson: JSON.stringify(mcpJson, null, 2),
commandLine: `npx -y @smithery/cli@latest run ${packageName} --config "${configString}"`,
instructions: "Add this to your ~/.cursor/mcp.json file to integrate with Cursor IDE"
};
}
/**
* Generate deployment instructions for Smithery
* @param {string} repoUrl - The GitHub repository URL
* @returns {object} - The deployment instructions
*/
export function getDeploymentInstructions(repoUrl) {
return {
steps: [
"1. Push your code to GitHub repository: " + repoUrl,
"2. Visit https://smithery.ai/dashboard",
"3. Click 'Deploy New Server'",
"4. Enter your repository URL",
"5. Follow the deployment instructions"
],
note: "Ensure your repository has a valid Dockerfile and smithery.yaml at the root"
};
}