WA MCP
Development guide

Read chats with the WhatsApp MCP Python SDK

The WhatsApp MCP Python SDK gives a script access to the same store and bridge as your assistant. Use the included reader to identify a chat, inspect recent messages and build a small report without starting an MCP client.

Read one conversation from the bridge

Suppose a book club wants a weekly list of books people have suggested. You can build the list from one conversation with the Python SDK. Start by finding the group and reading five messages. This gives you a short list that you can compare with the chat on your phone before writing a filter or saving any output.

From a source checkout, install the workspace dependencies with uv sync. Build or start the Go bridge, link your phone and wait for recent chats to appear. Run the included reader from the repository directory. Give it the same configuration file as the bridge, especially if you keep the store outside the checkout.

uv run python examples/python_sdk_basic.py --config config.json --chats 5

The first line reports the bridge version, connection state and login state. The script lists recent conversations and reads the newest one when you omit the chat argument. Look at the title and the group indicator before using that default for a report. A new message in another conversation can change which chat is first.

Keep the account and chat explicit

Once you have the intended chat identifier, use it for subsequent reads. A title is convenient for a human, but two groups can share a title. The SDK returns the identifier with each chat. Print it locally when selecting a group, then pass that value to the message query. The response comes newest first. Reverse the selected rows when a reader needs the discussion in chronological order.

from wa_mcp import config
from wa_mcp.client import Bridge

with Bridge(cfg=config.load("config.json")) as bridge:
    for chat in bridge.chats(limit=5):
        print(chat["jid"], chat.get("title"))

The example reader also accepts --chat and --messages. Try the same chat twice with a limit of five. Check the sender direction and timestamp against your phone. A voice message may have a media kind and an empty body. Treat that as a media entry when counting messages, even if your book-title filter only handles text.

Choose where to read encrypted fields

The reader above talks to the authenticated bridge API. The bridge handles its storage key, so the reader can obtain the requested fields without opening the encrypted database itself. A local script with the right configuration can also read stored history through the SDK's database module. This is useful for a report that reads many matching rows without needing new messages from the phone.

from wa_mcp import config, db, people

cfg = config.load("config.json")
db.connect(cfg)
people.connect(cfg)

for row in db.messages(query="paperback", limit=5):
    print(row["time"], people.name_of(row["conv"]))

This report prints the time and conversation name. The message text can stay out of your shell history, logs and exported reports. Run direct reads as an operating-system user with access to the configured key. If the API example works and the direct read fails, compare the store directory and key configuration used by each process.

Handle gaps and attachments

A new link receives the history the phone supplies. An empty result can mean that the conversation is outside that window. First read recent messages from the chosen chat without the search term. Then request older history for that chat or preview an existing chat export. Record the period covered by your report before interpreting a count as a full archive.

The example's optional --download switch saves an attachment and prints its local path. Leave it out for a text report. A saved file has its own storage and deletion requirements, even when the corresponding message fields are encrypted. A message ID paired with its chat ID is usually enough to return to the source later.

Keep a reporting job read-only

A script can finish after the last read. It needs no model credentials or running desktop assistant. Leave sending disabled in the bridge while developing a report. The SDK also exposes a send method for other applications. Calling it from a script puts the decision to send in that application, outside an MCP client's interactive confirmation.

If the script reports that the bridge is unreachable, check the process and the API address in the selected config. If it reports a missing token, start the bridge as the intended user and check the token settings. A successful status response with an empty chat list points to a different issue: check the linked account and allow time for the initial sync.

Questions

Does the WhatsApp MCP Python SDK require a running assistant?

No. The Bridge client reads through the authenticated Go bridge. A direct database reader uses the local store and needs access to its configured encryption key.

Can the reader run against an encrypted WhatsApp store?

Yes. The example reads through the authenticated bridge API. For direct database access the script also needs the configured storage key.

Read the project Python SDK tutorial