import { Tool } from '@modelcontextprotocol/sdk/types.js';
import { JsmClient } from '../api/jsmClient.js';
import { formatError, logDebug } from '../utils/index.js';
export const getObjectSchemasTool: Tool = {
name: 'get_object_schemas',
description: 'List all object schemas available in the JSM Assets workspace. Schemas contain related object types.',
inputSchema: {
type: 'object',
properties: {},
additionalProperties: false
}
};
export async function handleGetObjectSchemas(
client: JsmClient
): Promise<{ content: Array<{ type: string; text: string }> }> {
try {
logDebug('Fetching object schemas');
const result = await client.getObjectSchemas();
logDebug('Object schemas fetched', {
count: result.objectschemas?.length
});
const summary = `Found ${result.objectschemas?.length || 0} object schemas`;
let formattedResults = '';
if (result.objectschemas && result.objectschemas.length > 0) {
formattedResults = result.objectschemas.map((schema, index) => {
return `${index + 1}. ${schema.name} (ID: ${schema.id})
Key: ${schema.objectSchemaKey}
Status: ${schema.status}
Objects: ${schema.objectCount}
Object Types: ${schema.objectTypeCount}
Created: ${schema.created}
Updated: ${schema.updated}`;
}).join('\n\n');
}
return {
content: [
{
type: 'text',
text: `${summary}\n\n${formattedResults}`
}
]
};
} catch (error) {
logDebug('Get object schemas error', error);
return {
content: [
{
type: 'text',
text: `Error getting object schemas: ${formatError(error)}`
}
]
};
}
}