| 要求 | 最低版本 |
|---|---|
| Go | 1.25+ |
| Git | 2.0+ |
| SQLite | 3.0+ |
# 克隆项目
git clone https://github.com/charmbracelet/crush.git
cd crush
# 安装依赖
go mod download
# 构建
go build .
# 运行测试
go test ./...
# 开发模式
task dev
// 1. 定义参数结构
type MyToolParams struct {
Param1 string `json:"param1" description:"参数1描述"`
Param2 int `json:"param2" description:"参数2描述"`
}
// 2. 创建工具函数
func NewMyTool(dependencies...) fantasy.AgentTool {
return fantasy.NewAgentTool(
"my_tool", // 工具名称
"工具描述,用于 AI 理解工具用途",
func(ctx context.Context, params MyToolParams, call fantasy.ToolCall) (fantasy.ToolResponse, error) {
// 3. 实现工具逻辑
// 4. 返回结果
return fantasy.NewTextResponse("执行结果"), nil
},
)
}
func NewHelloTool() fantasy.AgentTool {
return fantasy.NewAgentTool(
"hello",
"向用户发送问候",
func(ctx context.Context, params HelloParams, call fantasy.ToolCall) (fantasy.ToolResponse, error) {
if params.Name == "" {
return fantasy.NewErrorResponse("name is required"), nil
}
message := "Hello, " + params.Name + "!"
return fantasy.NewTextResponse(message), nil
},
)
}
const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
const server = new Server({
name: 'my-mcp-server',
version: '1.0.0'
}, {
capabilities: { tools: {} }
});
// 定义工具
server.setRequestHandler('tools/list', async () => {
return {
tools: [{
name: 'my_tool',
description: '我的自定义工具',
inputSchema: {
type: 'object',
properties: {
param: { type: 'string', description: '参数描述' }
},
required: ['param']
}
}]
}
});
// 处理工具调用
server.setRequestHandler('tools/call', async (request) => {
const { name, arguments: args } = request.params;
if (name === 'my_tool') {
return {
content: [{
type: 'text',
text: `执行结果: ${args.param}`
}]
};
}
});
// 启动服务器
const transport = new StdioServerTransport();
server.connect(transport);
mcp:
servers:
my-server:
command: "node"
args:
- "/path/to/my-mcp-server/index.js"
env:
CUSTOM_VAR: "value"
agents:
my_coder:
description: "自定义编码助手"
system_prompt: |
你是一个专业的 Python 开发者。
专注于编写高质量的 Python 代码。
tools:
- read
- write
- edit
- bash
- grep
本文是《Crush 从入门到精通》系列文章的第十八章
还没有人回复