@websolutespa/payload-plugin-bowl-llm
Version:
LLM plugin for Bowl PayloadCms plugin
42 lines (41 loc) • 1.32 kB
JavaScript
/**
* MCP Tool Schema Registry
*
* Fetches JSON Schema input models at runtime from Robot's
* GET /api/llm/extension/tools/schemas endpoint.
*
* Robot generates schemas directly from Pydantic models,
* so any new tool added on Robot is automatically available.
*/ import { fetchRobot } from '../utils/robot';
export class ToolSchemaRegistry {
static cache = null;
/* Use Cache*/ static async fetchSchemas() {
if (this.cache) {
return this.cache;
}
try {
const response = await fetchRobot('api/llm/extension/tools/schemas', 'GET');
this.cache = response;
return this.cache;
} catch (error) {
console.error('[MCP] Failed to fetch tool schemas from Robot:', error);
return {};
}
}
static async get(functionName) {
const schemas = await this.fetchSchemas();
return schemas[functionName]?.inputSchema;
}
static async has(functionName) {
const schemas = await this.fetchSchemas();
return functionName in schemas;
}
static async keys() {
const schemas = await this.fetchSchemas();
return Object.keys(schemas);
}
static invalidate() {
this.cache = null;
}
}
//# sourceMappingURL=mcp.schemas.js.map