How to use Brave search MCP server
Quick answer
Use the
mcp Python SDK to connect to the Brave search MCP server via stdio or SSE transport. Implement a Server instance from mcp.server and handle requests by defining your agent logic, then run the server with stdio_server() to communicate with Brave search's MCP endpoint.PREREQUISITES
Python 3.8+pip install mcpAccess to Brave search MCP server (local or remote)Basic knowledge of Python async programming
Setup
Install the official mcp Python SDK and prepare your environment to connect to the Brave search MCP server. Ensure Python 3.8 or higher is installed.
pip install mcp Step by step
This example shows how to create a simple MCP server in Python that connects to Brave search MCP via stdio. The server listens for requests and responds with a fixed message.
from mcp.server import Server
from mcp.server.stdio import stdio_server
# Define your MCP server logic
class BraveSearchMCPServer(Server):
async def handle_request(self, request):
# Implement your request handling logic here
# For demo, respond with a fixed message
return {"response": "Hello from Brave search MCP server!"}
# Instantiate and run the server
if __name__ == "__main__":
server = BraveSearchMCPServer()
stdio_server(server) Common variations
You can run the MCP server over different transports such as SSE or TCP if supported. Also, customize handle_request to integrate with Brave search APIs or your own logic. Async handling allows concurrent requests.
from mcp.server import Server
from mcp.server.sse import sse_server
class BraveSearchMCPServer(Server):
async def handle_request(self, request):
# Custom logic here
return {"response": "Handled via SSE transport"}
if __name__ == "__main__":
server = BraveSearchMCPServer()
sse_server(server, port=8080) Troubleshooting
- If the server does not start, verify Python version and
mcpinstallation. - If no responses are received, check that the MCP client (Brave search) is correctly configured to connect to your server.
- Use logging inside
handle_requestto debug incoming requests and responses.
Key Takeaways
- Use the official
mcpPython SDK to implement Brave search MCP servers. - Run the server with
stdio_server()for stdio transport orsse_server()for SSE transport. - Customize
handle_requestto process incoming requests and integrate with Brave search APIs. - Ensure environment and dependencies are correctly set up to avoid connection issues.