1. Conduid
  2. AI
  3. Mimory MCP Focus Langchain
MCP server · AI

Mimory MCP Focus Langchain

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 control over MCP tool access.

Unclaimed MIT last commit 11 months ago ai
51Fair

Scored 3 months ago · breakdown

About Mimory MCP Focus Langchain

Mimory MCP Focus Langchain is an MCP server published by MimoryInc in the AI category: 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 control over MCP tool access. It has been installed 0 times through Conduid.

Six months or more without a commit doesn't mean the server is broken, but check the open issues (0) before depending on it in production.

Install

Install
npx mimory-mcp-focus-langchain

This server has no ConduID identity, so agent calls to it are not receipted. Pin the version you install and review the source before granting it credentials.

Ask AI

Ask AI about Mimory MCP Focus Langchain

Powered by Claude · Grounded in docs

I know everything about Mimory MCP Focus Langchain. Ask me about installation, configuration, usage, or troubleshooting.

Security checks

  • ·README presentNot checked yet.
  • ·License declaredNot checked yet.
  • ·Tests presentNot checked yet.
  • ·Dependencies pinnedNot checked yet.
  • ·No dynamic code executionNot checked yet.
  • !Scoped permissionsDoesn't declare a permission scope. Assume it can do anything its process can.

README

mimory-mcp-focus-langchain

PyPI version

LangChain integration for mimory-mcp-focus, providing focus capabilities to your LangChain MCP implementations.

Overview

mimory-mcp-focus-langchain extends LangChain's MCP (Model Context Protocol) integration with powerful focus capabilities. It allows you to:

  • Restrict tool access to specific MCP tools
  • Control parameter values with whitelists and ranges
  • Apply composite focus for complex tool-specific restrictions
  • Integrate seamlessly with LangChain's tool ecosystem

Installation

pip install mimory-mcp-focus-langchain

Dependencies

This package requires:

Quick Start

Basic Usage with 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())

Using Core FocusClient with LangChain

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 Configuration

Simple Focus

Restrict tools and parameters globally:

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
}

Composite Focus

Apply different restrictions per tool:

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 Configuration Structure

The focus_config dictionary supports the following structure:

For Simple Focus (focus_type: "simple"):

  • focus_tools: List of allowed tool names (use ["*"] to allow all tools)
  • focus_params: Dictionary mapping parameter names to allowed values
  • focus_type: Must be "simple"
  • strict: Boolean indicating whether to enforce strict mode

For Composite Focus (focus_type: "composite"):

  • focus: Dictionary mapping tool names to their parameter restrictions
  • focus_type: Must be "composite"
  • strict: Boolean indicating whether to enforce strict mode

Parameter Value Formats:

  • Exact values: ["value1", "value2"]
  • Numeric ranges: ["range:1-100"] (inclusive)
  • Wildcard: ["*"] (allows any value)

API Reference

FocusMultiServerMCPClient

Main class for focus-enabled multi-server MCP operations.

Constructor

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

Parameters:

  • connections: Dictionary mapping server names to connection configurations
  • focus_configs: Dictionary mapping server names to focus configurations

Methods

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

Get LangChain tools with focus restrictions applied.

Parameters:

  • server_name: Optional name of specific server. If None, returns tools from all servers.

Returns:

  • List of LangChain tools with focus applied
async session(server_name: str, *, auto_initialize: bool = True) -> AsyncIterator[ClientSession]

Create a focus-enabled MCP session.

Parameters:

  • server_name: Name of the server to connect to
  • auto_initialize: Whether to automatically initialize the session

Returns:

  • Async context manager yielding a focus-enabled ClientSession

Examples

Example 1: Basic Tool Restriction

# 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())

Example 2: Multi-Server with Composite Focus

# 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())

Example 3: Using with LangChain Agents

# 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())

Error Handling

The library uses standard Python exceptions for error handling. Focus-related errors will be raised as appropriate exceptions that you can catch and handle as needed.

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.

Links

Author

Travis McQueen - oss@mimory.io

Support

For support, please open an issue on GitHub.

README mirrored from the source repository 3 months ago. The original is authoritative.

Questions

About Mimory MCP Focus Langchain

How do I install Mimory MCP Focus Langchain?

Run npx mimory-mcp-focus-langchain, then add the server to your MCP client's configuration. Conduid has recorded 0 installs, so the command is known to work with current clients.

Is Mimory MCP Focus Langchain safe to use with an AI agent?

Its trust score is 51 out of 100 (fair). It passes 0 of 1 static security checks; the failures are listed above. It has no ConduID identity yet, so agent calls to it are not receipted.

Is Mimory MCP Focus Langchain still maintained?

The last commit was 11 months ago, with 0 open issues. That's long enough that you should check whether the maintainer is responding to issues before depending on it.