mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
add update and delete mutations
This commit is contained in:
parent
568ec2f7d5
commit
5a7bf0b35f
8 changed files with 114 additions and 11 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const { addTool } = require('@librechat/api');
|
const { addTool, updateTool, deleteTool } = require('@librechat/api');
|
||||||
const { callTool, verifyToolAuth, getToolCalls } = require('~/server/controllers/tools');
|
const { callTool, verifyToolAuth, getToolCalls } = require('~/server/controllers/tools');
|
||||||
const { getAvailableTools } = require('~/server/controllers/PluginController');
|
const { getAvailableTools } = require('~/server/controllers/PluginController');
|
||||||
const { toolCallLimiter } = require('~/server/middleware/limiters');
|
const { toolCallLimiter } = require('~/server/middleware/limiters');
|
||||||
|
|
@ -45,4 +45,21 @@ router.post('/:toolId/call', toolCallLimiter, callTool);
|
||||||
*/
|
*/
|
||||||
router.post('/add', addTool);
|
router.post('/add', addTool);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing tool/MCP in the system
|
||||||
|
* @route PUT /agents/tools/:mcp_id
|
||||||
|
* @param {string} mcp_id - The ID of the MCP to update
|
||||||
|
* @param {object} req.body - Request body containing updated tool/MCP data
|
||||||
|
* @returns {object} Updated tool/MCP object
|
||||||
|
*/
|
||||||
|
router.put('/:mcp_id', updateTool);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a tool/MCP from the system
|
||||||
|
* @route DELETE /agents/tools/:mcp_id
|
||||||
|
* @param {string} mcp_id - The ID of the MCP to delete
|
||||||
|
* @returns {object} Deletion confirmation
|
||||||
|
*/
|
||||||
|
router.delete('/:mcp_id', deleteTool);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
|
||||||
|
|
@ -62,3 +62,45 @@ export const useCreateMCPMutation = (
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useUpdateMCPMutation = (
|
||||||
|
options?: t.UpdateMCPMutationOptions,
|
||||||
|
): UseMutationResult<Record<string, unknown>, Error, { mcp_id: string; data: t.MCP }> => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation(
|
||||||
|
({ mcp_id, data }: { mcp_id: string; data: t.MCP }) => {
|
||||||
|
return dataService.updateMCP({ mcp_id, data });
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onMutate: (variables) => options?.onMutate?.(variables),
|
||||||
|
onError: (error, variables, context) => options?.onError?.(error, variables, context),
|
||||||
|
onSuccess: (data, variables, context) => {
|
||||||
|
// Invalidate tools list to trigger refetch
|
||||||
|
queryClient.invalidateQueries([QueryKeys.tools]);
|
||||||
|
return options?.onSuccess?.(data, variables, context);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useDeleteMCPMutation = (
|
||||||
|
options?: t.DeleteMCPMutationOptions,
|
||||||
|
): UseMutationResult<Record<string, unknown>, Error, { mcp_id: string }> => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation(
|
||||||
|
({ mcp_id }: { mcp_id: string }) => {
|
||||||
|
return dataService.deleteMCP({ mcp_id });
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onMutate: (variables) => options?.onMutate?.(variables),
|
||||||
|
onError: (error, variables, context) => options?.onError?.(error, variables, context),
|
||||||
|
onSuccess: (data, variables, context) => {
|
||||||
|
// Invalidate tools list to trigger refetch
|
||||||
|
queryClient.invalidateQueries([QueryKeys.tools]);
|
||||||
|
return options?.onSuccess?.(data, variables, context);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ export function useMCPSelect({ conversationId }: UseMCPSelectOptions) {
|
||||||
const [ephemeralAgent, setEphemeralAgent] = useRecoilState(ephemeralAgentByConvoId(key));
|
const [ephemeralAgent, setEphemeralAgent] = useRecoilState(ephemeralAgentByConvoId(key));
|
||||||
const { data: mcpToolDetails, isFetched } = useAvailableToolsQuery(EModelEndpoint.agents, {
|
const { data: mcpToolDetails, isFetched } = useAvailableToolsQuery(EModelEndpoint.agents, {
|
||||||
select: (data: TPlugin[]) => {
|
select: (data: TPlugin[]) => {
|
||||||
|
console.log('🔍 Raw tools data received:', JSON.stringify(data, null, 2));
|
||||||
|
|
||||||
const mcpToolsMap = new Map<string, TPlugin>();
|
const mcpToolsMap = new Map<string, TPlugin>();
|
||||||
data.forEach((tool) => {
|
data.forEach((tool) => {
|
||||||
const isMCP = tool.pluginKey.includes(Constants.mcp_delimiter);
|
const isMCP = tool.pluginKey.includes(Constants.mcp_delimiter);
|
||||||
|
|
@ -46,7 +48,10 @@ export function useMCPSelect({ conversationId }: UseMCPSelectOptions) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return Array.from(mcpToolsMap.values());
|
|
||||||
|
const result = Array.from(mcpToolsMap.values());
|
||||||
|
console.log('🔧 Processed MCP tools:', JSON.stringify(result, null, 2));
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
export * from './mcp/manager';
|
export * from './mcp/manager';
|
||||||
export * from './mcp/oauth';
|
export * from './mcp/oauth';
|
||||||
export * from './mcp/auth';
|
export * from './mcp/auth';
|
||||||
export * from './mcp/add';
|
export * from './mcp/mcpOps';
|
||||||
/* Utilities */
|
/* Utilities */
|
||||||
export * from './mcp/utils';
|
export * from './mcp/utils';
|
||||||
export * from './utils';
|
export * from './utils';
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
import { MCP } from 'librechat-data-provider';
|
|
||||||
import { Response } from 'express';
|
|
||||||
|
|
||||||
// just log the request
|
|
||||||
export const addTool = (req: { body: MCP }, res: Response) => {
|
|
||||||
console.log(JSON.stringify(req.body, null, 2));
|
|
||||||
res.send('ok');
|
|
||||||
};
|
|
||||||
17
packages/api/src/mcp/mcpOps.ts
Normal file
17
packages/api/src/mcp/mcpOps.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { MCP } from 'librechat-data-provider';
|
||||||
|
import { Response } from 'express';
|
||||||
|
|
||||||
|
export const addTool = (req: { body: MCP }, res: Response) => {
|
||||||
|
console.log('CREATE MCP:', JSON.stringify(req.body, null, 2));
|
||||||
|
res.send('ok');
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateTool = (req: { body: MCP; params: { mcp_id: string } }, res: Response) => {
|
||||||
|
console.log('UPDATE MCP:', req.params.mcp_id, JSON.stringify(req.body, null, 2));
|
||||||
|
res.send('ok');
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteTool = (req: { params: { mcp_id: string } }, res: Response) => {
|
||||||
|
console.log('DELETE MCP:', req.params.mcp_id);
|
||||||
|
res.send('ok');
|
||||||
|
};
|
||||||
|
|
@ -841,3 +841,26 @@ export const createMCP = (mcp: ag.MCP): Promise<Record<string, unknown>> => {
|
||||||
mcp,
|
mcp,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updateMCP = ({
|
||||||
|
mcp_id,
|
||||||
|
data,
|
||||||
|
}: {
|
||||||
|
mcp_id: string;
|
||||||
|
data: ag.MCP;
|
||||||
|
}): Promise<Record<string, unknown>> => {
|
||||||
|
return request.put(
|
||||||
|
endpoints.agents({
|
||||||
|
path: `tools/${mcp_id}`,
|
||||||
|
}),
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteMCP = ({ mcp_id }: { mcp_id: string }): Promise<Record<string, unknown>> => {
|
||||||
|
return request.delete(
|
||||||
|
endpoints.agents({
|
||||||
|
path: `tools/${mcp_id}`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -321,6 +321,13 @@ export type UpdatePluginAuthOptions = MutationOptions<types.TUser, types.TUpdate
|
||||||
|
|
||||||
export type CreateMCPMutationOptions = MutationOptions<Record<string, unknown>, MCP>;
|
export type CreateMCPMutationOptions = MutationOptions<Record<string, unknown>, MCP>;
|
||||||
|
|
||||||
|
export type UpdateMCPMutationOptions = MutationOptions<
|
||||||
|
Record<string, unknown>,
|
||||||
|
{ mcp_id: string; data: MCP }
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type DeleteMCPMutationOptions = MutationOptions<Record<string, unknown>, { mcp_id: string }>;
|
||||||
|
|
||||||
export type ToolParamsMap = {
|
export type ToolParamsMap = {
|
||||||
[Tools.execute_code]: {
|
[Tools.execute_code]: {
|
||||||
lang: string;
|
lang: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue