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
-
Clone the repository:
git clone <repository-url> cd MistralMCP
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
export MISTRAL_API_KEY="your_mistral_api_key_here"
Usage
Run the main application:
python main.py
Example Interactions
-
Use existing tools:
Describe your task: What is 5 * (2 + 3)? Result: Result: 25
-
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.
-
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 applicationsmistralai
: Official Mistral AI Python clientlangchain_community
: Community tools and integrationsopenai
: Alternative LLM provider (optional)
Development
Adding New Tools Manually
- Create a new file in
mcp_tools/
- Define a function and wrap it as a LangChain Tool
- 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
intask_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 inmain.py
Troubleshooting
Common Issues
- API Timeout: The system now uses direct tool creation for tool generation requests to avoid agent timeouts
- Import Errors: Ensure all dependencies are installed and the virtual environment is activated
- 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