UNPKG

@turbot/guardrails-mcp

Version:

MCP server for interacting with Turbot Guardrails.

84 lines (83 loc) 2.87 kB
import { executeQuery } from "../utils/graphqlClient.js"; import { logger } from '../services/pinoLogger.js'; import { formatJsonToolResponse, errorResponse, formatGraphQLError } from '../utils/responseFormatter.mjs'; export const tool = { name: "guardrails_resource_show", description: "Show detailed information about a specific resource.", inputSchema: { type: "object", properties: { id: { type: "string", description: "The ID or AKA of the resource to show (e.g. '320152411455166' or 'arn:aws:::634653137938')" } }, required: ["id"], additionalProperties: false }, handler: async ({ id }) => { logger.info("Starting show_guardrails_resource tool execution"); try { const query = ` query ShowResource($id: ID!) { resource(id: $id) { data metadata trunk { title } turbot { akas id tags parentId createTimestamp updateTimestamp versionId } type { uri } attachedSmartFolders { items { trunk { title } turbot { id } } } } } `; logger.debug("Executing GraphQL query with ID:", id); const result = JSON.parse(await executeQuery(query, { id })); logger.info("Query executed successfully"); // Transform the response to flatten and reorganize fields const resource = result.resource; const transformedResult = { id: resource.turbot.id, parentId: resource.turbot.parentId, typeUri: resource.type.uri, trunkTitle: resource.trunk?.title || null, akas: resource.turbot.akas, tags: resource.turbot.tags, createTimestamp: resource.turbot.createTimestamp, updateTimestamp: resource.turbot.updateTimestamp, versionId: resource.turbot.versionId, data: resource.data, metadata: resource.metadata, attachedSmartFolders: resource.attachedSmartFolders.items.map(folder => ({ id: folder.turbot.id, title: folder.trunk?.title || null })) }; return formatJsonToolResponse(transformedResult); } catch (error) { logger.error("Error in show_guardrails_resource:", error); return errorResponse(formatGraphQLError(error, id)); } } };