zuhairabbas1/legal-research-mcp
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.
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:
- MCP Server - A Flask-based server that exposes a Google Search tool
- 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
-
Create a project folder
mkdir legal-research-mcp cd legal-research-mcp -
Copy all files into this folder
- mcp_server.py
- client.py
- requirements.txt
- README.md
-
Install dependencies
pip install -r requirements.txt -
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:
- Send a search query to the MCP server
- Receive raw search results
- Create a prompt combining the question and results
- Send it to OpenAI for analysis
- 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:
- Define the legal question - Hard-coded N12 eviction question
- Call MCP tool - Sends HTTP POST to
/tools/callwith search query - Receive results - Gets back formatted search results
- Create LLM prompt - Combines question + results into a structured prompt
- Query OpenAI - Sends prompt to GPT-4o-mini
- 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:
- MCP Protocol Fundamentals - Understanding how MCP works at the HTTP/JSON level
- Separation of Concerns - Distinguishing between tool execution (search) and interpretation (LLM)
- API Integration - Working with both custom APIs (MCP) and third-party APIs (OpenAI)
- 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.