This repository now contains a complete implementation of a Brave Search MCP (Model Context Protocol) Server, enabling AI applications and agents to perform privacy-focused web searches through a standardized interface.
-
TypeScript Project Setup
- package.json with all required dependencies
- tsconfig.json with strict type checking
- .gitignore for Node.js/TypeScript projects
- .env.example for configuration
-
MCP Server Implementation
- Main server in
src/index.tsusing @modelcontextprotocol/sdk - Configuration management in
src/config.ts - Brave API client in
src/brave-api.ts
- Main server in
-
Search Tools (in
src/tools/)- web-search.ts - General web search
- local-search.ts - Local business search
- image-search.ts - Image search
- video-search.ts - Video search
- news-search.ts - News article search
- summarizer.ts - AI-powered summarization
- ✅ STDIO transport protocol support
- ✅ Environment-based configuration
- ✅ Zod schema validation for all inputs
- ✅ Type-safe TypeScript implementation
- ✅ Proper error handling
- ✅ Formatted markdown output for search results
- ✅ Support for all major Brave Search API endpoints
- ✅ Code compiles without errors
- ✅ CodeQL security scan passed (0 alerts)
- ✅ Code review completed and issues addressed
- ✅ Magic numbers extracted to constants
- ✅ Undefined value handling implemented
- ✅ No hardcoded secrets
- ✅ Comprehensive README with setup instructions
- ✅ Tool usage examples
- ✅ Integration guide for Claude Desktop
- ✅ Contributing guidelines
- ✅ MIT License
-
Setup
npm install cp .env.example .env # Add your BRAVE_API_KEY to .env npm run build -
Run
npm start # Production npm run dev # Development
-
Integrate with Claude Desktop Add to
claude_desktop_config.json:{ "mcpServers": { "brave-search": { "command": "node", "args": ["/path/to/Prime-security/dist/index.js"], "env": { "BRAVE_API_KEY": "your_api_key_here" } } } }
┌─────────────────┐
│ MCP Client │
│ (Claude, etc.) │
└────────┬────────┘
│ STDIO
│
┌────────▼────────┐
│ MCP Server │
│ (index.ts) │
├─────────────────┤
│ Tool Registry │
├─────────────────┤
│ Brave API │
│ Client │
└────────┬────────┘
│ HTTPS
│
┌────────▼────────┐
│ Brave Search │
│ API │
└─────────────────┘
-
API Key Protection
- API key stored in environment variables
- .env file excluded from git
- Example file provided without real credentials
-
Input Validation
- All user inputs validated with Zod schemas
- Type constraints enforced at runtime
- No direct string concatenation for API calls
-
Error Handling
- API errors caught and wrapped
- No sensitive data in error messages
- Proper error propagation to MCP client
-
Type Safety
- Strict TypeScript configuration
- Runtime validation with Zod
- No unsafe type assertions
- HTTP Transport: Not yet implemented (STDIO only)
- Type Definitions: Using
anyfor Brave API responses (common for third-party APIs) - Testing: No unit tests yet (can be added in future iterations)
- Caching: No result caching (direct API calls for every request)
- Add HTTP transport support
- Implement response caching
- Add comprehensive unit tests
- Create TypeScript interfaces for Brave API responses
- Add rate limiting protection
- Implement request retry logic
- Add telemetry and logging options
- @modelcontextprotocol/sdk: ^1.0.4
- dotenv: ^16.4.7
- zod: ^3.24.1
- @types/node: ^22.10.2
- tsx: ^4.19.2
- typescript: ^5.7.2
MIT License - See LICENSE file for details