Implementation:Langgenius Dify UseAllToolProviders
| Knowledge Sources | Dify |
|---|---|
| Domains | Plugin_System, Marketplace, Frontend |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Description
The UseAllToolProviders module spans two service files -- web/service/use-tools.ts for React Query hooks and web/service/tools.ts for imperative service functions. Together they provide the complete tool provider integration layer for the Dify frontend.
The hook layer (use-tools.ts) provides five category-specific query hooks:
- useAllToolProviders -- Fetches all registered tool provider collections.
- useAllBuiltInTools -- Fetches tools from built-in (platform-shipped) providers.
- useAllCustomTools -- Fetches tools from user-defined custom API providers.
- useAllWorkflowTools -- Fetches tools from Dify workflows exposed as tool providers.
- useAllMCPTools -- Fetches tools from Model Context Protocol (MCP) servers.
Each hook has a corresponding useInvalidate* companion for cache invalidation, and the useInvalidToolsByType utility provides type-indexed invalidation using a CollectionType dispatch map.
The service layer (tools.ts) provides imperative CRUD functions for tool providers: fetchCollectionList, fetchBuiltInToolList, fetchCustomToolList, createCustomCollection, updateCustomCollection, removeCustomCollection, updateBuiltInToolCredential, removeBuiltInToolCredential, and more.
Usage
The hooks are used in workflow editors, tool picker panels, and administration interfaces. The imperative functions are used in event handlers for creating, updating, and deleting tool providers.
Code Reference
Source Location
web/service/use-tools.ts (Lines 21--90) and web/service/tools.ts (Lines 14--59)
Signature
// Hook layer (use-tools.ts)
export const useAllToolProviders = (enabled = true) => {
return useQuery<Collection[]>({
queryKey: [NAME_SPACE, 'allToolProviders'],
queryFn: () => get<Collection[]>('/workspaces/current/tool-providers'),
enabled,
})
}
export const useAllBuiltInTools = () => {
return useQuery<ToolWithProvider[]>({
queryKey: [NAME_SPACE, 'builtIn'],
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/builtin'),
})
}
export const useAllCustomTools = () => {
return useQuery<ToolWithProvider[]>({
queryKey: [NAME_SPACE, 'customTools'],
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/api'),
})
}
export const useAllWorkflowTools = () => {
return useQuery<ToolWithProvider[]>({
queryKey: [NAME_SPACE, 'workflowTools'],
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/workflow'),
})
}
export const useAllMCPTools = () => {
return useQuery<ToolWithProvider[]>({
queryKey: [NAME_SPACE, 'MCPTools'],
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/mcp'),
})
}
export const useInvalidToolsByType = (type?: CollectionType | string) => {
const queryKey = type ? useInvalidToolsKeyMap[type] : undefined
return useInvalid(queryKey)
}
// Service layer (tools.ts)
export const fetchCollectionList = () => {
return get<Collection[]>('/workspaces/current/tool-providers')
}
export const fetchBuiltInToolList = (collectionName: string) => {
return get<Tool[]>(`/workspaces/current/tool-provider/builtin/${collectionName}/tools`)
}
export const createCustomCollection = (collection: CustomCollectionBackend) => {
return post('/workspaces/current/tool-provider/api/add', { body: { ...collection } })
}
export const updateCustomCollection = (collection: CustomCollectionBackend) => {
return post('/workspaces/current/tool-provider/api/update', { body: { ...collection } })
}
export const removeCustomCollection = (collectionName: string) => {
return post('/workspaces/current/tool-provider/api/delete', { body: { provider: collectionName } })
}
export const updateBuiltInToolCredential = (
collectionName: string,
credential: Record<string, unknown>,
) => {
return post(`/workspaces/current/tool-provider/builtin/${collectionName}/update`, {
body: { credentials: credential },
})
}
export const removeBuiltInToolCredential = (collectionName: string) => {
return post(`/workspaces/current/tool-provider/builtin/${collectionName}/delete`, { body: {} })
}
Import
import {
useAllToolProviders,
useAllBuiltInTools,
useAllCustomTools,
useAllWorkflowTools,
useAllMCPTools,
useInvalidToolsByType,
} from '@/service/use-tools'
import {
fetchCollectionList,
fetchBuiltInToolList,
createCustomCollection,
updateCustomCollection,
removeCustomCollection,
updateBuiltInToolCredential,
removeBuiltInToolCredential,
} from '@/service/tools'
I/O Contract
useAllToolProviders
| Direction | Field | Type | Description |
|---|---|---|---|
| Input | enabled | boolean (default true) |
Whether the query should execute |
| Output | data | Collection[] |
Array of all registered tool provider collections |
useAllBuiltInTools / useAllCustomTools / useAllWorkflowTools / useAllMCPTools
| Direction | Field | Type | Description |
|---|---|---|---|
| Input | (none) | -- | No parameters |
| Output | data | ToolWithProvider[] |
Array of tools with their parent provider metadata |
createCustomCollection
| Direction | Field | Type | Description |
|---|---|---|---|
| Input | collection | CustomCollectionBackend |
The custom API tool provider definition (name, schema, credentials, etc.) |
| Output | (server response) | varies | Confirmation of creation |
updateBuiltInToolCredential
| Direction | Field | Type | Description |
|---|---|---|---|
| Input | collectionName | string |
The built-in provider identifier |
| Input | credential | Record<string, unknown> |
The credential key-value pairs |
| Output | (server response) | varies | Confirmation of credential update |
Usage Examples
Populating a tool picker with all provider types
import { useAllBuiltInTools, useAllCustomTools, useAllWorkflowTools, useAllMCPTools } from '@/service/use-tools'
function ToolPicker() {
const { data: builtIn = [] } = useAllBuiltInTools()
const { data: custom = [] } = useAllCustomTools()
const { data: workflow = [] } = useAllWorkflowTools()
const { data: mcp = [] } = useAllMCPTools()
const allTools = [...builtIn, ...custom, ...workflow, ...mcp]
return <ToolList tools={allTools} />
}
Creating a custom API tool provider
import { createCustomCollection } from '@/service/tools'
await createCustomCollection({
name: 'My Weather API',
schema_type: 'openapi',
schema: openApiSchemaString,
credentials: { api_key: 'xxx' },
})
Invalidating tool cache after plugin installation
import { useInvalidateAllBuiltInTools } from '@/service/use-tools'
const invalidateBuiltIn = useInvalidateAllBuiltInTools()
// After installing a plugin that provides built-in tools:
invalidateBuiltIn()