Skip to content

API Reference parrot.integrations.telegram.mcp_persistence

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.integrations.telegram.mcp_persistence

View source

Telegram MCP Persistence Service — DocumentDB CRUD for /add_mcp configs.

Stores the non-secret subset of each /add_mcp JSON payload in the telegram_user_mcp_configs DocumentDB collection, scoped by (user_id, name). Secret fields (token, api_key, username, password) are never stored here — they live in the Vault. The vault_credential_name field in each document points to the relevant Vault entry.

Persistence uses Redis by default. When TELEGRAM_MCP_STORE=documentdb, the existing USE_DOCUMENTDB opt-in still applies; if it is disabled, every operation is a no-op so a deployment without DocumentDB never blocks a Telegram login on a connection attempt.

This module is Telegram-scoped and intentionally separate from :mod:parrot.handlers.mcp_persistence which handles catalog-activated MCP servers (UserMCPServerConfig / user_mcp_configs collection).

Usage::

svc = TelegramMCPPersistenceService()
await svc.save(user_id, name, public_params, vault_name)
configs = await svc.list(user_id)
removed = await svc.remove(user_id, name)

Alias DocumentDb

Re-exported from parrot.interfaces.documentdb.DocumentDb.

Class TelegramMCPPersistenceService

CRUD for the telegram_user_mcp_configs DocumentDB collection.

All documents are scoped by the compound key (user_id, name). Deactivation is a soft-delete (active=False) so configurations can be re-activated in the future without data loss.

Mirrors the pattern of :class:~parrot.handlers.mcp_persistence.MCPPersistenceService but is dedicated to the Telegram /add_mcp free-form flow.

Every method dispatches to Redis when configured; the DocumentDB path is a no-op when USE_DOCUMENTDB is false.

Attributes:

Attribute Type Description
COLLECTION str

Method TelegramMCPPersistenceService.save

Upsert a Telegram MCP server configuration in DocumentDB.

If a document with the same (user_id, name) already exists it is updated; otherwise a new document is inserted. The created_at timestamp is set only on first insert; updated_at is refreshed on every save.

save(user_id: str, name: str, params: TelegramMCPPublicParams, vault_credential_name: Optional[str]) -> None

Parameter Type Default Description
user_id str Telegram user identifier (tg:<telegram_id>).
name str Server name (must match params.name).
params TelegramMCPPublicParams Non-secret :class:TelegramMCPPublicParams to persist.
vault_credential_name Optional[str] Vault credential key for this server, or None when no secrets are stored (auth_scheme=none).

Method TelegramMCPPersistenceService.list

Load all active MCP server configs for a given Telegram user.

Inactive configs (active=False) are excluded from the results.

list(user_id: str) -> List[UserTelegramMCPConfig]

Parameter Type Default Description
user_id str Telegram user identifier.

Returns: List[UserTelegramMCPConfig] — List of :class:UserTelegramMCPConfig instances. Returns an empty list if none are found.

Method TelegramMCPPersistenceService.read_one

Retrieve a single active Telegram MCP config by name.

read_one(user_id: str, name: str) -> Optional[UserTelegramMCPConfig]

Parameter Type Default Description
user_id str Telegram user identifier.
name str Server name to look up.

Returns: Optional[UserTelegramMCPConfig] — class:UserTelegramMCPConfig instance, or None if not found or if the matching doc is inactive.

Method TelegramMCPPersistenceService.remove

Soft-delete a Telegram MCP server configuration.

Sets active=False on the document rather than hard-deleting it.

remove(user_id: str, name: str) -> tuple[bool, Optional[str]]

Parameter Type Default Description
user_id str Telegram user identifier.
name str Server name to deactivate.

Returns: tuple[bool, Optional[str]] — Tuple of (found, vault_credential_name). found is True if a matching document was found and deactivated, False if no document with the given compound key exists. vault_credential_name is the Vault key of the deleted document, or None if the document was not found or had no Vault entry.

Class TelegramMCPPublicParams

Non-secret subset of an /add_mcp payload safe to persist in DocumentDB.

Fields:

Field Type Default Description
name str Server name (the command's JSON name).
url str HTTP(S) endpoint of the MCP server.
transport str 'http' MCP transport protocol (default "http").
description Optional[str] None Optional human-readable description.
auth_scheme str 'none' Authentication scheme used ("none" | "bearer" | "api_key" | "basic").
api_key_header Optional[str] None Custom header name for api_key scheme only.
use_bearer_prefix Optional[bool] None Whether to add the Bearer prefix for api_key scheme.
headers Dict[str, str] Extra HTTP headers sent with every MCP request.
allowed_tools Optional[List[str]] None Whitelist of tool names; None means all tools.
blocked_tools Optional[List[str]] None Blacklist of tool names; None means none blocked.

Class UserTelegramMCPConfig

Persisted non-secret config for a /add_mcp HTTP server.

Fields:

Field Type Default Description
user_id str Telegram user identifier in tg:<telegram_id> format.
name str Server name (the command's JSON name).
params TelegramMCPPublicParams Non-secret connection parameters.
vault_credential_name Optional[str] None Vault key name ("tg_mcp_{name}") when secrets are present; None for auth_scheme=none.
active bool True False after a soft-delete via :meth:TelegramMCPPersistenceService.remove.
created_at datetime ISO-8601 UTC timestamp of first insert.
updated_at datetime ISO-8601 UTC timestamp of last upsert.

Function documentdb_enabled

Deprecated alias of :func:persistence_enabled (kept for importers).

documentdb_enabled() -> bool

Returns: bool

Attribute logger

Alias parrot_conf

Re-exported from parrot.conf.

Function persistence_enabled

Return whether the configured Telegram MCP persistence backend is enabled.

persistence_enabled() -> bool

Returns: bool

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally