Skip to content

feat: add create_group and leave_group MCP tools#239

Open
jayeshkaithwas wants to merge 1 commit into
lharries:mainfrom
jayeshkaithwas:feat/group-management
Open

feat: add create_group and leave_group MCP tools#239
jayeshkaithwas wants to merge 1 commit into
lharries:mainfrom
jayeshkaithwas:feat/group-management

Conversation

@jayeshkaithwas

Copy link
Copy Markdown

Summary

Adds two new MCP tools so the agent can manage groups, not just read/send into existing ones.

  • create_group(name, participants, is_community=False, community_parent_jid="") — wraps whatsmeow.CreateGroup. Participants accept either bare phone numbers (country code, no +) or full JIDs. The caller's own JID is added implicitly by WhatsApp, so it must not be included. Optionally creates a community parent (is_community=True) or attaches the new group as a sub-group of an existing community (community_parent_jid). Persists the resulting chat to the local SQLite so it shows up in list_chats right away.
  • leave_group(jid) — wraps whatsmeow.LeaveGroup. WhatsApp has no "delete group" primitive — this is the closest action; other members continue to see the group with you marked as left.

Changes

  • whatsapp-bridge/main.go: new /api/create_group and /api/leave_group endpoints + their request/response types and handlers.
  • whatsapp-mcp-server/whatsapp.py: matching create_group / leave_group HTTP helpers.
  • whatsapp-mcp-server/main.py: tool registrations.
  • README.md: tool list updated with the two new entries.

No dependency bumps. No changes to existing tools or storage schema. Builds cleanly against the whatsmeow version pinned in go.mod.

Test plan

  • go build clean against the existing pinned whatsmeow.
  • python3 -m py_compile clean on both server files.
  • Manually exercised on a live bridge: created a 2-person group via POST /api/create_group, confirmed it appeared in WhatsApp on both ends and in list_chats. Then left it via POST /api/leave_group and confirmed the "left" event on the other device.
  • Reviewer to verify behaviour against their own paired account.

Notes / open questions

  • I deliberately kept the surface minimal (just name, participants, plus the two community knobs that whatsmeow.ReqCreateGroup already exposes here). Happy to add announce/locked/ephemeral/join_approval_required in a follow-up — they need a newer whatsmeow than the one currently pinned.
  • create_group writes the new chat row directly to the bridge SQLite. WhatsApp's own events.JoinedGroup would also do this asynchronously; doing it eagerly just makes the tool's response immediately visible to subsequent list_chats calls in the same MCP session. Open to dropping that line if you'd rather rely on the event path alone.
  • Group names are silently capped by WhatsApp at 25 chars — I validate this client-side in the bridge and return a clear error rather than letting whatsmeow surface a 406.

🤖 Generated with Claude Code

Adds two new tools so the MCP agent can manage groups, not just
read/send into existing ones:

- create_group(name, participants, is_community=False, community_parent_jid=""):
  Create a new group via whatsmeow.CreateGroup. Participants accept either
  bare phone numbers (country code, no '+') or full JIDs. Optionally creates
  a community parent or attaches the new group as a sub-group of an existing
  community. Persists the resulting chat into the local SQLite so it shows
  up in list_chats immediately.
- leave_group(jid): Leave a group via whatsmeow.LeaveGroup. WhatsApp has no
  "delete group" primitive — this is the closest action.

Bridge: new POST /api/create_group and /api/leave_group endpoints.
MCP server: matching tools registered in main.py.
README: tool list updated.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
BenGedi added a commit to BenGedi/whatsapp-mcp that referenced this pull request May 30, 2026
Ports lharries#239. Adds create_group and leave_group end-to-end: Go HTTP handlers, Python wrappers, MCP tool registrations. Input validation returns 400; connection/network errors return 500. Upstream delta: context.Background() added to whatsmeow calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant