From 55c68a456403bd3bd6998893b5e900e379f98e00 Mon Sep 17 00:00:00 2001 From: ccbbccbb <59705750+ccbbccbb@users.noreply.github.com> Date: Thu, 13 Mar 2025 18:07:25 -0400 Subject: [PATCH 1/3] refactor: rename package to @mcpdotdirect/template-mcp-server and update README for user quickstart --- README.md | 10 +++------- package.json | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 722e2ef..064d4d2 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,21 @@ -# @mcpdotdirect/create-mcp-server +# @mcpdotdirect/template-mcp-server ![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg) ![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-3178C6) ![MCP](https://img.shields.io/badge/MCP-1.7+-green) -A CLI tool to create a new Model Context Protocol (MCP) server project. This package provides a template for building custom MCP servers that can be used by AI agents to interact with external systems and data sources. +A CLI tool to quickly get started building your very own MCP (Model Context Protocol) server. ## šŸ“‹ Usage -You can create a new MCP server project using npx: - ```bash -# Create a new MCP server in the current directory +# with npx npx @mcpdotdirect/create-mcp-server # Or with npm npm init @mcpdotdirect/create-mcp-server ``` -This will create a new MCP server project in the current directory with all the necessary files. You'll need to install the dependencies manually after creation. - ## šŸ”­ What's Included The template includes: diff --git a/package.json b/package.json index 774f843..63d53d6 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,49 @@ { - "name": "mcp-server", + "name": "@mcpdotdirect/create-mcp-server", "module": "src/index.ts", "type": "module", "version": "1.0.0", - "description": "Model Context Protocol (MCP) Server", - "private": true, + "description": "Model Context Protocol (MCP) Server Template Generator", + "private": false, + "main": "build/index.js", + "bin": { + "create-mcp-server": "build/index.js" + }, + "files": [ + "build", + "LICENSE", + "README.md" + ], "scripts": { "start": "bun run src/index.ts", "build": "bun build src/index.ts --outdir build --target node", "build:http": "bun build src/server/http-server.ts --outdir build --target node", "dev": "bun --watch src/index.ts", "start:http": "bun run src/server/http-server.ts", - "dev:http": "bun --watch src/server/http-server.ts" + "dev:http": "bun --watch src/server/http-server.ts", + "prepublishOnly": "bun run build" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/mcpdotdirect/template-mcp-server.git" + }, + "publishConfig": { + "access": "public" + }, + "keywords": [ + "mcp", + "model-context-protocol", + "ai", + "template", + "llm", + "generator" + ], + "author": "mcpdotdirect", + "license": "MIT", + "bugs": { + "url": "https://github.com/mcpdotdirect/template-mcp-server/issues" }, + "homepage": "https://github.com/mcpdotdirect/template-mcp-server#readme", "devDependencies": { "@types/bun": "latest", "@types/cors": "^2.8.17", From 4c12f4b8a84310656882b6fa0ce0f78a98bd2eaf Mon Sep 17 00:00:00 2001 From: ccbbccbb <59705750+ccbbccbb@users.noreply.github.com> Date: Thu, 13 Mar 2025 18:11:37 -0400 Subject: [PATCH 2/3] fix: typo --- package.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index 63d53d6..0f73ed4 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,11 @@ { - "name": "@mcpdotdirect/create-mcp-server", + "name": "@mcpdotdirect/template-mcp-server", "module": "src/index.ts", "type": "module", "version": "1.0.0", "description": "Model Context Protocol (MCP) Server Template Generator", "private": false, "main": "build/index.js", - "bin": { - "create-mcp-server": "build/index.js" - }, "files": [ "build", "LICENSE", From 8e1191e0e9e299fd0e02c4822d2141c64fe8d57e Mon Sep 17 00:00:00 2001 From: ccbbccbb <59705750+ccbbccbb@users.noreply.github.com> Date: Thu, 13 Mar 2025 18:25:42 -0400 Subject: [PATCH 3/3] feat: add CLI tool for creating MCP server projects and update package.json --- bin/create-mcp-server.js | 192 +++++++++++++++++++++++++++++++++++++++ package.json | 28 ++++-- 2 files changed, 213 insertions(+), 7 deletions(-) create mode 100755 bin/create-mcp-server.js diff --git a/bin/create-mcp-server.js b/bin/create-mcp-server.js new file mode 100755 index 0000000..e1a3c49 --- /dev/null +++ b/bin/create-mcp-server.js @@ -0,0 +1,192 @@ +#!/usr/bin/env node + +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import { execSync } from 'child_process'; + +// Get the directory where the source files are stored +const __filename = fileURLToPath(import.meta.url); +const rootDir = path.join(path.dirname(__filename), '..'); +const sourceDir = path.join(rootDir, 'src'); +const targetDir = process.cwd(); + +// Check if the target directory is empty +const isDirectoryEmpty = () => { + const files = fs.readdirSync(targetDir); + return files.length === 0 || (files.length === 1 && files[0] === '.git'); +}; + +// Print a colorful message +const printColorMessage = (message, color) => { + const colors = { + red: '\x1b[31m', + green: '\x1b[32m', + yellow: '\x1b[33m', + blue: '\x1b[34m', + magenta: '\x1b[35m', + cyan: '\x1b[36m', + reset: '\x1b[0m' + }; + + console.log(`${colors[color]}${message}${colors.reset}`); +}; + +// Main function +async function main() { + console.log('\n'); + printColorMessage('šŸš€ Creating a new MCP server project...', 'cyan'); + console.log('\n'); + + // Check if the directory is empty + if (!isDirectoryEmpty()) { + printColorMessage('āš ļø The current directory is not empty!', 'yellow'); + console.log('To avoid overwriting existing files, please run this command in an empty directory.'); + console.log('You can create a new directory and run the command there:'); + console.log('\n mkdir my-mcp-server && cd my-mcp-server && npx @mcpdotdirect/create-mcp-server\n'); + process.exit(1); + } + + // Check if source directory exists + if (!fs.existsSync(sourceDir)) { + printColorMessage('āš ļø Source directory not found!', 'red'); + console.log('This is likely an issue with the package installation.'); + console.log('Please report this issue at: https://github.com/mcpdotdirect/create-mcp-server/issues'); + process.exit(1); + } + + try { + // Copy source files to target directory + copyFiles(sourceDir, path.join(targetDir, 'src')); + + // Copy other important files + const filesToCopy = [ + '.gitignore', + 'tsconfig.json', + 'README.md' + ]; + + for (const file of filesToCopy) { + const srcPath = path.join(rootDir, file); + const destPath = path.join(targetDir, file); + + if (fs.existsSync(srcPath)) { + fs.copyFileSync(srcPath, destPath); + console.log(`šŸ“„ Created ${destPath}`); + } + } + + // Create a package.json for the new project + createProjectPackageJson(); + + printColorMessage('āœ… Source files copied successfully!', 'green'); + + printColorMessage('\nšŸŽ‰ MCP server project created successfully!', 'green'); + console.log('\nNext steps:'); + console.log(' 1. Install dependencies:'); + console.log(' npm install'); + console.log(' # or with yarn'); + console.log(' yarn'); + console.log(' # or with pnpm'); + console.log(' pnpm install'); + console.log(' # or with bun'); + console.log(' bun install'); + console.log(' 2. Review the README.md file for usage instructions'); + console.log(' 3. Run "npm start" or "npm run dev" to start the server'); + console.log('\nHappy coding! šŸš€\n'); + } catch (error) { + printColorMessage(`\nāŒ Error creating MCP server project: ${error.message}`, 'red'); + console.log('Please report this issue at: https://github.com/mcpdotdirect/create-mcp-server/issues'); + process.exit(1); + } +} + +// Function to copy files recursively +function copyFiles(source, destination) { + // Create destination directory if it doesn't exist + if (!fs.existsSync(destination)) { + fs.mkdirSync(destination, { recursive: true }); + } + + // Read all files/folders in the source directory + const entries = fs.readdirSync(source, { withFileTypes: true }); + + for (const entry of entries) { + const srcPath = path.join(source, entry.name); + const destPath = path.join(destination, entry.name); + + // Skip node_modules, package-lock.json, .git, and other unnecessary directories/files + // This ensures we don't copy any lock files or node_modules, letting the user generate their own + if (entry.name === 'node_modules' || + entry.name === 'package-lock.json' || + entry.name === 'npm-debug.log' || + entry.name === 'yarn.lock' || + entry.name === 'pnpm-lock.yaml' || + entry.name === 'bun.lock' || + entry.name === '.git' || + entry.name === 'bin' || + entry.name === '.cursor' || + entry.name === 'LICENSE' || + entry.name === 'build') { + continue; + } + + if (entry.isDirectory()) { + // Recursively copy directories + copyFiles(srcPath, destPath); + } else { + // Copy files + fs.copyFileSync(srcPath, destPath); + console.log(`šŸ“„ Created ${destPath}`); + } + } +} + +// Create a package.json for the new project +function createProjectPackageJson() { + const packageJsonPath = path.join(targetDir, 'package.json'); + + const projectPackageJson = { + name: "mcp-server", + module: "src/index.ts", + type: "module", + version: "1.0.0", + description: "Model Context Protocol (MCP) Server", + private: true, + scripts: { + "start": "bun run src/index.ts", + "build": "bun build src/index.ts --outdir build --target node", + "build:http": "bun build src/server/http-server.ts --outdir build --target node", + "dev": "bun --watch src/index.ts", + "start:http": "bun run src/server/http-server.ts", + "dev:http": "bun --watch src/server/http-server.ts" + }, + devDependencies: { + "@types/bun": "latest", + "@types/cors": "^2.8.17", + "@types/express": "^5.0.0", + "@types/node": "^20.11.0" + }, + peerDependencies: { + "typescript": "^5.8.2" + }, + dependencies: { + "@modelcontextprotocol/sdk": "^1.7.0", + "cors": "^2.8.5", + "express": "^4.21.2", + "zod": "^3.24.2" + } + }; + + fs.writeFileSync( + packageJsonPath, + JSON.stringify(projectPackageJson, null, 2) + ); + console.log(`šŸ“„ Created ${packageJsonPath}`); +} + +// Run the main function +main().catch(error => { + printColorMessage(`\nāŒ Unexpected error: ${error.message}`, 'red'); + process.exit(1); +}); \ No newline at end of file diff --git a/package.json b/package.json index 0f73ed4..1933e96 100644 --- a/package.json +++ b/package.json @@ -3,13 +3,20 @@ "module": "src/index.ts", "type": "module", "version": "1.0.0", - "description": "Model Context Protocol (MCP) Server Template Generator", + "description": "CLI tool to create a new MCP (Model Context Protocol) server project", "private": false, "main": "build/index.js", + "bin": { + "create-mcp-server": "./bin/create-mcp-server.js" + }, "files": [ - "build", - "LICENSE", - "README.md" + "bin", + "src/", + "build/", + ".gitignore", + "tsconfig.json", + "README.md", + "LICENSE" ], "scripts": { "start": "bun run src/index.ts", @@ -30,10 +37,14 @@ "keywords": [ "mcp", "model-context-protocol", - "ai", "template", - "llm", - "generator" + "server", + "ai", + "agent", + "create", + "generator", + "starter", + "boilerplate" ], "author": "mcpdotdirect", "license": "MIT", @@ -55,5 +66,8 @@ "cors": "^2.8.5", "express": "^4.21.2", "zod": "^3.24.2" + }, + "engines": { + "node": ">=18.0.0" } } \ No newline at end of file