教你如何實(shí)現(xiàn)容器化 MCP Server
大家好!我是韓老師。
寫在最前:容器化 MCP Server,有用。但是,你不一定需要。
WHY
如果你在開(kāi)發(fā)一個(gè) local MCP Server,并且有以下的任何一種情況:
- 需要安裝多個(gè) toolchain,才能運(yùn)行 local MCP Server
- 用于開(kāi)發(fā) local MCP Server 的語(yǔ)言,沒(méi)有像 npx 或者 uv 那樣一鍵運(yùn)行程序的工具
那么,容器化 MCP Server,對(duì)你的用戶是有用的。
反之,如果你已經(jīng)用主流的 Node.js 或者 Python 來(lái)開(kāi)發(fā) local MCP Server,并且沒(méi)有其他額外的依賴。
那么,你也許并不需要容器化。
WHAT
local MCP Server 其實(shí)就是個(gè) Node.js/Python/PHP/Go/Java/... 開(kāi)發(fā)的 Console App 而已,通過(guò) stdin/stdout 與 MCP Client 交互,沒(méi)有什么特別的地方。
所以,一般來(lái)說(shuō),你只需要一個(gè) Dockerfile 即可。
HOW
既然是容器化一個(gè)普通的 Console App,那么,一切就變得很簡(jiǎn)單了。
以下是 Code Runner MCP Server 的 Dockerfile :
## Stage 1: Builder FROM node:lts-alpine AS builder # Set working directory WORKDIR /app # Copy all files into the container COPY . . # Install dependencies without running scripts RUN npm install --ignore-scripts # Build the TypeScript source code RUN npm run build ## Stage 2: Runtime FROM node:lts-alpine WORKDIR /app # Install Python and other programming languages RUN apk add --no-cache \ python3 \ go \ php \ ruby # Copy only the necessary files from the builder stage COPY --from=builder /app/dist ./dist COPY package*.json ./ # Install only production dependencies RUN npm install --production --ignore-scripts # Use a non-root user for security (optional) RUN adduser -D mcpuser USER mcpuser # Set the entrypoint command CMD ["node", "./dist/index.js"]
這,就是一個(gè)標(biāo)準(zhǔn)的 multi-stage builds 的 Dockerfile。
由于 Code Runner MCP Server 需要支持多種編程語(yǔ)言的運(yùn)行,我在 Dockerfile 里面,預(yù)先安裝了幾個(gè)常用的編程語(yǔ)言的解釋器/編譯器。
這樣,用戶在使用的時(shí)候,唯一需要安裝的,就是 Docker 而已:
{ "mcp": { "inputs": [], "servers": { "mcp-server-code-runner": { "command": "docker", "args": [ "run", "--rm", "-i", "formulahendry/mcp-server-code-runner" ] } } } }
完整的代碼,可以參考 Code Runner MCP Server 的 repo,完全開(kāi)源:
https://github.com/formulahendry/mcp-server-code-runner
到此這篇關(guān)于教你如何實(shí)現(xiàn)容器化 MCP Server的文章就介紹到這了,更多相關(guān)容器化 MCP Server內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 輕松開(kāi)發(fā) Streamable HTTP MCP Server
- 在 VS Code 中,一鍵安裝 MCP Server!
- 從零開(kāi)始開(kāi)發(fā)一個(gè) MCP Server!
- VS?Code擴(kuò)展Code?Runner?MCP?Server來(lái)了
- Go語(yǔ)言開(kāi)發(fā)實(shí)現(xiàn)查詢IP信息的MCP服務(wù)器
- 一文弄懂用Go實(shí)現(xiàn)MCP服務(wù)的示例代碼
- 一文帶你學(xué)會(huì)使用Go語(yǔ)言實(shí)現(xiàn)自己的MCP服務(wù)端
- SpringBoot項(xiàng)目引入MCP的實(shí)現(xiàn)示例
- .NET?MCP?文檔詳細(xì)指南
- 把 MCP Server 打包進(jìn) VS Code extension
相關(guān)文章
nodejs實(shí)現(xiàn)OAuth2.0授權(quán)服務(wù)認(rèn)證
本篇文章主要介紹了nodejs實(shí)現(xiàn)OAuth2.0授權(quán)服務(wù)認(rèn)證,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-12-12nodejs通過(guò)phantomjs實(shí)現(xiàn)下載網(wǎng)頁(yè)
這篇文章主要介紹了nodejs通過(guò)phantomjs實(shí)現(xiàn)下載網(wǎng)頁(yè)的方法,有需要的小伙伴可以參考下。2015-05-05node.js中的fs.futimes方法使用說(shuō)明
這篇文章主要介紹了node.js中的fs.futimes方法使用說(shuō)明,本文介紹了fs.futimes方法說(shuō)明、語(yǔ)法、接收參數(shù)、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下2014-12-12node.js中的querystring.stringify方法使用說(shuō)明
這篇文章主要介紹了node.js中的querystring.stringify方法使用說(shuō)明,本文介紹了querystring.stringify的方法說(shuō)明、語(yǔ)法、接收參數(shù)、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下2014-12-12