Content
# Tool List
## This project was built on 2025-03-30 and is a sample implementation of MCP Client and MCP Server in Python.
## It is an optimized implementation based on https://github.com/sidharthrajaram/mcp-sse【The original project was based on (https://github.com/modelcontextprotocol/python-sdk/issues/145) for more information】.
## The original version was implemented using ANTHROPIC LLM, while this version uses OpenRouter.ai's LLM relay platform.
# SSE-based [MCP](https://modelcontextprotocol.io/introduction) Server and Client
## `mcp_server.py` is an SSE-based MCP server that provides a book search tool based on the Gutenberg Project API. Adapted from the [example STDIO server implementation](https://modelcontextprotocol.io/quickstart/server) in the MCP documentation.
## `client.py` is an MCP client that can connect to and use tools provided by the SSE-based MCP server. Adapted from the [example STDIO client implementation](https://modelcontextprotocol.io/quickstart/client) in the MCP documentation.
## System Requirements
- Python 3.13 or higher
- uv package manager (recommended) or pip
## Installation Steps
1. **Clone the Project**
```bash
git clone [your-repository-url]
cd jay-py-mcp-sse
```
2. **Environment Configuration**
Using uv (recommended):
```bash
# Install uv (if not installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create a virtual environment and install dependencies
uv venv
uv pip install .
```
Or using traditional pip:
```bash
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/MacOS
# or
.venv\Scripts\activate # Windows
# Install dependencies
pip install .
```
3. **Configure Environment Variables**
Copy the environment variable example file and fill in the necessary information:
```bash
cp .env.sample .env
```
Edit the `.env` file and enter your OpenRouter API key:
```plaintext
OPENROUTER_API_KEY=your_api_key_here
```
## Run the Service
1. **Start the Server**
```bash
uv run mcp_server.py
# or specify host and port
uv run mcp_server.py --host 127.0.0.1 --port 8080
```
2. **Start the Client**
```bash
uv run client.py http://localhost:8080/sse
```
## Example Output
```
Initialized SSE client...
Listing tools...
Connected to server, available tools: ['search_gutenberg_books']
AI assistant started!
Enter your question or type 'quit' to exit.
User: Recommend some works by James Joyce
AI: Let me search for James Joyce's works...
[Invoking tool search_gutenberg_books with parameters: {"search_terms": ["James Joyce"]}]
Found the following works:
- "Ulysses"
- "Dubliners"
- "A Portrait of the Artist as a Young Man"
...
```
## Project Structure
```
.
├── mcp_server.py # SSE server implementation
├── client.py # MCP client implementation
├── .env.sample # Environment variable example
├── pyproject.toml # Project dependency and configuration management
└── README.md # Project documentation
```
## Why This Approach?
This implementation means the MCP server can now run as a separate process, and agents can connect, use, and disconnect at will. In other words, the SSE-based server and client can be decoupled processes (even running on decoupled nodes). This is different from the STDIO-based approach, where the client itself starts the server as a subprocess. This approach is more suitable for "cloud-native" use cases.
## Troubleshooting
If issues arise, check:
1. Python version meets requirements (>=3.13)
2. Environment variables are correctly configured
3. All dependencies are correctly installed
4. Port 8080 is not occupied (if occupied, use the --port parameter to specify another port)
## Get Help
If issues arise, please:
1. Check the project's GitHub Issues page
2. Provide complete error information and running environment information
3. Describe steps to reproduce the issue