Summary
Enhance the Google Chat integration by implementing a persistent caching layer for People API data (e.g., user display names). Currently, author names are taken directly from the Chat message payload, which can be inconsistent or missing. A dedicated caching mechanism would improve performance and data consistency.
Current State
- The
list_chat_messages MCP tool extracts the author's displayName directly from the message object on each API call (e.g., message.get("author", {}).get("displayName")).
- There is no caching for People data.
- The existing cache in
gwsa/sdk/cache.py is an in-memory cache, meaning it does not persist across separate CLI command invocations.
Desired State
- User display names should be resolved from the People API and cached to reduce redundant API calls and provide consistent user information.
- The cache should persist across separate CLI and MCP tool invocations. This means it needs to be file-based, not just in-memory.
Proposed Implementation Plan
-
Enhance the Caching SDK (gwsa/sdk/cache.py):
- Modify the
ExpiringCache to support a file-based backend (e.g., using shelve or a simple JSON file).
- The cache should serialize and deserialize its content to/from a file in
~/.config/gworkspace-access/cache/.
- This will allow the cache to be shared between different processes and invocations.
-
Create a People SDK Module (gwsa/sdk/people.py):
- Create a new SDK module for interacting with the People API.
- Implement a function
get_user_display_name(user_id: str) that takes a user resource name (e.g., users/123456789).
- This function should first check the persistent cache for the user's display name.
- If the name is not in the cache (a cache miss), it should call the
people.get method of the People API, store the result in the cache, and then return the name.
-
Integrate Caching into Chat Tools (gwsa/mcp/server.py):
- Modify the
list_chat_messages tool.
- For each message, extract the author's user resource name (from
message.get("author", {}).get("name")).
- Call the new
gwsa.sdk.people.get_user_display_name() function to get the author's name (which will be served from the cache if available).
- Use this resolved name in the tool's output.
-
Add People API Scope:
- The
https://www.googleapis.com/auth/userinfo.profile scope (or a more specific People API scope) will need to be added to the default scopes to allow the People API calls.
Summary
Enhance the Google Chat integration by implementing a persistent caching layer for People API data (e.g., user display names). Currently, author names are taken directly from the Chat message payload, which can be inconsistent or missing. A dedicated caching mechanism would improve performance and data consistency.
Current State
list_chat_messagesMCP tool extracts the author'sdisplayNamedirectly from the message object on each API call (e.g.,message.get("author", {}).get("displayName")).gwsa/sdk/cache.pyis an in-memory cache, meaning it does not persist across separate CLI command invocations.Desired State
Proposed Implementation Plan
Enhance the Caching SDK (
gwsa/sdk/cache.py):ExpiringCacheto support a file-based backend (e.g., usingshelveor a simple JSON file).~/.config/gworkspace-access/cache/.Create a People SDK Module (
gwsa/sdk/people.py):get_user_display_name(user_id: str)that takes a user resource name (e.g.,users/123456789).people.getmethod of the People API, store the result in the cache, and then return the name.Integrate Caching into Chat Tools (
gwsa/mcp/server.py):list_chat_messagestool.message.get("author", {}).get("name")).gwsa.sdk.people.get_user_display_name()function to get the author's name (which will be served from the cache if available).Add People API Scope:
https://www.googleapis.com/auth/userinfo.profilescope (or a more specific People API scope) will need to be added to the default scopes to allow the People API calls.