Vizra.ai |

Documentation

πŸ”Œ

MCP Integration

Supercharge your agents with Model Context Protocol! Connect to filesystems, databases, APIs, and the entire MCP ecosystem with just one line of code. It's like giving your agents superpowers! πŸ¦Έβ€β™‚οΈ

🌟 What is MCP?

Model Context Protocol (MCP) is like "USB-C for AI applications" - a universal standard that lets your agents connect to external data sources and tools. Instead of building custom integrations for every service, you can use the growing ecosystem of MCP servers!

πŸ“ File Systems

Read, write, search files and directories with full filesystem access

πŸ™ GitHub Integration

Create issues, manage repos, read code, and automate workflows

πŸ—„οΈ Databases

Query PostgreSQL, MySQL, and other databases directly from agents

πŸ” Web Search

Search the web with Brave Search for real-time information

πŸ’¬ Team Tools

Integrate with Slack, Discord, and other communication platforms

🎯 Custom Servers

Build your own MCP servers in any language for specialized needs

⚑ Quick Start - Add MCP in 60 Seconds

Getting MCP working with your agents is incredibly simple. Here's how:

1️⃣ Install MCP Server

npm install -g @modelcontextprotocol/server-filesystem

2️⃣ Configure in Vizra

'mcp_servers' => [
    'filesystem' => [
        'command' => 'npx',
        'args' => [
            '@modelcontextprotocol/server-filesystem',
            storage_path('app'), // Allow access to storage directory
        ],
        'enabled' => true,
    ],
],

3️⃣ Create MCP-Enabled Agent

<?php
namespace App\Agents;

use Vizra\VizraADK\Agents\BaseLlmAgent;

class FileManagerAgent extends BaseLlmAgent
{
    protected string $name = 'file_manager';
    protected string $instructions = 'You can read, write, and manage files. Help users with file operations!';

    protected array $mcpServers = ['filesystem'];
}

4️⃣ Test It Out!

php artisan vizra:chat file_manager

πŸŽ‰ That's It!

Your agent now has access to all filesystem tools! It can read files, write content, search directories, and more. The MCP tools are automatically discovered and added to your agent.

πŸ› οΈ Available MCP Servers

Here are some popular MCP servers you can use right away:

πŸ“ Filesystem Server

Access local files and directories with comprehensive file operations.

Installation

npm install -g @modelcontextprotocol/server-filesystem

Configuration

'filesystem' => [
    'command' => 'npx',
    'args' => ['@modelcontextprotocol/server-filesystem', '/safe/path'],
    'enabled' => true,
],

Available Tools

β€’ read_file - Read file contents
β€’ write_file - Write to files
β€’ list_directory - List directory contents
β€’ search_files - Search for files and content

πŸ™ GitHub Server

Comprehensive GitHub integration for repository management and automation.

Installation

npm install -g @modelcontextprotocol/server-github

Configuration

'github' => [
    'command' => 'npx',
    'args' => ['@modelcontextprotocol/server-github', '--token', env('GITHUB_TOKEN')],
    'enabled' => !empty(env('GITHUB_TOKEN')),
],

Available Tools

β€’ create_issue - Create GitHub issues
β€’ search_repositories - Search repos
β€’ get_file_contents - Read files from repos
β€’ list_issues - List repository issues

πŸ—„οΈ PostgreSQL Server

Direct database access for queries and data manipulation.

Installation

npm install -g @modelcontextprotocol/server-postgres

Configuration

'postgres' => [
    'command' => 'npx',
    'args' => ['@modelcontextprotocol/server-postgres', '--connection-string', env('DATABASE_URL')],
    'enabled' => !empty(env('DATABASE_URL')),
],

Available Tools

β€’ query - Execute SQL queries
β€’ describe_table - Get table schema
β€’ list_tables - List all tables
β€’ get_schema - Get database schema

πŸš€ Advanced Configuration

Environment-Based Setup

Use environment variables to control MCP servers across different environments:

# Enable/disable servers per environment
MCP_FILESYSTEM_ENABLED=true
MCP_GITHUB_ENABLED=true
MCP_POSTGRES_ENABLED=false

# Server-specific configuration
GITHUB_TOKEN=your_github_token_here
DATABASE_URL=postgresql://user:pass@localhost/db
BRAVE_API_KEY=your_brave_search_key
MCP_NPX_PATH="/path/to/npx"  # Optional: specify npx path if not in PATH
'mcp_servers' => [
    'filesystem' => [
        'command' => 'npx',
        'args' => ['@modelcontextprotocol/server-filesystem', storage_path('app')],
        'enabled' => env('MCP_FILESYSTEM_ENABLED', false),
        'timeout' => 30,
    ],

    'github' => [
        'command' => 'npx',
        'args' => ['@modelcontextprotocol/server-github', '--token', env('GITHUB_TOKEN')],
        'enabled' => env('MCP_GITHUB_ENABLED', false) && !empty(env('GITHUB_TOKEN')),
        'timeout' => 45,
    ],

    'postgres' => [
        'command' => 'npx',
        'args' => ['@modelcontextprotocol/server-postgres', '--connection-string', env('DATABASE_URL')],
        'enabled' => env('MCP_POSTGRES_ENABLED', false) && !empty(env('DATABASE_URL')),
        'timeout' => 30,
    ],
],

Multiple Servers per Agent

Agents can use multiple MCP servers simultaneously:

class DeveloperAssistantAgent extends BaseLlmAgent
{
    protected string $name = 'developer_assistant';

    protected string $instructions = 'You are a comprehensive development assistant with access to:

    πŸ“ **File System**: Read, write, and search project files
    πŸ™ **GitHub**: Manage repositories, issues, and pull requests
    πŸ—„οΈ **Database**: Query and analyze data directly

    Use these tools together to provide powerful development support!';

    protected array $mcpServers = ['filesystem', 'github', 'postgres'];
}

πŸ§‘β€πŸ’» Management Commands

Vizra ADK provides helpful commands to manage your MCP integration:

List Configured Servers

php artisan vizra:mcp:servers

Shows all configured MCP servers and their status

Test Server Connectivity

php artisan vizra:mcp:servers --test

Tests connections and shows available tools from each server

πŸ’‘ Real-World Examples

Code Review Assistant

class CodeReviewAgent extends BaseLlmAgent
{
    protected string $name = 'code_reviewer';

    protected string $instructions = 'You are an expert code reviewer. You can:

    1. Read code files to understand implementations
    2. Search for patterns and potential issues
    3. Create GitHub issues for problems found
    4. Suggest improvements and best practices

    Always provide constructive feedback with specific examples.';

    protected array $mcpServers = ['filesystem', 'github'];
}

Example Conversation

User: "Review the authentication code in src/Auth/"
Agent: "I'll examine the authentication code for you..."
β†’ Uses filesystem tools to read auth files
β†’ Analyzes code for security issues
β†’ Creates GitHub issue for potential vulnerability
Agent: "Found 3 areas for improvement. Created issue #42 for the critical security concern."

Data Analysis Assistant

class DataAnalystAgent extends BaseLlmAgent
{
    protected string $name = 'data_analyst';

    protected string $instructions = 'You are a data analysis expert. You can:

    1. Query databases to extract insights
    2. Generate reports and save them as files
    3. Create data visualizations and charts
    4. Identify trends and anomalies in data

    Always explain your analysis methodology and findings clearly.';

    protected array $mcpServers = ['postgres', 'filesystem'];
}

πŸ”’ Security Best Practices

πŸ›‘οΈ Filesystem Security

  • β€’ Limit directory access - Only allow access to safe directories
  • β€’ Use storage paths - Prefer storage_path() over system directories
  • β€’ Validate file operations - MCP servers should validate all file paths
  • β€’ Monitor file access - Log all file operations for audit trails

πŸ” API Token Security

  • β€’ Use environment variables - Never hardcode tokens in config
  • β€’ Minimal permissions - Grant only necessary API permissions
  • β€’ Rotate tokens regularly - Set up token rotation schedules
  • β€’ Monitor usage - Track API calls and unusual activity

πŸ—οΈ Environment Isolation

  • β€’ Separate configs - Different MCP servers for dev/staging/prod
  • β€’ Sandbox testing - Test MCP integrations in isolated environments
  • β€’ Resource limits - Set appropriate timeouts and resource constraints
  • β€’ Error handling - Graceful degradation when MCP servers are unavailable

πŸ› Troubleshooting

Server Connection Failed

Error: "Failed to start MCP server"

β€’ Check that the MCP server package is installed globally
β€’ Verify the command path and arguments in config
β€’ Run php artisan vizra:mcp:servers --test for details

Tools Not Available

Error: "Tool not found" or tools not appearing

β€’ Ensure the server is enabled in configuration
β€’ Check that the mcpServers property includes the server
β€’ Clear cache and restart the application

Permission Denied

Error: "Access denied" or "Insufficient permissions"

β€’ Check filesystem permissions for directory access
β€’ Verify API tokens have necessary permissions
β€’ Ensure environment variables are set correctly

🎯 Best Practices

🎨 Agent Design

  • β€’ Single responsibility - Each agent should have a clear, focused purpose
  • β€’ Appropriate tools - Only include MCP servers the agent actually needs
  • β€’ Clear instructions - Explain what MCP capabilities the agent has
  • β€’ Error handling - Handle MCP failures gracefully in agent instructions

⚑ Performance

  • β€’ Cache wisely - MCP tool discovery is cached for 5 minutes
  • β€’ Connection pooling - MCP clients are reused across requests
  • β€’ Timeout settings - Set appropriate timeouts for different server types
  • β€’ Monitor usage - Track MCP server performance and availability

πŸ”§ Development Workflow

  • β€’ Test locally first - Use --test flag to verify servers
  • β€’ Gradual rollout - Enable MCP servers incrementally
  • β€’ Monitor logs - Watch for MCP-related errors and performance issues
  • β€’ Documentation - Document which agents use which MCP servers

Ready for Professional AI Agent Evaluation? πŸš€

Evaluate and debug your Vizra ADK agents with professional cloud tools. Get early access to Vizra Cloud and be among the first to experience advanced evaluation and trace analysis at scale.

Cloud evaluation runs
Trace visualization
Team collaboration

Join other developers already on the waitlist. No spam, just launch updates.