Add Tenant Access Token (TAT) support for MCP tools#263
Add Tenant Access Token (TAT) support for MCP tools#263marco0158 wants to merge 3 commits intolarksuite:mainfrom
Conversation
- Add mcpAuthMode config option ('user' | 'tenant' | 'auto') to FeishuAccountConfigSchema
- Implement TAT caching mechanism in tool-client for efficient token reuse
- Add getMcpAuthMode() function to read auth mode from config
- Update callMcpTool() to support both UAT and TAT via header flags
- Update registerMcpTool() to handle three auth modes:
- 'tenant': Use Tenant Access Token for all MCP calls
- 'auto': Try TAT first, fallback to UAT on failure
- 'user' (default): Use User Access Token as before
This allows MCP tools to operate with application-level permissions
without requiring user authorization, suitable for background tasks
and automation scenarios.
Co-Authored-By: Claude <noreply@anthropic.com>
HanShaoshuai-k
left a comment
There was a problem hiding this comment.
Review: PR #263 — Add Tenant Access Token (TAT) support for MCP tools
Thanks for the contribution! Adding TAT support for MCP tools makes sense directionally — Feishu's MCP gateway already supports X-Lark-MCP-TAT, and the plugin side is missing this. However, I have concerns about the use case and config design that I think should be resolved first.
1. Does the use case exist in the current architecture?
The PR description mentions "background tasks and automation scenarios where user authorization is not practical or possible." However, in openclaw-lark, all tool invocations are triggered by user messages — there's no scheduler, no external API trigger, no background task mechanism. Every call has a senderOpenId. So the "no user context" scenario doesn't actually exist today.
Could you clarify the real-world scenario you're solving for? If it's about reducing OAuth friction or providing a fallback when UAT is unavailable, that would lead to a different design.
2. Account-level config is too coarse
Per Feishu MCP docs, different tools support different auth methods (e.g., search-user only supports UAT). A global mcpAuthMode: "tenant" would silently break these tools.
Auth mode compatibility is a server-side property of each tool, not a user preference. Rather than a global config, consider letting each tool declare its supported auth modes, and determining the actual mode from runtime context.
3. auto mode fallback is wasteful
auto tries TAT first, falling back to UAT on failure. For UAT-only tools, this means a wasted request on every call. The fallback direction should be reconsidered.
I'd suggest aligning on the use case and config design before diving into implementation details. Happy to discuss!
Summary
This PR adds Tenant Access Token (TAT) support for MCP tools, allowing MCP tools to operate with application-level permissions without requiring user authorization.
Changes
mcpAuthModeconfig option (user|tenant|auto) toFeishuAccountConfigSchematool-clientfor efficient token reusegetMcpAuthMode()function to read auth mode from configcallMcpTool()to support both UAT and TAT via header flagsregisterMcpTool()to handle three auth modes:tenant: Use Tenant Access Token for all MCP callsauto: Try TAT first, fallback to UAT on failureuser(default): Use User Access Token as beforeUse Cases
This is suitable for background tasks and automation scenarios where user authorization is not practical or possible.
Example Configuration
{ "channels": { "feishu": { "mcpAuthMode": "tenant" } } }Testing