Content
# This project was built on 2025-03-30 and is a sample implementation of MCP Client and MCP Server (Python version)
## It is based on https://github.com/sidharthrajaram/mcp-sse for optimization and implementation [The original project is based on the original discussion of (https://github.com/modelcontextprotocol/python-sdk/issues/145), you can download the original project for more information].
## The original version was implemented using ANTHROPIC LLM, and this version is adjusted to use OpenRouter.ai's LLM transfer call 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 an 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 use 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 sample 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 the 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: Please recommend some works by James Joyce
AI: Let me help you search for works by James Joyce...
[Calling tool search_gutenberg_books, 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 be a running process, and the proxy (client) can connect, use, and disconnect at any time. 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 child process. This approach is more suitable for "cloud-native" use cases.
## Troubleshooting
If you encounter problems, please check:
1. Whether the Python version meets the requirements (>=3.13)
2. Whether the environment variables are configured correctly
3. Whether all dependencies are installed correctly
4. Whether port 8080 is occupied (if it is occupied, you can use the --port parameter to specify another port)
## Get Help
If you encounter problems, please:
1. Check the project's GitHub Issues page
2. Provide complete error information and runtime environment information
3. Describe the steps to reproduce the problem
Connection Info
You Might Also Like
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
firecrawl
Firecrawl MCP Server enables web scraping, crawling, and content extraction.
servers
Model Context Protocol Servers
Time
A Model Context Protocol server for time and timezone conversions.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.
Sequential Thinking
A structured MCP server for dynamic problem-solving and reflective thinking.