type account param as Optional[str] to fix single-account tool failures - #137
Merged
Merged
Conversation
chigwell
approved these changes
Jun 3, 2026
KiaroSama
pushed a commit
to KiaroSama/telegram-mcp
that referenced
this pull request
Aug 25, 2026
…unt-param type account param as Optional[str] to fix single-account tool failures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
All tool functions declare the
accountparameter asaccount: str = None.In Pydantic v2, this generates a JSON schema that marks
accountas a requiredstring field — despite the
Nonedefault. When an LLM-backed MCP client receivesthis schema, it treats
accountas required and passes an empty string""whenit has no value to supply.
get_client("")then raises: ValueError: Unknown account ''. Available accounts: defaultThis breaks every tool call in single-account setups, which is the most common
configuration and is documented as supported.
How to reproduce
Set up the server in single-account mode. Connect any LLM-backed MCP client.
Then try these two prompts back to back:
Prompt 1 — fails:
The LLM picks
list_contactsorget_contact_ids, passesaccount="", and getsa
CONTACT-ERR-*error. The tool never executes.Prompt 2 — works (same intent, split into two steps):
In step one, the LLM picks
search_contactswhich has aqueryparam to focuson, so it omits
accountentirely.get_client(None)auto-selects the onlyconfigured account and succeeds. Step two then uses
chat_iddirectly, alsobypassing the
accountproblem.Same underlying intent. Same tools available. The only difference is whether
the LLM feels obligated to fill
account.Root cause
Pydantic v2 no longer infers
Optionalfromfield: str = None. The correctannotation is
Optional[str].With the correct annotation, LLM clients see
accountas optional and omit it.get_client(None)then auto-selects the single configured account, as intended.No logic in
runtime.pyneeded to change.Change
account: str = None→account: Optional[str] = Noneacross all tool files.No behavior change. No logic change. Purely a type annotation correction.
Files changed:
telegram_mcp/tools/contacts.py(will change other files in the similar manner after testing and verifying that no new issues are introduced)
Affected users
Anyone running single-account mode with an LLM-backed MCP client
(Claude Desktop via
langchain-mcp-adapters, Cursor, or similar).Direct programmatic callers are unaffected.