From 0185e2e36b9582dc09855de3a799725951eec38a Mon Sep 17 00:00:00 2001 From: Ivan Kolodrivskyi Date: Wed, 8 Apr 2026 19:22:05 +0300 Subject: [PATCH 1/2] feat: add send_contact tool to send phone contacts via MCP --- main.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/main.py b/main.py index 77a4470..dab5049 100644 --- a/main.py +++ b/main.py @@ -3609,6 +3609,49 @@ async def send_gif(chat_id: Union[int, str], gif_id: int) -> str: return log_and_format_error("send_gif", e, chat_id=chat_id, gif_id=gif_id) +@mcp.tool(annotations=ToolAnnotations(title="Send Contact", openWorldHint=True, destructiveHint=True)) +@validate_id("chat_id") +async def send_contact( + chat_id: Union[int, str], + phone_number: str, + first_name: str, + last_name: str = "", + vcard: str = "", +) -> str: + """ + Send a contact to a chat. + Args: + chat_id: The chat ID or username. + phone_number: Contact's phone number. + first_name: Contact's first name. + last_name: Contact's last name (optional). + vcard: Additional vCard data (optional). + """ + try: + entity = await resolve_entity(chat_id) + from telethon.tl.types import InputMediaContact + import random + + await client( + functions.messages.SendMediaRequest( + peer=entity, + media=InputMediaContact( + phone_number=phone_number, + first_name=first_name, + last_name=last_name, + vcard=vcard, + ), + message="", + random_id=random.randint(0, 2**63 - 1), + ) + ) + return f"Contact sent to chat {chat_id}." + except Exception as e: + return log_and_format_error( + "send_contact", e, chat_id=chat_id, phone_number=phone_number + ) + + @mcp.tool(annotations=ToolAnnotations(title="Get Bot Info", openWorldHint=True, readOnlyHint=True)) async def get_bot_info(bot_username: str) -> str: """ From e2ca3c78feaeac5dfeaceb7f55e9c65db6538ff7 Mon Sep 17 00:00:00 2001 From: Ivan Kolodrivskyi Date: Thu, 9 Apr 2026 09:23:07 +0300 Subject: [PATCH 2/2] style: apply black formatting to send_contact --- main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index dab5049..a1f7f65 100644 --- a/main.py +++ b/main.py @@ -3609,7 +3609,9 @@ async def send_gif(chat_id: Union[int, str], gif_id: int) -> str: return log_and_format_error("send_gif", e, chat_id=chat_id, gif_id=gif_id) -@mcp.tool(annotations=ToolAnnotations(title="Send Contact", openWorldHint=True, destructiveHint=True)) +@mcp.tool( + annotations=ToolAnnotations(title="Send Contact", openWorldHint=True, destructiveHint=True) +) @validate_id("chat_id") async def send_contact( chat_id: Union[int, str], @@ -3647,9 +3649,7 @@ async def send_contact( ) return f"Contact sent to chat {chat_id}." except Exception as e: - return log_and_format_error( - "send_contact", e, chat_id=chat_id, phone_number=phone_number - ) + return log_and_format_error("send_contact", e, chat_id=chat_id, phone_number=phone_number) @mcp.tool(annotations=ToolAnnotations(title="Get Bot Info", openWorldHint=True, readOnlyHint=True))