使用说明
Conduit-通用人工智能框架和MCP平台
⚠️ BETA软件警告
导管当前处于 beta开发The MCP服务器核心功能稳定 并准备好与MCP客户端(VS Code Copilot、Cline、Claude Desktop)一起通用。然而, LLM集成、Agent框架和Swarm功能都是实验性的 并且仍在进行测试。在生产环境中谨慎使用这些高级功能。请报告问题并提供反馈,以帮助改进项目。
Conduit是一个全面的AI框架和通用的MCP平台,将传统的MCP工具与先进的AI代理系统连接起来。内置Go,它提供了从简单的工具执行到具有多LLM协调的复杂多代理集群的一切。无论您是需要基本的MCP客户端集成还是复杂的自主AI工作流程,Conduit都可以从简单的库使用扩展到企业级代理编排,并支持本地模型(Ollama)和云提供商(OpenAI、DeepInfra)。
通用MCP兼容性
Conduit实现了标准的MCP(模型上下文协议)规范,并与任何兼容MCP的客户端配合使用。
✅ 经过测试和验证的客户
- VS代码副本 -与所有31个工具完全集成
- 克莱恩 -完整的工具发现和功能
- 克劳德桌面 -标准MCP标准支持
🔄 与任何MCP客户端兼容
由于导管遵循MCP规范,因此应与以下设备配合使用:
- 拟人克劳德桌面
- Continue.dev
- 光标IDE
- 任何自定义MCP客户端实现
经过测试和确认
- Vs代码副驾驶
- Vs代码临床
- Warp命令行界面
所有客户都可以访问Conduit的31个工具的完整工具包,以增强人工智能辅助。
✅ 已验证的工具调用
Conduit的工具调用系统已经过彻底的测试,并通过真实的LLM实施进行了验证:
Olama集成✅
- 模型:llama3.2(及兼容型号)
- 工具选择: ✅ LLM自动选择正确的工具
- 参数提取: ✅ LLM正确地从自然语言中提取参数
- 工具执行: ✅ 所有31个工具均成功执行
- 结果处理: ✅ LLM处理工具结果并生成自然响应
- 错误处理: ✅ 正确的错误处理和用户反馈 注意:Ollama是用于mcp测试的,所以预计会有重大变化。主要重点是向llm客户提供mcp。
验证交互示例
# ✅ Text manipulation - VERIFIED WORKING
User: "convert hello world to uppercase"
LLM: Automatically selects `uppercase` tool → Returns "HELLO WORLD"
# ✅ UUID generation - VERIFIED WORKING
User: "generate a UUID for me"
LLM: Automatically selects `uuid` tool → Returns generated UUID
# ✅ Base64 encoding - VERIFIED WORKING
User: "encode Mountain123 in base64"
LLM: Automatically selects `base64_encode` tool → Returns "TW91bnRhaW4xMjM="
# ✅ Memory operations - VERIFIED WORKING
User: "remember that my favorite color is blue"
LLM: Automatically selects `remember` tool → Stores information
结果:自动工具选择和执行的成功率为100%。
入门指南
1.安装导管
go get github.com/benozo/conduit
2.创建您的MCP服务器
// main.go
package main
import (
"log"
conduit "github.com/benozo/conduit/lib"
"github.com/benozo/conduit/lib/tools"
"github.com/benozo/conduit/mcp"
)
func main() {
config := conduit.DefaultConfig()
config.Mode = mcp.ModeStdio
server := conduit.NewServer(config)
tools.RegisterTextTools(server)
tools.RegisterMemoryTools(server)
tools.RegisterUtilityTools(server)
log.Fatal(server.Start())
}
3.选择您的使用模式
适用于MCP客户端(VS代码副本、Cline等)
go build -o my-mcp-server .
添加到MCP客户端配置中:
{
"command": "/path/to/my-mcp-server",
"args": ["--stdio"]
}
与Ollama进行LLM工具调用
# Start Ollama
ollama serve
ollama pull llama3.2
# Start your tool-enabled server
./my-mcp-server --http
# Test natural language tool calling
curl -X POST http://localhost:8080/chat \
-H "Content-Type: application/json" \
-d '{"message": "convert hello world to uppercase"}'
特性
- 🌐 通用MCP兼容性:适用于任何MCP客户端(VS Code Copilot、Cline、Claude Desktop等)
- 🤖 AI代理框架:完整的自主代理系统,包括任务规划、执行和监控
- 🐝 多代理群集:受OpenAI Swarm启发的智能任务路由和切换协调
- 🧠 多LLM架构:每个代理都可以使用专门的LLM提供商(Ollama、OpenAI、DeepInfra等)
- ⚡ 智能工具调用:LLM根据自然语言请求自动选择和执行工具
- 🔄 高级工作流:DAG、主管、管道和条件工作流编排模式
- 💭 重演推理:内置推理和行动能力,决策透明
- 🏠 本地AI支持:通过Ollama集成实现以隐私为重点的本地模式
- ☁️ 云AI集成:生产就绪的OpenAI、DeepInfra和自定义API支持
- 🔧 双协议支持:stdio(用于MCP客户端)和HTTP/SSE(用于web应用程序)
- 📚 嵌入式设计:用作独立服务器、Go库或嵌入现有应用程序
- 🛠️ 增强的工具注册:丰富的模式支持,具有类型验证和全面的文档
- 💾 内存管理:用于上下文、对话历史和代理协调的持久记忆系统
- 🎯 生产就绪:企业级错误处理、日志记录、监控和配置
- 🛠️ 综合工具套件:31多种经过实战测试的文本、内存和实用程序操作工具
🤖 AI代理框架
Conduit包括一个强大的AI代理框架,该框架为创建可以使用MCP工具执行复杂任务的自主代理提供了高级抽象。
关键代理功能
- 代理管理:创建、配置和管理多个专用AI代理
- 任务执行:通过自动规划和执行将复杂任务分配给代理
- 专业代理:用于数学、文本处理、内存管理和实用程序的预构建代理
- 海关代理:使用特定的工具集和行为创建自定义代理
- 任务监控:实时任务进度跟踪和执行监控
- 内存集成:每个代理的内存和上下文管理
快速代理示例
package main
import (
"github.com/benozo/conduit/agents"
conduit "github.com/benozo/conduit/lib"
"github.com/benozo/conduit/lib/tools"
)
func main() {
// Create MCP server
config := conduit.DefaultConfig()
server := conduit.NewEnhancedServer(config)
tools.RegisterTextTools(server)
tools.RegisterMemoryTools(server)
tools.RegisterUtilityTools(server)
// Create agent manager
agentManager := agents.NewMCPAgentManager(server)
// Create specialized agents
agentManager.CreateSpecializedAgents()
// Create and execute a math task
task, _ := agentManager.CreateTaskForAgent("math_agent", agents.TaskTypeMath, map[string]interface{}{
"a": 25.0,
"b": 15.0,
"operation": "multiply",
})
// Start server and execute task
go server.Start()
agentManager.ExecuteTask(task.ID)
// Task automatically plans and executes: 25 × 15 = 375
}
🧠 多LLM代理支持
导管现在支持 多代理、多LLM架构,允许群中的每个代理使用其自己的专用LLM提供者和模型。这使得能够为特定任务选择最佳模型,同时保持完全的向后兼容性。
关键的多LLM功能
- 每个代理LLM配置:每个代理都可以使用不同的LLM提供商(Ollama、OpenAI、DeepInfra等)
- 任务特定模型选择:将模型与其优势相匹配(代码生成、内容创建、分析)
- 成本优化:使用本地模型(Ollama)进行路由,使用云模型(GPT-4)进行复杂推理
- 供应商冗余:可靠性的后备机制和供应商多样性
- 完全向后兼容性:现有的群体代码继续工作不变
快速多LLM示例
// Create agents with different LLM providers
coordinator := swarmClient.CreateAgentWithModel("coordinator",
"Route tasks efficiently", []string{},
&conduit.ModelConfig{
Provider: "ollama", Model: "llama3.2",
URL: "http://localhost:11434",
})
dataAnalyst := swarmClient.CreateAgentWithModel("analyst",
"Perform complex analysis", []string{"word_count"},
&conduit.ModelConfig{
Provider: "openai", Model: "gpt-4",
APIKey: os.Getenv("OPENAI_API_KEY"),
})
codeGenerator := swarmClient.CreateAgentWithModel("coder",
"Generate optimized code", []string{"json_format"},
&conduit.ModelConfig{
Provider: "deepinfra", Model: "Qwen/Qwen2.5-Coder-32B-Instruct",
APIKey: os.Getenv("DEEPINFRA_API_KEY"),
})
支持的提供商
- 奥拉马:本地型号(llama3.2、qwen2.5、codellama)-快速、私密、经济高效
- OpenAI:GPT-4、GPT-3.5涡轮增压-高级推理和分析
- DeepInfra:Qwen Coder,Llama型号-专业代码生成和处理
看 examples/multi_llm_swarm/ 一个完整的工作示例。
可用代理类型
- 数学代理:专门从事数学计算(
add,multiply) - 文本代理:文本处理和分析(
word_count,uppercase,lowercase) - 内存代理:数据存储和检索(
remember,recall,forget) - 公用事业代理:编码、散列、生成(
base64_encode,uuid,timestamp) - 总代理人:具有混合工具功能的多用途代理
看 agents/README.md 获取完整的文档和示例。
🐝 Agent Swarm框架
导管包括一个强大的 Agent Swarm 该框架受OpenAI Swarm模式的启发,实现了与MCP工具的复杂多代理协调。该系统侧重于使用两个关键原语进行轻量级、可扩展的代理编排: 代理 和 递手传球.
Swarm架构
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Coordinator │───▶│ ContentCreator │ │ DataAnalyst │
│ (Task Router) │ │ (Text Processing)│ │ (Data Analysis) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │
│ ┌──────────────────┐ │
└─────────────▶│ MemoryManager │◀──────────┘
│ (Info Storage) │
└──────────────────┘
主要特点
- 代理商协调:轻量级代理切换和通信
- 上下文变量:跨代理对话共享状态管理
- 函数调用:与MCP服务器功能的丰富工具集成
- 内存持久性:跨代理交互的共享内存
- 自然语言接口:人性化的多代理工作流
快速Swarm示例
// Create swarm client with MCP tools
swarm := conduit.NewSwarmClient(mcpServer)
// Define specialized agents
coordinatorAgent := swarm.CreateAgent("coordinator", "Route tasks to appropriate agents", []string{
"transfer_to_content", "transfer_to_data", "transfer_to_memory",
})
contentAgent := swarm.CreateAgent("content_creator", "Handle text processing tasks", []string{
"uppercase", "lowercase", "snake_case", "camel_case", "word_count",
})
// Execute swarm workflow
result := swarm.Run(coordinatorAgent, []conduit.Message{
{Role: "user", Content: "Convert 'Agent Swarm Integration' to snake_case and remember it"},
}, map[string]interface{}{
"session_id": "demo_session",
})
// → Coordinator routes to ContentCreator for text processing
// → Then routes to MemoryManager for storage
// → Result: agent_swarm_integration stored in memory
演示场景
- 文本处理:跨代理的多步文本转换
- 数据管道:分析、编码和存储工作流
- 存储器操作:智能信息管理
- 复杂的协调:多代理任务分解和执行
看 examples/agent_swarm/, examples/agent_swarm_simple/,以及 examples/agent_swarm_llm/ 获取完整的文档和示例。
高级工作流模式
Agent Swarm框架包括复杂的工作流编排模式:
- 顺序的:有序逐步执行(ETL管道)
- 并行:并发独立执行(批处理)
- 有向无环图:基于依赖关系的执行图(复杂数据处理)
- 主管:分级监督和控制(关键任务流程)
- 管道:转换阶段的数据流(内容处理)
- 条件式:基于运行时条件的动态分支(质量控制)
看 examples/agent_swarm_workflows/ 查看高级工作流模式示例。
运行Agent Swarm
# Basic agent swarm demo (rule-based)
cd examples/agent_swarm
go run main.go
# LLM-powered agent swarm with Ollama
cd examples/agent_swarm_llm
go run main.go
# Advanced workflow patterns demo
cd examples/agent_swarm_workflows
go run main.go
# Simple swarm demo
cd examples/agent_swarm_simple
# Install dependencies
go mod tidy
# Run the full demo
go run main.go
# Or run with custom LLM integration
go run llm_demo.go
# Or use the test script
./test_agent_swarm.sh
快速开始
图书馆(推荐)
在Go项目中安装Conduit:
go get github.com/benozo/conduit
然后创建自己的MCP服务器:
package main
import (
"log"
conduit "github.com/benozo/conduit/lib"
"github.com/benozo/conduit/lib/tools"
"github.com/benozo/conduit/mcp"
)
func main() {
// Create configuration
config := conduit.DefaultConfig()
config.Port = 8080
config.Mode = mcp.ModeStdio // For MCP clients
// Create server
server := conduit.NewServer(config)
// Register tool packages
tools.RegisterTextTools(server)
tools.RegisterMemoryTools(server)
tools.RegisterUtilityTools(server)
// Register custom tools
server.RegisterTool("my_tool", func(params map[string]interface{}, memory *mcp.Memory) (interface{}, error) {
return map[string]string{"result": "Hello from my tool!"}, nil
})
// Start server
log.Fatal(server.Start())
}
使用增强的工具注册
对于需要丰富参数验证和文档的工具:
package main
import (
"log"
conduit "github.com/benozo/conduit/lib"
"github.com/benozo/conduit/lib/tools"
"github.com/benozo/conduit/mcp"
)
func main() {
config := conduit.DefaultConfig()
config.Mode = mcp.ModeStdio
// Create enhanced server
server := conduit.NewEnhancedServer(config)
// Register standard tools
tools.RegisterTextTools(server.Server)
tools.RegisterMemoryTools(server.Server)
// Register custom tool with rich schema
server.RegisterToolWithSchema("weather",
func(params map[string]interface{}, memory *mcp.Memory) (interface{}, error) {
city := params["city"].(string)
return map[string]interface{}{
"result": fmt.Sprintf("Weather in %s: Sunny, 72°F", city),
"city": city, "temperature": "72°F", "condition": "Sunny",
}, nil
},
conduit.CreateToolMetadata("weather", "Get weather for a city", map[string]interface{}{
"city": conduit.StringParam("City name to get weather for"),
}, []string{"city"}))
log.Fatal(server.Start())
}
与任何MCP客户端一起构建和使用:
go build -o my-mcp-server .
./my-mcp-server --stdio # For MCP clients
./my-mcp-server --http # For HTTP API
./my-mcp-server --both # For both protocols
独立使用(开发/测试)
对于开发或测试,您还可以克隆并直接运行:
git clone https://github.com/benozo/conduit
cd conduit
go run main.go --stdio # For MCP clients (VS Code Copilot, Cline, etc.)
go run main.go --http # For HTTP API and web applications
go run main.go --both # For both protocols simultaneously
MCP客户端配置
VS代码副本:
{
"mcp.mcpServers": {
"my-mcp-server": {
"command": "/path/to/my-mcp-server",
"args": ["--stdio"],
"env": {}
}
}
}
克莱恩:
{
"mcpServers": {
"my-mcp-server": {
"autoApprove": [],
"disabled": false,
"timeout": 60,
"type": "stdio",
"command": "/path/to/my-mcp-server",
"args": ["--stdio"]
}
}
}
克劳德桌面:
{
"mcpServers": {
"my-mcp-server": {
"command": "/path/to/my-mcp-server",
"args": ["--stdio"]
}
}
}
嵌入式使用
将Conduit直接嵌入到现有的Go应用程序中:
package main
import (
"log"
conduit "github.com/benozo/conduit/lib"
"github.com/benozo/conduit/lib/tools"
"github.com/benozo/conduit/mcp"
)
func main() {
// Create configuration
config := conduit.DefaultConfig()
config.Port = 8081
config.Mode = mcp.ModeHTTP
// Create server
server := conduit.NewServer(config)
// Register tool packages
tools.RegisterTextTools(server)
tools.RegisterMemoryTools(server)
tools.RegisterUtilityTools(server)
// Register custom tools
server.RegisterTool("my_tool", func(params map[string]interface{}, memory *mcp.Memory) (interface{}, error) {
return map[string]string{"result": "Hello from my tool!"}, nil
})
// Start server
log.Fatal(server.Start())
}
纯库使用
直接使用MCP组件,无需任何服务器(您自己实现):
package main
import "github.com/benozo/conduit/mcp"
func main() {
// Create components
memory := mcp.NewMemory()
tools := mcp.NewToolRegistry()
// Register tools
tools.Register("my_tool", func(params map[string]interface{}, memory *mcp.Memory) (interface{}, error) {
return map[string]string{"result": "Hello!"}, nil
})
// Use directly
result, err := tools.Call("my_tool", map[string]interface{}{}, memory)
// Integrate into your own web server, CLI, gRPC service, etc.
}
库API
服务器配置
config := &conduit.Config{
Port: 8080, // HTTP server port
OllamaURL: "http://localhost:11434", // Ollama API URL
Mode: mcp.ServerMode // Server mode
Environment map[string]string // Environment variables
EnableCORS bool // Enable CORS
EnableHTTPS bool // Enable HTTPS
CertFile string // HTTPS certificate file
KeyFile string // HTTPS key file
EnableLogging bool // Enable logging
}
创建服务器
// Standard server with default config
server := conduit.NewServer(nil)
// Standard server with custom config
server := conduit.NewServer(config)
// Enhanced server with rich schema support
server := conduit.NewEnhancedServer(config)
// Standard server with custom model
server := conduit.NewServerWithModel(config, myModelFunc)
注册工具
// Register tool packages
tools.RegisterTextTools(server) // Text manipulation tools
tools.RegisterMemoryTools(server) // Memory management tools
tools.RegisterUtilityTools(server) // Utility tools
// Register individual tools
server.RegisterTool("my_tool", func(params map[string]interface{}, memory *mcp.Memory) (interface{}, error) {
// Tool implementation
return result, nil
})
增强的工具注册(具有丰富的模式)
对于需要丰富参数验证和文档的工具,请使用增强的注册系统:
// Create enhanced server
server := conduit.NewEnhancedServer(config)
// Register standard tools (optional)
tools.RegisterTextTools(server.Server)
tools.RegisterMemoryTools(server.Server)
tools.RegisterUtilityTools(server.Server)
// Register custom tools with full schema metadata
server.RegisterToolWithSchema("calculate",
func(params map[string]interface{}, memory *mcp.Memory) (interface{}, error) {
operation := params["operation"].(string)
a := params["a"].(float64)
b := params["b"].(float64)
var result float64
switch operation {
case "add":
result = a + b
case "multiply":
result = a * b
default:
return nil, fmt.Errorf("unknown operation: %s", operation)
}
return map[string]interface{}{"result": result}, nil
},
conduit.CreateToolMetadata("calculate", "Perform mathematical operations", map[string]interface{}{
"operation": conduit.EnumParam("Mathematical operation", []string{"add", "multiply"}),
"a": conduit.NumberParam("First number"),
"b": conduit.NumberParam("Second number"),
}, []string{"operation", "a", "b"}))
// Start with enhanced schema support
server.Start()
模式帮助函数
// Parameter type helpers
conduit.NumberParam("Description") // Numbers
conduit.StringParam("Description") // Strings
conduit.BoolParam("Description") // Booleans
conduit.ArrayParam("Description", "itemType") // Arrays
conduit.EnumParam("Description", []string{"opt1", "opt2"}) // Enums
// Complete metadata builder
conduit.CreateToolMetadata(name, description, properties, required)
增强注册的好处
- 🔍 丰富的模式:完整的JSON模式验证,包括参数类型和描述
- 📖 更好的文档:MCP客户端显示详细的参数信息
- ✅ 类型安全:自动参数验证和错误处理
- 🎯 IDE支持:MCP客户端中更好的自动补全和提示
- 🔧 专业的:生产就绪工具定义
模型集成
// Use default Ollama model
server := conduit.NewServer(config) // Uses default Ollama
// Set custom model
server.SetModel(func(ctx mcp.ContextInput, req mcp.MCPRequest, memory *mcp.Memory, onToken mcp.StreamCallback) (string, error) {
// Custom model implementation
return response, nil
})
// Use built-in model helpers
ollamaModel := conduit.CreateOllamaModel("http://localhost:11434")
server.SetModel(ollamaModel)
可用工具
文本工具
uppercase-将文本转换为大写lowercase-将文本转换为小写reverse-反转文本word_count-统计文本中的单词trim-修剪空白title_case-转换为标题大小写snake_case-转换为snake_casecamel_case-转换为camelCasereplace-替换文本模式extract_words-从文本中提取单词sort_words-按字母顺序对单词排序char_count-统计字符数remove_whitespace-删除空白
内存工具
remember-将信息存储在内存中recall-检索存储的信息forget-从内存中删除信息list_memories-列出所有存储的内存clear_memory-清除所有记忆memory_stats-获取内存统计信息
实用工具
timestamp-生成时间戳uuid-生成UUIDbase64_encode-Base64编码base64_decode-Base64解码url_encode-URL编码url_decode-URL解码hash_md5-MD5哈希hash_sha256-SHA256哈希json_format-格式化JSONjson_minify-缩小JSONrandom_number-生成随机数random_string-生成随机字符串
HTTP API
在HTTP模式下运行时,服务器会公开以下端点:
GET /schema-列出可用工具及其模式GET /health-健康检查端点POST /tool-直接工具调用端点(JSON)POST /chat-具有自动工具选择功能的自然语言聊天(JSON)POST /mcp-带有服务器发送事件(SSE)的MCP协议端点POST /react-用于推理和行动的ReAct代理端点
直接工具调用
# Call a specific tool directly
curl -X POST http://localhost:8080/tool \
-H "Content-Type: application/json" \
-d '{"name": "uppercase", "params": {"text": "hello world"}}'
自然语言聊天工具选择
这 /chat 端点允许LLM(如Ollama)根据自然语言输入自动选择和调用工具:
# Let the LLM decide which tools to use
curl -X POST http://localhost:8080/chat \
-H "Content-Type: application/json" \
-d '{"message": "convert hello world to uppercase"}'
# The LLM will automatically:
# 1. Analyze the request
# 2. Select the appropriate tool (uppercase)
# 3. Execute the tool with correct parameters
# 4. Return a natural language response
架构发现
# Get available tools
curl http://localhost:8080/schema
# Health check
curl http://localhost:8080/health
LLM集成和工具调用
导管包括内置的LLM集成支持和自动工具选择。LLM可以分析自然语言请求并自动选择合适的工具。
Olama集成
Conduit为本地LLM工具调用提供了与Ollama的无缝集成:
package main
import (
"log"
"os"
conduit "github.com/benozo/conduit/lib"
"github.com/benozo/conduit/lib/tools"
"github.com/benozo/conduit/mcp"
)
func main() {
config := conduit.DefaultConfig()
config.Mode = mcp.ModeHTTP
config.Port = 9090
// Configure Ollama integration
config.OllamaURL = "http://localhost:11434" // Your Ollama server
model := "llama3.2" // Or any Ollama model you have
server := conduit.NewEnhancedServer(config)
// Register all available tools
tools.RegisterTextTools(server.Server)
tools.RegisterMemoryTools(server.Server)
tools.RegisterUtilityTools(server.Server)
// Set up Ollama model with tool awareness
ollamaModel := conduit.CreateOllamaToolAwareModel(config.OllamaURL, server.GetTools())
server.SetModel(ollamaModel)
log.Printf("Starting Ollama-powered server on port %d", config.Port)
log.Fatal(server.Start())
}
工具调用流程
当您向发送请求时 /chat,事情是这样的:
- 用户请求:“将hello world转换为大写”
- LLM分析:Ollama分析请求和可用工具
- 工具选择:LLM选择
uppercase工具自动 - 工具执行:使用参数运行工具
{"text": "hello world"} - 结果集成:LLM接收工具结果并生成自然响应
- 最终响应:“大写的文本‘hello world’是:hello world”
示例用法
# Start your Ollama server
ollama serve
# Pull a model (if not already available)
ollama pull llama3.2
# Test natural language tool calling
curl -X POST http://localhost:9090/chat \
-H "Content-Type: application/json" \
-d '{"message": "generate a UUID for me"}'
curl -X POST http://localhost:9090/chat \
-H "Content-Type: application/json" \
-d '{"message": "encode the text Mountain123 in base64"}'
curl -X POST http://localhost:9090/chat \
-H "Content-Type: application/json" \
-d '{"message": "remember that my favorite color is blue"}'
LLM工具调用的好处
- ✅ 自然语言:通过对话请求使用工具
- ✅ 自动选择:LLM为每项任务选择合适的工具
- ✅ 上下文感知:LLM了解工具关系,可以连锁操作
- ✅ 错误处理:LLM可以重试或解释工具故障
- ✅ 丰富的响应:使用工具结果获取自然语言解释
💡 现场演示
| 示例 | 类型 | 描述 | 试试 |
|---|---|---|---|
| OpenAI集成 | 生产API | 全面的OpenAI与综合工具的集成 | examples/openai |
| 当地Ollama | 本地LLM | 以隐私为重点的本地AI,具有工具调用功能 | examples/ollama |
| Agent Swarm | 多代理 | 智能代理协调和切换 | examples/agent_swarm_simple |
| 纯图书馆 | Go Integration | 在应用程序中嵌入MCP组件 | examples/pure_library |
快速演示命令
# 🤖 OpenAI-powered tool server (production-ready)
cd examples/openai && OPENAI_API_KEY=sk-your-key go run main.go
# 🏠 Local Ollama integration (privacy-focused)
cd examples/ollama && go run main.go
# 🐝 Multi-agent coordination (autonomous)
cd examples/agent_swarm_simple && go run main.go
# 📚 Library-only usage (embeddable)
cd examples/pure_library && go run main.go
查看完整示例列表 → examples/README.md
例子
这 examples/ 目录包含不同使用模式的完整演示:
核心示例
pure_library/-在应用程序中使用Conduit作为Go库pure_library_cli/-使用Conduit构建的命令行工具pure_library_web/-带有嵌入式Conduit的Web服务器embedded/-在现有应用中嵌入导管custom_tools/-使用增强的模式注册自定义工具
协议示例
stdio_example/-用于VS Code Copilot、Cline等的MCP stdio服务器。sse_example/-web应用程序的HTTP服务器发送事件pure_mcp/-纯MCP实现
LLM集成示例
ollama/-通过工具调用完成Ollama集成model_integration/-自定义模型集成模式react/-用推理和行动重新扮演代理人
Agent和Swarm示例
ai_agents/-具有任务管理的AI代理框架agents_test/-基本代理功能测试agents_ollama/-与Ollama LLM集成的代理商agents_deepinfra/-与DeepInfra LLM集成的代理agents_library_mode/-库模式代理使用情况agents_mock_llm/-用于测试试剂的模拟LLMagents_vue_builder/-Vue.js应用程序构建器代理agent_swarm/-基本代理群协调(基于规则)agent_swarm_llm/-具有Ollama智能的LLM智能代理群agent_swarm_simple/-简单代理群演示agent_swarm_workflows/-高级工作流模式(DAG、Supervisor、Pipeline、Conditional等)
运行示例
# Try the Ollama integration example
cd examples/ollama
go run main.go
# Test with curl
curl -X POST http://localhost:9090/chat \
-H "Content-Type: application/json" \
-d '{"message": "convert hello world to uppercase"}'
# Try the stdio example for MCP clients
cd examples/stdio_example
go run main.go --stdio
# Test the pure library example
cd examples/pure_library
go run main.go
# Try AI Agents framework
cd examples/ai_agents
go run main.go
# Try basic Agent Swarm (rule-based)
cd examples/agent_swarm
go run main.go
# Try LLM-powered Agent Swarm with Ollama
cd examples/agent_swarm_llm
go run main.go
# Try advanced workflow patterns
cd examples/agent_swarm_workflows
go run main.go
# Try Agents with Ollama
cd examples/agents_ollama
go run main.go
每个示例都包含一个README,其中包含具体的说明和用例。
服务器模式
- 调制解调器:运行stdio MCP服务器以实现通用MCP客户端集成
- HTTP模式:为web应用程序和自定义集成运行HTTP/SSE服务器
- ModeBoth:同时运行两个协议以实现最大兼容性
配置选项
type Config struct {
Port: 8080, // HTTP server port (default: 8080)
OllamaURL: "http://localhost:11434", // Ollama API URL
Mode: mcp.ServerMode // Server mode
Environment map[string]string // Environment variables
EnableCORS bool // Enable CORS
EnableHTTPS bool // Enable HTTPS
CertFile string // HTTPS certificate file
KeyFile string // HTTPS key file
EnableLogging bool // Enable logging
}
例子
检查 examples/ 更多使用示例的目录:
stdio_example/- MCP stdio服务器 用于客户端集成(VS Code、Cline等)sse_example/- HTTP/SSE服务器 用于web应用程序和实时集成embedded/-服务器包装器的基本嵌入式用法custom_tools/- 增强工具注册 具有丰富的模式和验证model_integration/-自定义模型集成模式pure_library/-无需任何服务器的纯库使用pure_library_cli/-使用MCP组件的CLI工具pure_library_web/-使用MCP组件的自定义web服务器pure_mcp/-直接MCP使用示例ollama/-Ollama与当地LLM支持的整合direct_ollama/-无需服务器即可直接使用Olama模型
react/-ReAct代理(推理+代理)模式direct_mcp/-原始MCP包ReAct使用
ai_agents/- AI代理框架 具有自主任务执行功能agents_test/-基本代理功能和测试agents_ollama/- Ollama的经纪人 LLM集成agents_deepinfra/- DeepInfra代理 LLM集成agents_library_mode/-库模式代理使用模式agents_mock_llm/-用于代理测试和开发的模拟LLMagents_vue_builder/- Vue.js应用程序构建器 代理agent_swarm/- 基本代理群 协调和交接(基于规则)agent_swarm_llm/- LLM驱动的代理群 Ollama情报agent_swarm_simple/- 简单代理群 演示agent_swarm_workflows/- 高级工作流模式 (DAG、主管、管道、条件等)
快速入门示例
1.MCP标准服务器(用于VS Code、Cline等):
cd examples/stdio_example && go run main.go
# Stdio MCP server for client integration
2.HTTP/SSE服务器(用于web应用程序):
cd examples/sse_example && go run main.go
# HTTP server at http://localhost:8090 with SSE support
# Visit http://localhost:8090/demo for interactive demo
3.Olama整合:
cd examples/ollama && go run main.go
# Server at http://localhost:8084 with Ollama backend
4.重新代理:
cd examples/react && go run main.go
# ReAct pattern server at http://localhost:8085
5.直接使用MCP:
cd examples/react/direct_mcp && go run main.go
# Pure MCP package demo (no server)
6.人工智能代理框架:
cd examples/ai_agents && go run main.go
# AI Agents with autonomous task execution
7.Agent Swarm基础:
cd examples/agent_swarm && go run main.go
# Multi-agent coordination and handoffs
8.高级工作流模式:
cd examples/agent_swarm_workflows && go run main.go
# DAG, Supervisor, Pipeline, and Conditional workflows
9.Ollama的代理人:
cd examples/agents_ollama && go run main.go
# AI Agents powered by Ollama LLM
建筑
# Install as library (recommended)
go get github.com/benozo/conduit
# Build your own MCP server
go build -o my-mcp-server .
# Run tests (if developing Conduit itself)
go test ./...
MCP客户端集成
使用Conduit构建自己的MCP服务器后(通过 go get github.com/benozo/conduit),配置任何兼容MCP的客户端:
VS代码副本
{
"mcp.mcpServers": {
"my-conduit-server": {
"command": "/path/to/my-mcp-server",
"args": ["--stdio"],
"env": {}
}
}
}
克莱恩
{
"mcpServers": {
"my-conduit-server": {
"autoApprove": [],
"disabled": false,
"timeout": 60,
"type": "stdio",
"command": "/path/to/my-mcp-server",
"args": ["--stdio"]
}
}
}
克劳德桌面
{
"mcpServers": {
"my-conduit-server": {
"command": "/path/to/my-mcp-server",
"args": ["--stdio"]
}
}
}
其他MCP客户端
对于任何其他MCP客户端,请使用标准MCP stdio配置:
- 命令:
/path/to/my-mcp-server - 参数:
["--stdio"] - 协议标准: stdio
注: 替换 /path/to/my-mcp-server 使用构建二进制文件的实际路径。
验证集成
要测试所有工具是否可用于任何MCP客户端:
# Test your built MCP server
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | \
./my-mcp-server --stdio | jq '.result.tools | length'
应显示31个可用工具。
测试专用工具
要验证编码/格式化工具是否正常工作:
# Test base64_decode
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "base64_decode", "arguments": {"text": "SGVsbG8gV29ybGQ="}}}' | ./my-mcp-server --stdio
# Test url_decode
echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "url_decode", "arguments": {"text": "Hello%20World%21"}}}' | ./my-mcp-server --stdio
# Test json_format
echo '{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "json_format", "arguments": {"text": "{\"name\":\"test\",\"value\":123}"}}}' | ./my-mcp-server --stdio
# Test json_minify
echo '{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "json_minify", "arguments": {"text": "{\n \"name\": \"test\",\n \"value\": 123\n}"}}}' | ./my-mcp-server --stdio
所有工具都应该返回正确的JSON-RPC响应和结果。
故障排除
错误:“没有必需的模块提供包”
- 确保你已经跑过了
go get github.com/benozo/conduit - 确保您的
go.mod文件包括导管依赖关系 - 跑
go mod tidy解决依赖关系
错误:“连接已关闭”
- 验证您的二进制构建是否正确:
go build -o my-mcp-server . - 手动测试二进制文件:
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | ./my-mcp-server --stdio
MCP客户端未检测到工具
- 验证客户端是否支持MCP stdio协议
- 检查客户端配置指向正确的二进制路径
- 手动测试stdio接口(请参阅上面的验证步骤)
- 确保适当的超时设置(某些客户端可能需要30-60秒)
许可证
MIT许可证-有关详细信息,请参阅许可证文件。
