BirdNet-Pi MCP server

Integrates BirdNet-Pi's bird detection capabilities with a JSON-RPC interface, enabling retrieval and analysis of acoustic monitoring data for ornithological research and conservation efforts.
Back to servers
Setup instructions
Provider
DMontgomery40
Release date
Nov 27, 2024
Language
Python
Stats
3 stars

This MCP server for BirdNet-Pi provides an API to access bird detection data, audio recordings, detection statistics, and reporting capabilities. It follows the Model Context Protocol to integrate seamlessly with BirdNet-Pi systems.

Installation

Prerequisites

  • Python 3.8 or newer
  • The following Python packages:
    • FastAPI
    • Uvicorn
    • Other dependencies (included in requirements.txt)

Setup Steps

  1. Clone the repository:

    git clone https://github.com/YourUsername/mcp-server.git
    cd mcp-server
    
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows use: venv\Scripts\activate
    
  3. Install required dependencies:

    pip install -r requirements.txt
    
  4. Create necessary data directories:

    mkdir -p data/audio data/reports
    

Configuration

The server can be customized through environment variables:

  • BIRDNET_DETECTIONS_FILE: Location of the detections JSON file (default: 'data/detections.json')
  • BIRDNET_AUDIO_DIR: Directory for audio files (default: 'data/audio')
  • BIRDNET_REPORT_DIR: Directory for generated reports (default: 'data/reports')

Example configuration

# Set custom paths
export BIRDNET_DETECTIONS_FILE=/path/to/my/detections.json
export BIRDNET_AUDIO_DIR=/path/to/audio/files

Running the Server

To start the MCP server:

python server.py

The server will be accessible at http://localhost:8000.

Using the API

The server provides two main endpoints:

  • GET /functions: Lists all available functions
  • POST /invoke: Executes a specific function

Available Functions

Get Bird Detections

Retrieve bird detection data with filtering options:

{
  "name": "getBirdDetections",
  "parameters": {
    "startDate": "2023-01-01",
    "endDate": "2023-01-31",
    "species": "American Robin"
  }
}

Get Detection Statistics

Obtain statistics about detections over a time period:

{
  "name": "getDetectionStats",
  "parameters": {
    "period": "week",
    "minConfidence": 0.75
  }
}

Valid period values: 'day', 'week', 'month', 'all'

Access Audio Recordings

Retrieve audio recordings associated with detections:

{
  "name": "getAudioRecording",
  "parameters": {
    "filename": "recording_20230115_072530.wav",
    "format": "base64"
  }
}

Format options: 'base64' or 'buffer'

View Daily Activity Patterns

Analyze bird activity patterns for specific dates:

{
  "name": "getDailyActivity",
  "parameters": {
    "date": "2023-01-15",
    "species": "Northern Cardinal"
  }
}

Generate Reports

Create summarized reports of bird detections:

{
  "name": "generateDetectionReport",
  "parameters": {
    "startDate": "2023-01-01",
    "endDate": "2023-01-31",
    "format": "html"
  }
}

Format options: 'html' or 'json'

Example API Usage

Using curl to list available functions:

curl -X GET http://localhost:8000/functions

Using curl to retrieve recent detections:

curl -X POST http://localhost:8000/invoke \
  -H "Content-Type: application/json" \
  -d '{
    "name": "getBirdDetections",
    "parameters": {
      "startDate": "2023-01-01",
      "endDate": "2023-01-31"
    }
  }'

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "birdnet-pi" '{"command":"python","args":["server.py"]}'

See the official Claude Code MCP documentation for more details.

For 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 > Tools & Integrations and click "New MCP Server".

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

{
    "mcpServers": {
        "birdnet-pi": {
            "command": "python",
            "args": [
                "server.py"
            ]
        }
    }
}

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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "birdnet-pi": {
            "command": "python",
            "args": [
                "server.py"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

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