npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@memberjunction/ai-agent-client

v5.37.0

Published

MemberJunction: Framework-agnostic Agent Client SDK - transport, tool registry, session management

Readme

@memberjunction/ai-agent-client

Framework-agnostic SDK for connecting client applications to MemberJunction AI agents. Provides session management, client-side tool registration, and agent execution -- all over GraphQL transport via GraphQLDataProvider.

Architecture

+----------------------------------+
|  Your Application (Angular, etc) |
+----------------------------------+
          |
          v
+----------------------------------+
|   AgentClientSession             |  <-- This package
|   - Session lifecycle            |
|   - Tool registration & dispatch |
|   - RxJS observables             |
+----------------------------------+
          |
          v
+----------------------------------+
|   GraphQLDataProvider            |  <-- @memberjunction/graphql-dataprovider
|   - ClientToolRequests (sub)     |
|   - ExecuteGQL (mutation)        |
|   - GraphQLAIClient (agent runs) |
+----------------------------------+
          |
          v
+----------------------------------+
|   MJAPI GraphQL Server           |
+----------------------------------+

No WebSocket layer. All communication flows through Metadata.Provider (a GraphQLDataProvider instance), which handles GraphQL subscriptions, mutations, and queries internally. The SDK has zero framework dependencies -- Angular, React, or plain TypeScript all work the same way.

Key Classes

AgentClientSession

The main entry point. Manages a bidirectional session with an MJ agent:

  • StartSession(sessionId) -- Subscribes to ClientToolRequests via the data provider. Incoming tool requests are dispatched to registered handlers automatically.
  • StopSession() -- Unsubscribes and cleans up.
  • RunAgent(params) -- Executes an agent via GraphQLAIClient.RunAIAgentFromConversationDetail().
  • RunAgentFromConversationDetail(params) -- Optimized path that loads conversation history server-side.
  • RegisterTool(tool) / UnregisterTool(name) -- Register client-side tool handlers that agents can invoke.
  • Dispose() -- Completes all observables and releases resources.

RxJS Observables

| Observable | Emits | |---|---| | ToolRequested$ | When a tool request arrives from the server (before execution) | | ToolExecuted$ | After a tool handler finishes (with result) | | Error$ | On communication or execution errors | | SessionActive$ | true on start, false on stop | | AgentProgress$ | Progress updates during agent execution |

ClientToolRegistry

Manages registered tool definitions and handles execution with timeout protection.

  • Register(tool) -- Add a tool (throws on duplicate name).
  • Unregister(name) -- Remove a tool.
  • Execute(name, params, timeoutMs?) -- Run a tool handler with configurable timeout (default 30s).
  • GetTool(name) / GetAllTools() -- Lookup tools.

Tool Decoration

For metadata-driven tools that need runtime context enrichment:

  • RegisterToolDecorator(toolName, decorator) -- Register a function that enriches a tool's metadata.
  • SetDecoratorContext(context) -- Update the runtime context (available entities, current app, etc.).
  • DecorateAndSendTools(baseTools) -- Apply decorators and send enriched definitions to the server.

Usage

import { AgentClientSession } from '@memberjunction/ai-agent-client';

// 1. Create a session
const session = new AgentClientSession();

// 2. Register client-side tools
session.RegisterTool({
    Name: 'NavigateToRecord',
    Description: 'Open an entity record in the UI',
    ParameterSchema: {
        type: 'object',
        properties: {
            EntityName: { type: 'string' },
            RecordID: { type: 'string' },
        },
        required: ['EntityName', 'RecordID'],
    },
    Handler: async (params) => {
        // Your app-specific navigation logic
        router.navigate(['/entity', params['EntityName'], params['RecordID']]);
        return { Success: true, Data: 'navigated' };
    },
});

// 3. Subscribe to events
session.ToolRequested$.subscribe(event =>
    console.log(`Tool requested: ${event.Request.ToolName}`)
);
session.ToolExecuted$.subscribe(event =>
    console.log(`Tool result: ${event.Result.Success}`)
);
session.Error$.subscribe(err =>
    console.error(`Session error: ${err.Message}`)
);

// 4. Start session (begins listening for tool requests)
session.StartSession('your-session-id');

// 5. Run an agent
const result = await session.RunAgent({
    AgentId: 'agent-uuid',
    Messages: [{ role: 'user', content: 'Show me active members' }],
});

// 6. Or run from an existing conversation detail
const result2 = await session.RunAgentFromConversationDetail({
    ConversationDetailId: 'detail-uuid',
    AgentId: 'agent-uuid',
    MaxHistoryMessages: 20,
});

// 7. Clean up when done
session.Dispose();

Client Tools Guide

For detailed documentation on the client tools protocol -- how tools are defined on the server, dispatched to clients, and how results flow back -- see:

packages/AI/Agents/docs/CLIENT_TOOLS_GUIDE.md

Angular Integration

For Angular applications, use @memberjunction/ng-agent-client which provides an injectable Angular service wrapping this SDK. See packages/Angular/Generic/agent-client/README.md.