UNPKG

@blario/mcp

Version:

Blar Model Context Protocol server

78 lines (77 loc) 3.45 kB
import { z } from 'zod'; import { blarAPIClient, BLAR_API_BASE } from '../api-client.js'; export const createConsiderationSchema = { repo_name: z.string().describe('Repository name where the consideration should be created'), consideration_title: z.string().describe('Title of the consideration'), consideration_description: z.string().describe('Detailed description of the consideration'), consideration_code_snippet: z.string().optional().describe('Optional code snippet related to the consideration'), consideration_tags: z.array(z.enum(['context', 'design_pattern'])).describe('Required array of tags for the consideration. Use ["context"] for descriptive background info, ["design_pattern"] for enforceable rules/patterns, or ["context", "design_pattern"] for both'), relative_file_path: z.string().optional().describe('Optional relative path to a specific file or folder within the repository. If provided, the consideration will be scoped to that file/folder and propagate down to its contents. Leave empty for global repository-wide considerations'), }; export async function createConsiderationHandler({ repo_name, consideration_title, consideration_description, consideration_code_snippet, consideration_tags, relative_file_path, }) { const url = `${BLAR_API_BASE}/wiki/consideration/from-mcp`; const requestData = { repo_name, consideration_title, consideration_description, consideration_code_snippet: consideration_code_snippet || '', consideration_tags: consideration_tags, relative_file_path: relative_file_path || '', }; const response = await blarAPIClient.makePostRequest(url, requestData); if (response.error) { if (response.status === 400 && response.error.repos) { return { content: [ { type: 'text', text: `Error: Multiple repositories found with name '${repo_name}'. Available repositories: ${response.error.repos.join(', ')}. Please specify a unique repository name.`, }, ], isError: true, }; } return { content: [ { type: 'text', text: `Error creating consideration: ${JSON.stringify(response.error, null, 2)}`, }, ], isError: true, }; } if (!response.data) { return { content: [ { type: 'text', text: 'Failed to create consideration', }, ], isError: true, }; } // Format success response const consideration = response.data; const formatted = [ 'Consideration created successfully!', '', `ID: ${consideration.id}`, `Title: ${consideration.title}`, `Description: ${consideration.description}`, `Tags: ${consideration.tags.join(', ')}`, `Code Snippet: ${consideration.code_snippet || 'No code snippet'}`, `Active: ${consideration.active ? 'Yes' : 'No'}`, `Created At: ${consideration.created_at}`, `Source Type: ${consideration.source_type_name}`, ].join('\n'); return { content: [ { type: 'text', text: formatted, }, ], }; }