Content
# This project was created on 2025-03-30 and is a sample implementation of MCP Client and MCP Server (Python version)
## It is optimized based on https://github.com/sidharthrajaram/mcp-sse【The original project is based on the original discussion at (https://github.com/modelcontextprotocol/python-sdk/issues/145), and you can download the original project for more details】.
## The original version was implemented using ANTHROPIC LLM, while this version has been adjusted to use the LLM proxy calling platform from OpenRouter.ai.
# 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. It is 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 the tools provided by the SSE-based MCP server. It is 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 sample environment variable 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
```
## Running 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
```
SSE client initialized...
Listing tools...
Connected to the server, available tools: ['search_gutenberg_books']
AI assistant is up!
Enter your question or type 'quit' to exit.
User: Please recommend some works by James Joyce
AI: Let me help you search for works by James Joyce...
[Calling 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 sample
├── pyproject.toml # Project dependencies and configuration management
└── README.md # Project documentation
```
## Why Choose This Approach?
This implementation means that the MCP server can now run as an active process, allowing clients to connect, use, and disconnect at any time and from anywhere. In other words, the SSE-based server and client can be decoupled processes (and can even run on decoupled nodes). This is different from the STDIO-based model, where the client itself starts the server as a subprocess. This approach is more suitable for "cloud-native" use cases.
## Troubleshooting
If you encounter issues, please check:
1. Whether the Python version meets the requirements (>=3.13)
2. Whether the environment variables are correctly configured
3. Whether all dependencies are correctly installed
4. Whether port 8080 is occupied (if occupied, you can specify another port using the --port parameter)
## Getting Help
If you encounter issues, please:
1. Check the project's GitHub Issues page
2. Provide complete error messages and environment information
3. Describe the steps to reproduce the issue
Connection Info
You Might Also Like
MarkItDown MCP
Converting files and office documents to Markdown.
Time
Obtaining current time information and converting time between different...
Filesystem
Model Context Protocol Servers
Sequential Thinking
Offers a structured approach to dynamic and reflective problem-solving,...
Git
Model Context Protocol Servers
Context 7
Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors