Token导航 LogoToken导航TokenDH.com
Mimory MCP Focus Langchain logo
运维云端stdio官方级别未说明来源级核验

Mimory MCP Focus Langchain

MCP Server

mimory-mcp-focus-langchain是一个为LangChain MCP实现提供焦点能力的集成工具,允许限制工具访问和控制参数值。

工具数

0

提示词数

0

GitHub Stars

0

资源数

0
Python机器学习云端部署

安装说明

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

作者 / 组织

MimoryInc

提供方

MimoryInc

最后核验

2026/5/17 20:20

快速接入

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

命令预览

pip install mimory-mcp-focus-langchain

详细介绍

记忆-MCP-焦点-LangChain(或“记忆-多模态控制协议-焦点-语言链”)

](https://badge.fury.io/py/mimory-mcp-focus-langchain) ![Python 3.10+](https://www.python.org/downloads/) ![License: MIT](https://opensource.org/licenses/MIT)

LangChain 的集成用于 “mimory-mcp-focus”可以翻译为“记忆-MCP(多通道处理/模块控制平台)焦点”或根据具体上下文调整为更贴切的表述,如“记忆-MCP核心关注点”等。这里,“mimory”可能是一个特定于某个领域或产品的术语,我将其翻译为“记忆”,但具体含义可能需要根据上下文来确定;“mcp”通常代表“Multi-Channel Processing”(多通道处理)或“Module Control Platform”(模块控制平台)等,具体含义同样取决于上下文;“focus”则翻译为“焦点”或“核心关注点”为您的LangChain MCP实现提供焦点(或核心)功能。

概述

mimory-mcp-focus-langchain 扩展了LangChain的MCP(模型上下文协议)集成,增强了其聚焦功能。它使您能够:

  • 限制工具访问 针对特定的MCP工具
  • 控制参数值 带有白名单和范围
  • 应用复合焦点 对于复杂的工具特定限制
  • 无缝集成 借助LangChain的工具生态系统

安装

pip install mimory-mcp-focus-langchain

依赖项

这个软件包需要:

快速入门

使用 FocusMultiServerMCPClient 的基本用法

import asyncio
from mim_mcp_focus_langchain import FocusMultiServerMCPClient
from langchain_mcp_adapters.sessions import Connection

async def main():
    # Define MCP server connections
    connections = {
        "everything": {
            "transport": "stdio",
            "command": "npx",
            "args": ["-y", "@modelcontextprotocol/server-everything"]
        },
        "time": {
            "transport": "stdio", 
            "command": "python",
            "args": ["-m", "mcp_server_time"]
        }
    }
    
    # Configure focus restrictions
    focus_configs = {
        "everything": {
            "focus_tools": ["echo", "add"],  # Only allow these tools
            "focus_params": {
                "message": ["hello", "world"],  # Restrict message values
                "a": ["range:1-10"]  # Restrict 'a' parameter to 1-10
            }
        },
        "time": {
            "focus_tools": ["get_current_time"],  # Only allow time tool
            "focus_params": {
                "timezone": ["America/New_York", "Europe/London"]  # Restrict timezones
            }
        }
    }
    
    # Create focus-enabled client
    client = FocusMultiServerMCPClient(connections, focus_configs)
    
    # Get tools with focus applied
    tools = await client.get_tools()
    
    # Use tools in your LangChain application
    for tool in tools:
        print(f"Tool: {tool.name} - {tool.description}")

if __name__ == "__main__":
    asyncio.run(main())

使用LangChain结合Core FocusClient

import asyncio
from mimory_mcp_focus import focus_client_simple, focus_client_composite
from langchain_mcp_adapters.sessions import Connection, create_session
from langchain_mcp_adapters.tools import load_mcp_tools

async def main():
    # Create MCP connection
    connection = {
        "transport": "stdio",
        "command": "npx", 
        "args": ["-y", "@modelcontextprotocol/server-everything"]
    }
    
    # Create focus-enabled session
    async with create_session(connection) as session:
        await session.initialize()
        
        # Apply focus restrictions using simple focus
        focus_session = focus_client_simple(
            session,
            focus_tools=["echo", "add"],
            focus_params={
                "message": ["hello", "world"],
                "a": ["range:1-10"]
            },
            strict=False
        )
        
        # Load tools with focus applied
        tools = await load_mcp_tools(focus_session)
        
        # Use tools in LangChain
        for tool in tools:
            print(f"Tool: {tool.name}")

if __name__ == "__main__":
    asyncio.run(main())

焦点配置

简单聚焦

全局限制工具和参数:

focus_config = {
    "focus_tools": ["tool1", "tool2"],  # Allowed tools
    "focus_params": {
        "param1": ["value1", "value2"],  # Allowed values
        "param2": ["range:1-100"]  # Numeric range
    },
    "focus_type": "simple",  # How the focus params are encoded
    "strict": False  # Whether to enforce strict mode
}

复合焦点

为每种工具应用不同的限制:

focus_config = {
    "focus": {
        "tool1": {
            "param1": ["value1", "value2"],
            "param2": ["range:1-10"]
        },
        "tool2": {
            "param3": ["value3", "value4"],
            "param4": ["value5"]
        }
    },
    "focus_type": "composite",  # How the focus params are encoded
    "strict": True
}

焦点配置结构

focus_config 字典支持以下结构:

对于简易对焦(focus_type: "simple"):

  • focus_tools允许使用的工具名称列表(使用 ["*"] 允许所有工具)
  • focus_params参数名称到允许值的字典映射
  • focus_type必须是 "simple"
  • strict布尔值,指示是否启用严格模式

对于复合焦点(focus_type: "composite"):

  • focus字典,用于将工具名称映射到其参数限制
  • focus_type必须是 "composite"
  • strict布尔值,指示是否启用严格模式

参数值格式:

  • 确切数值: ["value1", "value2"]
  • 数字范围: ["range:1-100"] (包括)
  • 通配符: ["*"] (允许任何值)

API 参考文档

FocusMultiServerMCPClient 翻译为中文是:“焦点多服务器MCP客户端”

用于支持焦点功能的多服务器MCP操作的主类。

构造函数

FocusMultiServerMCPClient(
    connections: Optional[Dict[str, Connection]] = None,
    focus_configs: Optional[Dict[str, Dict[str, Any]]] = None
)

参数:

  • connections将服务器名称映射到连接配置的字典
  • focus_configs字典,用于将服务器名称映射到焦点配置

方法

async get_tools(server_name: Optional[str] = None) -> List[BaseTool]

获取应用了焦点限制的LangChain工具。

参数:

  • server_name可选的特定服务器名称。如果为 None,则返回所有服务器的工具。

返回:

  • 应用了重点的LangChain工具列表

async session(server_name: str, *, auto_initialize: bool = True) -> AsyncIterator[ClientSession]

创建一个启用焦点功能的MCP会话。

参数:

  • server_name要连接的服务器名称
  • auto_initialize是否自动初始化会话

返回值:

  • 异步上下文管理器,生成一个启用焦点的ClientSession

示例

示例1:基本工具限制

# examples/basic_restriction.py
import asyncio
from mim_mcp_focus_langchain import FocusMultiServerMCPClient

async def main():
    connections = {
        "everything": {
            "transport": "stdio",
            "command": "npx",
            "args": ["-y", "@modelcontextprotocol/server-everything"]
        }
    }
    
    focus_configs = {
        "everything": {
            "focus_tools": ["echo"],  # Only allow echo tool
            "focus_params": {
                "message": ["hello", "world", "test"]  # Restrict message values
            },
            "focus_type": "simple",
            "strict": False
        }
    }
    
    client = FocusMultiServerMCPClient(connections, focus_configs)
    tools = await client.get_tools()
    
    print("Available tools:")
    for tool in tools:
        print(f"- {tool.name}: {tool.description}")

if __name__ == "__main__":
    asyncio.run(main())

示例2:具有复合焦点的多服务器

# examples/multi_server_composite.py
import asyncio
from mim_mcp_focus_langchain import FocusMultiServerMCPClient

async def main():
    connections = {
        "everything": {
            "transport": "stdio",
            "command": "npx",
            "args": ["-y", "@modelcontextprotocol/server-everything"]
        },
        "time": {
            "transport": "stdio",
            "command": "python", 
            "args": ["-m", "mcp_server_time"]
        }
    }
    
    focus_configs = {
        "everything": {
            "focus": {
                "echo": {
                    "message": ["hello", "world"]
                },
                "add": {
                    "a": ["range:1-5"],
                    "b": ["range:1-5"]
                }
            },
            "focus_type": "composite",
            "strict": False
        },
        "time": {
            "focus_tools": ["get_current_time"],
            "focus_params": {
                "timezone": ["America/New_York", "Europe/London"]
            },
            "focus_type": "simple",
            "strict": False
        }
    }
    
    client = FocusMultiServerMCPClient(connections, focus_configs)
    tools = await client.get_tools()
    
    print("Available tools:")
    for tool in tools:
        print(f"- {tool.name}: {tool.description}")

if __name__ == "__main__":
    asyncio.run(main())

示例3:与LangChain代理一起使用

# examples/langchain_agent.py
import asyncio
from mim_mcp_focus_langchain import FocusMultiServerMCPClient
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_openai import ChatOpenAI

async def main():
    # Setup MCP connections with focus
    connections = {
        "everything": {
            "transport": "stdio",
            "command": "npx",
            "args": ["-y", "@modelcontextprotocol/server-everything"]
        }
    }
    
    focus_configs = {
        "everything": {
            "focus_tools": ["echo", "add"],
            "focus_params": {
                "message": ["hello", "world", "test"],
                "a": ["range:1-10"],
                "b": ["range:1-10"]
            },
            "focus_type": "simple",
            "strict": False
        }
    }
    
    # Create focus-enabled client
    client = FocusMultiServerMCPClient(connections, focus_configs)
    
    # Get tools
    tools = await client.get_tools()
    
    # Create LangChain agent
    llm = ChatOpenAI(model="gpt-4", temperature=0)
    agent = create_tool_calling_agent(llm, tools, "You are a helpful assistant with access to focused MCP tools.")
    agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
    
    # Run agent
    result = await agent_executor.ainvoke({"input": "Echo 'hello' and add 5 + 3"})
    print(result)

if __name__ == "__main__":
    asyncio.run(main())

错误处理

该库使用标准的Python异常来处理错误。与焦点相关的错误将作为适当的异常抛出,您可以根据需要捕获并处理这些异常。

做出贡献

欢迎贡献!请随时提交拉取请求。

许可证

这个项目采用MIT许可证授权——详见 许可证 详情请见文件。

链接

作者

特拉维斯·麦克奎因 - oss@mimory.io(注:这是一封电子邮件地址,直接翻译为中文形式即保持原样,因为电子邮件地址在中文中通常也直接使用其原始形式。)

支持

如需支持,请在(相关平台/项目)上提交一个问题 。

目录标签

目录标签

Python机器学习云端部署LangChain集成本地部署工具限制参数控制

接入字段

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

stdio

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

session

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

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

0

权限和风险

stdiosession部署方式未说明

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

安装前确认

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

来源信息

继续浏览同类 MCP