Files
goclaw/internal/mcp/crud_test_helpers_test.go
293aa2a5e1 (feat) MCP Server (#1365)
* feat(hooks/observe): add structured output validation hook (ObserveHook)

- hooks/types.go: Add ObserveHook interface + BuiltInHookType enum
- hooks/dispatcher.go: HookDispatcher emits ObserveHook with PhaseResult payload
- pipeline/observe_stage.go: ObserveStage emits hook after ObserveResult built
- pipeline/substates.go: ObserveStageResult carries hook results + validation errors
- hooks/config.go: BuiltInHookTypeObserve added to BuiltInHookType enum

PhaseResult carries structured output, token usage, tool calls + validation errors
emitted post-ObserveStage. ObserveHook implementations can validate structured
output against schemas, detect tool-call loops, enforce token budgets, etc.

Hook fires after ObserveStage produces ObserveResult, before results propagate
to next stage. ValidationError returned by hook halts pipeline and propagates
error to caller without further stage execution.

Co-Authored-By: Claude <noreply@anthropic.com>

* ui(hooks): add post_model_response event to web UI

- Add event to Zod schema, filter dropdown, and form dialog
- Implement conditional test panel UI for model response payload
- Add translations (en/zh/vi) for new test panel fields
- Updated beta description to reference the new event

Co-Authored-By: Claude <noreply@anthropic.com>

* feat(mcp): add MCP CRUD server exposing goclaw resources at /api/mcp/ with Bearer token auth
and X-GoClaw-Tenant-Id header, default to master tenant

* feat(mcp): add goclaw_skills_write_file tool to edit skill files on disk

The CRUD MCP server's goclaw_skills_update only touched skill DB metadata,
with no way to edit a skill's SKILL.md/file content on the filesystem. Extract
the versioned write logic from the web UI's skill file editor
(SkillsHandler.handleWriteFile) into skills.WriteVersionedFile so both
surfaces share identical validation and versioning, and expose it as a new
MCP tool.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

---------

Co-authored-by: Bruno Clermont <bruno.clermont@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-07-15 09:56:43 +07:00

53 lines
1.8 KiB
Go

package mcp
// crud_test_helpers_test.go provides small shared helpers for invoking
// registered MCP tool handlers directly in tests, without going through the
// HTTP/streamable transport. mcp-go's *mcpserver.MCPServer exposes GetTool()
// which returns the registered ServerTool{Tool, Handler} — calling Handler
// directly is the most faithful way to exercise the exact registration code
// path (tool names, required-arg validation via req.RequireString, etc.)
// without needing a real network listener.
import (
"context"
"testing"
mcpgo "github.com/mark3labs/mcp-go/mcp"
mcpserver "github.com/mark3labs/mcp-go/server"
)
// newTestMCPServer builds a bare MCPServer suitable for registering CRUD tool
// families in tests.
func newTestMCPServer() *mcpserver.MCPServer {
return mcpserver.NewMCPServer("goclaw-crud-test", "test", mcpserver.WithToolCapabilities(false))
}
// callTool looks up a registered tool by name and invokes its handler with
// the given arguments, failing the test immediately if the tool isn't
// registered.
func callTool(t *testing.T, srv *mcpserver.MCPServer, name string, args map[string]any) *mcpgo.CallToolResult {
t.Helper()
tool := srv.GetTool(name)
if tool == nil {
t.Fatalf("tool %q not registered", name)
}
req := mcpgo.CallToolRequest{}
req.Params.Name = name
req.Params.Arguments = args
result, err := tool.Handler(context.Background(), req)
if err != nil {
t.Fatalf("tool %q handler returned transport error: %v", name, err)
}
return result
}
// toolResultText extracts the concatenated text content of a tool result.
func toolResultText(result *mcpgo.CallToolResult) string {
return extractTextContent(result)
}
// toolIsError reports whether result represents an MCP tool-level error.
func toolIsError(result *mcpgo.CallToolResult) bool {
return result != nil && result.IsError
}