d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
85 lines
2.4 KiB
TypeScript
85 lines
2.4 KiB
TypeScript
/**
|
|
* Hook for discovering and managing MCP tools
|
|
*
|
|
* This hook provides a unified interface for accessing MCP tools
|
|
* using TanStack Query for optimal caching and performance
|
|
*/
|
|
|
|
import type { ComponentType, SVGProps } from 'react'
|
|
import { useCallback, useMemo } from 'react'
|
|
import { createLogger } from '@sim/logger'
|
|
import { useQueryClient } from '@tanstack/react-query'
|
|
import { McpIcon } from '@/components/icons'
|
|
import { createMcpToolId } from '@/lib/mcp/shared'
|
|
import type { McpToolSchema } from '@/lib/mcp/types'
|
|
import { mcpKeys, useMcpToolsQuery } from '@/hooks/queries/mcp'
|
|
|
|
const logger = createLogger('useMcpTools')
|
|
|
|
export interface McpToolForUI {
|
|
id: string
|
|
name: string
|
|
description?: string
|
|
serverId: string
|
|
serverName: string
|
|
type: 'mcp'
|
|
inputSchema: McpToolSchema
|
|
bgColor: string
|
|
icon: ComponentType<SVGProps<SVGSVGElement>>
|
|
}
|
|
|
|
export interface UseMcpToolsResult {
|
|
mcpTools: McpToolForUI[]
|
|
isLoading: boolean
|
|
error: string | null
|
|
refreshTools: () => Promise<void>
|
|
getToolsByServer: (serverId: string) => McpToolForUI[]
|
|
}
|
|
|
|
export function useMcpTools(workspaceId: string): UseMcpToolsResult {
|
|
const queryClient = useQueryClient()
|
|
|
|
const { data: mcpToolsData, isLoading, error: queryError } = useMcpToolsQuery(workspaceId)
|
|
|
|
const mcpTools = useMemo<McpToolForUI[]>(() => {
|
|
return mcpToolsData.map((tool) => ({
|
|
id: createMcpToolId(tool.serverId, tool.name),
|
|
name: tool.name,
|
|
description: tool.description,
|
|
serverId: tool.serverId,
|
|
serverName: tool.serverName,
|
|
type: 'mcp' as const,
|
|
inputSchema: tool.inputSchema,
|
|
bgColor: '#6366F1',
|
|
icon: McpIcon,
|
|
}))
|
|
}, [mcpToolsData])
|
|
|
|
// Soft refresh — invalidate per-server entries. For cache-bypass, use `useForceRefreshMcpTools`.
|
|
const refreshTools = useCallback(async () => {
|
|
if (!workspaceId) {
|
|
logger.warn('Cannot refresh tools: no workspaceId provided')
|
|
return
|
|
}
|
|
|
|
await queryClient.invalidateQueries({
|
|
queryKey: mcpKeys.serverToolsWorkspace(workspaceId),
|
|
})
|
|
}, [workspaceId, queryClient])
|
|
|
|
const getToolsByServer = useCallback(
|
|
(serverId: string): McpToolForUI[] => {
|
|
return mcpTools.filter((tool) => tool.serverId === serverId)
|
|
},
|
|
[mcpTools]
|
|
)
|
|
|
|
return {
|
|
mcpTools,
|
|
isLoading,
|
|
error: queryError instanceof Error ? queryError.message : null,
|
|
refreshTools,
|
|
getToolsByServer,
|
|
}
|
|
}
|