Token导航 LogoToken导航TokenDH.com
Mimory MCP Focus Langchainjs logo
安全风控stdio官方级别未说明来源级核验

Mimory MCP Focus Langchainjs

MCP Server

一个用于LangChain MCP客户端的工具和参数限制包装器,提供对AI代理的工具访问增强安全和控制。

工具数

0

提示词数

0

GitHub Stars

0

资源数

0
安全TypeScript开发工具

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

MimoryInc

提供方

MimoryInc

最后核验

2026/5/17 20:20

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

pip install mcp-server-time

详细介绍

mimory mcp焦点langchainjs

](https://badge.fury.io/js/mimory-mcp-focus-langchainjs) ![License: MIT](https://opensource.org/licenses/MIT)

LangChain MCP(模型上下文协议)客户端的焦点强制包装器,允许您限制AI代理可以使用哪些工具和参数,从而增强对MCP工具访问的安全性和控制。

特性

  • 工具限制:限制您的AI代理可以使用哪些MCP工具
  • 参数验证:使用简单模式或范围限制参数值
  • 多服务器支持:跨多个MCP服务器管理焦点配置
  • LangChain集成:与LangChain的MCP适配器无缝集成
  • TypeScript支持:完整的TypeScript定义,以获得更好的开发体验
  • 灵活的配置:支持简单和复合聚焦模式

安装

npm install mimory-mcp-focus-langchainjs

对等依赖关系

此包需要以下对等依赖关系:

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

快速开始

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);

焦点配置模式

简单专注

简单的焦点允许您限制所有工具的工具和参数:

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

复合焦点

复合焦点允许每个工具有不同的限制:

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

api参考

FocusMultiServerMCPClient

将LangChain的MultiServerMCPClient与焦点功能封装在一起的主类。

构造函数

constructor(
  connections?: Record,
  focusConfigs?: Record
)

方法

  • getTools(serverName?: string):从应用了焦点的指定服务器获取工具
  • getClient(serverName: string):为特定服务器获取一个专注的MCP客户端
  • close():关闭所有连接并清理
  • getServerFocusConfig(serverName: string):获取服务器的焦点配置
  • setServerFocusConfig(serverName: string, focusConfig: FocusConfig):设置服务器的焦点配置

工厂功能

createFocusClientSimple

function createFocusClientSimple(
  connections: Record,
  focusTools?: Record,
  focusParams?: Record,
  strict: boolean = false
): FocusMultiServerMCPClient

createFocusComposite

function createFocusClientComposite(
  connections: Record,
  focus?: Record,
  strict: boolean = false
): FocusMultiServerMCPClient

例子

基本工具限制

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" });

多服务器设置

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);

与LangChain代理一起使用

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'"
});

支持的MCP服务器

所有MCP服务器

实现各种MCP功能的测试服务器:

设置:

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

可用工具:

  • echo:回显输入消息
  • add:将两个数字相加

时间MCP服务器

提供时间和时区转换功能:

设置:

pip install mcp-server-time

可用工具:

  • get_current_time:获取特定时区的当前时间
  • convert_time:在时区之间转换时间

错误处理

该库为焦点相关问题提供了全面的错误处理:

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);
  }
}

配置选项

FocusConfig接口

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
}

参数值模式

  • 精确值: ["value1", "value2"]
  • 范围: ["range:1-100"] 用于数值范围
  • 通配符: ["*"] 允许所有值

贡献

欢迎投稿!请随时提交拉取请求。

许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

相关项目

支持

如需支持,请在 或联系我们oss@mimory.io.

作者

特拉维斯·麦昆 - oss@mimory.io

______________________________________________________________________

*该库是模拟生态系统的一部分,为人工智能应用程序提供对MCP工具的安全和受控访问。*

目录标签

目录标签

安全TypeScript开发工具AI安全本地部署工具限制LangChain集成参数验证多服务器管理

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP