Appearance
MCP(Model Context Protocol)是扩展 Kiro 能力的标准方式,允许你为 Kiro 接入第三方工具服务器。本节以两个实用示例展示 MCP 的价值:一是通过记忆 MCP 服务器让 Kiro 跨会话保存操作历史,并据此自动生成 commit 消息;二是通过顺序思维 MCP 服务器让 Kiro 在动手之前先做更深入的规划。你将学会编写 mcp.json 配置,以及用 steering 文件修改 Kiro 的默认行为。
用 MCP 扩展 Kiro
本节假设你已完成前置模块。之前我们已经:
现在进入更高级的定制——通过 MCP(Model Context Protocol)为 Kiro 接入新的工具和行为。
配置 MCP 服务器
Kiro 内置 MCP 支持。点击 Kiro 幽灵图标,找到 "MCP Servers",点击 + 添加服务器。
修改打开的 mcp.json 文件。本示例使用 Podman 容器运行 MCP 服务器,保持主机环境整洁:
json
{
"mcpServers": {
"memory": {
"enabled": true,
"command": "podman",
"args": [
"run",
"-i",
"--rm",
"-v",
"memories:/memories",
"--env",
"MEMORY_FILE_PATH=/memories/memory.json",
"mcp/memory"
],
"autoApprove": [
"create_entities",
"create_relations",
"add_observations",
"delete_entities",
"delete_observations",
"delete_relations",
"read_graph",
"search_nodes",
"open_nodes"
]
},
"sequentialthinking": {
"command": "podman",
"args": [
"run",
"-i",
"--rm",
"mcp/sequentialthinking"
],
"autoApprove": [
"sequentialthinking"
]
}
}
}这个配置引入了两个 MCP 服务器:
- memory:提供长期记忆存储能力,数据保存在 Podman volume 中,可跨 Kiro 会话持久化,也可在 Kiro 外部读写这份记忆。
- sequentialthinking:让 Kiro 在执行任务前花更多时间做结构化规划。
让 Kiro 记录操作历史
在 .kiro/steering/behavior.md 创建 steering 文件,写入以下内容:
Each time you start working, put a `user_request`
type entity into the knowledge graph using the `create_entities` tool.
After you work, add observations to that entity
about what you did, how many files you touched, how many lines, etc.然后让 Kiro 做一件事:
Rewrite the README.md as if it was written by a pirate.完成后,查询知识图谱:
Search nodes for user_request and write me
a commit message based on what you seeKiro 会根据记录的操作历史生成 commit 消息,例如:
docs: transform README.md with pirate-themed language
- Rewrote entire README.md in pirate style
- Added nautical references and pirate slang throughout
- Maintained all original information and links
- Changed section titles to pirate-appropriate terms
- Added humorous pirate expressions and threats
- Preserved functionality while enhancing user experience with thematic language修改思维模式
更新 .kiro/steering/behavior.md 的内容为:
When planning how to do something, use the sequentialthinking tool to plan the next several steps.然后试试:
Let's do something super cool in this projectKiro 会在开始动手之前,用 sequentialthinking 工具先规划出完整的步骤链。
发现更多 MCP 服务器
本节小结
通过 MCP,Kiro 可以接入任意外部工具——上下文来源、专用 API、结构化记忆……可以组合出非常丰富的工作流。
前往:课程总结
常见问题
Q:MCP 服务器必须用 Podman 运行吗?
A:不是必须。Podman 只是本教程的示例方案。大多数 MCP 服务器也支持通过 npx、uvx 或直接运行可执行文件的方式启动,具体看各服务器的文档。
Q:autoApprove 列表有什么作用,不填会怎样?
A:列入 autoApprove 的 MCP 工具调用无需每次弹出确认。不填时,每次 Kiro 调用这些工具都会向你请求授权,适合敏感操作;高频只读工具建议加入 autoApprove 以减少打断。
Q:Steering 文件和 hooks 有什么区别?
A:steering 文件描述 Kiro 的持续性行为倾向(每次开始工作都要做 X),相当于给 Kiro 写的工作守则;hooks 则是事件驱动的一次性响应(当某个文件变化时做 X)。两者可以配合使用。