Skip to main content
Glama

MistralMCP

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]

-
security - not tested
F
license - not found
-
quality - not tested

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

  1. Features
    1. Architecture
      1. Setup
        1. Usage
          1. Example Interactions
        2. Project Structure
          1. Key Components
            1. AgentTaskChain
            2. Dynamic Tool Generation
            3. Tool Registry
          2. API Keys Required
            1. Dependencies
              1. Development
                1. Adding New Tools Manually
                2. Customizing the System
              2. Troubleshooting
                1. Common Issues
                2. Debug Mode
              3. License
                1. Contributing

                  Related MCP Servers

                  • -
                    security
                    F
                    license
                    -
                    quality
                    Provides code completion, bug fixing, and test generation for multiple programming languages, integrating with the Mistral Codestral API to enhance code development processes.
                    Last updated -
                    2
                    TypeScript
                  • -
                    security
                    F
                    license
                    -
                    quality
                    Provides code generation and completion capabilities using the DeepSeek API, with support for tool chaining and cost optimization.
                    Last updated -
                    3
                    JavaScript
                  • A
                    security
                    F
                    license
                    A
                    quality
                    Enables AI models to dynamically create and execute their own custom tools through a meta-function architecture, supporting JavaScript, Python, and Shell runtimes with sandboxed security and human approval flows.
                    Last updated -
                    5
                    5
                    JavaScript
                  • -
                    security
                    A
                    license
                    -
                    quality
                    Provides a standardized protocol for tool invocation, enabling an AI system to search the web, retrieve information, and provide relevant answers through integration with LangChain, RAG, and Ollama.
                    Last updated -
                    2
                    Python
                    MIT License

                  View all related MCP servers

                  MCP directory API

                  We provide all the information about MCP servers via our MCP API.

                  curl -X GET 'https://glama.ai/api/mcp/v1/servers/abigaillhiggins/MistralMCP'

                  If you have feedback or need assistance with the MCP directory API, please join our Discord server