get_commentaries
Retrieve a list of commentary references for a Jewish text by specifying its reference. Facilitates access to traditional interpretations and analyses within the Sefaria library.
Instructions
get a list of references of commentaries for a jewish text
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| reference | Yes | the reference of the jewish text, e.g. 'שולחן ערוך אורח חיים סימן א' or 'Genesis 1:1' |
Implementation Reference
- The primary handler function that implements the core logic for retrieving a list of commentary references for a given Jewish text reference using the Sefaria API's related links endpoint.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
- MCP server tool call handler branch that dispatches the 'get_commentaries' tool: extracts 'reference' argument, calls the core handler, joins results, and returns MCP-formatted TextContent response.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)}" )]
- JSON schema definition for the 'get_commentaries' tool input (requires 'reference' string), including description; part of the tool registration in handle_list_tools().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"], }, ),
- src/sefaria_jewish_library/server.py:35-64 (registration)Tool registration via @server.list_tools(): returns the list of available tools including 'get_commentaries' with its schema.return [ types.Tool( name="get_text", description="get a jewish text from the jewish library", inputSchema={ "type": "object", "properties": { "reference": { "type": "string", "description": "The reference of the jewish text, e.g. 'שולחן ערוך אורח חיים סימן א' or 'Genesis 1:1'", }, }, "required": ["reference"], }, ), 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"], }, ), ]
- Utility helper function called by get_commentaries to perform HTTP GET requests to the Sefaria API and handle JSON responses.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