Skip to main content
Glama
yoda-digital

Cerebra Legal MCP Server

by yoda-digital

legal_attempt_completion

Formats legal analysis results into structured documents with proper citations and professional formatting for clear communication of findings and recommendations.

Instructions

A specialized tool for presenting legal analysis results and conclusions. This tool formats legal conclusions with proper structure, extracts and formats citations, and provides a professional legal document format.

When to use this tool:

  • When presenting the final results of a legal analysis

  • When summarizing legal findings and recommendations

  • When providing a structured legal opinion

  • When concluding a legal reasoning process

Key features:

  • Automatic detection of legal domains

  • Proper legal document formatting

  • Citation extraction and formatting

  • Structured sections for clear communication

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYesThe legal analysis result or conclusion
commandNoA CLI command to execute (optional)
contextNoAdditional context about the legal issue (optional)

Implementation Reference

  • The primary handler function for the 'legal_attempt_completion' tool. It validates input, detects the legal domain, formats the result using helper functions if needed, and returns a structured ToolResponse.
    function processLegalAttemptCompletion(input: unknown): { content: Array<{ type: string; text: string }>; isError?: boolean } {
      try {
        const data = input as Record<string, unknown>;
        
        // Validate input
        if (!data.result || typeof data.result !== 'string') {
          throw new Error('Invalid result: must be a string');
        }
        
        // Detect domain from result and context
        const textToAnalyze = data.context 
          ? `${data.result} ${data.context}`
          : data.result as string;
        const domain = detectDomain(textToAnalyze);
        
        // Format the result with proper legal structure
        let result = data.result as string;
        
        // If result doesn't have a good structure, apply template
        if (!hasGoodStructure(result)) {
          result = applyTemplateStructure(result, domain);
        }
        
        // Prepare response
        return {
          content: [{
            type: "text",
            text: JSON.stringify({
              result,
              command: data.command,
              detectedDomain: domain,
              formattedCitations: []
            }, null, 2)
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: JSON.stringify({
              error: error instanceof Error ? error.message : String(error),
              status: 'failed'
            }, null, 2)
          }],
          isError: true
        };
      }
    }
  • src/index.ts:133-167 (registration)
    Tool registration definition including name, description, and input schema. This object is returned in ListTools and dispatched in CallToolRequestHandler.
    const LEGAL_ATTEMPT_COMPLETION_TOOL: Tool = {
      name: "legal_attempt_completion",
      description: `A specialized tool for presenting legal analysis results and conclusions.
    This tool formats legal conclusions with proper structure, extracts and formats citations, and provides a professional legal document format.
    
    When to use this tool:
    - When presenting the final results of a legal analysis
    - When summarizing legal findings and recommendations
    - When providing a structured legal opinion
    - When concluding a legal reasoning process
    
    Key features:
    - Automatic detection of legal domains
    - Proper legal document formatting
    - Citation extraction and formatting
    - Structured sections for clear communication`,
      inputSchema: {
        type: "object",
        properties: {
          result: {
            type: "string",
            description: "The legal analysis result or conclusion"
          },
          command: {
            type: "string",
            description: "A CLI command to execute (optional)"
          },
          context: {
            type: "string",
            description: "Additional context about the legal issue (optional)"
          }
        },
        required: ["result"]
      }
    };
  • TypeScript interfaces defining the input and output structures for the legal_attempt_completion tool.
    export interface LegalAttemptCompletionInput {
      result: string;
      command?: string;
      context?: string;
    }
    
    /**
     * Legal attempt completion response data
     */
    export interface LegalAttemptCompletionResponse {
      result: string;
      command?: string;
      detectedDomain: string;
      formattedCitations: string[];
    }
  • Helper function used by the handler to determine if the input result already has good legal structure, avoiding unnecessary reformatting.
    function hasGoodStructure(result: string): boolean {
      // Check for section headers (numbered or with clear titles)
      const hasNumberedSections = /\n\s*\d+\.\s+[A-Z]/.test(result);
      const hasTitledSections = /\n\s*[A-Z][a-zA-Z\s]+:/.test(result);
      
      // Check for bullet points
      const hasBulletPoints = /\n\s*[-•*]\s+/.test(result);
      
      // Check for clear paragraphs
      const hasClearParagraphs = result.split('\n\n').length >= 3;
      
      return (hasNumberedSections || hasTitledSections) && (hasBulletPoints || hasClearParagraphs);
    }
  • Helper function that applies domain-specific template structure to the result when the original lacks proper formatting.
    function applyTemplateStructure(result: string, domain: string): string {
      // Get domain-specific completion template
      const template = domainCompletionTemplates[domain] || domainCompletionTemplates["legal_reasoning"];
      
      // Add a title based on domain
      let formattedResult = '';
      
      switch (domain) {
        case 'ansc_contestation':
          formattedResult += 'Legal Analysis Summary:\n\n';
          break;
        case 'consumer_protection':
          formattedResult += 'Consumer Protection Analysis:\n\n';
          break;
        case 'contract_analysis':
          formattedResult += 'Contract Analysis Report:\n\n';
          break;
        default:
          formattedResult += 'Legal Analysis Report:\n\n';
      }
      
      // Add a brief introduction
      formattedResult += `${result}\n\n`;
      
      // Add template structure
      formattedResult += template.split('\n\n').slice(1).join('\n\n');
      
      return formattedResult;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but provides minimal behavioral disclosure. It mentions formatting features but doesn't address permissions needed, whether it modifies data, rate limits, error conditions, or what the output looks like. For a tool with 3 parameters and no output schema, this leaves significant gaps in understanding how the tool actually behaves.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, usage guidelines, key features) and efficiently communicates core information. While slightly verbose in listing multiple 'when to use' examples, each sentence adds value and the overall length is appropriate for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 3 parameters, no annotations, and no output schema, the description provides adequate purpose and usage context but lacks sufficient behavioral details. It explains what the tool does and when to use it, but doesn't adequately address how it works, what permissions are needed, or what the output format will be. This leaves gaps for a tool that presumably generates formatted legal documents.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters. The description adds no specific information about parameter usage, relationships, or examples beyond what's in the schema. The baseline of 3 is appropriate when the schema does the heavy lifting, though the description could have explained how parameters interact with the formatting features mentioned.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'presenting legal analysis results and conclusions' with specific functions like formatting, citation extraction, and document structuring. It distinguishes from sibling tools (legal_ask_followup_question, legal_think) by focusing on final presentation rather than analysis or questioning, though it doesn't explicitly name these alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The 'When to use this tool' section provides clear context: presenting final results, summarizing findings, providing structured opinions, and concluding legal reasoning. It implicitly distinguishes from siblings by focusing on completion rather than intermediate steps, but doesn't explicitly state when NOT to use it or name specific alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yoda-digital/mcp-cerebra-legal-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server