Merge pull request #75 from mxl/feat/search-public-chats-pagination
Add limit parameter to public chat search
This commit is contained in:
commit
418cc8bbd1
2 changed files with 8 additions and 7 deletions
|
|
@ -116,7 +116,7 @@ This MCP server exposes a huge suite of Telegram tools. **Every major Telegram/T
|
||||||
- **edit_chat_photo(chat_id, file_path)**: Update chat photo from allowed roots
|
- **edit_chat_photo(chat_id, file_path)**: Update chat photo from allowed roots
|
||||||
|
|
||||||
### Search & Discovery
|
### Search & Discovery
|
||||||
- **search_public_chats(query)**: Search public chats/channels/bots
|
- **search_public_chats(query, limit)**: Search public chats/channels/bots with a configurable result limit
|
||||||
- **search_messages(chat_id, query, limit)**: Search messages in a chat
|
- **search_messages(chat_id, query, limit)**: Search messages in a chat
|
||||||
- **resolve_username(username)**: Resolve a username to ID
|
- **resolve_username(username)**: Resolve a username to ID
|
||||||
|
|
||||||
|
|
@ -533,13 +533,14 @@ Successfully joined chat: Developer Community
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
async def search_public_chats(query: str) -> str:
|
async def search_public_chats(query: str, limit: int = 20) -> str:
|
||||||
"""
|
"""
|
||||||
Search for public chats, channels, or bots by username or title.
|
Search for public chats, channels, or bots by username or title.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
result = await client(functions.contacts.SearchRequest(q=query, limit=20))
|
result = await client(functions.contacts.SearchRequest(q=query, limit=limit))
|
||||||
return json.dumps([format_entity(u) for u in result.users], indent=2)
|
entities = [format_entity(e) for e in result.chats + result.users]
|
||||||
|
return json.dumps(entities, indent=2)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"Error searching public chats: {e}"
|
return f"Error searching public chats: {e}"
|
||||||
```
|
```
|
||||||
|
|
|
||||||
6
main.py
6
main.py
|
|
@ -3196,16 +3196,16 @@ async def get_media_info(chat_id: Union[int, str], message_id: int) -> str:
|
||||||
@mcp.tool(
|
@mcp.tool(
|
||||||
annotations=ToolAnnotations(title="Search Public Chats", openWorldHint=True, readOnlyHint=True)
|
annotations=ToolAnnotations(title="Search Public Chats", openWorldHint=True, readOnlyHint=True)
|
||||||
)
|
)
|
||||||
async def search_public_chats(query: str) -> str:
|
async def search_public_chats(query: str, limit: int = 20) -> str:
|
||||||
"""
|
"""
|
||||||
Search for public chats, channels, or bots by username or title.
|
Search for public chats, channels, or bots by username or title.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
result = await client(functions.contacts.SearchRequest(q=query, limit=20))
|
result = await client(functions.contacts.SearchRequest(q=query, limit=limit))
|
||||||
entities = [format_entity(e) for e in result.chats + result.users]
|
entities = [format_entity(e) for e in result.chats + result.users]
|
||||||
return json.dumps(entities, indent=2)
|
return json.dumps(entities, indent=2)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return log_and_format_error("search_public_chats", e, query=query)
|
return log_and_format_error("search_public_chats", e, query=query, limit=limit)
|
||||||
|
|
||||||
|
|
||||||
@mcp.tool(
|
@mcp.tool(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue