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

mimory-mcp-focus-langchainjs

v0.1.1

Published

Focus-enforcing wrapper for LangChain MCP clients

Readme

mimory-mcp-focus-langchainjs

npm version License: MIT

A focus-enforcing wrapper for LangChain MCP (Model Context Protocol) clients that allows you to restrict which tools and parameters can be used by AI agents, providing enhanced security and control over MCP tool access.

Features

  • Tool Restriction: Limit which MCP tools are available to your AI agents
  • Parameter Validation: Restrict parameter values using simple patterns or ranges
  • Multi-Server Support: Manage focus configurations across multiple MCP servers
  • LangChain Integration: Seamless integration with LangChain's MCP adapters
  • TypeScript Support: Full TypeScript definitions for better development experience
  • Flexible Configuration: Support for both simple and composite focus patterns

Installation

npm install mimory-mcp-focus-langchainjs

Peer Dependencies

This package requires the following peer dependencies:

npm install @langchain/mcp-adapters @mimory/mim-mcp-focus-js

Quick Start

import { FocusMultiServerMCPClient } from 'mimory-mcp-focus-langchainjs';

// Define MCP server connections
const connections = {
  everything: {
    transport: "stdio",
    command: "npx",
    args: ["-y", "@modelcontextprotocol/server-everything"]
  }
};

// Configure focus restrictions
const focusConfigs = {
  everything: {
    focusTools: ["echo"], // Only allow echo tool
    focusParams: {
      message: ["hello", "world", "test"] // Restrict message values
    },
    focusType: "simple",
    strict: false
  }
};

// Create focus-enabled client
const client = new FocusMultiServerMCPClient(connections, focusConfigs);

// Get restricted tools
const tools = await client.getTools();
console.log("Available tools:", tools);

Focus Configuration Patterns

Simple Focus

Simple focus allows you to restrict tools and parameters across all tools:

const focusConfig = {
  focusTools: ["tool1", "tool2"],
  focusParams: {
    param1: ["value1", "value2"],
    param2: ["range:1-100"]
  },
  focusType: "simple",
  strict: false
};

Composite Focus

Composite focus allows different restrictions per tool:

const focusConfig = {
  focus: {
    tool1: {
      param1: ["value1", "value2"],
      param2: ["range:1-10"]
    },
    tool2: {
      param3: ["value3", "value4"]
    }
  },
  focusType: "composite",
  strict: true
};

API Reference

FocusMultiServerMCPClient

The main class that wraps LangChain's MultiServerMCPClient with focus functionality.

Constructor

constructor(
  connections?: Record<string, Connection>,
  focusConfigs?: Record<string, FocusConfig>
)

Methods

  • getTools(serverName?: string): Get tools from specified servers with focus applied
  • getClient(serverName: string): Get a focused MCP client for a specific server
  • close(): Close all connections and clean up
  • getServerFocusConfig(serverName: string): Get focus configuration for a server
  • setServerFocusConfig(serverName: string, focusConfig: FocusConfig): Set focus configuration for a server

Factory Functions

createFocusClientSimple

function createFocusClientSimple(
  connections: Record<string, Connection>,
  focusTools?: Record<string, FocusTools>,
  focusParams?: Record<string, FocusParams>,
  strict: boolean = false
): FocusMultiServerMCPClient

createFocusClientComposite

function createFocusClientComposite(
  connections: Record<string, Connection>,
  focus?: Record<string, FocusComposite>,
  strict: boolean = false
): FocusMultiServerMCPClient

Examples

Basic Tool Restriction

import { FocusMultiServerMCPClient } from 'mimory-mcp-focus-langchainjs';

const connections = {
  everything: {
    transport: "stdio",
    command: "npx",
    args: ["-y", "@modelcontextprotocol/server-everything"]
  }
};

const focusConfigs = {
  everything: {
    focusTools: ["echo"],
    focusParams: {
      message: ["hello", "world", "test"]
    },
    focusType: "simple",
    strict: false
  }
};

const client = new FocusMultiServerMCPClient(connections, focusConfigs);
const tools = await client.getTools();

// Use tools with LangChain agents
const tool = tools[0];
const result = await tool.invoke({ message: "hello" });

Multi-Server Setup

const connections = {
  everything: {
    transport: "stdio",
    command: "npx",
    args: ["-y", "@modelcontextprotocol/server-everything"]
  },
  time: {
    transport: "stdio",
    command: "python",
    args: ["-m", "mcp_server_time"]
  }
};

const focusConfigs = {
  everything: {
    focus: {
      echo: {
        message: ["hello", "world", "composite", "focus"]
      },
      add: {
        a: ["range:1-5"],
        b: ["range:1-5"]
      }
    },
    focusType: "composite",
    strict: false
  },
  time: {
    focusTools: ["get_current_time"],
    focusParams: {
      timezone: ["America/New_York", "Europe/London", "Asia/Tokyo"]
    },
    focusType: "simple",
    strict: false
  }
};

const client = new FocusMultiServerMCPClient(connections, focusConfigs);

Using with LangChain Agents

import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/core/agents";
import { FocusMultiServerMCPClient } from 'mimory-mcp-focus-langchainjs';

// Create focus-enabled client
const client = new FocusMultiServerMCPClient(connections, focusConfigs);
const tools = await client.getTools();

// Create LangChain agent with restricted tools
const model = new ChatOpenAI({ model: "gpt-4" });
const agent = await createReactAgent({
  llm: model,
  tools,
  messagesPlaceholder: "You are a helpful assistant with access to restricted tools."
});

// Use the agent
const result = await agent.invoke({
  input: "Echo the message 'hello'"
});

Supported MCP Servers

Everything MCP Server

A test server that implements various MCP features:

Setup:

npm install -g @modelcontextprotocol/server-everything@latest

Available Tools:

  • echo: Echo back input messages
  • add: Add two numbers together

Time MCP Server

Provides time and timezone conversion capabilities:

Setup:

pip install mcp-server-time

Available Tools:

  • get_current_time: Get current time in a specific timezone
  • convert_time: Convert time between timezones

Error Handling

The library provides comprehensive error handling for focus-related issues:

try {
  const result = await tool.invoke({ message: "forbidden" });
} catch (error) {
  if (error.name === 'FocusError') {
    console.log('Focus restriction violated:', error.message);
  } else {
    console.log('Other error:', error.message);
  }
}

Configuration Options

FocusConfig Interface

interface FocusConfig {
  focusTools?: FocusTools;           // Allowed tools
  focusParams?: FocusParams;         // Parameter restrictions
  focus?: FocusComposite;            // Composite focus configuration
  focusType?: 'simple' | 'composite'; // Focus type
  strict?: boolean;                  // Strict mode enforcement
}

Parameter Value Patterns

  • Exact values: ["value1", "value2"]
  • Ranges: ["range:1-100"] for numeric ranges
  • Wildcards: ["*"] to allow all values

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Related Projects

Support

For support, please open an issue on GitHub or contact us at [email protected].

Author

Travis McQueen - [email protected]


This library is part of the mimory ecosystem, providing secure and controlled access to MCP tools for AI applications.