Compare commits
9 Commits
511137edae
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| dce352b02a | |||
| 73fb7000b5 | |||
| 741714a4bc | |||
| 208e4195b0 | |||
| 63617550a1 | |||
| f9c7b446d5 | |||
| a98903c048 | |||
| b0f19810d4 | |||
| dbddfcd61d |
@@ -0,0 +1,32 @@
|
|||||||
|
# MCP Summary Server - Environment Variables
|
||||||
|
|
||||||
|
# Server Configuration
|
||||||
|
PORT=8080
|
||||||
|
|
||||||
|
# Authentication (optional)
|
||||||
|
# If set, requests must include: Authorization: Bearer <API_KEY>
|
||||||
|
API_KEY=
|
||||||
|
|
||||||
|
# LLM Configuration
|
||||||
|
OPENAPI_URL=http://localhost:8080/v1
|
||||||
|
OPENAPI_API_KEY=
|
||||||
|
MODEL_NAME=gpt-4o
|
||||||
|
|
||||||
|
# LLM Call Timeout in seconds (increase for large documents)
|
||||||
|
LLM_TIMEOUT=120
|
||||||
|
|
||||||
|
# Summarization Configuration
|
||||||
|
# Characters per chunk when splitting long text
|
||||||
|
CHUNK_SIZE=4000
|
||||||
|
|
||||||
|
# Characters of overlap between chunks to maintain context
|
||||||
|
OVERLAP=200
|
||||||
|
|
||||||
|
# Target length for intermediate chunk summaries (words)
|
||||||
|
TARGET_INTERMEDIATE_SUMMARY_LENGTH=150
|
||||||
|
|
||||||
|
# Maximum length for final synthesized summary (words)
|
||||||
|
MAX_DIRECT_SUMMARY_LENGTH=100
|
||||||
|
|
||||||
|
# Maximum text length (characters) before chunking is triggered
|
||||||
|
MAX_DIRECT_TEXT_LENGTH=8000
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
# Dockerfile for MCP Summary Server
|
||||||
|
#
|
||||||
|
# Usage (from directory containing this Dockerfile and mcp_summary_server.py):
|
||||||
|
#
|
||||||
|
# docker build -t mcp-summary .
|
||||||
|
# docker run -p 8080:8080 --env-file .env mcp-summary
|
||||||
|
#
|
||||||
|
|
||||||
|
FROM python:3.12-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install runtime dependencies
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt && rm requirements.txt
|
||||||
|
|
||||||
|
# Copy the server script
|
||||||
|
COPY mcp_summary_server.py /app/mcp_summary_server.py
|
||||||
|
|
||||||
|
# Expose HTTP port
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
# Environment variables
|
||||||
|
ENV PORT=8080
|
||||||
|
ENV OPENAPI_URL=http://localhost:8080/v1
|
||||||
|
ENV OPENAPI_API_KEY=
|
||||||
|
ENV MODEL_NAME=gpt-4o
|
||||||
|
ENV CHUNK_SIZE=4000
|
||||||
|
ENV OVERLAP=200
|
||||||
|
ENV TARGET_INTERMEDIATE_SUMMARY_LENGTH=150
|
||||||
|
ENV MAX_DIRECT_SUMMARY_LENGTH=100
|
||||||
|
ENV MAX_DIRECT_TEXT_LENGTH=8000
|
||||||
|
ENV LLM_TIMEOUT=120
|
||||||
|
ENV API_KEY=
|
||||||
|
|
||||||
|
# Start the MCP summary server
|
||||||
|
ENTRYPOINT ["python", "-u", "/app/mcp_summary_server.py"]
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
# MCP Summary Server
|
||||||
|
|
||||||
|
An MCP (Model Context Protocol) server for document summarization that keeps full text out of the chat context window.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Automatically determines whether to summarize directly or use chunked summarization
|
||||||
|
- All processing happens server-side
|
||||||
|
- Returns only the summary to the client
|
||||||
|
- Configurable chunking parameters
|
||||||
|
- Bearer token authentication (optional)
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
### Environment Variables
|
||||||
|
|
||||||
|
Copy `.env.example` to `.env` and configure:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
```
|
||||||
|
|
||||||
|
| Variable | Default | Description |
|
||||||
|
|----------|---------|-------------|
|
||||||
|
| PORT | 8080 | HTTP server port |
|
||||||
|
| API_KEY | (empty) | Bearer token for authentication |
|
||||||
|
| OPENAPI_URL | http://localhost:8080/v1 | LLM API endpoint |
|
||||||
|
| OPENAPI_API_KEY | (empty) | LLM API key |
|
||||||
|
| MODEL_NAME | gpt-4o | LLM model to use |
|
||||||
|
| LLM_TIMEOUT | 120 | LLM call timeout in seconds |
|
||||||
|
| CHUNK_SIZE | 4000 | Characters per chunk |
|
||||||
|
| OVERLAP | 200 | Characters of overlap between chunks |
|
||||||
|
| TARGET_INTERMEDIATE_SUMMARY_LENGTH | 150 | Words per chunk summary |
|
||||||
|
| MAX_DIRECT_SUMMARY_LENGTH | 100 | Max final summary length |
|
||||||
|
| MAX_DIRECT_TEXT_LENGTH | 8000 | Max text length before chunking |
|
||||||
|
|
||||||
|
## Running
|
||||||
|
|
||||||
|
### Docker
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build
|
||||||
|
docker build -t mcp-summary .
|
||||||
|
|
||||||
|
# Run with environment file
|
||||||
|
docker run -p 8080:8080 --env-file .env mcp-summary
|
||||||
|
|
||||||
|
# Run with inline environment variables
|
||||||
|
docker run -p 8080:8080 \
|
||||||
|
-e OPENAPI_URL=http://localhost:8080/v1 \
|
||||||
|
-e OPENAPI_API_KEY=your-key \
|
||||||
|
-e MODEL_NAME=gpt-4o \
|
||||||
|
mcp-summary
|
||||||
|
```
|
||||||
|
|
||||||
|
### Python
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install -r requirements.txt
|
||||||
|
python mcp_summary_server.py
|
||||||
|
```
|
||||||
|
|
||||||
|
## Connecting to OpenWebUI
|
||||||
|
|
||||||
|
### In OpenWebUI Admin Settings
|
||||||
|
|
||||||
|
1. Go to **Admin Settings → External Tools**
|
||||||
|
2. Click **+ (Add Server)**
|
||||||
|
3. Set **Type** to **MCP (Streamable HTTP)**
|
||||||
|
4. Enter your **Server URL**
|
||||||
|
5. Set **Authentication**:
|
||||||
|
- **None** if no API key is configured
|
||||||
|
- **Bearer** if API_KEY is set (provide the key)
|
||||||
|
6. Save
|
||||||
|
|
||||||
|
### Docker Networking
|
||||||
|
|
||||||
|
If running both OpenWebUI and MCP Summary in Docker:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Use host.docker.internal to reach host machine
|
||||||
|
docker run -p 8080:8080 \
|
||||||
|
-e OPENAPI_URL=http://host.docker.internal:3000/v1 \
|
||||||
|
-e OPENAPI_API_KEY=your-key \
|
||||||
|
mcp-summary
|
||||||
|
```
|
||||||
|
|
||||||
|
If both containers are on the same Docker network, use the container name directly:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --network mynetwork -p 8080:8080 \
|
||||||
|
-e OPENAPI_URL=http://openwebui-container:8080/v1 \
|
||||||
|
-e OPENAPI_API_KEY=your-key \
|
||||||
|
mcp-summary
|
||||||
|
```
|
||||||
|
|
||||||
|
## MCP Tool
|
||||||
|
|
||||||
|
### summarize_document
|
||||||
|
|
||||||
|
Summarizes a document, automatically handling chunking for long text.
|
||||||
|
|
||||||
|
**Parameters:**
|
||||||
|
- `text` (string, required): The document text to summarize
|
||||||
|
- `max_length` (integer, optional): Maximum summary length in words (default: 100)
|
||||||
|
|
||||||
|
**Returns:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"summary": "The summarized text...",
|
||||||
|
"original_length": 12345,
|
||||||
|
"method": "direct", // or "chunked"
|
||||||
|
"chunks": 1 // number of chunks used
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### "Failed to connect to MCP server"
|
||||||
|
|
||||||
|
1. **Check authentication**: Ensure you haven't selected `Bearer` without a key. Switch to `None` if no token is needed.
|
||||||
|
2. **Check network connectivity**: Ensure OpenWebUI can reach the MCP server URL
|
||||||
|
3. **Check LLM connectivity**: Ensure the MCP server can reach the LLM at OPENAPI_URL
|
||||||
|
4. **Check timeouts**: Increase LLM_TIMEOUT if summarization takes too long
|
||||||
|
|
||||||
|
### Infinite loading screen
|
||||||
|
|
||||||
|
This may occur if you configured the server as OpenAPI instead of MCP. Fix by:
|
||||||
|
|
||||||
|
1. Opening Admin Settings → External Tools
|
||||||
|
2. Disabling/deleting the problematic connection
|
||||||
|
3. Re-adding with **Type** set to **MCP (Streamable HTTP)**
|
||||||
|
|
||||||
|
### Slow initialization
|
||||||
|
|
||||||
|
If the server takes longer than 10 seconds to initialize:
|
||||||
|
- Increase `MCP_INITIALIZE_TIMEOUT` in OpenWebUI (default: 10 seconds)
|
||||||
Binary file not shown.
+34
@@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Diagnostic script for MCP Summary Server
|
||||||
|
|
||||||
|
echo "================================"
|
||||||
|
echo "MCP Summary Server Diagnostics"
|
||||||
|
echo "================================"
|
||||||
|
|
||||||
|
# Check if server is running
|
||||||
|
echo -e "\n1. Checking if server process is running..."
|
||||||
|
ps aux | grep mcp_summary_server || echo "Server process not found"
|
||||||
|
|
||||||
|
# Check if port is listening
|
||||||
|
echo -e "\n2. Checking if port is listening..."
|
||||||
|
netstat -tlnp 2>/dev/null | grep 8080 || echo "Port 8080 not listening"
|
||||||
|
|
||||||
|
# Test basic connectivity
|
||||||
|
echo -e "\n3. Testing basic connectivity..."
|
||||||
|
curl -s http://localhost:8080/ || echo "Cannot connect to localhost:8080"
|
||||||
|
|
||||||
|
# Test MCP initialize
|
||||||
|
echo -e "\n4. Testing MCP initialize..."
|
||||||
|
curl -s -X POST http://localhost:8080/ \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"test","version":"1.0.0"}}}' | jq .
|
||||||
|
|
||||||
|
# Test tools list
|
||||||
|
echo -e "\n5. Testing tools list..."
|
||||||
|
curl -s -X POST http://localhost:8080/ \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' | jq .
|
||||||
|
|
||||||
|
echo -e "\n================================"
|
||||||
|
echo "Diagnostics complete"
|
||||||
|
echo "================================"
|
||||||
+571
-307
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,4 @@
|
|||||||
|
# requirements.txt for MCP Summary Server
|
||||||
|
|
||||||
|
# HTTP requests for LLM communication
|
||||||
|
requests>=2.31.0
|
||||||
Reference in New Issue
Block a user