環(huán)境準(zhǔn)備
操作系統(tǒng):Windows 10/11 或 macOS 10.15+(暫不支持Linux) 硬件配置:雙核CPU、8GB內(nèi)存、2GB存儲(chǔ)空間 軟件依賴: Claude Desktop(最新版,作為MCP宿主應(yīng)用) Node.js v18+(建議LTS版本,用于運(yùn)行JavaScript/TypeScript服務(wù)) Python 3.10+(需添加到PATH,用于Python版服務(wù)) UV(Python包管理器,替代pip) Git(版本控制工具)
powershell 復(fù)制 # 安裝包管理器 winget install --id astral-sh.uv -e winget install git.git sqlite.sqlite # 安裝Node.js服務(wù) npm install -g @ 創(chuàng)建MCP Server基礎(chǔ)Python服務(wù)示例python 復(fù)制
高級(jí)服務(wù)類型(通過npm安裝)bash 復(fù)制
配置MCP Client
json 復(fù)制 { 'mcpservers': { '本地計(jì)算服務(wù)': { 'command': 'python', 'args': ['C:/path/to/server_demo.py'], 'env': {'PYTHONPATH': 'C:/Python310'} }, '文件服務(wù)': { 'command': 'npx', 'args': ['-y', '@
部署流程
bash 復(fù)制 # Python服務(wù) uv venv .venv source .venv/bin/activate python server_demo.py # Node.js服務(wù) npx @
python 復(fù)制 # client_demo.py from mcp.client.stdio import stdio_client async with stdio_client(command='python', args=['server_demo.py']) as (read, write): async with ClientSession(read, write) as session: tools = await session.list_tools() print(f'可用工具: {tools}') 擴(kuò)展部署
json 復(fù)制 { 'mcpservers': { 'github': { 'command': 'npx', 'args': ['@
使用uv secret管理敏感數(shù)據(jù) 啟用TLS加密通信(需配置SSL證書) 設(shè)置IP白名單(僅限localhost訪問) 故障排查
服務(wù)未啟動(dòng):檢查進(jìn)程是否存活ps aux | grep mcp 依賴缺失:運(yùn)行uv pip check驗(yàn)證Python依賴 路徑錯(cuò)誤:Windows需使用雙反斜杠C:\\path\\to\\server
bash 復(fù)制 # 查看服務(wù)日志 uvx mcp-server-sqlite --log-level debug # 網(wǎng)絡(luò)診斷 curl ![]() |
|
來(lái)自: 創(chuàng)業(yè)情報(bào)局 > 《AI電商》