feat(kit): central tools for harnesses through the egress proxy and gateway task-tool RPCs
This commit is contained in:
41 files changed
+2187
-189
No files matched your search
@@ -0,0 +1,61 @@
|
||||
// Package tasktools adapts task-scoped central tools to the Gateway contract.
|
||||
package tasktools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/gateway/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
"github.com/samcharles93/archie-core/internal/domain/presence"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
|
||||
)
|
||||
|
||||
// Client never accepts an identity, org or permission list from the harness.
|
||||
type Client struct{ rpc pb.TaskToolsServiceClient }
|
||||
|
||||
func NewClient(conn grpc.ClientConnInterface) *Client {
|
||||
return &Client{rpc: pb.NewTaskToolsServiceClient(conn)}
|
||||
}
|
||||
|
||||
func (c *Client) List(ctx context.Context, credential string) ([]*mcp.Tool, error) {
|
||||
r, err := c.rpc.ListTaskTools(ctx, &pb.ListTaskToolsRequest{RunCredential: credential})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var tools []*mcp.Tool
|
||||
err = json.Unmarshal(r.ToolsJson, &tools)
|
||||
return tools, err
|
||||
}
|
||||
|
||||
func (c *Client) Call(ctx context.Context, credential, name string, args json.RawMessage) (*mcp.CallToolResult, error) {
|
||||
r, err := c.rpc.CallTaskTool(ctx, &pb.CallTaskToolRequest{RunCredential: credential, Name: name, ArgumentsJson: args})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result mcp.CallToolResult
|
||||
err = json.Unmarshal(r.ResultJson, &result)
|
||||
return &result, err
|
||||
}
|
||||
|
||||
func (c *Client) Close(ctx context.Context, credential string) error {
|
||||
_, err := c.rpc.CloseTaskTools(ctx, &pb.CloseTaskToolsRequest{RunCredential: credential})
|
||||
return err
|
||||
}
|
||||
|
||||
// Dial opens the Gateway's task-tools contract as the authenticated daemon.
|
||||
func Dial(target string, id *rpctls.Identity) (*Client, func(), error) {
|
||||
creds, err := id.DialOption(target, presence.Gateway)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
conn, err := grpc.NewClient(target, creds, grpc.WithUnaryInterceptor(staterpc.UnaryClientCredentialInterceptor(presence.Daemon, "")), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(messaging.MaxInboundAttachmentBytes+(1<<20))))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return NewClient(conn), func() { _ = conn.Close() }, nil
|
||||
}
|
||||
Reference in new issue
Block a user