A Streamlit-based AI agent application that supports multiple LLM providers and integrates with Model Context Protocol (MCP) servers for enhanced functionality through tools, resources, and prompts.
- π€ Multiple LLM Providers: Support for OpenAI, Anthropic, and Google models
- π§ MCP Integration: Connect to MCP servers for tools and resources
- π¬ Interactive Chat: Real-time conversation with streaming responses
- βοΈ Configurable Settings: Customizable system prompts, temperature, and token limits
- π οΈ Tool Execution: Automatic parsing and execution of tool calls
- π Resource Access: Access to MCP resources and prompts
- π¨ Modern UI: Clean, responsive Streamlit interface
# Clone the repository
git clone <repository-url>
cd ai-agent-mcp
# Install dependencies
pip install -r requirements.txtCreate a .env file based on env_example.txt:
# Copy the example file
cp env_example.txt .env
# Edit with your API keys
OPENAI_API_KEY=your_openai_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
GOOGLE_API_KEY=your_google_api_key_herestreamlit run app.pyThe application will open in your browser at http://localhost:8501.
The application supports three LLM providers:
- Models: GPT-4, GPT-4 Turbo, GPT-3.5 Turbo
- API Key: Set
OPENAI_API_KEYin your environment
- Models: Claude-3 Opus, Claude-3 Sonnet, Claude-3 Haiku
- API Key: Set
ANTHROPIC_API_KEYin your environment
- Models: Gemini Pro, Gemini Pro Vision
- API Key: Set
GOOGLE_API_KEYin your environment
MCP (Model Context Protocol) servers provide tools, resources, and prompts to extend the agent's capabilities. The application uses the same configuration format as Claude Desktop.
- Go to the "MCP Servers" tab
- Click "β Add New MCP Server"
- Provide:
- Server Name: A unique identifier (e.g., filesystem, brave-search)
- Command: The command to run (e.g., npx, uvx, python)
- Arguments: One per line (e.g., -y, @modelcontextprotocol/server-filesystem)
- Environment Variables: KEY=VALUE format (optional)
- Click "Add Server"
Filesystem Server:
{
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"]
}Brave Search:
{
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
"env": {
"BRAVE_API_KEY": "your-api-key"
}
}PostgreSQL:
{
"command": "uvx",
"args": ["mcp-server-postgres", "postgresql://user:pass@localhost/db"]
}The application can load and save configurations directly from/to claude_desktop_config.json, making it fully compatible with Claude Desktop's MCP server setup:
- Load from Claude Desktop: Click "π Load from claude_desktop_config.json" to import existing servers
- Save for Claude Desktop: Click "πΎ Save to claude_desktop_config.json" to export your configuration
- Same Format: Uses identical JSON structure as Claude Desktop for seamless compatibility
- Configure your LLM provider in the sidebar
- Initialize the agent
- Start chatting in the Chat tab
The agent can automatically use available MCP tools. Simply ask for something that requires tool usage:
"Can you list the files in my documents folder?"
"What's the weather like in New York?"
"Search for information about Python asyncio"
The agent will:
- Identify the appropriate tool
- Execute the tool call
- Provide results in a user-friendly format
Customize the agent's behavior with system prompts:
You are a helpful coding assistant. Always provide code examples and explain your reasoning.
- 0.0: Deterministic, focused responses
- 0.7: Balanced creativity and consistency (default)
- 1.0+: More creative and varied responses
Control response length with max tokens (100-8000).
Extend the BaseLLMProvider class:
from src.llm_providers import BaseLLMProvider, Message, LLMResponse
class CustomProvider(BaseLLMProvider):
async def generate_response(self, messages, system_prompt=None, **kwargs):
# Implement your custom logic
pass
async def stream_response(self, messages, system_prompt=None, **kwargs):
# Implement streaming logic
passCreate MCP servers that implement the Model Context Protocol:
# Example tool registration
tools = [
{
"name": "calculate",
"description": "Perform mathematical calculations",
"inputSchema": {
"type": "object",
"properties": {
"expression": {"type": "string"}
}
}
}
]src/agent.py: Main AI agent implementationsrc/llm_providers.py: LLM provider abstractionssrc/mcp_client.py: MCP server integrationsrc/config.py: Configuration managementapp.py: Streamlit UI application
- User input β Streamlit UI
- UI β AI Agent
- Agent β LLM Provider (for response generation)
- Agent β MCP Servers (for tool execution)
- Results β UI β User
- Check API keys are correctly set
- Verify network connectivity
- Ensure LLM provider is accessible
- Verify server path is correct
- Check server is executable
- Review server arguments
- Check MCP server is running
- Verify tool parameters
- Review server logs
Enable debug logging:
import logging
logging.basicConfig(level=logging.DEBUG)For better performance:
- Use streaming responses for long outputs
- Limit conversation history length
- Optimize MCP server response times
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For questions and support:
- Create an issue on GitHub
- Check the documentation
- Review example configurations