MCP-Powered RAG for Complex Documents: An Implementation Example
Standard RAG pipelines chunk and embed clean prose well, but they stumble on real-world documents: multi-column layouts, tables, embedded charts, and diagrams that carry meaning the plain-text extraction throws away. This example builds a pipeline that survives those documents by putting a purpose-built parsing service behind an MCP server, then driving it from an IDE.
The stack
- MCP client: Cursor IDE — issues tool calls and consumes results.
- MCP server: a local
FastMCPserver that exposes ingestion and search as tools. - Parsing and retrieval: GroundX, used for layout-aware parsing and search over the ingested documents.
How it works
The client and the knowledge base talk through the MCP server:
- The user works in the MCP client (Cursor).
- The client connects to the local MCP server and picks a tool — for example,
search_document. - That tool calls the GroundX API to run a context-aware search over the ingested documents.
- Results return to the client, which uses them to generate a grounded answer.
Implementation
The full source for this example lives in the ai-engineering-hub repository. The steps below describe what each piece does.
1. Stand up the MCP server. Create a local server with FastMCP and give it a descriptive name — the name and tool descriptions are what the client’s model reasons over when deciding which tool to call.
2. Create the parsing client. Obtain a GroundX API key, store it in a .env file, and initialize the client from that key. Keeping the key out of source is the only handling detail that matters here.
3. Add an ingestion tool. Expose an MCP tool that takes a local file path and adds the document to the GroundX knowledge base, so users can index new material without leaving the client.
4. Add a search tool. Expose a second tool that takes a query and returns the most relevant chunks from the indexed documents. This is the tool the model calls at answer time.
5. Start the server over stdio. Run the server using standard input/output as the transport — the right choice for a server that a local IDE launches and talks to directly.
6. Connect the client. In Cursor, open Settings → Cursor Settings → MCP, add the server’s launch command, and start it. The ingestion and search tools then appear to the agent.
Once connected, you can index and question complex documents from inside the IDE, with the layout-aware parsing and retrieval handled by the backing service.
Why route through a specialized parser
The pipeline works because the hard part — turning a messy document into something a model can use — is delegated to a service built for it. A parser like GroundX chunks by meaning rather than by character count and interprets text, tables, and diagrams together, emitting structured output an LLM can consume directly. Fronting that capability with an MCP server is what makes it reusable: any MCP-compatible client can ingest and query the same knowledge base through the same two tools.

