fix: address PR #574 review comments

Restore contact email/birthday/nickname data and per-event calendar
source that were silently dropped during response model wrapping.
Remove dead elif branches in OAuth deck tests, add regression tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-02-20 09:39:46 +01:00
co-authored by Claude Opus 4.6
parent 8887aa241a
commit 76e305006c
5 changed files with 176 additions and 29 deletions
+28 -7
View File
@@ -8,6 +8,7 @@ from nextcloud_mcp_server.context import get_client
from nextcloud_mcp_server.models.contacts import (
AddressBook,
Contact,
ContactField,
ListAddressBooksResponse,
ListContactsResponse,
)
@@ -52,14 +53,34 @@ def configure_contacts_tools(mcp: FastMCP):
"""List all contacts in the specified addressbook."""
client = await get_client(ctx)
contacts_data = await client.contacts.list_contacts(addressbook=addressbook)
contacts = [
Contact(
uid=c["vcard_id"],
fn=c.get("contact", {}).get("fullname", ""),
etag=c.get("getetag"),
contacts = []
for c in contacts_data:
contact_info = c.get("contact", {})
# Convert email field (str, list, or None) to list[ContactField]
raw_email = contact_info.get("email")
emails: list[ContactField] = []
if isinstance(raw_email, list):
emails = [ContactField(type="email", value=e) for e in raw_email if e]
elif isinstance(raw_email, str) and raw_email:
emails = [ContactField(type="email", value=raw_email)]
# Nickname goes into custom_fields (no dedicated model field)
custom_fields: dict[str, str] = {}
nickname = contact_info.get("nickname")
if nickname:
custom_fields["nickname"] = nickname
contacts.append(
Contact(
uid=c["vcard_id"],
fn=contact_info.get("fullname", ""),
etag=c.get("getetag"),
birthday=contact_info.get("birthday"),
emails=emails,
custom_fields=custom_fields,
)
)
for c in contacts_data
]
return ListContactsResponse(
contacts=contacts, addressbook=addressbook, total_count=len(contacts)
)