Skip to content

About

AI Agent with MCP Integration - Streamlit app supporting multiple LLM providers with Claude Desktop compatible MCP server configuration

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Agent with MCP Integration

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.

Features

  • πŸ€– 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

Quick Start

1. Installation

# Clone the repository
git clone <repository-url>
cd ai-agent-mcp

# Install dependencies
pip install -r requirements.txt

2. Environment Setup

Create 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_here

3. Run the Application

streamlit run app.py

The application will open in your browser at http://localhost:8501.

Configuration

LLM Providers

The application supports three LLM providers:

OpenAI

  • Models: GPT-4, GPT-4 Turbo, GPT-3.5 Turbo
  • API Key: Set OPENAI_API_KEY in your environment

Anthropic

  • Models: Claude-3 Opus, Claude-3 Sonnet, Claude-3 Haiku
  • API Key: Set ANTHROPIC_API_KEY in your environment

Google

  • Models: Gemini Pro, Gemini Pro Vision
  • API Key: Set GOOGLE_API_KEY in your environment

MCP Servers

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.

Adding MCP Servers

  1. Go to the "MCP Servers" tab
  2. Click "βž• Add New MCP Server"
  3. 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)
  4. Click "Add Server"

Example MCP Server Configurations

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"]
}

Claude Desktop Configuration Compatibility

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

Usage

Basic Chat

  1. Configure your LLM provider in the sidebar
  2. Initialize the agent
  3. Start chatting in the Chat tab

Using Tools

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:

  1. Identify the appropriate tool
  2. Execute the tool call
  3. Provide results in a user-friendly format

Advanced Configuration

System Prompts

Customize the agent's behavior with system prompts:

You are a helpful coding assistant. Always provide code examples and explain your reasoning.

Temperature Control

  • 0.0: Deterministic, focused responses
  • 0.7: Balanced creativity and consistency (default)
  • 1.0+: More creative and varied responses

Token Limits

Control response length with max tokens (100-8000).

API Integration

Creating Custom LLM Providers

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
        pass

Custom MCP Servers

Create 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"}
            }
        }
    }
]

Architecture

Core Components

  • src/agent.py: Main AI agent implementation
  • src/llm_providers.py: LLM provider abstractions
  • src/mcp_client.py: MCP server integration
  • src/config.py: Configuration management
  • app.py: Streamlit UI application

Data Flow

  1. User input β†’ Streamlit UI
  2. UI β†’ AI Agent
  3. Agent β†’ LLM Provider (for response generation)
  4. Agent β†’ MCP Servers (for tool execution)
  5. Results β†’ UI β†’ User

Troubleshooting

Common Issues

"Failed to initialize agent"

  • Check API keys are correctly set
  • Verify network connectivity
  • Ensure LLM provider is accessible

"MCP server not found"

  • Verify server path is correct
  • Check server is executable
  • Review server arguments

"Tool call failed"

  • Check MCP server is running
  • Verify tool parameters
  • Review server logs

Logging

Enable debug logging:

import logging
logging.basicConfig(level=logging.DEBUG)

Performance

For better performance:

  • Use streaming responses for long outputs
  • Limit conversation history length
  • Optimize MCP server response times

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For questions and support:

  • Create an issue on GitHub
  • Check the documentation
  • Review example configurations

About

AI Agent with MCP Integration - Streamlit app supporting multiple LLM providers with Claude Desktop compatible MCP server configuration

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages