Skip to content

Commit 193a00b

Browse files
authored
Merge pull request #10 from WebexCommunity/claude/webex-teams-api-tools-1veX9
2 parents 06197ab + d0db9d8 commit 193a00b

5 files changed

Lines changed: 877 additions & 3 deletions

File tree

CLAUDE.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ src/webex_bot_mcp/
2929
Adaptive Card send/build tools
3030
memberships.py — Membership CRUD (list, add, update, delete) + space aliases
3131
people.py — get_webex_me, list_webex_people
32+
teams.py — Team tools (list, get, update, delete) + team membership tools
33+
Note: create_webex_team is intentionally absent — bots cannot
34+
create teams (Webex returns 401); only user/integration tokens can.
3235
3336
tests/
3437
test_messages.py — Unit tests (85 cases); mocks webexpythonsdk at sys.modules level
38+
test_teams.py — Unit tests (40 cases); same mock pattern
3539
3640
.github/
3741
workflows/
@@ -44,11 +48,16 @@ tests/
4448
## Key Conventions
4549

4650
### Tool count
47-
27 tools total: 5 room + 5 space-room aliases + 4 message + 2 space-message aliases +
51+
34 tools total: 5 room + 5 space-room aliases + 4 message + 2 space-message aliases +
4852
2 adaptive-card + 1 adaptive-card-space alias + 1 adaptive-card-builder +
49-
4 membership + 2 space-membership aliases + 2 people.
53+
4 membership + 2 space-membership aliases + 2 people +
54+
4 team + 3 team-membership.
5055
Update `tools_count` in the `server_version` resource (`src/webex_bot_mcp/main.py`) when adding tools.
5156

57+
Note: `create_webex_team` is intentionally not implemented. Bots cannot create teams —
58+
the Webex platform returns 401 for `POST /teams` with bot tokens regardless of scopes.
59+
Only user tokens or OAuth integrations with `spark:teams_write` can create teams.
60+
5261
### Error handling — always use structured responses
5362
Every tool must return via `create_error_response` or `create_success_response` from
5463
`tools/common.py`. Never return a bare `{'success': False, 'error': str(e)}` dict.

src/webex_bot_mcp/main.py

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
list_webex_space_memberships, add_webex_space_membership,
4949
# People functions
5050
get_webex_me, list_webex_people,
51+
# Team functions
52+
list_webex_teams, get_webex_team,
53+
update_webex_team, delete_webex_team,
54+
list_webex_team_memberships, add_webex_team_membership,
55+
delete_webex_team_membership,
5156
)
5257

5358
# Import version and error handling from common
@@ -119,6 +124,17 @@ async def dispatch(self, request, call_next):
119124
mcp.tool()(get_webex_me)
120125
mcp.tool()(list_webex_people)
121126

127+
# Team management tools
128+
mcp.tool()(list_webex_teams)
129+
mcp.tool()(get_webex_team)
130+
mcp.tool()(update_webex_team)
131+
mcp.tool()(delete_webex_team)
132+
133+
# Team membership tools
134+
mcp.tool()(list_webex_team_memberships)
135+
mcp.tool()(add_webex_team_membership)
136+
mcp.tool()(delete_webex_team_membership)
137+
122138

123139
# ========== RESOURCES ==========
124140
# Resources provide contextual information that AI assistants can read
@@ -336,6 +352,89 @@ def webex_adaptive_cards_guide():
336352
"""
337353

338354

355+
@mcp.resource("webex://help/teams")
356+
def webex_teams_guide():
357+
"""Bot access model and guidance for Webex Teams tools"""
358+
return """# Webex Teams — Bot Access Guide
359+
360+
## What is a Team in Webex?
361+
362+
A team is a named group of people with a shared set of rooms. Teams are a higher-level
363+
construct than rooms: a team contains rooms, and all team members can see every room in
364+
the team. The team membership and team room membership are separate concepts.
365+
366+
## Bot Access Model (Verified Against the Webex API)
367+
368+
Bot tokens operate under stricter rules than user or integration tokens for the Teams API.
369+
Understanding these rules prevents confusing errors.
370+
371+
### What bots CAN do
372+
373+
| Tool | Requirement |
374+
|------|-------------|
375+
| `list_webex_teams` | Bot is a member of at least one team |
376+
| `get_webex_team` | Bot is a member of that team |
377+
| `list_webex_team_memberships` | Bot is a member of that team |
378+
| `update_webex_team` | Bot has the **moderator** role in that team |
379+
| `delete_webex_team` | Bot has the **moderator** role in that team |
380+
| `add_webex_team_membership` | Bot has the **moderator** role in that team |
381+
| `delete_webex_team_membership` | Bot has the **moderator** role in that team |
382+
383+
### What bots CANNOT do
384+
385+
| Operation | Reason |
386+
|-----------|--------|
387+
| **Create a team** | Hard platform restriction — `POST /teams` returns 401 for bot tokens regardless of scopes. This is not an error in the MCP; it is enforced by the Webex platform. |
388+
389+
`create_webex_team` is intentionally not implemented in this MCP server. To create a
390+
team, use a personal access token or an OAuth integration with the `spark:teams_write`
391+
scope.
392+
393+
## Getting the Bot Into a Team
394+
395+
Before any team tool will work, a human user must add the bot to the team:
396+
397+
1. **Via Webex UI**: Open the team in the Webex app → Members → Add member → paste the
398+
bot's email address (visible in `get_webex_me`).
399+
2. **Via API with a user token**:
400+
```
401+
POST https://webexapis.com/v1/team/memberships
402+
{ "teamId": "<id>", "personEmail": "<bot-email>", "isModerator": true }
403+
```
404+
Set `isModerator: true` if you want the bot to be able to update the team or manage
405+
members.
406+
407+
## Understanding 404 vs 403 Errors
408+
409+
- **404 "not found"** from a team tool usually means the bot is not a member of the team,
410+
not that the team ID is wrong. Verify the bot has been added first.
411+
- **403 "forbidden"** from a write tool means the bot is a regular member but not a
412+
moderator. Upgrade the bot's role in the team to moderator.
413+
414+
## Typical Workflow
415+
416+
```
417+
1. list_webex_teams()
418+
→ Empty? A human must add the bot to a team first (see above).
419+
420+
2. list_webex_teams()
421+
→ Returns teams the bot belongs to. Pick a team_id.
422+
423+
3. get_webex_team(team_id)
424+
→ Confirm team details.
425+
426+
4. list_webex_team_memberships(team_id)
427+
→ See who is in the team. Check bot's isModerator value.
428+
429+
5. add_webex_team_membership(team_id, person_email="...", is_moderator=False)
430+
→ Requires bot to be a moderator.
431+
432+
6. delete_webex_team_membership(membership_id)
433+
→ Requires bot to be a moderator.
434+
```
435+
"""
436+
437+
339438
@mcp.resource("webex://config/current")
340439
def webex_current_config():
341440
"""Current Webex bot configuration and status"""
@@ -1018,7 +1117,7 @@ def server_version():
10181117
"streamable-http", "stdio",
10191118
"error-handling", "versioning"
10201119
],
1021-
"tools_count": 27,
1120+
"tools_count": 34,
10221121
"resources_count": 11,
10231122
"prompts_count": 8,
10241123
"breaking_changes": {

src/webex_bot_mcp/tools/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
get_webex_me, list_webex_people,
2727
)
2828

29+
from .teams import (
30+
list_webex_teams, get_webex_team,
31+
update_webex_team, delete_webex_team,
32+
list_webex_team_memberships, add_webex_team_membership,
33+
delete_webex_team_membership,
34+
)
35+
2936
__all__ = [
3037
# Room functions
3138
'list_webex_rooms', 'create_webex_room', 'update_webex_room',
@@ -48,4 +55,9 @@
4855
'list_webex_space_memberships', 'add_webex_space_membership',
4956
# People functions
5057
'get_webex_me', 'list_webex_people',
58+
# Team functions
59+
'list_webex_teams', 'get_webex_team',
60+
'update_webex_team', 'delete_webex_team',
61+
'list_webex_team_memberships', 'add_webex_team_membership',
62+
'delete_webex_team_membership',
5163
]

0 commit comments

Comments
 (0)