@@ -11,7 +11,7 @@ import { __unsafePrisma } from '@/prisma';
1111import { McpServerToolPermission , Prisma } from '@sourcebot/db' ;
1212import { captureEvent } from '@/lib/posthog' ;
1313import type { AskMcpAnalyticsSource } from '@/lib/posthogEvents' ;
14- import { redis } from '@/lib/redis' ;
14+ import { getRedisClient } from '@/lib/redis' ;
1515import {
1616 createMissingMcpServerToolRows ,
1717 getMcpServerToolPermission ,
@@ -129,6 +129,7 @@ function getMcpListToolsCacheKey(client: McpToolSet): string {
129129
130130async function getCachedListTools ( cacheKey : string ) : Promise < ListToolsResult | undefined > {
131131 try {
132+ const redis = getRedisClient ( ) ;
132133 const cached = await redis . get ( cacheKey ) ;
133134 return cached ? JSON . parse ( cached ) as ListToolsResult : undefined ;
134135 } catch ( error ) {
@@ -142,6 +143,7 @@ async function getCachedListTools(cacheKey: string): Promise<ListToolsResult | u
142143
143144async function setCachedListTools ( cacheKey : string , toolDefinitions : ListToolsResult ) {
144145 try {
146+ const redis = getRedisClient ( ) ;
145147 await redis . set ( cacheKey , JSON . stringify ( toolDefinitions ) , 'EX' , MCP_LIST_TOOLS_CACHE_TTL_SECONDS ) ;
146148 } catch ( error ) {
147149 logger . warn ( 'Failed to cache MCP tool definitions.' , {
@@ -200,10 +202,14 @@ export async function getMcpTools(clients: McpToolSet[], analyticsContext?: McpT
200202 const prefix = `mcp_${ sanitizedName } ` ;
201203 await createMissingMcpServerToolRows ( {
202204 serverId,
203- tools : toolDefinitions . tools . map ( ( tool ) => ( {
204- toolName : tool . name ,
205- readOnlyHint : tool . annotations ?. readOnlyHint ,
206- } ) ) ,
205+ tools : toolDefinitions . tools . map ( ( tool ) => {
206+ const readOnlyHint = tool . annotations ?. readOnlyHint ;
207+
208+ return {
209+ toolName : tool . name ,
210+ ...( typeof readOnlyHint === 'boolean' ? { readOnlyHint } : { } ) ,
211+ } ;
212+ } ) ,
207213 } ) ;
208214 const permissionsByServerId = await getMcpServerToolPermissionsByServerId ( {
209215 serverIds : [ serverId ] ,
@@ -212,10 +218,11 @@ export async function getMcpTools(clients: McpToolSet[], analyticsContext?: McpT
212218
213219 for ( const [ toolName , tool ] of Object . entries ( tools ) ) {
214220 const def = toolDefinitions . tools . find ( t => t . name === toolName ) ;
221+ const readOnlyHint = def ?. annotations ?. readOnlyHint ;
215222 const permission = getMcpServerToolPermission (
216223 permissionsByToolName ,
217224 toolName ,
218- def ?. annotations ?. readOnlyHint ,
225+ typeof readOnlyHint === 'boolean' ? readOnlyHint : undefined ,
219226 ) ;
220227 if ( permission === McpServerToolPermission . DISABLED ) {
221228 continue ;
0 commit comments