Automating Server Deployment with Claude AI: Building a Deploy MCP for Seamless Operations

Automate Server Deployment with a Single Command
Hello.
Last time, we set up Git MCP so that Claude can execute Git commands directly.
Now, when you tell Claude:
Check current changes.
Commit them.
Push to Git.
the development server will automatically perform these Git operations for you.
However, pushing to Git doesn't automatically update the live service. The production server (operational environment) needs to pull the latest code to reflect changes in the actual service.
Typically, developers would SSH into the production server and run:
cd /home/pohanginfo
git pull origin mainPerforming this manually is tedious and prone to errors like executing commands on the wrong server or project.
This lesson will create a Deploy MCP that allows you to simply say:
"Deploy PohangInfo production server."
and have Claude automatically execute git pull on the production server.
Today's Completed Functionality
The Deploy MCP we're building will work like this:
Claude
↓
Deploy PohangInfo production server
↓
Deploy MCP executes
↓
SSH Key authentication
↓
Connects to production server
↓
cd /home/pohanginfo
↓
git pull origin main
↓
Deployment completeDevelopment Environment Setup
This lesson uses the following environment:
Development server
192.168.0.33
↓
Git Push
↓
Git repository
↓
Deploy MCP
↓
SSH
↓
Production server (operational)
192.168.0.5
↓
git pull origin mainThe Deploy MCP runs on the development server and connects to the production server via SSH.
Creating the Deploy MCP Project
Create a new project directory:
cd /home/pc
mkdir deploy-mcp
cd deploy-mcpInitialize the Node.js project:
npm init -yInstall necessary packages:
npm install @modelcontextprotocol/sdk ssh2 dotenv zodThe project structure will look like this:
deploy-mcp
index.js
package.json
.envGenerating SSH Keys
In professional environments, SSH key authentication is safer than passwords.
Create the SSH keys on the development server (192.168.0.33):
ssh-keygen -t ed25519 -C "deploy-mcp"After creation, these files will be generated:
/home/pc/.ssh/id_ed25519
/home/pc/.ssh/id_ed25519.pubid_ed25519: Private keyid_ed25519.pub: Public key
Registering the Public Key on Production Server
Register the generated public key on the production server.
The simplest way is to use this command:
ssh-copy-id -i ~/.ssh/id_ed25519.pub pc@192.168.0.5After entering the password once, the public key will be automatically registered.
Test it with:
ssh pc@192.168.0.5If you can connect without a password, SSH key authentication is set up correctly.
Configuring Git safe.directory
Git 2.35+ may show this error if the repository ownership differs on the production server:
fatal: detected dubious ownership in repositoryTo fix it, run once on the production server:
git config --global --add safe.directory /home/pohanginfoVerify with:
git config --global --get-all safe.directoryExpected output:
/home/pohanginfoThis configuration only needs to be done once.
Setting Up the .env File
Enter SSH information for the Deploy MCP:
SSH_HOST=192.168.0.5
SSH_PORT=22
SSH_USER=pc
SSH_KEY=/home/pc/.ssh/id_ed25519Important: SSH_KEY must point to the private key, not the public key (.pub).
Correct example:
/home/pc/.ssh/id_ed25519Writing the Deploy MCP Code
Now, create index.js using CommonJS format.
This MCP will:
Authenticate via SSH key
Connect to production server
Navigate to project directory
Execute Git Pull
const path = require("path");
require("dotenv").config({
path: path.join(__dirname, ".env"),
quiet: true,
});
const { Client } = require("ssh2");
const { z } = require("zod");
const { McpServer } = require("@modelcontextprotocol/sdk/server/mcp.js");
const { StdioServerTransport } = require("@modelcontextprotocol/sdk/server/stdio.js");
const server = new McpServer({
name: "deploy-mcp",
version: "1.0.0"
});
function executeSSH(command) {
return new Promise((resolve, reject) => {
const conn = new Client();
conn.on("ready", () => {
console.error("[Deploy MCP] SSH Connected");
conn.exec(command, (err, stream) => {
if (err) {
conn.end();
return reject(err);
}
let stdout = "";
let stderr = "";
stream.on("close", (code) => {
conn.end();
resolve({
code,
stdout,
stderr
});
});
stream.on("data", (data) => {
stdout += data.toString();
});
stream.stderr.on("data", (data) => {
stderr += data.toString();
});
});
});
conn.on("error", reject);
conn.connect({
host: process.env.SSH_HOST,
port: Number(process.env.SSH_PORT),
username: process.env.SSH_USER,
password: process.env.SSH_PASSWORD,
// SSH Key usage
privateKey: require("fs").readFileSync(process.env.SSH_KEY)
});
});
}
server.tool(
"deploy_project",
"Deploys PohangInfo production server.",
{},
async () => {
const command = `
cd /home/pohanginfo &&
git pull origin main
`;
try {
const result = await executeSSH(command);
return {
content: [
{
type: "text",
text:
`================================
Deploy Success
================================
Exit Code : ${result.code}
---------- STDOUT ----------
${result.stdout}
---------- STDERR ----------
${result.stderr || "None"}
`
}
]
};
} catch (err) {
return {
content: [
{
type: "text",
text:
`Deploy Failed
${err.message}`
}
]
};
}
}
);
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error("[Deploy MCP] Started");
}
main();Testing the Deploy MCP Execution
First, verify that the MCP server starts correctly:
node index.jsIf it runs without errors, stop with Ctrl + C.
Registering Deploy MCP with Claude
Add the Deploy MCP to Claude:
claude mcp add deploy-mcp node /home/pc/deploy-mcp/index.jsVerifying Registration
Confirm the registration was successful:
claude mcp get deploy-mcpOr check with:
claude mcp listIf deploy-mcp appears in the list, registration is complete.
Testing with Claude
Run Claude from your project directory:
cd /home/pc/ukulscore/pohanginfo
claudeThen ask:
Deploy PohangInfo production server.The Deploy MCP will SSH into the production server and run:
cd /home/pohanginfo
git pull origin mainExpected Results
If the server is already up to date, you'll see:
Already up to date.If new commits exist, it will show something like:
Updating...
Fast-forward
index.php
config.php
...This confirms the latest code has been successfully deployed.
Verifying Live Service
After deployment, always check the live website:
Are changes visible on screen?
No PHP errors present?
CSS and JavaScript working correctly?
Main features functioning as expected?
Just because Git Pull succeeded doesn't mean deployment is complete. Always verify the live site.
What We Learned Today
This lesson covered building a Deploy MCP to automate production server deployments:
Create Deploy MCP project
Generate SSH keys
Register public key on production server
Configure Git safe.directory
Add SSH key to .env file
Create Deploy MCP code
Add with
claude mcp addVerify registration with
claude mcp getRequest deployment via natural language to Claude
Closing Thoughts
Last time, we automated Git commits and pushes using Git MCP.
This time, we built a Deploy MCP that automates the entire production deployment process.
Now developers no longer need to manually SSH into servers or run Git commands repeatedly—they simply say:
"Deploy PohangInfo production server."
and the latest code is automatically reflected on the live server.
FAQ
Why use SSH keys instead of passwords?
SSH keys provide stronger security than password-based authentication, reducing the risk of unauthorized access.
What if Git shows 'dubious ownership' error?
Run `git config --global --add safe.directory /home/pohanginfo` on the production server to resolve this.
Korean Source
This article is an English localization of a Korean-language report from BlogScore. Original: [AI 개발환경 구축 프로젝트] 14강 Deploy MCP 만들기, Claude AI로 운영 서버 자동 배포하기