/** * JSON Schemas for AI Universe Conversation MCP Server * * These schemas define the structure for all MCP tool requests and responses. * They can be used for validation, documentation, and code generation. */ // Health Check Schemas export const healthCheckRequestSchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'HealthCheckRequest', type: 'object', properties: {}, additionalProperties: false } as const; export const healthCheckResponseSchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'HealthCheckResponse', type: 'object', required: ['status', 'service', 'version', 'timestamp', 'type'], properties: { status: { type: 'string', const: 'healthy' }, service: { type: 'string' }, version: { type: 'string' }, timestamp: { type: 'string', format: 'date-time' }, type: { type: 'string' }, conversationCount: { type: 'number', minimum: 0 } }, additionalProperties: false } as const; // Send Message Schemas export const sendMessageRequestSchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'SendMessageRequest', type: 'object', required: ['userId', 'content', 'role'], properties: { userId: { type: 'string', minLength: 1, maxLength: 100, pattern: '^[a-zA-Z0-9._@-]+$', description: 'User identifier - alphanumeric characters and ._@- allowed' }, conversationId: { type: 'string', minLength: 1, description: 'Optional conversation ID. Omit for auto-creation. Cannot be empty or whitespace.' }, convo_id: { type: 'string', minLength: 1, description: 'Alias for conversationId (for compatibility). conversationId takes precedence.' }, content: { type: 'string', minLength: 1, maxLength: 200000, description: 'Message content' }, role: { type: 'string', enum: ['user', 'assistant'], description: 'Message sender role' }, title: { type: 'string', maxLength: 200, description: 'Optional title for auto-created conversations' }, metadata: { type: 'object', description: 'Optional metadata attached to the message', additionalProperties: true } }, additionalProperties: false } as const; export const sendMessageResponseSchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'SendMessageResponse', type: 'object', required: ['conversationId', 'messageId', 'sequence', 'created', 'title', 'timestamp'], properties: { conversationId: { type: 'string', minLength: 1, description: 'Conversation ID (existing or newly created)' }, messageId: { type: 'string', minLength: 1, description: 'Unique message identifier' }, sequence: { type: 'number', minimum: 0, description: 'Message sequence number in conversation' }, created: { type: 'boolean', description: 'True if conversation was auto-created, false if added to existing' }, title: { type: 'string', description: 'Conversation title' }, timestamp: { type: 'string', format: 'date-time', description: 'ISO-8601 timestamp of message creation' }, metadata: { type: 'object', description: 'Optional message metadata', additionalProperties: true } }, additionalProperties: false } as const; // Get Conversation Schemas export const getConversationRequestSchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'GetConversationRequest', type: 'object', required: ['userId', 'conversationId'], properties: { userId: { type: 'string', minLength: 1, maxLength: 100, pattern: '^[a-zA-Z0-9._@-]+$' }, conversationId: { type: 'string', minLength: 1 } }, additionalProperties: false } as const; export const conversationMetadataSchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'ConversationMetadata', type: 'object', required: ['conversationId', 'userId', 'title', 'messageCount', 'createdAt', 'updatedAt', 'lastMessage'], properties: { conversationId: { type: 'string', minLength: 1 }, userId: { type: 'string', minLength: 1 }, title: { type: 'string' }, messageCount: { type: 'number', minimum: 0 }, createdAt: { type: 'string', format: 'date-time' }, updatedAt: { type: 'string', format: 'date-time' }, lastMessage: { type: ['string', 'null'], description: 'Content of the last message, or null if no messages' }, metadata: { type: 'object', description: 'Optional conversation-level metadata', additionalProperties: true } }, additionalProperties: false } as const; // Get History Schemas export const getHistoryRequestSchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'GetHistoryRequest', type: 'object', required: ['userId', 'conversationId'], properties: { userId: { type: 'string', minLength: 1, maxLength: 100, pattern: '^[a-zA-Z0-9._@-]+$' }, conversationId: { type: 'string', minLength: 1 }, limit: { type: 'number', minimum: 1, maximum: 100, default: 50, description: 'Maximum number of messages to return' }, cursor: { type: 'string', description: 'Pagination cursor from previous response' } }, additionalProperties: false } as const; export const messageSchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'Message', type: 'object', required: ['messageId', 'conversationId', 'content', 'role', 'sequence', 'timestamp'], properties: { messageId: { type: 'string', minLength: 1 }, conversationId: { type: 'string', minLength: 1 }, content: { type: 'string' }, role: { type: 'string', enum: ['user', 'assistant'] }, sequence: { type: 'number', minimum: 0 }, timestamp: { type: 'string', format: 'date-time' }, metadata: { type: 'object', description: 'Optional message metadata', additionalProperties: true } }, additionalProperties: false } as const; export const getHistoryResponseSchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'GetHistoryResponse', type: 'object', required: ['conversationId', 'messages', 'hasMore'], properties: { conversationId: { type: 'string', minLength: 1 }, messages: { type: 'array', items: messageSchema }, hasMore: { type: 'boolean', description: 'True if more messages are available' }, nextCursor: { type: 'string', description: 'Cursor for fetching next page (only present if hasMore is true)' } }, additionalProperties: false } as const; // Get Message Schemas export const getMessageRequestSchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'GetMessageRequest', type: 'object', required: ['userId', 'conversationId', 'messageId'], properties: { userId: { type: 'string', minLength: 1, maxLength: 100, pattern: '^[a-zA-Z0-9._@-]+$' }, conversationId: { type: 'string', minLength: 1 }, messageId: { type: 'string', minLength: 1 } }, additionalProperties: false } as const; // List Conversations Schemas export const listConversationsRequestSchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'ListConversationsRequest', type: 'object', required: ['userId'], properties: { userId: { type: 'string', minLength: 1, maxLength: 100, pattern: '^[a-zA-Z0-9._@-]+$' }, pageSize: { type: 'number', minimum: 1, maximum: 100, default: 10, description: 'Number of conversations to return per page' }, cursor: { type: 'string', description: 'Pagination cursor from previous response' } }, additionalProperties: false } as const; export const conversationSummarySchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'ConversationSummary', type: 'object', required: ['conversationId', 'title', 'messageCount', 'createdAt', 'updatedAt'], properties: { conversationId: { type: 'string', minLength: 1 }, title: { type: 'string' }, messageCount: { type: 'number', minimum: 0 }, createdAt: { type: 'string', format: 'date-time' }, updatedAt: { type: 'string', format: 'date-time' }, metadata: { type: 'object', description: 'Optional conversation-level metadata', additionalProperties: true } }, additionalProperties: false } as const; export const listConversationsResponseSchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'ListConversationsResponse', type: 'object', required: ['conversations', 'totalCount', 'hasMore'], properties: { conversations: { type: 'array', items: conversationSummarySchema }, totalCount: { type: 'number', minimum: 0, description: 'Total number of conversations for this user' }, hasMore: { type: 'boolean', description: 'True if more conversations are available' }, nextCursor: { type: 'string', description: 'Cursor for fetching next page (only present if hasMore is true)' } }, additionalProperties: false } as const; // Generic MCP Tool Response Wrapper export const mcpToolResponseSchema = { $schema: 'http://json-schema.org/draft-07/schema#', title: 'MCPToolResponse', type: 'object', required: ['success'], properties: { success: { type: 'boolean' }, data: { description: 'Response data (present when success is true)' }, error: { type: 'string', description: 'Error message (present when success is false)' }, message: { type: 'string', description: 'Optional additional message' } } } as const; // All schemas combined for easy access export const schemas = { // Health check 'health-check': { request: healthCheckRequestSchema, response: healthCheckResponseSchema }, // Send message (auto-creation) 'convo.send-message': { request: sendMessageRequestSchema, response: sendMessageResponseSchema }, // Get conversation metadata 'convo.get-conversation': { request: getConversationRequestSchema, response: conversationMetadataSchema }, // Get conversation history 'convo.get-history': { request: getHistoryRequestSchema, response: getHistoryResponseSchema }, // Get single message 'convo.get-message': { request: getMessageRequestSchema, response: messageSchema }, // List conversations 'convo.list-conversations': { request: listConversationsRequestSchema, response: listConversationsResponseSchema }, // Generic wrapper mcpToolResponse: mcpToolResponseSchema } as const; // Export individual request schemas export const requestSchemas = { 'health-check': healthCheckRequestSchema, 'convo.send-message': sendMessageRequestSchema, 'convo.get-conversation': getConversationRequestSchema, 'convo.get-history': getHistoryRequestSchema, 'convo.get-message': getMessageRequestSchema, 'convo.list-conversations': listConversationsRequestSchema } as const; // Export individual response schemas export const responseSchemas = { 'health-check': healthCheckResponseSchema, 'convo.send-message': sendMessageResponseSchema, 'convo.get-conversation': conversationMetadataSchema, 'convo.get-history': getHistoryResponseSchema, 'convo.get-message': messageSchema, 'convo.list-conversations': listConversationsResponseSchema } as const; // Helper types for schema validation export type SchemaType = typeof schemas; export type RequestSchemaType = typeof requestSchemas; export type ResponseSchemaType = typeof responseSchemas;