What is MCP?

MCP (Model Context Protocol) allows your ElizaOS agent to use external tools and services. Think of it as giving your agent abilities like web search, file access, or API connections.

Quick Setup

Step 1: Install the MCP Plugin

bun add @elizaos/plugin-mcp

Step 2: Add MCP to Your Character

Add '@elizaos/plugin-mcp' to your character’s plugins array:
export const character: Character = {
  name: 'YourAgent',
  plugins: [
    '@elizaos/plugin-sql',
    '@elizaos/plugin-openrouter',
    '@elizaos/plugin-openai',
    '@elizaos/plugin-bootstrap',
    '@elizaos/plugin-mcp', // Add this
    // ... other plugins
  ],
  // ... rest of configuration
};
STDIO servers run as local processes and communicate through standard input/output.

Configuration

export const character: Character = {
  name: 'WebSearchAgent',
  plugins: [
    '@elizaos/plugin-sql',
    '@elizaos/plugin-openrouter',
    '@elizaos/plugin-openai',
    '@elizaos/plugin-mcp',
    '@elizaos/plugin-bootstrap',
  ],
  settings: {
    mcp: {
      servers: {
        firecrawl: {
          type: 'stdio',
          command: 'npx',
          args: ['-y', 'firecrawl-mcp'],
          env: {
            // Optional: Add your Firecrawl API key if you have one
            FIRECRAWL_API_KEY: process.env.FIRECRAWL_API_KEY || '',
          },
        },
      },
    },
  },
  system: 'You are a helpful assistant with web search capabilities.',
};

What It Can Do

  • Search the web for current information
  • Extract content from websites
  • Perform deep research on topics
  • Scrape structured data

Usage Examples

User: "Search for the latest AI news"
Agent: *searches the web and provides current information*

User: "What's on example.com?"
Agent: *scrapes and summarizes the website content*

Example 2: SSE Server (Remote API Connection)

SSE (Server-Sent Events) servers connect to remote APIs through HTTP.

Configuration

export const character: Character = {
  name: 'APIAgent',
  plugins: ['@elizaos/plugin-sql', '@elizaos/plugin-mcp', '@elizaos/plugin-bootstrap'],
  settings: {
    mcp: {
      servers: {
        myApiServer: {
          type: 'sse',
          url: 'https://your-api-server.com/sse', // Replace with your SSE server URL
        },
      },
    },
  },
  system: 'You are a helpful assistant with API access capabilities.',
};

What It Can Do

Depends on the specific SSE server, but typically:
  • Real-time data access
  • API interactions
  • Custom tool execution
  • Dynamic resource fetching

Usage Examples

User: "Get the latest data from the API"
Agent: *fetches and returns real-time data*

User: "Execute the custom tool"
Agent: *runs the tool provided by the SSE server*

Complete Example

Here’s a complete character configuration with both server types:
import { type Character } from '@elizaos/core';

export const character: Character = {
  name: 'Eliza',
  plugins: [
    '@elizaos/plugin-sql',
    ...(process.env.ANTHROPIC_API_KEY ? ['@elizaos/plugin-anthropic'] : []),
    ...(process.env.OPENAI_API_KEY ? ['@elizaos/plugin-openai'] : []),
    '@elizaos/plugin-bootstrap',
    '@elizaos/plugin-mcp',
  ],
  settings: {
    mcp: {
      servers: {
        // STDIO server example - runs locally
        firecrawl: {
          type: 'stdio',
          command: 'npx',
          args: ['-y', 'firecrawl-mcp'],
          env: {},
        },
        // SSE server example - connects to remote API
        customApi: {
          type: 'sse',
          url: 'https://your-api.com/sse',
        },
      },
    },
  },
  system: 'You are a helpful assistant with access to web search and API tools.',
  bio: [
    'Can search the web for information',
    'Can connect to external APIs',
    'Provides helpful responses',
  ],
};

How to Test

  1. Start your agent:
bun run start
  1. Ask your agent to use the tools:
    • For web search: “Search for [topic]”
    • For API tools: Use commands specific to your SSE server

Troubleshooting

  • Server not connecting: Check that the command/URL is correct
  • Tools not available: Ensure @elizaos/plugin-mcp is in your plugins array
  • Permission errors: For STDIO servers, ensure the command can be executed

That’s It!

You now have MCP set up with your ElizaOS agent. Each MCP server adds different capabilities - just add them to your settings.mcp.servers configuration.