feat: 打通 Dispatcher→MCP 工具调用链路 (core NATS request-reply)
第 4 层 Dispatcher 经 NATS request-reply + 队列组同步调用第 5 层 MCP 工具, 工具不可用/超时即降级,不阻断主流程。 - shared/contract: ToolCall/ToolResult + sundynix.tools.go.* subject 约定 + ToolSubjectGo/Py - shared/bus: CallTool(发起) / ServeTool(队列组订阅+应答) - mcp-go: 接共享 bus,gateway 通配订阅按工具名分发(wiki_search/echo),main 优雅退出 - dispatcher: ToolCaller 接口 + Orchestrator.retrieveContext(调 wiki_search,超时3s降级) - e2e: TestToolCallRoundTrip(PASS);demo.sh 加 mcp-go(就绪门避免启动竞态),live 跑通 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -93,6 +93,53 @@ func TestTaskRoundTrip(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestToolCallRoundTrip 模拟 Dispatcher 经 NATS 调用 → mcp-go 响应 的工具调用闭环。
|
||||
func TestToolCallRoundTrip(t *testing.T) {
|
||||
url := startEmbeddedNATS(t)
|
||||
|
||||
// --- mcp-go 侧:以队列组订阅工具主题并响应 ---
|
||||
srv, err := bus.Connect(url)
|
||||
if err != nil {
|
||||
t.Fatalf("mcp connect: %v", err)
|
||||
}
|
||||
defer srv.Close()
|
||||
|
||||
unsub, err := srv.ServeTool(contract.SubjectToolsGoAll, contract.QueueToolsGo,
|
||||
func(_ context.Context, call *contract.ToolCall) *contract.ToolResult {
|
||||
if call.Tool != "wiki_search" {
|
||||
return &contract.ToolResult{OK: false, Error: "unknown tool"}
|
||||
}
|
||||
return &contract.ToolResult{OK: true, Content: "命中:" + call.Args["q"].(string)}
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("serve tool: %v", err)
|
||||
}
|
||||
defer func() { _ = unsub() }()
|
||||
|
||||
// --- Dispatcher 侧:同步调用工具 ---
|
||||
dp, err := bus.Connect(url)
|
||||
if err != nil {
|
||||
t.Fatalf("dispatcher connect: %v", err)
|
||||
}
|
||||
defer dp.Close()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
res, err := dp.CallTool(ctx, contract.ToolSubjectGo("wiki_search"), &contract.ToolCall{
|
||||
Tool: "wiki_search",
|
||||
TaskID: "task_tool_001",
|
||||
Args: map[string]any{"q": "向量检索"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("call tool: %v", err)
|
||||
}
|
||||
if !res.OK || res.Content != "命中:向量检索" {
|
||||
t.Fatalf("tool result = %+v, want ok content=命中:向量检索", res)
|
||||
}
|
||||
t.Logf("✓ 工具调用闭环:Dispatcher → sundynix.tools.go.wiki_search → mcp-go → %q", res.Content)
|
||||
}
|
||||
|
||||
// TestTokenStreamRoundTrip 模拟 Dispatcher 回流 Token → Gateway 订阅 的流式闭环。
|
||||
func TestTokenStreamRoundTrip(t *testing.T) {
|
||||
url := startEmbeddedNATS(t)
|
||||
|
||||
Reference in New Issue
Block a user