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.
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
Before using the server, you need to configure it with your Brave Leo API key.
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
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
The server supports both HTTP POST requests and WebSocket connections for querying the Brave Leo model.
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
}'
prompt
(required): The text prompt to send to the modelmodel
(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 tokensFor 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();
}
});
The server provides descriptive error messages when something goes wrong:
If you encounter errors, check your API key and request format first.
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.
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.
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"
]
}
}
}
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.
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.