@websolutespa/payload-plugin-bowl-llm
Version:
LLM plugin for Bowl PayloadCms plugin
64 lines (63 loc) • 2.48 kB
JavaScript
import { fetchRobot } from '../utils/robot';
import { ToolSchemaRegistry } from './mcp.schemas';
export async function buildMcpToolsForApp(app) {
const appTools = app.settings.appTools?.filter((t)=>t.isActive) || [];
const descriptors = [];
for (const tool of appTools){
if (await ToolSchemaRegistry.has(tool.functionName)) {
const schema = await ToolSchemaRegistry.get(tool.functionName);
descriptors.push({
name: tool.functionId,
description: tool.functionDescription || tool.description || tool.name,
inputSchema: schema || {
type: 'object',
properties: {}
}
});
}
}
return descriptors;
}
// ---------- Tool Execution ----------
export async function executeTool(payload, app, functionId, args) {
// Find the tool in the app
const tool = app.settings.appTools?.find((t)=>t.functionId === functionId && t.isActive);
if (!tool) {
throw {
status: 404,
message: `Tool not found: ${functionId}`
};
}
// Build the appTool payload for Robot (matches LlmAppTool fields)
const appTool = {
name: tool.name,
description: tool.description,
type: tool.type,
functionId: tool.functionId,
functionName: tool.functionName,
functionDescription: tool.functionDescription,
secrets: tool.secrets,
llmChainSettings: tool.llmChainSettings,
searchSettings: tool.searchSettings,
dataSource: tool.dataSource,
dbSettings: tool.dbSettings,
apiSettings: tool.apiSettings,
integrations: tool.knowledgeBase?.integrations || [],
externalEndpoints: tool.knowledgeBase?.externalEndpoints || [],
waitingMessage: tool.waitingMessage,
vectorDbType: tool.knowledgeBase?.vectorDbType || 'faiss',
vectorDbFile: tool.knowledgeBase?.vectorDbFile?.filename || null,
isActive: true
};
// Call Robot direct tool execution (no agent, no LLM chain)
const request = {
provider: app.settings.llmConfig.provider || 'openai',
model: app.settings.llmConfig.model || 'gpt-4o',
secrets: app.settings.llmConfig.secrets || {},
appTool,
arguments: args
};
const result = await fetchRobot('api/llm/tool/execute', 'POST', request);
return result;
}
//# sourceMappingURL=mcp.adapter.js.map