Skip to main content
Glama
OpenTorah-ai

Sefaria Jewish Library MCP Server

by OpenTorah-ai

get_commentaries

Retrieve commentary references for Jewish texts from the Sefaria library to analyze interpretations and scholarly perspectives.

Instructions

get a list of references of commentaries for a jewish text

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
referenceYesthe reference of the jewish text, e.g. 'שולחן ערוך אורח חיים סימן א' or 'Genesis 1:1'

Implementation Reference

  • Primary implementation of the get_commentaries tool. Queries the Sefaria API for related content to the given reference and returns a list of commentary references (sourceHeRef).
    async def get_commentaries(parasha_ref)-> list[str]:
        """
        Retrieves and filters commentaries on the given verse.
        """
        data = get_request_json_data("api/related/", parasha_ref)
    
        commentaries = []
        if data and "links" in data:
            for linked_text in data["links"]:
                if linked_text.get('type') == 'commentary':
                    commentaries.append(linked_text.get('sourceHeRef'))
    
        return commentaries
  • Registration of the 'get_commentaries' tool within the server's list_tools() method, defining its name, description, and input schema.
    types.Tool(
        name="get_commentaries",
        description="get a list of references of commentaries for a jewish text",
        inputSchema={
            "type": "object",
            "properties": {
                "reference": {
                    "type": "string",
                    "description": "the reference of the jewish text, e.g. 'שולחן ערוך אורח חיים סימן א' or 'Genesis 1:1'",
                },
            },
            "required": ["reference"],
        },
    ),
  • Server-side handler within call_tool() that processes requests for get_commentaries, invokes the tool implementation, and returns the result as MCP TextContent.
    elif name == "get_commentaries":
        try:
            reference = arguments.get("reference")
            if not reference:
                raise ValueError("Missing  parameter")
            logger.debug(f"handle_get_commentaries: {reference}")
            commentaries = await get_commentaries(reference)
            
            return [types.TextContent(
                type="text",
                text="\n".join(commentaries)
            )]
        except Exception as err:
            logger.error(f"retreive commentaries error: {err}", exc_info=True)
            return [types.TextContent(
                type="text",
                text=f"Error: {str(err)}"
            )]
  • Utility helper function used by get_commentaries to perform HTTP GET requests to the Sefaria API and retrieve JSON data.
    def get_request_json_data(endpoint, ref=None, param=None):
        """
        Helper function to make GET requests to the Sefaria API and parse the JSON response.
        """
        url = f"{SEFARIA_API_BASE_URL}/{endpoint}"
    
        if ref:
            url += f"{ref}"
    
        if param:
            url += f"?{param}"
    
        try:
            response = requests.get(url)
            response.raise_for_status()  # Raise an exception for bad status codes
            data = response.json()
            return data
        except requests.exceptions.RequestException as e:
            print(f"Error during API request: {e}")
            return None
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/OpenTorah-ai/mcp-sefaria-server'

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