legal-research-mcp

zuhairabbas1/legal-research-mcp

3.2

If you are the rightful owner of legal-research-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

The Legal Research MCP Tool is a Python application designed to facilitate legal research using the Model Context Protocol (MCP) and OpenAI's GPT-4o-mini.

Tools
1
Resources
0
Prompts
0

Legal Research MCP Tool

A two-part Python application for legal research that demonstrates the Model Context Protocol (MCP) from first principles.

🎯 Project Overview

This project consists of:

  1. MCP Server - A Flask-based server that exposes a Google Search tool
  2. Client Application - A script that uses the MCP server to research legal questions and generates structured summaries using OpenAI's GPT-4o-mini

📋 Research Question

The application is designed to answer:

"What are the key requirements for a landlord in Ontario to issue an N12 eviction notice for 'landlord's own use,' and what are the potential penalties for issuing one in bad faith?"

🚀 Setup Instructions

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)
  • OpenAI API key

Installation

  1. Create a project folder

    mkdir legal-research-mcp
    cd legal-research-mcp
    
  2. Copy all files into this folder

    • mcp_server.py
    • client.py
    • requirements.txt
    • README.md
  3. Install dependencies

    pip install -r requirements.txt
    
  4. Set up your OpenAI API key

    export OPENAI_API_KEY='your-api-key-here'
    

    Or on Windows:

    set OPENAI_API_KEY=your-api-key-here
    

🎮 Usage

Step 1: Start the MCP Server

Open a terminal and run:

python mcp_server.py

You should see:

🚀 MCP Server starting on http://localhost:5000
📋 Available endpoints:
   - POST /tools/list - List available tools
   - POST /tools/call - Invoke a tool
   - GET /health - Health check

Keep this terminal running!

Step 2: Run the Client Application

Open a new terminal (keep the server running in the first one) and run:

python client.py

The client will:

  1. Send a search query to the MCP server
  2. Receive raw search results
  3. Create a prompt combining the question and results
  4. Send it to OpenAI for analysis
  5. Display a structured summary

📁 Project Structure

legal-research-mcp/
├── mcp_server.py       # Flask MCP server exposing Google Search tool
├── client.py           # Client application for legal research
├── requirements.txt    # Python dependencies
└── README.md          # This file

🔧 How It Works

MCP Server (mcp_server.py)

The server implements MCP endpoints from scratch:

  • POST /tools/list - Returns available tools (google_search)
  • POST /tools/call - Executes a tool with given arguments

The server accepts JSON requests in this format:

{
  "name": "google_search",
  "arguments": {
    "query": "your search query"
  }
}

Client Application (client.py)

The client follows this workflow:

  1. Define the legal question - Hard-coded N12 eviction question
  2. Call MCP tool - Sends HTTP POST to /tools/call with search query
  3. Receive results - Gets back formatted search results
  4. Create LLM prompt - Combines question + results into a structured prompt
  5. Query OpenAI - Sends prompt to GPT-4o-mini
  6. Display output - Prints structured legal summary

🐛 Troubleshooting

"Connection refused" error

  • Make sure the MCP server is running on port 5000
  • Check if another application is using port 5000

"OpenAI API key not set" warning

  • Set the OPENAI_API_KEY environment variable
  • Make sure to export/set it in the same terminal where you run client.py

No search results

  • The current implementation uses mock data for educational purposes
  • For production, integrate with Google Custom Search API

🎓 Learning Objectives

This project teaches:

  1. MCP Protocol Fundamentals - Understanding how MCP works at the HTTP/JSON level
  2. Separation of Concerns - Distinguishing between tool execution (search) and interpretation (LLM)
  3. API Integration - Working with both custom APIs (MCP) and third-party APIs (OpenAI)
  4. Structured Prompting - Creating effective prompts that combine context and questions

📝 License

This is an educational project. Feel free to use and modify as needed.


Note: This project intentionally avoids using pre-built MCP libraries to understand the protocol from first principles.