Skip to content

Commit 1c0f199

Browse files
fix: type account param as Optional[str] to fix single-account tool failures
1 parent 786243d commit 1c0f199

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

telegram_mcp/tools/contacts.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""Contacts MCP tools."""
22

33
from telegram_mcp.runtime import *
4+
from typing import Optional
45

56

67
@mcp.tool(
78
annotations=ToolAnnotations(title="List Contacts", openWorldHint=True, readOnlyHint=True)
89
)
910
@with_account(readonly=True)
10-
async def list_contacts(account: str = None) -> str:
11+
async def list_contacts(account: Optional[str] = None) -> str:
1112
"""
1213
List all contacts in your Telegram account.
1314
@@ -43,7 +44,7 @@ async def list_contacts(account: str = None) -> str:
4344
annotations=ToolAnnotations(title="Search Contacts", openWorldHint=True, readOnlyHint=True)
4445
)
4546
@with_account(readonly=True)
46-
async def search_contacts(query: str, account: str = None) -> str:
47+
async def search_contacts(query: str, account: Optional[str] = None) -> str:
4748
"""
4849
Search for contacts by name, username, or phone number using Telethon's SearchRequest.
4950
Args:
@@ -81,7 +82,7 @@ async def search_contacts(query: str, account: str = None) -> str:
8182
annotations=ToolAnnotations(title="Get Contact Ids", openWorldHint=True, readOnlyHint=True)
8283
)
8384
@with_account(readonly=True)
84-
async def get_contact_ids(account: str = None) -> str:
85+
async def get_contact_ids(account: Optional[str] = None) -> str:
8586
"""
8687
Get all contact IDs in your Telegram account.
8788
"""
@@ -102,7 +103,7 @@ async def get_contact_ids(account: str = None) -> str:
102103
)
103104
)
104105
@with_account(readonly=True)
105-
async def get_direct_chat_by_contact(contact_query: str, account: str = None) -> str:
106+
async def get_direct_chat_by_contact(contact_query: str, account: Optional[str] = None) -> str:
106107
"""
107108
Find a direct chat with a specific contact by name, username, or phone.
108109
@@ -168,7 +169,7 @@ async def get_direct_chat_by_contact(contact_query: str, account: str = None) ->
168169
)
169170
@with_account(readonly=True)
170171
@validate_id("contact_id")
171-
async def get_contact_chats(contact_id: Union[int, str], account: str = None) -> str:
172+
async def get_contact_chats(contact_id: Union[int, str], account: Optional[str] = None) -> str:
172173
"""
173174
List all chats involving a specific contact.
174175
@@ -237,7 +238,7 @@ async def get_contact_chats(contact_id: Union[int, str], account: str = None) ->
237238
)
238239
@with_account(readonly=True)
239240
@validate_id("contact_id")
240-
async def get_last_interaction(contact_id: Union[int, str], account: str = None) -> str:
241+
async def get_last_interaction(contact_id: Union[int, str], account: Optional[str] = None) -> str:
241242
"""
242243
Get the most recent message with a contact.
243244
@@ -291,7 +292,7 @@ async def get_last_interaction(contact_id: Union[int, str], account: str = None)
291292
)
292293
@with_account(readonly=False)
293294
async def add_contact(
294-
account: str = None,
295+
account: Optional[str] = None,
295296
phone: Optional[str] = None,
296297
first_name: str = "",
297298
last_name: str = "",
@@ -428,7 +429,7 @@ async def add_contact(
428429
)
429430
@with_account(readonly=False)
430431
@validate_id("user_id")
431-
async def delete_contact(user_id: Union[int, str], account: str = None) -> str:
432+
async def delete_contact(user_id: Union[int, str], account: Optional[str] = None) -> str:
432433
"""
433434
Delete a contact by user ID.
434435
Args:
@@ -450,7 +451,7 @@ async def delete_contact(user_id: Union[int, str], account: str = None) -> str:
450451
)
451452
@with_account(readonly=False)
452453
@validate_id("user_id")
453-
async def block_user(user_id: Union[int, str], account: str = None) -> str:
454+
async def block_user(user_id: Union[int, str], account: Optional[str] = None) -> str:
454455
"""
455456
Block a user by user ID.
456457
Args:
@@ -472,7 +473,7 @@ async def block_user(user_id: Union[int, str], account: str = None) -> str:
472473
)
473474
@with_account(readonly=False)
474475
@validate_id("user_id")
475-
async def unblock_user(user_id: Union[int, str], account: str = None) -> str:
476+
async def unblock_user(user_id: Union[int, str], account: Optional[str] = None) -> str:
476477
"""
477478
Unblock a user by user ID.
478479
Args:
@@ -491,7 +492,7 @@ async def unblock_user(user_id: Union[int, str], account: str = None) -> str:
491492
annotations=ToolAnnotations(title="Import Contacts", openWorldHint=True, destructiveHint=True)
492493
)
493494
@with_account(readonly=False)
494-
async def import_contacts(contacts: list, account: str = None) -> str:
495+
async def import_contacts(contacts: list, account: Optional[str] = None) -> str:
495496
"""
496497
Import a list of contacts. Each contact should be a dict with phone, first_name, last_name.
497498
"""
@@ -517,7 +518,7 @@ async def import_contacts(contacts: list, account: str = None) -> str:
517518
annotations=ToolAnnotations(title="Export Contacts", openWorldHint=True, readOnlyHint=True)
518519
)
519520
@with_account(readonly=True)
520-
async def export_contacts(account: str = None) -> str:
521+
async def export_contacts(account: Optional[str] = None) -> str:
521522
"""
522523
Export all contacts as a JSON string.
523524
"""
@@ -535,7 +536,7 @@ async def export_contacts(account: str = None) -> str:
535536
annotations=ToolAnnotations(title="Get Blocked Users", openWorldHint=True, readOnlyHint=True)
536537
)
537538
@with_account(readonly=True)
538-
async def get_blocked_users(account: str = None) -> str:
539+
async def get_blocked_users(account: Optional[str] = None) -> str:
539540
"""
540541
Get a list of blocked users.
541542
"""
@@ -559,7 +560,7 @@ async def send_contact(
559560
first_name: str,
560561
last_name: str = "",
561562
vcard: str = "",
562-
account: str = None,
563+
account: Optional[str] = None,
563564
) -> str:
564565
"""
565566
Send a contact to a chat.

0 commit comments

Comments
 (0)