write_mcp_server
Generate and configure MCP server files by automatically creating directories and writing specified content to designated paths based on user requirements.
Instructions
Write files for an MCP server based on our discussion with the user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| outputDir | Yes | Directory where server files should be created | |
| files | Yes |
Implementation Reference
- src/main.ts:66-106 (handler)The request handler for CallToolRequestSchema checks if the tool name is 'write_mcp_server' and executes the logic: creates directory, writes files from the provided list, and returns success or error message.this.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name !== "write_mcp_server") { throw new Error(`Unknown tool: ${request.params.name}`); } const args = request.params.arguments as { outputDir: string; files: Array<{ path: string; content: string; }>; }; try { await mkdir(args.outputDir, { recursive: true }); const createdFiles = []; for (const file of args.files) { const fullPath = `${args.outputDir}/${file.path}`; await mkdir(fullPath.substring(0, fullPath.lastIndexOf('/')), { recursive: true }); await writeFile(fullPath, file.content); createdFiles.push(file.path); } return { content: [{ type: "text", text: `Successfully created MCP server:\n${createdFiles.map(f => `- ${f}`).join('\n')}` }] }; } catch (error) { console.error("Error creating server:", error); return { content: [{ type: "text", text: `Failed to create server: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } });
- src/main.ts:16-40 (schema)Tool schema definition including name 'write_mcp_server', description, and inputSchema for outputDir and files array.const CREATE_MCP_TOOL = { name: "write_mcp_server", description: "Write files for an MCP server based on our discussion with the user", inputSchema: { type: "object", properties: { outputDir: { type: "string", description: "Directory where server files should be created" }, files: { type: "array", items: { type: "object", properties: { path: { type: "string" }, content: { type: "string" } }, required: ["path", "content"] } } }, required: ["outputDir", "files"] } };
- src/main.ts:62-64 (registration)Tool is registered for listing by returning CREATE_MCP_TOOL in ListToolsRequestSchema handler.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [CREATE_MCP_TOOL] }));