Wire hexis.resolve_target to real Nexus, fix changes cursor, pass full execute fields over MCP

resolve_target previously returned a hardcoded "requires_nexus_resolution"
placeholder; it now calls Nexus's /api/v1/resolve via a new minimal
internal/nexusclient, configurable with -nexus (default localhost:8987).

/api/v1/changes ignored the since query param and always returned from
sequence 0 (`since = 0` regardless of what was parsed) — fixed to actually
parse and use it, so change-cursor polling works.

The MCP hexis.execute tool only forwarded capability_id/target_entity_id/
arguments/idempotency_key, silently dropping entity_version, requested_by,
origin, correlation_id, causation_id, resolution_evidence, and
confirmation_id even though the native HTTP API and domain.ExecuteRequest
already supported all of them — MCP callers now get full parity.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ghELqYhZNLub2TXGMazqA
This commit is contained in:
kami
2026-07-20 11:28:13 +04:00
parent ed593efb71
commit 74b19e091e
5 changed files with 262 additions and 13 deletions
+85 -11
View File
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"
"strings"
"github.com/mark3labs/mcp-go/mcp"
@@ -11,6 +12,7 @@ import (
"github.com/kami/hexis/internal/domain"
"github.com/kami/hexis/internal/execution"
"github.com/kami/hexis/internal/nexusclient"
"github.com/kami/hexis/internal/storage"
)
@@ -18,12 +20,14 @@ type Adapter struct {
server *server.MCPServer
store storage.Interface
engine *execution.Engine
nexus nexusclient.Client
}
func New(store storage.Interface, engine *execution.Engine) *Adapter {
func New(store storage.Interface, engine *execution.Engine, nexus nexusclient.Client) *Adapter {
a := &Adapter{
store: store,
engine: engine,
nexus: nexus,
}
mcpServer := server.NewMCPServer(
@@ -75,6 +79,27 @@ func New(store storage.Interface, engine *execution.Engine) *Adapter {
mcp.WithString("idempotency_key",
mcp.Description("Idempotency key for safe retry"),
),
mcp.WithString("entity_version",
mcp.Description("Expected Nexus entity version, for optimistic concurrency"),
),
mcp.WithString("requested_by",
mcp.Description("JSON string describing the requester (e.g. {\"type\":\"user\",\"id\":\"...\"})"),
),
mcp.WithString("origin",
mcp.Description("JSON string describing the request origin (e.g. {\"system\":\"maven\",\"channel\":\"voice\"})"),
),
mcp.WithString("correlation_id",
mcp.Description("Correlation ID for cross-system tracing"),
),
mcp.WithString("causation_id",
mcp.Description("Causation ID of the event/request that triggered this execute"),
),
mcp.WithString("resolution_evidence",
mcp.Description("JSON array of evidence objects backing target_entity_id's resolution"),
),
mcp.WithString("confirmation_id",
mcp.Description("Confirmation ID for capabilities that require confirmation"),
),
), a.handleExecute)
mcpServer.AddTool(mcp.NewTool("hexis.execution_status",
@@ -167,13 +192,25 @@ func (a *Adapter) handleResolveTarget(ctx context.Context, req mcp.CallToolReque
if query == "" {
return mcp.NewToolResultError("query is required"), nil
}
if a.nexus == nil {
return mcp.NewToolResultError("resolve_target unavailable: no Nexus URL configured"), nil
}
// In a real setup, this would call Nexus API.
// For now, return a placeholder indicating Nexus resolution is needed.
result := map[string]any{
"query": query,
"status": "requires_nexus_resolution",
"message": "Connect to Nexus to resolve this query to a canonical entity ID",
var types []string
if capName := req.GetString("capability", ""); capName != "" {
if caps, err := a.store.ListCapabilities(""); err == nil {
for _, c := range caps {
if c.Name == capName {
types = c.TargetTypes
break
}
}
}
}
result, err := a.nexus.Resolve(ctx, query, types)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("nexus resolve: %v", err)), nil
}
data, _ := json.MarshalIndent(result, "", " ")
@@ -199,11 +236,48 @@ func (a *Adapter) handleExecute(ctx context.Context, req mcp.CallToolRequest) (*
json.Unmarshal([]byte(argsStr), &args)
}
var entityVersion int64
if v := req.GetString("entity_version", ""); v != "" {
parsed, err := strconv.ParseInt(v, 10, 64)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("entity_version must be an integer: %v", err)), nil
}
entityVersion = parsed
}
var requestedBy map[string]string
if v := req.GetString("requested_by", ""); v != "" {
if err := json.Unmarshal([]byte(v), &requestedBy); err != nil {
return mcp.NewToolResultError(fmt.Sprintf("requested_by must be a JSON object: %v", err)), nil
}
}
var origin map[string]string
if v := req.GetString("origin", ""); v != "" {
if err := json.Unmarshal([]byte(v), &origin); err != nil {
return mcp.NewToolResultError(fmt.Sprintf("origin must be a JSON object: %v", err)), nil
}
}
var resolutionEvidence []map[string]any
if v := req.GetString("resolution_evidence", ""); v != "" {
if err := json.Unmarshal([]byte(v), &resolutionEvidence); err != nil {
return mcp.NewToolResultError(fmt.Sprintf("resolution_evidence must be a JSON array: %v", err)), nil
}
}
execReq := &domain.ExecuteRequest{
CapabilityID: capID,
TargetEntityID: targetID,
Arguments: args,
IdempotencyKey: idempKey,
CapabilityID: capID,
TargetEntityID: targetID,
EntityVersion: entityVersion,
Arguments: args,
RequestedBy: requestedBy,
Origin: origin,
IdempotencyKey: idempKey,
CorrelationID: req.GetString("correlation_id", ""),
CausationID: req.GetString("causation_id", ""),
ResolutionEvidence: resolutionEvidence,
ConfirmationID: req.GetString("confirmation_id", ""),
}
result, err := a.engine.Execute(execReq)