|
| 1 | +# MCP Server |
| 2 | + |
| 3 | +The MCP Server is a Model Context Protocol (MCP) server that provides a bridge between MCP-compatible clients and the RAG backend. It enables AI assistants and other tools to interact with the RAG system through standardized MCP tools. |
| 4 | + |
| 5 | +## Features 🚀 |
| 6 | + |
| 7 | +- **Simple Chat Interface**: Basic question-answering without conversation history |
| 8 | +- **Chat with History**: Conversational interface that maintains context across messages |
| 9 | +- **Citation Support**: Returns source documents and metadata for transparency |
| 10 | +- **Streamable HTTP Transport**: Uses HTTP-based transport for reliable communication |
| 11 | +- **Configurable Settings**: Environment-based configuration for different deployment scenarios |
| 12 | + |
| 13 | +## Architecture |
| 14 | + |
| 15 | +The server consists of several key components: |
| 16 | + |
| 17 | +- **RagMcpServer**: Main server class that handles MCP tool registration and request routing |
| 18 | +- **Dependency Container**: Manages dependency injection for clean architecture |
| 19 | +- **Settings**: Environment-based configuration management |
| 20 | +- **RAG Backend Client**: Auto-generated OpenAPI client for backend communication |
| 21 | + |
| 22 | +## Requirements |
| 23 | + |
| 24 | +All required python libraries can be found in the [pyproject.toml](pyproject.toml) file. |
| 25 | +The MCP server uses Poetry for dependency management and shares the base Dockerfile pattern with other services in the RAG template. |
| 26 | + |
| 27 | +## Available Tools |
| 28 | + |
| 29 | +The server exposes two main MCP tools for interacting with the RAG system: |
| 30 | + |
| 31 | +### `chat_simple` |
| 32 | + |
| 33 | +Simple question-answering interface that returns plain text responses. |
| 34 | + |
| 35 | +**Parameters:** |
| 36 | + |
| 37 | +- `session_id` (str): Unique identifier for the chat session |
| 38 | +- `message` (str): The question or message to send to the RAG system |
| 39 | + |
| 40 | +**Returns:** |
| 41 | + |
| 42 | +- `str`: Plain text answer from the RAG system |
| 43 | + |
| 44 | +### `chat_with_history` |
| 45 | + |
| 46 | +Advanced chat interface that supports conversation history and returns structured responses with citations. |
| 47 | + |
| 48 | +**Parameters:** |
| 49 | + |
| 50 | +- `session_id` (str): Unique identifier for the chat session |
| 51 | +- `message` (str): The current question or message |
| 52 | +- `history` (list[dict], optional): Previous conversation history |
| 53 | + |
| 54 | +**History Format:** |
| 55 | +Each history item should be a dictionary with: |
| 56 | + |
| 57 | +- `role`: Either "user" or "assistant" |
| 58 | +- `message`: The message content |
| 59 | + |
| 60 | +**Returns:** |
| 61 | + |
| 62 | +- `dict`: Structured response containing: |
| 63 | + - `answer`: The response text |
| 64 | + - `finish_reason`: Why the response ended |
| 65 | + - `citations`: List of source documents with content and metadata |
| 66 | + |
| 67 | +## Configuration |
| 68 | + |
| 69 | +The server supports configuration through environment variables with the following prefixes: |
| 70 | + |
| 71 | +### MCP Settings (`MCP_` prefix) |
| 72 | + |
| 73 | +- `MCP_HOST`: Server bind address (default: `0.0.0.0`) |
| 74 | +- `MCP_PORT`: Server port (default: `8000`) |
| 75 | +- `MCP_NAME`: Server name (default: `RAG MCP server`) |
| 76 | + |
| 77 | +### Backend Settings (`BACKEND_` prefix) |
| 78 | + |
| 79 | +- `BACKEND_BASE_PATH`: RAG backend URL (default: `http://127.0.0.1:8080`) |
| 80 | + |
| 81 | +## Deployment |
| 82 | + |
| 83 | +The MCP server is designed to be deployed alongside the main RAG backend as a sidecar container. A detailed explanation of the deployment can be found in the [main README](../README.md) and the [infrastructure README](../rag-infrastructure/README.md) of the project. |
| 84 | + |
| 85 | +### Docker Support |
| 86 | + |
| 87 | +The server includes Docker support for containerized deployment and is integrated into the main Tilt development workflow. |
| 88 | + |
| 89 | +### Integration in RAG Template |
| 90 | + |
| 91 | +The MCP server is automatically deployed when `backend.mcp.enabled=true` is set in the Helm values. It runs as a sidecar container alongside the main RAG backend, accessible via: |
| 92 | + |
| 93 | +- **Port**: 8000 (configurable via `MCP_PORT`) |
| 94 | +- **Endpoint**: `/mcp` path through the main ingress |
| 95 | +- **Development**: Port-forwarded to 9090 in local Tilt setup |
| 96 | + |
| 97 | +## Development |
| 98 | + |
| 99 | +The MCP server is integrated into the main RAG template development workflow: |
| 100 | + |
| 101 | +- **Tilt Integration**: Automatically built and deployed with live reload |
| 102 | +- **Linting**: Included in the main linting pipeline |
| 103 | +- **Testing**: Part of the overall test suite |
| 104 | +- **Debugging**: Supports the same debugging workflow as other services |
| 105 | + |
| 106 | +For detailed development setup instructions, see the [main README](../README.md). |
0 commit comments