Brave Search MCP server

Integrates with Brave Search API to enable secure and privacy-focused web searches for research and content aggregation tasks.
Back to servers
Provider
human-spider
Release date
Feb 22, 2025
Language
TypeScript

The MCP (Model Context Protocol) server is a lightweight implementation for interfacing with the Brave Leo LLM. This server allows you to query the Brave Leo model through a simple API interface, supporting both HTTP and WebSocket protocols for flexible integration into your applications.

Installation

You can install the MCP server using npm:

npm install mcp-server-brave

For development purposes, you can also clone the repository and install dependencies:

git clone https://github.com/yourusername/mcp-server-brave.git
cd mcp-server-brave
npm install

Configuration

Before using the server, you need to configure it with your Brave Leo API key.

Setting Up Environment Variables

Create a .env file in the root directory of your project and add your Brave Leo API key:

BRAVE_LEO_API_KEY=your_api_key_here

Alternatively, you can set the environment variable directly when running the server:

BRAVE_LEO_API_KEY=your_api_key_here npm start

Starting the Server

To start the MCP server, run:

npm start

By default, the server runs on port 3000. You can customize the port by setting the PORT environment variable:

PORT=8080 npm start

Using the MCP Server

The server supports both HTTP POST requests and WebSocket connections for querying the Brave Leo model.

HTTP API

You can send a POST request to the server with your prompt:

curl -X POST http://localhost:3000/v1/generate \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Explain quantum computing in simple terms",
    "model": "leo-hessianai-7b",
    "max_tokens": 100,
    "temperature": 0.7
  }'

Query Parameters

  • prompt (required): The text prompt to send to the model
  • model (optional): The specific model to use (default: "leo-hessianai-7b")
  • max_tokens (optional): Maximum number of tokens to generate (default: 1000)
  • temperature (optional): Controls randomness of outputs (default: 0.7)
  • top_p (optional): Controls diversity via nucleus sampling (default: 0.95)
  • stop (optional): Sequences where the API will stop generating further tokens

WebSocket Connection

For streaming responses, you can use WebSocket connections:

const WebSocket = require('ws');
const ws = new WebSocket('ws://localhost:3000/v1/generate');

ws.on('open', function open() {
  ws.send(JSON.stringify({
    prompt: "Write a short poem about coding",
    model: "leo-hessianai-7b",
    max_tokens: 150
  }));
});

ws.on('message', function incoming(data) {
  const response = JSON.parse(data);
  console.log(response.text);
  
  if (response.done) {
    ws.close();
  }
});

Error Handling

The server provides descriptive error messages when something goes wrong:

  • 400 Bad Request: When your request is malformed or missing required fields
  • 401 Unauthorized: When the API key is invalid or missing
  • 500 Internal Server Error: For unexpected server errors

If you encounter errors, check your API key and request format first.

Rate Limiting

Be aware that the Brave Leo API has rate limits. The server will pass through any rate limiting errors from the upstream API. If you're making many requests, implement appropriate backoff strategies in your client application.

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later