Skip to content

Build @nodespace/agent-tools TypeScript gRPC client package #1122

Closed

Description

@malibio

Overview

Create @nodespace/agent-tools, a TypeScript npm package that exposes NodeSpace knowledge graph operations as callable functions backed by a gRPC client to nodespaced. This is the shared foundation that all per-agent extension shims (next issue) depend on. There is no MCP server — all tool access goes through gRPC directly.

Problem Statement

PTY-spawned agents (Claude Code, Codex, Gemini CLI, Pi, OpenCode) need a way to read and write the NodeSpace knowledge graph during a session. Each agent has its own native extension API, but they all need the same underlying operations. A single shared package avoids duplicating the gRPC client and tool logic in every per-agent shim.

Proposed Solution

A pure TypeScript npm package using @grpc/grpc-js (no native bindings) that connects to nodespaced on localhost:50051. It exports five functions matching the most agent-relevant NodeService operations. Per-agent shims import this package and register the functions as native tools using each agent's extension API.

Acceptance Criteria

  • packages/agent-tools/ npm package created and added to the Bun workspace
  • @grpc/grpc-js client connects to nodespaced on localhost:50051
  • searchSemantic(query: string, limit?: number) calls SearchNodes in semantic mode and returns results
  • getNode(nodeId: string) calls GetNode and returns the node with content
  • createNode(type: string, content: string, parentId?: string) calls CreateNode and returns the new node
  • updateNode(nodeId: string, content: string) calls UpdateNode and returns the updated node
  • getChildren(nodeId: string) calls GetChildren and returns the child node list
  • Connection error (nodespaced not running) returns a structured error object, not an uncaught exception
  • Package builds cleanly (bun run build in the package directory)
  • Unit tests cover: each tool function, connection error handling
  • All workspace tests pass (bun run test:all from repo root)
  • Code passes bun run quality:fix

Technical Specifications

Package location and structure

packages/agent-tools/
├── package.json
├── tsconfig.json
├── src/
│   ├── client.ts      # gRPC channel init, NodeServiceClient
│   ├── tools.ts       # searchSemantic, getNode, createNode, updateNode, getChildren
│   ├── types.ts       # NodeResult, SearchResult, ToolError
│   └── index.ts       # re-exports
└── src/tests/
    └── tools.test.ts

package.json

{
  "name": "@nodespace/agent-tools",
  "version": "0.1.0",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "dependencies": {
    "@grpc/grpc-js": "^1.10",
    "@grpc/proto-loader": "^0.7"
  }
}

Proto loading

Load the node_service.proto at runtime using @grpc/proto-loader pointing to packages/daemon/proto/node_service.proto (resolved relative to the package). This avoids duplicating the proto file.

// client.ts
import * as protoLoader from '@grpc/proto-loader';
import * as grpc from '@grpc/grpc-js';

const PROTO_PATH = path.resolve(__dirname, '../../daemon/proto/node_service.proto');

Tool function signatures

export interface NodeResult {
  id: string;
  nodeType: string;
  content: string;
  parentId?: string;
}

export interface SearchResult {
  nodes: NodeResult[];
  query: string;
}

export async function searchSemantic(query: string, limit?: number): Promise<SearchResult>
export async function getNode(nodeId: string): Promise<NodeResult>
export async function createNode(type: string, content: string, parentId?: string): Promise<NodeResult>
export async function updateNode(nodeId: string, content: string): Promise<NodeResult>
export async function getChildren(nodeId: string): Promise<NodeResult[]>

Error handling

All functions catch gRPC errors and rethrow as a typed ToolError:

export class ToolError extends Error {
  constructor(public code: string, message: string) { super(message); }
}
// e.g. new ToolError('UNAVAILABLE', 'nodespaced is not running on localhost:50051')

Connection singleton

The gRPC channel is created once (lazy singleton) and reused across calls. Connection is not established until the first call.

Reference files

Dependencies

Non-Goals

  • Per-agent shims that register these functions as native tools (next issue)
  • AgentSessionService operations in this package (session management is done by the desktop UI / CLI, not by agents calling tools)
  • Authentication or API keys (gRPC is local-only, no auth needed)

Activity

  1. malibio commented on May 18, 2026

    @malibio
    CollaboratorAuthor

    Test baseline before starting work: 128 test files, 3918 tests passed (frontend).

  2. self-assigned this
    on May 18, 2026
  3. added a commit that references this issue on Jun 22, 2026
    f352720
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions