ollie-remote: fix empty output and wire generic tool dispatch

Shell results were returned as raw strings but the agent expects
structured content blocks ({content:[{type:text,text:...}]}). Fixed
shell handler to return the same format as the local Server.CallTool.

Shell errors now return as isError content blocks rather than RPC
errors, matching local behavior (output is preserved in errors).

The default RPC handler now dispatches to srv.CallTool() for any
unknown method, enabling named tools (file_read, file_grep, etc.)
from the embedded tools to be called remotely.
This commit is contained in:
Levi Neely 2026-07-31 11:32:46 +02:00
parent 0c75d06c59
commit eb7bacc243
1 changed files with 27 additions and 6 deletions

View File

@ -167,13 +167,18 @@ func serveRPC(ctx context.Context, srv *toolsrv.Server, in io.Reader, out io.Wri
enc.Encode(rpcResponse{ enc.Encode(rpcResponse{
JSONRPC: "2.0", JSONRPC: "2.0",
ID: req.ID, ID: req.ID,
Error: &rpcError{Code: -32000, Message: err.Error()}, Result: map[string]any{
"isError": true,
"content": []map[string]string{{"type": "text", "text": err.Error()}},
},
}) })
} else { } else {
enc.Encode(rpcResponse{ enc.Encode(rpcResponse{
JSONRPC: "2.0", JSONRPC: "2.0",
ID: req.ID, ID: req.ID,
Result: result, Result: map[string]any{
"content": []map[string]string{{"type": "text", "text": result}},
},
}) })
} }
@ -213,11 +218,27 @@ func serveRPC(ctx context.Context, srv *toolsrv.Server, in io.Reader, out io.Wri
}) })
default: default:
enc.Encode(rpcResponse{ // Dispatch to named tool via the tool server's CallTool.
JSONRPC: "2.0", streamCtx := toolsrv.WithOutputStream(ctx, func(data string) {
ID: req.ID, enc.Encode(rpcResponse{
Error: &rpcError{Code: -32601, Message: "method not found: " + req.Method}, JSONRPC: "2.0",
Result: outputNotif{Data: data},
})
}) })
result, err := srv.CallTool(streamCtx, req.Method, req.Params)
if err != nil {
enc.Encode(rpcResponse{
JSONRPC: "2.0",
ID: req.ID,
Error: &rpcError{Code: -32000, Message: err.Error()},
})
} else {
enc.Encode(rpcResponse{
JSONRPC: "2.0",
ID: req.ID,
Result: json.RawMessage(result),
})
}
} }
} }
} }