JUHE API Marketplace
abigaillhiggins avatar
MCP Server

MistralMCP

A Python system that dynamically generates and orchestrates code-based tools in response to user requests using Mistral AI and LangChain.

0
GitHub Stars
8/5/2025
Last Updated
No Configuration
Please check the documentation below.

README Documentation

MistralMCP - Dynamic Tool Generation with Mistral AI

A Python-based system that uses LangChain and Mistral AI to dynamically generate and orchestrate MCP (Managed Code Platform) tools based on high-level user tasks.

Features

  • Dynamic Tool Generation: Automatically creates new Python tools based on user requests
  • Mistral AI Integration: Uses Mistral's LLM for intelligent tool orchestration and generation
  • LangChain Framework: Built on LangChain for robust agent and chain management
  • Tool Registry: Centralized management of all available tools
  • Agent Orchestration: Intelligent tool selection and execution through Mistral agents

Architecture

User Input → Intent Detection → Tool Selection → Agent Orchestration → Tool Execution
     ↓              ↓              ↓              ↓              ↓
Tool Creation ← Dynamic Generation ← Code Extraction ← LLM Response ← Mistral AI

Setup

  1. Clone the repository:

    git clone <repository-url>
    cd MistralMCP
    
  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Set up environment variables:

    export MISTRAL_API_KEY="your_mistral_api_key_here"
    

Usage

Run the main application:

python main.py

Example Interactions

  1. Use existing tools:

    Describe your task: What is 5 * (2 + 3)?
    Result: Result: 25
    
  2. Create a new tool:

    Describe your task: create a tool that converts text to uppercase
    Tool created! You can now use it in the chat.
    
  3. Use the newly created tool:

    Describe your task: convert "hello world" to uppercase
    Result: HELLO WORLD
    

Project Structure

MistralMCP/
├── main.py                 # Entry point and user interaction loop
├── requirements.txt        # Python dependencies
├── tool_registry.py        # Central tool registry
├── chains/
│   └── task_chain.py       # Core agent and tool orchestration logic
└── mcp_tools/             # Directory containing all tools
    ├── echo_tool.py        # Basic echo functionality
    ├── calculator_tool.py  # Mathematical operations
    ├── reverse_tool.py     # String reversal
    └── create_tool.py      # Tool creation placeholder

Key Components

AgentTaskChain

The main orchestrator that:

  • Uses Mistral LLM for intelligent decision making
  • Manages tool selection and execution
  • Handles dynamic tool creation requests
  • Provides fallback mechanisms for tool creation

Dynamic Tool Generation

The system can automatically:

  • Parse user intent for tool creation
  • Generate Python code for new tools
  • Save tools to the mcp_tools/ directory
  • Register tools in the central registry
  • Import and make tools available immediately

Tool Registry

Centralized management of all available tools with:

  • Automatic import handling
  • Dynamic registration of new tools
  • Consistent naming and organization

API Keys Required

  • Mistral API Key: Required for LLM operations and agent orchestration

Dependencies

  • langchain: Framework for building LLM applications
  • mistralai: Official Mistral AI Python client
  • langchain_community: Community tools and integrations
  • openai: Alternative LLM provider (optional)

Development

Adding New Tools Manually

  1. Create a new file in mcp_tools/
  2. Define a function and wrap it as a LangChain Tool
  3. Import and register it in tool_registry.py

Example:

from langchain.tools import Tool

def my_tool_func(input_text: str) -> str:
    return f"Processed: {input_text}"

my_tool = Tool(
    name="MyTool",
    func=my_tool_func,
    description="Processes input text."
)

Customizing the System

  • System Prompts: Modify SYSTEM_PROMPT in task_chain.py to change agent behavior
  • Tool Creation Logic: Customize the dynamic_create_tool method for different generation strategies
  • Intent Detection: Update is_tool_creation_request patterns in main.py

Troubleshooting

Common Issues

  1. API Timeout: The system now uses direct tool creation for tool generation requests to avoid agent timeouts
  2. Import Errors: Ensure all dependencies are installed and the virtual environment is activated
  3. Tool Registration: Check that new tools are properly imported in tool_registry.py

Debug Mode

The system includes debug print statements to help track:

  • Tool selection and execution
  • Dynamic tool creation process
  • Agent decision making

License

[Add your license information here]

Contributing

[Add contribution guidelines here]

Quick Actions

Key Features

Model Context Protocol
Secure Communication
Real-time Updates
Open Source