import { z } from "zod";
import path from "path";
export const generateClientConfigSchema = {
name: "generate_client_config",
description: "Generate configuration JSON for Claude Desktop or MCP Clients",
inputSchema: z.object({
type: z
.enum(["local", "cloud"])
.describe(
"Type of configuration: 'local' (StdIO) or 'cloud' (Railway Bridge)",
),
serverUrl: z
.string()
.optional()
.describe("URL of the Cloud Server (Required for 'cloud')"),
apiKey: z
.string()
.optional()
.describe("API Key for the Cloud Server (Required for 'cloud')"),
}),
};
export async function generateClientConfigHandler(args: {
type: "local" | "cloud";
serverUrl?: string;
apiKey?: string;
}) {
if (args.type === "cloud" && (!args.serverUrl || !args.apiKey)) {
throw new Error(
"serverUrl and apiKey are required for 'cloud' configuration.",
);
}
let config: any = {};
const repoPath = process.cwd().replace(/\\/g, "/"); // Normalize path for JSON
if (args.type === "local") {
config = {
mcpServers: {
"code-mcp-local": {
command: "node",
args: [`${repoPath}/dist/index.js`],
},
},
};
} else {
config = {
mcpServers: {
"code-mcp-cloud": {
command: "node",
args: [
`${repoPath}/dist/bridge.js`,
"--url",
args.serverUrl,
"--key",
args.apiKey,
],
},
},
};
}
return {
content: [
{
type: "text",
text: `Here is your '${args.type}' configuration. Add this to your MCP Client config file (e.g., claude_desktop_config.json):\n\n\`\`\`json\n${JSON.stringify(config, null, 2)}\n\`\`\``,
},
],
};
}