LA

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:

git clone https://github.com/GongRzhe/Langflow-DOC-QA-SERVER.git
cd Langflow-DOC-QA-SERVER
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Environment variables Create a .env file or export variables in your environment. Common variables:

VariableDescriptionExample
LANGFLOW_URLHTTP URL of the Langflow serverhttp://localhost:8080
MODEL_PROVIDERModel provider used by Langflow (if needed)openai
OPENAI_API_KEYOpenAI API key (if using OpenAI)sk-xxxx
VECTOR_STORE_PATHPath to vector index or DB config./indexes/faiss.db
PORTPort to run this MCP server on8000

Example .env:

LANGFLOW_URL=http://localhost:8080
OPENAI_API_KEY=sk-REDACTED
VECTOR_STORE_PATH=./indexes/faiss.db
PORT=8000

Run locally with Uvicorn:

uvicorn main:app --host 0.0.0.0 --port 8000 --reload

Or build and run with Docker:

docker build -t langflow-doc-qa .
docker run -p 8000:8000 --env-file .env langflow-doc-qa

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:

curl -X POST http://localhost:8000/mcp/events \
  -H "Content-Type: application/json" \
  -d '{
    "events": [
      {"type": "user", "text": "What does the refund policy say about cancellations?"}
    ],
    "session_id": "session-123"
  }'

Example response (simplified):

{
  "session_id": "session-123",
  "events": [
    {"type": "assistant", "text": "The refund policy states that cancellations within 14 days ...", "sources": ["policy.pdf#page=3"]}
  ]
}

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

  1. Ingest your product docs into the vector store using the provided loader script.
  2. Open Langflow and load the included RAG flow or customize it (change retrieval size, prompt template).
  3. 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,