Skip to main content
Glama

import_bibtex

Add BibTeX entries to Zotero for organized reference management. Specify a collection to organize imported citations.

Instructions

Import BibTeX entries into Zotero

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bibtexYes
collection_keyNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The tool registration and entry point for importing BibTeX.
    @mcp.tool(description="Import BibTeX entries into Zotero")
    def import_bibtex(bibtex: str, collection_key: str = "") -> str:
        """Parse BibTeX string and create items in Zotero."""
        keys = _get_client().import_bibtex(bibtex, collection_key)
        return json.dumps({"created_keys": keys, "count": len(keys)}, ensure_ascii=False)
  • The business logic implementation for processing BibTeX string and creating items.
    def import_bibtex(self, bibtex: str, collection_key: str = "") -> list[str]:
        """Import BibTeX entries. Returns list of created item keys."""
        entries = self._parse_bibtex(bibtex)
        keys = []
        for entry in entries:
            if collection_key:
                entry["collections"] = [collection_key]
            resp = self.zot.create_items([entry])
            created = resp.get("successful", resp.get("success", {}))
            if created:
                val = list(created.values())[0] if isinstance(created, dict) else created[0]
                key = val.get("key", val.get("data", {}).get("key", "")) if isinstance(val, dict) else str(val)
                keys.append(key)
        return keys
  • The helper function that performs the actual regex-based parsing of the BibTeX input string.
    @staticmethod
    def _parse_bibtex(bibtex: str) -> list[dict]:
        """Parse BibTeX string into Zotero item dicts."""
        entries = []
        pattern = r"@(\w+)\{([^,]*),(.*?)\n\}"
        for match in re.finditer(pattern, bibtex, re.DOTALL):
            bib_type = match.group(1).lower()
            body = match.group(3)
    
            type_map = {
                "article": "journalArticle",
                "inproceedings": "conferencePaper",
                "conference": "conferencePaper",
                "book": "book",
                "incollection": "bookSection",
                "phdthesis": "thesis",
                "mastersthesis": "thesis",
                "misc": "document",
                "techreport": "report",
            }
            item_type = type_map.get(bib_type, "document")
    
            fields = {}
            for fmatch in re.finditer(r"(\w+)\s*=\s*\{(.*?)\}", body, re.DOTALL):
                fields[fmatch.group(1).lower()] = fmatch.group(2).strip()
    
            creators = []
            if "author" in fields:
                for author in re.split(r"\s+and\s+", fields["author"]):
                    parts = [p.strip() for p in author.split(",", 1)]
                    if len(parts) == 2:
                        creators.append({
                            "creatorType": "author",
                            "firstName": parts[1],
                            "lastName": parts[0],
                        })
                    else:
                        name_parts = parts[0].rsplit(" ", 1)
                        creators.append({
                            "creatorType": "author",
                            "firstName": name_parts[0] if len(name_parts) > 1 else "",
                            "lastName": name_parts[-1],
                        })
    
            item = {
                "itemType": item_type,
                "title": fields.get("title", ""),
                "creators": creators,
                "date": fields.get("year", ""),
                "DOI": fields.get("doi", ""),
                "url": fields.get("url", ""),
                "abstractNote": fields.get("abstract", ""),
            }
    
            if item_type == "journalArticle":
                item["publicationTitle"] = fields.get("journal", "")
                item["volume"] = fields.get("volume", "")
                item["pages"] = fields.get("pages", "")
            elif item_type == "conferencePaper":
                item["conferenceName"] = fields.get("booktitle", "")
            elif item_type == "bookSection":
                item["bookTitle"] = fields.get("booktitle", "")
            elif item_type == "book":
                item["publisher"] = fields.get("publisher", "")
    
            entries.append(item)
    
        return entries
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the basic action without disclosing behavioral traits. It doesn't mention permissions required, whether imports are reversible, rate limits, or what happens on failure (e.g., invalid BibTeX). This leaves significant gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words, making it easy to parse and front-loaded. It directly conveys the core purpose without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (which handles return values) and no annotations, the description is minimally adequate but incomplete. It covers the basic action but lacks details on parameters, behavioral context, and differentiation from siblings, which are needed for a mutation tool with 2 parameters.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate but adds no parameter details. It doesn't explain what 'bibtex' should contain (e.g., raw BibTeX text) or what 'collection_key' does (e.g., target collection identifier), leaving both parameters undocumented beyond their schema types.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('import') and target ('BibTeX entries into Zotero'), making the tool's purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'create_item' or 'create_item_from_doi' that might also add content to Zotero, missing explicit distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives such as 'create_item' or 'create_item_from_doi', nor does it mention prerequisites like needing valid BibTeX format. Usage is implied but not explicitly stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/BirdInTheTree/zotero-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server