Skip to content

Fix get_sources and get_events missing event-level source citations - #7

Open
dmarshall-rgb wants to merge 5 commits into
airy10:mainfrom
dmarshall-rgb:fix-get-sources-missing-gedcom-event-citations
Open

Fix get_sources and get_events missing event-level source citations#7
dmarshall-rgb wants to merge 5 commits into
airy10:mainfrom
dmarshall-rgb:fix-get-sources-missing-gedcom-event-citations

Conversation

@dmarshall-rgb

Copy link
Copy Markdown
Contributor

Three related gaps in citation resolution, all sharing the same root cause: GEDCOM SOUR citations nested under a specific event (BIRT, DEAT, MARR, etc.) or attribute were either invisible entirely or only captured as a bare pointer string.

  1. _get_sources_internal only scanned an entity's direct top-level children for SOUR, missing any citation nested inside an event or (for a person) inside a FAMS-linked family's events (e.g. MARR).

  2. decode_event_details captured event-level SOUR citations but only stored the raw pointer string, never resolving title/author/publication/repository/page/quality, nor the previously-uncaptured DATA/TEXT, DATA/DATE, and citation-level NOTE.

  3. The ATTRIBUTE_TYPES branch in _get_events_internal had an independent, separately-shallow copy of the same SOUR-as-bare-string bug.

Fix: added a shared _resolve_source_citation(sour_element, gedcom_ctx) helper that fully resolves a single SOUR element, and applied it at all three call sites. _get_sources_internal now also scans EVENT_TYPES-matching children (and FAMS-linked family events, for persons) the same way _get_events_internal already does, tagging each result with which event (and family_id, where applicable) it supports.

Verified against Thomas Marshall (@i54@) in a real FTM export: get_sources now returns all 8 event-level citations (2 BIRT, 1 RESI, 2 DEAT, 3 MARR across two marriages) with full bibliographic and citation detail, matching get_events output exactly. Tested via direct repro scripts and live MCP tool calls.

Three related gaps in citation resolution, all sharing the same root cause: GEDCOM SOUR citations nested under a specific event (BIRT, DEAT, MARR, etc.) or attribute were either invisible entirely or only captured as a bare pointer string.

1. _get_sources_internal only scanned an entity's direct top-level children for SOUR, missing any citation nested inside an event or (for a person) inside a FAMS-linked family's events (e.g. MARR).

2. decode_event_details captured event-level SOUR citations but only stored the raw pointer string, never resolving title/author/publication/repository/page/quality, nor the previously-uncaptured DATA/TEXT, DATA/DATE, and citation-level NOTE.

3. The ATTRIBUTE_TYPES branch in _get_events_internal had an independent, separately-shallow copy of the same SOUR-as-bare-string bug.

Fix: added a shared _resolve_source_citation(sour_element, gedcom_ctx) helper that fully resolves a single SOUR element, and applied it at all three call sites. _get_sources_internal now also scans EVENT_TYPES-matching children (and FAMS-linked family events, for persons) the same way _get_events_internal already does, tagging each result with which event (and family_id, where applicable) it supports.

Verified against Thomas Marshall (@i54@) in a real FTM export: get_sources now returns all 8 event-level citations (2 BIRT, 1 RESI, 2 DEAT, 3 MARR across two marriages) with full bibliographic and citation detail, matching get_events output exactly. Tested via direct repro scripts and live MCP tool calls.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a helper function _resolve_source_citation to parse detailed source citations and integrates it into event decoding and source retrieval. It also fixes a bug in _get_notes_internal where notes were prematurely truncated due to an incorrect break statement, and enhances _get_sources_internal to extract event-level citations for individuals and families. The review feedback suggests ensuring that citation fields default to empty strings if their values are None to maintain type consistency, and extending the source extraction logic to include attributes (ATTRIBUTE_TYPES) in addition to events.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/gedcom_mcp/gedcom_data_access.py Outdated
Comment thread src/gedcom_mcp/gedcom_data_access.py Outdated
Comment on lines +428 to +433
if tag == "PAGE":
citation["page"] = value
elif tag == "QUAY":
citation["quality"] = value
elif tag == "NOTE":
citation["note"] = value

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similarly, ensure that citation-specific fields remain strings by defaulting to an empty string if value is None.

Suggested change
if tag == "PAGE":
citation["page"] = value
elif tag == "QUAY":
citation["quality"] = value
elif tag == "NOTE":
citation["note"] = value
if tag == "PAGE":
citation["page"] = value or ""
elif tag == "QUAY":
citation["quality"] = value or ""
elif tag == "NOTE":
citation["note"] = value or ""

Comment thread src/gedcom_mcp/gedcom_data_access.py Outdated
Comment thread src/gedcom_mcp/gedcom_data_access.py Outdated
dmarshall-rgb and others added 3 commits July 20, 2026 12:59
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@dmarshall-rgb

Copy link
Copy Markdown
Contributor Author

I Wanted to take a moment away from bug reports to say thank you for building and maintaining this project.

I came to GedcomMCP after running mcp-server-ancestry (now archived/deprecated) and hitting a data-loss bug there that put my confidence in it at zero. Finding this project — actively maintained, with a much richer and more thoughtfully structured tool set — was a real turning point for how I've been able to do genealogical research using Claude Desktop.

What's made the biggest difference isn't just that the tools work, but that when I have run into bugs (the ZeroDivisionError, the argument-order mismatch, the AKA-name selection issue, the FunctionTool shadowing bugs, the get_notes truncation, and now the missing event-level source citations), I've been able to actually track them down, fix them, and contribute them back rather than just working around them or reporting them into a void. That loop — find a real gap while doing actual family history research, patch it same day, verify it against real GEDCOM data, and ship it upstream — has been genuinely energizing, and it's meaningfully improved the tool for anyone else doing this kind of source-critical, citation-heavy genealogical work with an LLM.

Thanks again for putting in the work to build and maintain this. It's made a real difference.

…ations

Two related bugs found in _resolve_source_citation (introduced in this same branch):

1. The citation's DATA/TEXT field only read the first line, ignoring CONT/CONC continuation lines -- a multi-paragraph citation text (e.g. a transcribed will) was truncated to just its first line.

2. The citation's NOTE field was a single overwritable string, but GEDCOM allows multiple NOTE tags under one SOUR citation (e.g. FTM's separate 'Notes' tab and 'Web address' field both export as NOTE lines at the same level). The second NOTE silently overwrote the first.

Fix: added a shared _extract_cont_conc_text(element) helper that reassembles CONT/CONC continuation lines, matching the pattern already used elsewhere in this file. Applied it to DATA/TEXT to fix truncation. Changed the citation's note field from a single string to a notes list, appending each NOTE tag found (resolving @n...@ references via note_lookup, or reassembling inline CONT/CONC text) instead of overwriting.

Verified against a real citation (@s162@, attached to both a WILL and PROB event on @i62@) deliberately populated with distinct ~33-line content in both FTM's Notes tab and Web address field: text now returns the full citation text, and notes correctly returns both the full reference-note content and the separate URL note, matching manual .ged inspection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant