Zotero Model Context Protocol Server

repository·main·Indexed 41 days ago

https://github.com/kujenga/zotero-mcp

A Python-based Model Context Protocol (MCP) server version 0.3.1 that provides AI assistants access to Zotero libraries via the local desktop API or Zotero Web API. It includes tools for searching items (zotero_search_items), retrieving metadata (zotero_item_metadata), and extracting full-text content (zotero_item_fulltext).

Tokens
2.1K
Snippets
9
Records
12
Agent score
51%

What's inside Zotero MCP

  1. Install Zotero MCP via uvx (Local API)

    main

    To run the server using the local Zotero API with Claude Desktop, add the following configuration to your mcpServers settings. This method uses uvx to run the package directly.

    {
      "mcpServers": {
        "zotero": {
          "command": "uvx",
          "args": ["zotero-mcp@latest"],
          "env": {
            "ZOTERO_LOCAL": "true",
            "ZOTERO_API_KEY": "",
            "ZOTERO_LIBRARY_ID": ""
          }
        }
      }
    }
  2. Install Zotero MCP via Docker (Web API)

    main

    To run the server in a Docker container using the Zotero Web API, add the following to your mcpServers configuration. Replace PLACEHOLDER with your actual Zotero API key and Library ID.

    {
      "mcpServers": {
        "zotero": {
          "command": "docker",
          "args": [
            "run",
            "--rm",
            "-i",
            "-e", "ZOTERO_API_KEY=PLACEHOLDER",
            "-e", "ZOTERO_LIBRARY_ID=PLACEHOLDER",
            "ghcr.io/kujenga/zotero-mcp:main"
          ]
        }
      }
    }

    To update the image, run: docker pull ghcr.io/kujenga/zotero-mcp:main

  3. Enable the Zotero Local API

    main

    To use the server with the local Zotero desktop application (which is often more responsive), you must enable the local API in Zotero:

    1. Open the Zotero desktop application.
    2. Open Zotero Settings.
    3. Navigate to the Advanced tab.
    4. Check the box: "Allow other applications on this computer to communicate with Zotero".

    Note: The local API indexes citation keys for quick searches, whereas the Web API does not.

  4. Develop Zotero MCP locally

    main

    To contribute to or develop the Zotero MCP server:

    1. Clone the repository.
    2. Install dependencies using uv:
      uv sync
    3. Create a .env file in the project root and populate it with the required environment variables (ZOTERO_LOCAL, ZOTERO_API_KEY, etc.).

    Debugging with MCP Inspector

    To test the server locally using the MCP Inspector, run:

    npx @modelcontextprotocol/inspector uv run zotero-mcp

    Testing against Claude Desktop

    1. Find the path to your local virtual environment binary:
      echo $PWD/.venv/bin/zotero-mcp
    2. Add that path to your Claude Desktop configuration:
    ```json
    {
      "mcpServers": {
        "zotero": {
          "command": "/path/to/zotero-mcp/.venv/bin/zotero-mcp",
          "env": {
            "ZOTERO_LOCAL": "true"
          }
        }
      }
    }
  5. Configure Zotero MCP environment variables

    main

    The server uses the following environment variables for configuration:

    VariableDescription
    ZOTERO_LOCALSet to true to use the local Zotero desktop API. Default is false.
    ZOTERO_API_KEYYour Zotero Web API key (not required if ZOTERO_LOCAL=true).
    ZOTERO_LIBRARY_IDYour Zotero library ID (usually your User ID). Not required if ZOTERO_LOCAL=true.
    ZOTERO_LIBRARY_TYPEThe type of library: user or group. Default is user.
  6. Available Zotero MCP Tools

    main

    The Zotero MCP server provides three primary tools for interacting with your Zotero library through an AI assistant:

    • zotero_search_items: Search for items in your Zotero library using a text query.
    • zotero_item_metadata: Retrieves complete metadata for a specific item, including publication details, identifiers, timestamps, and library information.
    • zotero_item_fulltext: Retrieves the full text content of a specific item (e.g., the contents of a PDF).

    AI assistants can use these tools sequentially, for example, by searching for an item first and then retrieving its metadata or full text.

  7. Initialize a Zotero client with get_zotero_client()

    main

    Use get_zotero_client() to obtain an authenticated pyzotero.Zotero instance. The function automatically reads configuration from environment variables. It supports both the remote Zotero Web API and a local Zotero instance.

    Required Environment Variables

    • ZOTERO_LIBRARY_ID: Your Zotero library ID.
    • ZOTERO_API_KEY: Your Zotero API key (required for Web API).

    Optional Environment Variables

    • ZOTERO_LIBRARY_TYPE: The type of library (e.g., user or group). Defaults to user.
    • ZOTERO_LOCAL: Set to true, yes, or 1 to use the local Zotero API. When true, ZOTERO_LIBRARY_ID defaults to "0" if not provided.
    from zotero_mcp.client import get_zotero_client
    
    # This will use environment variables like ZOTERO_LIBRARY_ID and ZOTERO_API_KEY
    zot = get_zotero_client()
  8. Retrieve attachment details with get_attachment_details()

    main

    The get_attachment_details() function extracts the primary attachment information (ID and content type) for a given Zotero item.

    Behavior

    1. Direct Attachments: If the item itself is an attachment, it returns its key and contentType.
    2. Child Attachments: If the item is a regular bibliographic entry, the function searches for child attachments. It prioritizes attachments in the following order:
      • application/pdf (highest priority)
      • text/html
      • Other content types
    3. Tie-breaking: Within a content type group, the function selects the attachment with the largest size (using the md5 field as a proxy for size).
    4. Error Handling: If no attachments are found or an error occurs during lookup, the function returns None rather than raising an exception, allowing the caller to proceed with the available metadata.
    from zotero_mcp.client import get_zotero_client, get_attachment_details
    
    zot = get_zotero_client()
    item = {"data": {"key": "ABC12345", "itemType": "book"}}
    
    details = get_attachment_details(zot, item)
    if details:
        print(f"Key: {details.key}, Type: {details.content_type}")
  9. Configure Zotero MCP transport options

    main

    The CLI accepts the following transport configuration:

    FlagChoicesDefaultDescription
    --transportstdio, ssestdioThe communication protocol used by the MCP server. Use stdio for local process communication or sse for HTTP-based streaming.
    --transport
        choices=["stdio", "sse"]
        default="stdio"
        help="Transport to use"
  10. Start the Zotero MCP server via CLI

    main

    The Zotero Model Context Protocol (MCP) server can be started using the command line. You can specify the communication transport method using the --transport flag. By default, the server uses stdio transport, which is standard for local MCP integrations (e.g., with Claude Desktop). Alternatively, you can use sse (Server-Sent Events) for web-based transport.

    # Start with default stdio transport
    python -m zotero_mcp.cli
    
    # Start with SSE transport
    python -m zotero_mcp.cli --transport sse
  11. Use the AttachmentDetails data model

    main

    The AttachmentDetails class is a Pydantic model used to represent the metadata of a Zotero attachment.

    FieldTypeDescription
    keystrThe unique Zotero key for the attachment item.
    content_typestrThe MIME type of the attachment (e.g., application/pdf).
    from zotero_mcp.client import AttachmentDetails
    
    # Example of the structure returned by get_attachment_details
    details = AttachmentDetails(key="XYZ789", content_type="application/pdf")