Skip to main content
Glama

export_bibtex

Generate a BibTeX file from HTML hyperlinks by fetching and combining BibTeX entries, replacing citation keys, and saving results with a timestamped filename.

Instructions

Export BibTeX entries from a collection of HTML hyperlinks. Arguments:

  • links (string, required): HTML string containing one or more key links. The href attribute should contain a URL to a BibTeX file, and the link text is used as the citation key. Example input with three links: "<a href=https://dblp.org/rec/journals/example1.bib>Smith2023 <a href=https://dblp.org/rec/conf/example2.bib>Jones2022 <a href=https://dblp.org/rec/journals/example3.bib>Brown2021" Process:

  • For each link, the tool fetches the BibTeX content from the URL

  • The citation key in each BibTeX entry is replaced with the key from the link text

  • All entries are combined and saved to a .bib file with a timestamp filename Returns:

  • A message with the full path to the saved .bib file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
linksYes

Implementation Reference

  • Handler for the 'export_bibtex' tool: validates input, calls helper to export BibTeX entries to file, clears the session buffer, and returns success message.
    case "export_bibtex":
        if not bibtex_buffer:
            return [
                types.TextContent(
                    type="text",
                    text="Error: Collection is empty. Add entries using add_bibtex_entry first.",
                )
            ]
    
        path = arguments.get("path")
        if not path:
            return [
                types.TextContent(
                    type="text",
                    text="Error: Missing required parameter 'path'",
                )
            ]
    
        # Convert dict values to list for writing
        entries = list(bibtex_buffer.values())
        filepath = export_bibtex_entries(entries, path)
    
        count = len(bibtex_buffer)
        bibtex_buffer.clear()  # Clear after export
    
        return [
            types.TextContent(
                type="text", text=f"Exported {count} references to {filepath}"
            )
        ]
    case _:
  • Tool schema definition for 'export_bibtex', including name registration, description, and input schema requiring 'path' parameter.
    types.Tool(
        name="export_bibtex",
        description=(
            "Export all collected BibTeX entries to a .bib file. Call this after adding all entries with add_bibtex_entry.\n"
            "Workflow:\n"
            "  1. Saves all collected entries to a .bib file at the specified path\n"
            "  2. Clears the collection for next export\n"
            "  3. Returns the full path to the exported file\n"
            "Returns error if no entries have been added yet."
        ),
        inputSchema={
            "type": "object",
            "properties": {
                "path": {
                    "type": "string",
                    "description": "Absolute path for the .bib file (e.g., '/path/to/refs.bib'). The .bib extension is added automatically if missing. Parent directories are created if needed.",
                },
            },
            "required": ["path"],
        },
    ),
  • Helper function that writes the list of BibTeX entries to the specified file path, auto-adding .bib extension and creating directories.
    def export_bibtex_entries(entries, path):
        """Export BibTeX entries to a file at the specified path."""
        # Ensure .bib extension
        if not path.endswith(".bib"):
            path = f"{path}.bib"
    
        # Create parent directories if needed
        parent_dir = os.path.dirname(path)
        if parent_dir:
            os.makedirs(parent_dir, exist_ok=True)
    
        with open(path, "w", encoding="utf-8") as f:
            for entry in entries:
                f.write(entry + "\n\n")
    
        return path

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Related 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/szeider/mcp-dblp'

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