Content
# MCP Server
A WebSocket-based MCP (Model Control Protocol) server for handling model requests and providing responses.
## Project Structure
```
MCPServerDemo/
├── src/ # Source code directory
│ └── mcp/ # MCP implementation
│ ├── handlers/ # Request handlers
│ ├── models/ # Data models
│ ├── protocol/ # Protocol definitions
│ └── server/ # Server implementation
├── client/ # Client example
│ └── index.html # HTML client for testing
├── .env # Environment variable configuration (needs to be created from .env.example)
├── .env.example # Environment variable example
├── main.py # Application entry point
└── README.md # Project description
```
## Installation
This project uses uv for dependency management.
```bash
# Install dependencies
uv pip install fastapi uvicorn pydantic pydantic-settings
```
## Configuration
1. Copy the environment variable example file and configure it:
```bash
cp .env.example .env
```
2. Edit the `.env` file to set your configuration.
## Running
```bash
# Start the server
python main.py
```
The server will run at `http://localhost:8000`, with the WebSocket endpoint at `ws://localhost:8000/ws`.
## Testing Client
Open the `client/index.html` file in a browser to test the MCP server.
## MCP Protocol
The MCP protocol is a WebSocket-based protocol for controlling and managing AI models.
### Request Format
```json
{
"id": "Request ID",
"type": "request",
"action": "Action Name",
"messages": [
{
"role": "user",
"content": "Message Content"
}
],
"parameters": {
"Parameter Name": "Parameter Value"
}
}
```
### Response Format
```json
{
"id": "Request ID",
"type": "response",
"action": "Action Name",
"messages": [
{
"role": "assistant",
"content": "Response Content"
}
],
"metadata": {
"Metadata Name": "Metadata Value"
}
}
```
### Error Format
```json
{
"id": "Request ID",
"type": "error",
"action": "Action Name",
"error": "Error Message",
"details": {
"Detail Name": "Detail Value"
}
}
```
### Event Format
```json
{
"id": "Event ID",
"type": "event",
"event": "Event Name",
"data": {
"Data Name": "Data Value"
}
}
```
## Supported Actions
- `chat`: Chat request
- `completion`: Text completion request
## Extension
You can extend the MCP server in the following ways:
1. Create new handlers in the `src/mcp/handlers/` directory
2. Register new handlers in `main.py`
3. Customize protocol implementations in the `src/mcp/protocol/` directory
Connection Info
You Might Also Like
everything-claude-code
Complete Claude Code configuration collection - agents, skills, hooks,...
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
servers
Model Context Protocol Servers
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.