Brave Search MCP Server

repository·main·Indexed 23 days ago

https://github.com/brave/brave-search-mcp-server

An MCP (Model Context Protocol) server implementation that integrates the Brave Search API. It provides tools for web, local, video, image, news, and place searches, as well as AI-powered summarization via brave_summarizer and LLM-optimized context retrieval via brave_llm_context for RAG pipelines.

Tokens
15.9K
Snippets
35
Records
72
Agent score
79%

What's inside brave-search-mcp-server

  1. How to use Summarizer Search (`brave_summarizer`)

    main

    Generates AI-powered summaries from web search results using Brave's summarization API.

    Workflow:

    1. Perform a web search using brave_web_search and set the summary parameter to true.
    2. Extract the returned summary key from the results.
    3. Pass that key to the brave_summarizer tool.

    Parameters:

    • key (string, required): Summary key from web search results
    • entity_info (boolean, optional): Include entity information (default: false)
    • inline_references (boolean, optional): Add source URL references (default: false)
  2. Develop with Brave Search MCP Server using Docker Compose

    main

    For local development with Docker, use Docker Compose:

    docker-compose up --build

    Ensure BRAVE_API_KEY (or BRAVE_API_KEY_FILE) is set in your shell or a .env file.

    Using Docker Compose Secrets

    To avoid plain-text environment variables, use Docker Compose secrets:

    1. Prepare the secret file:
    cp secrets/brave_api_key.txt.example secrets/brave_api_key.txt
    1. Add your key to secrets/brave_api_key.txt.
    2. Start the stack with the secrets override:
    docker compose -f docker-compose.yml -f docker-compose.secrets.example.yml up --build
    docker compose -f docker-compose.yml -f docker-compose.secrets.example.yml up --build
  3. Install Brave Search MCP Server for VS Code

    main

    You can install the server in VS Code using one-click buttons (available in the repository README) or by manually adding the configuration to your User Settings (JSON) or .vscode/mcp.json.

    Manual Docker Configuration

    {
      "inputs": [
        {
          "password": true,
          "id": "brave-api-key",
          "type": "promptString",
          "description": "Brave Search API Key",
        }
      ],
      "servers": {
        "brave-search": {
          "command": "docker",
          "args": ["run", "-i", "--rm", "-e", "BRAVE_API_KEY", "mcp/brave-search"],
          "env": {
            "BRAVE_API_KEY": "${input:brave-api-key}"
          }
        }
      }
    }

    Manual NPX Configuration

    {
      "inputs": [
        {
          "password": true,
          "id": "brave-api-key",
          "type": "promptString",
          "description": "Brave Search API Key",
        }
      ],
      "servers": {
        "brave-search-mcp-server": {
          "command": "npx",
          "args": ["-y", "@brave/brave-search-mcp-server", "--transport", "stdio"],
          "env": {
            "BRAVE_API_KEY": "${input:brave-api-key}"
          }
        }
      }
    }
    {
      "inputs": [
        {
          "password": true,
          "id": "brave-api-key",
          "type": "promptString",
          "description": "Brave Search API Key",
        }
      ],
      "servers": {
        "brave-search": {
          "command": "docker",
          "args": ["run", "-i", "--rm", "-e", "BRAVE_API_KEY", "mcp/brave-search"],
          "env": {
            "BRAVE_API_KEY": "${input:brave-api-key}"
          }
        }
      }
    }
  4. Configure the Brave Search MCP Server transport mode

    main

    By default, the Brave Search MCP server uses STDIO transport. If you need to use HTTP transport, you must explicitly configure it using one of the following methods:

    1. Set the BRAVE_MCP_TRANSPORT environment variable to http.
    2. Provide the --transport http runtime argument when launching the server.
  5. Install Brave Search MCP Server for Claude Desktop

    main

    To use the server with Claude Desktop, add a configuration entry to your claude_desktop_config.json.

    Using Docker

    {
      "mcpServers": {
        "brave-search": {
          "command": "docker",
          "args": ["run", "-i", "--rm", "-e", "BRAVE_API_KEY", "docker.io/mcp/brave-search"],
          "env": {
            "BRAVE_API_KEY": "YOUR_API_KEY_HERE"
          }
        }
      }
    }

    Using NPX

    {
      "mcpServers": {
        "brave-search": {
          "command": "npx",
          "args": ["-y", "@brave/brave-search-mcp-server", "--transport", "http"],
          "env": {
            "BRAVE_API_KEY": "YOUR_API_KEY_HERE"
          }
        }
      }
    }
    {
      "mcpServers": {
        "brave-search": {
          "command": "docker",
          "args": ["run", "-i", "--rm", "-e", "BRAVE_API_KEY", "docker.io/mcp/brave-search"],
          "env": {
            "BRAVE_API_KEY": "YOUR_API_KEY_HERE"
          }
        }
      }
    }
  6. Test the server with MCP Inspector

    main

    To test the server using the MCP Inspector:

    1. Build and start the server:
    npm run build
    node dist/index.js
    1. In a separate terminal, start the Inspector:
    npx @modelcontextprotocol/inspector node dist/index.js

    Note: For HTTP mode testing, add --transport http to the arguments in the Inspector UI.

    npx @modelcontextprotocol/inspector node dist/index.js
  7. Understand the structure of SummaryMessage

    main

    A SummaryMessage is a component of the summary array in a SummarizerSearchApiResponse. It uses a type field to define how to interpret the data field, allowing the summary to mix text, entities, and structural elements like lists.

    Message Types

    • token: A text excerpt from the summary. data is a text string (represented as a SummaryEntity in this schema's type definition, though typically used for text segments).
    • enum_item: Represents a summary entity. data is a SummaryEntity.
    • enum_start: Indicates the beginning of a list of entities. data contains the list type: ol (ordered list) or ul (unordered list).
    • enum_end: Indicates the end of the entity list.
    • inline_reference: An inline reference to a source. data is a SummaryInlineReference.

    Note: inline_reference requires the inline_references query parameter to be set in the request.

    interface SummaryMessage {
      type: string;
      data?: SummaryEntity | SummaryInlineReference;
    }
  8. Understand the Web Search Query metadata

    main

    The Query interface provides context about the search request. It includes the original query string and an altered version if the engine modified it. It also provides metadata such as:

    • safesearch: Boolean indicating if safesearch was active.
    • is_geolocal: Whether the query was treated as location-sensitive.
    • language: The detected language of the query.
    • country: The country used for the request.
    • is_trending: Whether the query is currently trending.
    • lat/long/city/state: Geographic context gathered from the query.
  9. Understand ImageResult metadata and properties

    main

    Each image result in a brave_image_search response provides several layers of metadata:

    • thumbnail: Contains a src URL and dimensions (width, height) for a smaller preview.
    • properties: Contains the direct url of the image, a placeholder (lower resolution version), and the image's dimensions.
    • meta_url: Provides structural information about the host URL, including the scheme, hostname, path, and the favicon URL.
    • confidence: An enum indicating the search engine's confidence in the result: low, medium, or high.
  10. Configure Brave Search MCP Server via Environment Variables

    main

    The server can be configured using the following environment variables:

    VariableDescription
    BRAVE_API_KEYYour Brave Search API key (required unless BRAVE_API_KEY_FILE is set)
    BRAVE_API_KEY_FILEPath to a file containing your API key. Takes precedence over BRAVE_API_KEY. Useful for Docker secrets.
    BRAVE_MCP_TRANSPORTTransport mode: http or stdio (default: stdio)
    BRAVE_MCP_PORTHTTP server port (default: 8080)
    BRAVE_MCP_HOSTHTTP server host (default: 127.0.0.1). Set to 0.0.0.0 for containers or Amazon Bedrock AgentCore.
    BRAVE_MCP_ALLOWED_ORIGINSSpace- or comma-separated list of permitted Origin header values for HTTP transport.
    BRAVE_MCP_ALLOWED_HOSTSSpace- or comma-separated list of permitted Host header values for HTTP transport.
    BRAVE_MCP_LOG_LEVELLogging level: debug, info, notice, warning, error, critical, alert, or emergency (default: info)
    BRAVE_MCP_ENABLED_TOOLSSpace-separated whitelist of supported tools
    BRAVE_MCP_DISABLED_TOOLSSpace-separated blacklist of tools
    BRAVE_MCP_STATELESSHTTP stateless mode (default: true). Set to true when running on Amazon Bedrock Agentcore.