MCP 是什麼?爲什麼這麼厲害?
全部開啟MCP 是給 Kiro 的 AI 加上“特殊技能”的機制。比如:
- 能夠搜索 AWS 官方文檔
- 能夠操作 GitHub 倉庫
- 能夠進行網頁搜索
- 能夠連接數據庫 這些能力就像插件一樣,可以隨時添加進來,讓 AI 變得更加萬能,幫你搞定各種開發任務!
主要 MCP 服務器的設置與使用方法
全部開啟
// 追加到 .kiro/settings/mcp.json
{
"mcpServers": {
"aws-docs": {
"command": "uvx",
"args": ["awslabs.aws-documentation-mcp-server@latest"],
"env": {
"FASTMCP_LOG_LEVEL": "ERROR" // 日誌級別設爲最小,減少輸出
},
"disabled": false,
"autoApprove": [
"mcp_aws_docs_search_documentation", // 搜索請求自動批准
"mcp_aws_docs_read_documentation" // 讀取請求自動批准
]
}
}
}
實際使用示例:
# 只需在聊天中提問
"S3 的生命週期策略是什麼?"
"Lambda 函數的冷啓動如何優化?"
"DynamoDB 分區鍵設計的最佳實踐有哪些?"
# Kiro 會自動搜索 AWS 官方文檔並回答
必要的準備工作:
# 安裝 uv(首次使用時執行)
curl -LsSf https://astral.sh/uv/install.sh | sh
# 需要 Python 3.10 及以上版本
uv python install 3.10
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_TOKEN"
}
}
}
}
實際使用示例:
# 獲取倉庫信息
"告訴我 facebook/react 倉庫的最新發布信息"
# 代碼搜索
"幫我在 tensorflow/tensorflow 倉庫裏找 conv2d 的實現"
# 創建 Issue
"幫我爲這個 bug 創建一個 Issue"
# 創建 PR
"從 feature/login 分支向 main 分支創建一個 PR"
GitHub 令牌的創建方法:
- 進入 GitHub → 設置(Settings)→ 開發者設置(Developer settings)
- 選擇個人訪問令牌(Personal access tokens)→ 生成新令牌(Generate new 令牌)
- 需要的權限:repo,user
- 設置環境變量:匯出 GitHub_TOKEN=“ghp_xxxx”
{
"mcpServers": {
"web-search": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-bravesearch"],
"env": {
"BRAVE_API_KEY": "$BRAVE_API_KEY"
},
"autoApprove": ["brave_search"] // 搜索自動執行
}
}
}
實際使用示例:
# 最新技術資訊
"幫我搜索一下 React 19 的新功能"
# 故障排查
"調查一下 Next.js 14 出現 hydration error 的原因"
# 新聞動態
"幫我總結一下本週 JavaScript 領域的新聞"
Brave 搜尋 API 密鑰獲取方法:
1. 造訪 https://brave.com/search/api/
2. 註冊免費套餐(每月免費額度 5000 次查詢)
3. 將 API 金鑰設定到環境變數中
你也可以打造專屬於自己的 MCP 服務器! 比如,連接公司內部 API 的專用服務器:
// my-company-mcp-server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
const server = new Server(
{
name: 'my-company-tools',
version: '1.0.0',
},
{
capabilities: {
tools: {},
},
}
);
// 工具定義
server.setRequestHandler('tools/list', async () => ({
tools: [
{
name: 'search_company_docs',
description: '搜索公司內部文檔',
inputSchema: {
type: 'object',
properties: {
query: {
type: 'string',
description: '搜索關鍵詞'
},
department: {
type: 'string',
enum: ['engineering', 'design', 'marketing'],
description: '按部門篩選'
}
},
required: ['query']
}
},
{
name: 'get_employee_info',
description: '獲取員工信息',
inputSchema: {
type: 'object',
properties: {
email: {
type: 'string',
description: '員工郵箱地址'
}
},
required: ['email']
}
}
]
}));
// 工具實現
server.setRequestHandler('tools/call', async (request) => {
const { name, arguments: args } = request.params;
switch (name) {
case 'search_company_docs':
// 實際搜索處理
const results = await searchInternalDocs(args.query, args.department);
return {
content: [{
type: 'text',
text: `搜索結果:\n${results.map(r => `- ${r.title}: ${r.url}`).join('\n')}`
}]
};
case 'get_employee_info':
// 獲取員工信息
const info = await getEmployeeInfo(args.email);
return {
content: [{
type: 'text',
text: `員工信息:\n姓名: ${info.name}\n部門: ${info.department}\n內線: ${info.extension}`
}]
};
default:
throw new Error(`未知的工具名稱: ${name}`);
}
});
// 啓動服務器
const transport = new StdioServerTransport();
await server.connect(transport);
添加到配置中:
{
"mcpServers": {
"company-tools": {
"command": "node",
"args": ["./mcp-servers/my-company-mcp-server.js"],
"env": { "COMPANY_API_KEY": "${COMPANY_API_KEY}" }
}
}
}