教你如何實(shí)現(xiàn)容器化 MCP Server
大家好!我是韓老師。
寫在最前:容器化 MCP Server,有用。但是,你不一定需要。
WHY
如果你在開發(fā)一個(gè) local MCP Server,并且有以下的任何一種情況:
- 需要安裝多個(gè) toolchain,才能運(yùn)行 local MCP Server
- 用于開發(fā) local MCP Server 的語言,沒有像 npx 或者 uv 那樣一鍵運(yùn)行程序的工具
那么,容器化 MCP Server,對(duì)你的用戶是有用的。
反之,如果你已經(jīng)用主流的 Node.js 或者 Python 來開發(fā) local MCP Server,并且沒有其他額外的依賴。
那么,你也許并不需要容器化。
WHAT
local MCP Server 其實(shí)就是個(gè) Node.js/Python/PHP/Go/Java/... 開發(fā)的 Console App 而已,通過 stdin/stdout 與 MCP Client 交互,沒有什么特別的地方。
所以,一般來說,你只需要一個(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ùn)行,我在 Dockerfile 里面,預(yù)先安裝了幾個(gè)常用的編程語言的解釋器/編譯器。
這樣,用戶在使用的時(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,完全開源:
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)文章希望大家以后多多支持腳本之家!
- 輕松開發(fā) Streamable HTTP MCP Server
- 在 VS Code 中,一鍵安裝 MCP Server!
- 從零開始開發(fā)一個(gè) MCP Server!
- VS?Code擴(kuò)展Code?Runner?MCP?Server來了
- Go語言開發(fā)實(shí)現(xiàn)查詢IP信息的MCP服務(wù)器
- 一文弄懂用Go實(shí)現(xiàn)MCP服務(wù)的示例代碼
- 一文帶你學(xué)會(huì)使用Go語言實(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)證,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-12-12nodejs通過phantomjs實(shí)現(xiàn)下載網(wǎng)頁
這篇文章主要介紹了nodejs通過phantomjs實(shí)現(xiàn)下載網(wǎng)頁的方法,有需要的小伙伴可以參考下。2015-05-05node.js中的querystring.stringify方法使用說明
這篇文章主要介紹了node.js中的querystring.stringify方法使用說明,本文介紹了querystring.stringify的方法說明、語法、接收參數(shù)、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下2014-12-12