feat(cli): mcp serve curated stdio MCP server

`weknora mcp serve` — long-lived stdio MCP (Model Context Protocol)
transport that exposes a fixed, curated tool surface to MCP-aware
agents (Claude Desktop, Claude Code, custom MCP clients).

Curated tool set (readonly by default):
- whoami — active context + tenant
- search (hybrid retrieval against a KB)
- kb list / view
- doc list / view
- agent list / view / invoke
- session list / view

The list is intentionally narrow to the read + agent-invoke surface;
destructive verbs (`delete` / `empty` / `upload`) are gated behind
`--write`. Schema is built from each leaf cobra command's flags so
adding a new tool is a single registry entry plus a Service interface.

Includes the simplify post-review polish + a second simplify pass to
fold the resulting feedback (typed schemas, agent_help wording, unify
chat / agent invoke option names).
This commit is contained in:
nullkey
2026-05-14 23:28:14 +08:00
committed by lyingbug
parent 493fc41e98
commit 9bb83b47fd
14 changed files with 1213 additions and 154 deletions
+5 -5
View File
@@ -150,7 +150,7 @@ func (c *createSessionTracker) CreateSession(ctx context.Context, req *sdk.Creat
return c.InvokeService.CreateSession(ctx, req)
}
func TestInvoke_ToolCallsCaptured(t *testing.T) {
func TestInvoke_ToolEventsCaptured(t *testing.T) {
out, _ := iostreams.SetForTest(t)
svc := &scriptedInvokeSvc{events: []*sdk.AgentStreamResponse{
toolCallEvent("call_1", "knowledge_search"),
@@ -167,11 +167,11 @@ func TestInvoke_ToolCallsCaptured(t *testing.T) {
if err := json.Unmarshal(out.Bytes(), &env); err != nil {
t.Fatalf("parse: %v", err)
}
if len(env.Data.ToolCalls) != 1 {
t.Fatalf("expected 1 tool call, got %d", len(env.Data.ToolCalls))
if len(env.Data.ToolEvents) != 1 {
t.Fatalf("expected 1 tool call, got %d", len(env.Data.ToolEvents))
}
if env.Data.ToolCalls[0].ID != "call_1" {
t.Errorf("tool_calls[0].id = %q, want call_1", env.Data.ToolCalls[0].ID)
if env.Data.ToolEvents[0].ID != "call_1" {
t.Errorf("tool_calls[0].id = %q, want call_1", env.Data.ToolEvents[0].ID)
}
}