Langflow Document QA MCP Server
Query documents with a Langflow-backed MCP server for quick, accurate document Q&A and learn core MCP concepts via a simple, interactive interface.
Overview
This project implements a lightweight MCP (Model Context Protocol) server that connects document-oriented question answering to Langflow flows. It lets you expose a simple HTTP endpoint that accepts MCP-style event payloads, runs a Langflow workflow (retrieval, embeddings, LLM) against an indexed document collection, and returns concise, sourced answers. The server is intended for developers who want an interactive, reproducible way to prototype document Q&A systems while learning core MCP concepts.
The server is useful when you need quick, accurate answers from a corpus (docs, manuals, FAQs, PDFs) and prefer to iterate visually on the model pipeline with Langflow. It abstracts the transport-level MCP patterns (events, roles, streaming) and delegates the actual prompt, retrieval and generation logic to Langflow flows so you can iterate without modifying server code.
Features
- Exposes an HTTP MCP-compatible endpoint for sending events (user queries) and receiving model responses.
- Integrates with Langflow to run visual flows (retrieval → prompt → LLM) for document QA.
- Supports document ingestion and vector search (common vector stores / FAISS-style indexing).
- Configurable model and embedding providers via Langflow or environment variables.
- Docker-ready and runnable via Uvicorn/ASGI for local or containerized deployment.
- Example flows and sample documents to help you get started quickly.
Installation / Configuration
Prerequisites:
- Python 3.9+
- pip
- Optional: Docker
Clone and install:
Environment variables Create a .env file or export variables in your environment. Common variables:
| Variable | Description | Example |
|---|---|---|
| LANGFLOW_URL | HTTP URL of the Langflow server | http://localhost:8080 |
| MODEL_PROVIDER | Model provider used by Langflow (if needed) | openai |
| OPENAI_API_KEY | OpenAI API key (if using OpenAI) | sk-xxxx |
| VECTOR_STORE_PATH | Path to vector index or DB config | ./indexes/faiss.db |
| PORT | Port to run this MCP server on | 8000 |
Example .env:
LANGFLOW_URL=http://localhost:8080
OPENAI_API_KEY=sk-REDACTED
VECTOR_STORE_PATH=./indexes/faiss.db
PORT=8000
Run locally with Uvicorn:
Or build and run with Docker:
Available Tools / Resources
- Langflow visual editor: edit or create flows that define how inputs are embedded, retrieved, and composed into prompts for the LLM.
- Sample flows: included example workflows demonstrate a typical RAG (retrieval-augmented generation) pipeline.
- Document loaders: helper scripts to ingest plain text, Markdown, or PDF files into the configured vector store.
- Vector store adapters: connectors or instructions for common stores (FAISS/local, Pinecone, Milvus) — configure via env vars or Langflow flows.
API / Example Requests
The server accepts MCP-style event payloads (JSON). The exact event wrapper matches typical MCP semantics: an array of events where each event contains at least a type and text content. Example request:
Example response (simplified):
If your client supports streaming MCP events, the server streams partial generation tokens back as events (depending on the configured Langflow flow and model).
Use Cases
- Internal knowledge base assistant: index product docs, run queries via a small web widget sending MCP events to this server, and return sourced answers to employees.
- Customer support augmentation: integrate with chat tooling to answer policy and billing questions by routing concerned queries to the document QA flow.
- Documentation search and summarization: provide quick summaries of long manuals or whitepapers by querying the server for topic-specific extractions.
- Legal / compliance review: ingest contracts or terms and use the Langflow-defined retrieval + LLM workflow to extract clauses and provide citations.
Concrete example
- Ingest your product docs into the vector store using the provided loader script.
- Open Langflow and load the included RAG flow or customize it (change retrieval size, prompt template).
- Start the MCP server and POST user events to /mcp/events. The server invokes Langflow, returns an answer with inline source references, and you can iterate on the flow for quality improvements.
Notes for Developers
- The server intentionally defers prompt and workflow logic to Langflow so you can experiment visually with chaining, prompt engineering, and retriever settings.
- Keep sensitive keys out of source control; prefer runtime secrets (Kubernetes secrets, Docker –env-file, or environment variables).
- If you add a new document loader or vector store adapter,