mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-13 21:14:24 +01:00
mcp example, mock i/o for client-to-server communications
This commit is contained in:
parent
799f0e5810
commit
7251308244
9 changed files with 343 additions and 22 deletions
|
|
@ -2,6 +2,7 @@
|
|||
export * from './mcp/manager';
|
||||
export * from './mcp/oauth';
|
||||
export * from './mcp/auth';
|
||||
export * from './mcp/add';
|
||||
/* Utilities */
|
||||
export * from './mcp/utils';
|
||||
export * from './utils';
|
||||
|
|
|
|||
81
packages/api/src/mcp/add.ts
Normal file
81
packages/api/src/mcp/add.ts
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { logger } from '@librechat/data-schemas';
|
||||
|
||||
interface CreateToolRequest extends Request {
|
||||
body: {
|
||||
name: string;
|
||||
description: string;
|
||||
type: 'function' | 'code_interpreter' | 'file_search';
|
||||
metadata?: Record<string, unknown>;
|
||||
};
|
||||
user?: {
|
||||
id: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new tool to the system
|
||||
* @route POST /agents/tools/add
|
||||
* @param {object} req.body - Request body containing tool data
|
||||
* @param {string} req.body.name - Tool name
|
||||
* @param {string} req.body.description - Tool description
|
||||
* @param {string} req.body.type - Tool type (function, code_interpreter, file_search)
|
||||
* @param {object} [req.body.metadata] - Optional metadata
|
||||
* @returns {object} Created tool object
|
||||
*/
|
||||
export const addTool = async (req: CreateToolRequest, res: Response) => {
|
||||
try {
|
||||
const { name, description, type, metadata } = req.body;
|
||||
|
||||
// Log the incoming request for development
|
||||
logger.info(
|
||||
'Add Tool Request:' +
|
||||
JSON.stringify({
|
||||
name,
|
||||
description,
|
||||
type,
|
||||
metadata,
|
||||
userId: req.user?.id,
|
||||
}),
|
||||
);
|
||||
|
||||
// Validate required fields
|
||||
if (!name || !description || !type) {
|
||||
return res.status(400).json({
|
||||
error: 'Missing required fields: name, description, and type are required',
|
||||
});
|
||||
}
|
||||
|
||||
// Validate tool type
|
||||
const validTypes = ['function', 'code_interpreter', 'file_search'];
|
||||
if (!validTypes.includes(type)) {
|
||||
return res.status(400).json({
|
||||
error: `Invalid tool type. Must be one of: ${validTypes.join(', ')}`,
|
||||
});
|
||||
}
|
||||
|
||||
// For now, return a mock successful response
|
||||
// TODO: Implement actual tool creation logic
|
||||
const mockTool = {
|
||||
id: `tool-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
||||
type,
|
||||
function: {
|
||||
name,
|
||||
description,
|
||||
},
|
||||
metadata: metadata || {},
|
||||
created_at: new Date().toISOString(),
|
||||
updated_at: new Date().toISOString(),
|
||||
};
|
||||
|
||||
logger.info('Tool created successfully:' + JSON.stringify(mockTool));
|
||||
|
||||
res.status(201).json(mockTool);
|
||||
} catch (error) {
|
||||
logger.error('Error adding tool:', error);
|
||||
res.status(500).json({
|
||||
error: 'Internal server error while adding tool',
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -312,6 +312,30 @@ export const getToolCalls = (params: q.GetToolCallParams): Promise<q.ToolCallRes
|
|||
);
|
||||
};
|
||||
|
||||
export const createTool = (toolData: {
|
||||
name: string;
|
||||
description: string;
|
||||
type: 'function' | 'code_interpreter' | 'file_search';
|
||||
metadata?: Record<string, unknown>;
|
||||
}): Promise<{
|
||||
id: string;
|
||||
type: string;
|
||||
function: {
|
||||
name: string;
|
||||
description: string;
|
||||
};
|
||||
metadata: Record<string, unknown>;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}> => {
|
||||
return request.post(
|
||||
endpoints.agents({
|
||||
path: 'tools/add',
|
||||
}),
|
||||
toolData,
|
||||
);
|
||||
};
|
||||
|
||||
/* Files */
|
||||
|
||||
export const getFiles = (): Promise<f.TFile[]> => {
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ export enum QueryKeys {
|
|||
banner = 'banner',
|
||||
/* Memories */
|
||||
memories = 'memories',
|
||||
mcpTools = 'mcpTools',
|
||||
}
|
||||
|
||||
export enum MutationKeys {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue