Skip to content

Commit 468384d

Browse files
authored
Fix issues blocking build (#1269)
Fix issues blocking build
1 parent 5448e7d commit 468384d

4 files changed

Lines changed: 23 additions & 11 deletions

File tree

packages/web/src/app/(app)/settings/workspaceAskAgent/connectors/[serverId]/tools/mcpToolPermissionsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ export function McpToolPermissionsPage({ serverId }: McpToolPermissionsPageProps
339339
}, [permissionFilter, searchInput, tools]);
340340
const filteredToolGroups = useMemo<ToolGroup[]>(() => [
341341
{
342-
id: 'read-only',
342+
id: 'read-only' as const,
343343
label: 'Read-only tools',
344344
tools: filteredTools.filter((tool) => tool.annotations?.readOnlyHint === true),
345345
},
346346
{
347-
id: 'write-delete',
347+
id: 'write-delete' as const,
348348
label: 'Write/delete tools',
349349
tools: filteredTools.filter((tool) => tool.annotations?.readOnlyHint !== true),
350350
},

packages/web/src/ee/features/chat/mcp/mcpToolSets.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ vi.mock('@/lib/posthog', () => ({
4747
}));
4848

4949
vi.mock('@/lib/redis', () => ({
50-
redis: {
50+
getRedisClient: () => ({
5151
get: (...args: unknown[]) => mockRedisGet(...args),
5252
set: (...args: unknown[]) => mockRedisSet(...args),
53-
},
53+
}),
5454
}));
5555

5656
vi.mock('ai', () => ({

packages/web/src/ee/features/chat/mcp/mcpToolSets.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { __unsafePrisma } from '@/prisma';
1111
import { McpServerToolPermission, Prisma } from '@sourcebot/db';
1212
import { captureEvent } from '@/lib/posthog';
1313
import type { AskMcpAnalyticsSource } from '@/lib/posthogEvents';
14-
import { redis } from '@/lib/redis';
14+
import { getRedisClient } from '@/lib/redis';
1515
import {
1616
createMissingMcpServerToolRows,
1717
getMcpServerToolPermission,
@@ -129,6 +129,7 @@ function getMcpListToolsCacheKey(client: McpToolSet): string {
129129

130130
async 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

143144
async 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;

packages/web/src/lib/redis.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ import 'server-only';
22

33
import { createRedisClient } from '@sourcebot/shared';
44

5-
export const redis = createRedisClient();
5+
let redis: ReturnType<typeof createRedisClient> | undefined;
6+
7+
export function getRedisClient() {
8+
redis ??= createRedisClient();
9+
return redis;
10+
}

0 commit comments

Comments
 (0)