MCP Long Context Reader
Provides integration with OpenAI's API for embeddings and language models, enabling RAG and summary-based document querying.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Long Context ReaderSummarize the main points of annual_report.pdf using map reduce"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Long Context Reader
MCP Long Context Reader is a Python-based toolkit designed to overcome the context window limitations and high costs associated with Large Language Models (LLMs) processing extensive documents. It provides a FastMCP server with multiple, powerful strategies for an LLM agent to "read" and query long documents without needing to load the entire text into its context window.
This project features an intelligent, filesystem-based caching backend. When a document is processed for the first time with a specific strategy, the expensive work (like generating embeddings) is cached. Subsequent queries on the same document are significantly faster.
Features
This toolkit provides five distinct strategies as MCP tools:
glance: Provides a quick look at the beginning of a file, showing the first few thousands characters and total line count.search_with_regex: Finds and extracts text snippets using regular expression patterns. Ideal for precise, pattern-based lookups.retrieve_with_rag: Uses a Retrieval-Augmented Generation (RAG) pipeline to find the most semantically relevant document chunks based on a natural language question.summarize_with_map_reduce: A classic "divide and conquer" strategy that summarizes large chunks in parallel and then combines those summaries. Best for getting the gist of a very long document.summarize_with_sequential_notes: An advanced strategy where an LLM reads the document sequentially, taking query-aware notes. Best for tasks requiring strict order and detail sensitivity (e.g., "needle-in-a-haystack").
Related MCP server: distill-mcp-v2
Getting Started
1. Prerequisites
Python 3.10 or newer.
uvPython package manager. If you don't have it, install it withpip install uv.An OpenAI API Key for the RAG and LLM-based strategies.
2. Environment Setup
First, clone the repository to your local machine:
git clone <repository-url>
cd mcp-long-context-readerNext, create and activate a virtual environment using uv:
uv venv
source .venv/bin/activate
# On Windows, use: .venv\Scripts\activate3. Install Dependencies
Install the project and its required dependencies:
uv pip install .This command builds and installs the project and its core dependencies into your virtual environment, making it ready for use.
4. Configure Environment Variables
This project requires environment variables to be set for configuration and security.
Workspace Directory (Required): You must specify a sandboxed directory from which the server is allowed to read files. This is a critical security measure.
export MCP_WORKSPACE_DIRECTORY="/path/to/your/documents/dir"Model Provider & API Key (Required)
Choose one of the following providers and set the corresponding environment variables.
OpenAI
export MCP_API_PROVIDER="openai" export MCP_EMBEDDING_MODEL="text-embedding-3-small" export MCP_LLM_MODEL="gpt-4o" export OPENAI_API_KEY="sk-..."DashScope
export MCP_API_PROVIDER="dashscope" export MCP_EMBEDDING_MODEL="text-embedding-v3" export MCP_LLM_MODEL="qwen-max" export DASHSCOPE_API_KEY="sk-..."Cache Directory (Required): You must specify where to store the cache files.
export MCP_CACHE_DIRECTORY="/path/to/your/cache"Optional Environment Variables
OpenAI API Base URL: If you are using a custom OpenAI API base URL, you can set it here.
export OPENAI_API_BASE_URL="https://your.api.base.url/v1"
Usage
Starting the Server
To start the FastMCP server, set the required environment variables and run the server.py module from the project root:
uv run fastmcp run src/mcp_long_context_reader/server.py --transport sse --port 8000This command sets up the MCP server on SSE at http://localhost:8000/sse. For detailed information, see the FastMCP Documentation.
Calling from a Client (Python)
Once the server is running, you can call its tools from a Python client. The following example demonstrates how to use the search_with_regex tool.
First, ensure you have fastmcp installed in your client environment: pip install fastmcp.
import asyncio
from fastmcp import Client
async def main():
# Connect to the server running on localhost port 8000
client = Client("http://localhost:8000/sse")
async with client:
result = await client.call_tool(
"search_with_regex",
{
# This path should be relative to this python script
"context_path": "path/to/context.txt",
"regex_pattern": " hello ",
},
)
print(result)
if __name__ == "__main__":
asyncio.run(main())You can find this and other examples in the examples/ folder.
JSON Configuration
The following configuration sets up the MCP server on stdio, which is useful for integrating with Claude Desktop. Remember to replace the placeholder with the absolute path to the server.py file in your cloned repository.
{
"mcpServers": {
"mcp-long-context-reader": {
"command": "python",
"args": [
"/path/to/your/cloned/repo/src/mcp_long_context_reader/server.py"
],
"env": {
"MCP_WORKSPACE_DIRECTORY": "/path/to/your/documents/dir",
"MCP_CACHE_DIRECTORY": "/path/to/your/cache",
"MCP_API_PROVIDER": "openai",
"MCP_EMBEDDING_MODEL": "text-embedding-3-small",
"MCP_LLM_MODEL": "gpt-4o",
"OPENAI_API_KEY": "sk-..."
}
}
}
}Local Example
We have prepared a simple run-and-test script for you.
# 1. Set the necessary environment variables in examples/run_server_sse.sh
# 2. Run the server:
bash examples/run_server_sse.sh
# 3. In another terminal, run the client:
uv run examples/example_client.pyDevelopment
Development Setup
If you plan to contribute to the project, you'll need to install the full set of development dependencies, which include tools for testing, formatting, and building documentation.
The recommended way is to use uv sync, which installs all packages from the uv.lock file:
uv sync(Alternative option) This is equivalent to installing the dev extras defined in pyproject.toml:
uv pip install -e ".[dev]"Running Tests
The project uses pytest for testing. To run the full test suite, execute the following command:
uv run pytestBuilding Documentation
The documentation is generated using Sphinx. To build the HTML documentation locally, navigate to the docs/ directory and use the provided Makefile:
cd docs
make htmlAfter the build is complete, you can view the documentation by opening docs/build/html/index.html in your web browser.
Code Quality and Pre-commit Hooks
This project uses pre-commit to maintain code quality. To set up:
uv run pre-commit installTo run checks manually:
uv run pre-commit run --all-filesAll code must be checked before committing.
Available Tools
5 toolsglanceA
Provides a quick look at the beginning of a file or a string, showing the first few thousands
characters and total line count.
Exactly one of context_path or context_text must be provided. Do NOT provide both.
Args:
context_path (str): The path to the file to glance at.
context_text (str): The text content to glance at.
Returns:
A string containing a snippet of the file/text and metadata.
| Name | Required | Description | Default |
|---|---|---|---|
| context_path | No | ||
| context_text | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden. It discloses the read-only nature via 'quick look', the mutual-exclusivity constraint, and the return format ('string containing a snippet of the file/text and metadata'). However, 'metadata' is vague and no error handling or permission details are mentioned, preventing a higher score.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is well-structured with a front-loaded purpose, then constraints, then argument definitions, then return value. It is mostly concise, but it redundantly states the mutual-exclusivity twice ('Exactly one...' and 'Do NOT provide both'), and 'first few thousands' is awkward phrasing. Minor issues, but overall efficient.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple tool with no output schema, the description explains the main behavior and return value. However, it leaves gaps: 'metadata' is unspecified beyond the earlier mention of line count, the exact character limit is vague ('few thousands'), and error scenarios (e.g., nonexistent file) are not addressed. This is adequate but not fully comprehensive.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, so the description must compensate. It clearly defines context_path as 'the path to the file to glance at' and context_text as 'the text content to glance at', adding meaning beyond the bare schema. It also explicitly states the critical mutual-exclusivity requirement, which the schema does not convey since both fields have defaults and are optional.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states a specific action: 'Provides a quick look at the beginning of a file or a string, showing the first few thousands characters and total line count.' This differentiates it from sibling tools like summarize, search, and retrieve by emphasizing a lightweight, read-only preview. The verb 'glance' is apt, and the resource (file/text) is explicit.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No explicit guidance on when to use this tool vs. alternatives is provided. The phrase 'quick look' implies a lightweight preview use case, but there are no clear exclusions or comparisons to sibling tools. The description does explain the parameter constraint ('Exactly one of context_path or context_text must be provided'), but this is parameter usage, not tool selection guidance.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
retrieve_with_ragA
Retrieves relevant passages from a document or string based on a query using RAG.
Exactly one of context_path or context_text must be provided. Do NOT provide both.
Args:
context_path (str): The path to the context file.
context_text (str): The text content to search.
query (str): The query to search for.
Returns:
str: A string containing the relevant passages.
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | ||
| context_path | No | ||
| context_text | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden. It discloses that the tool performs a read-only retrieval operation and enforces a mutual-exclusion rule for context inputs. However, it does not mention potential side effects, limitations of RAG, or what 'relevant' means. It is adequately transparent for a simple retrieval tool but lacks depth.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is compact and well-structured: a single sentence for purpose, one sentence for the key constraint, then clean Args and Returns sections. Every sentence adds value, with no filler or repetition.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a tool with 3 parameters, no output schema, and no annotations, the description provides sufficient information for invocation: purpose, parameters, constraint, and return type. It does not explain RAG concepts or alternative use cases, but it is functionally complete for an agent to select and call the tool correctly.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Since schema description coverage is 0%, the description compensates by explaining each parameter's meaning: context_path ('path to the context file'), context_text ('text content to search'), and query ('query to search for'). It also clarifies the exclusivity rule. However, it does not explicitly state whether query is required or optional, leaving slight ambiguity.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's function with a specific verb ('Retrieves'), a specific resource ('relevant passages from a document or string'), and a mechanism ('using RAG'). This distinguishes it from sibling tools like summarize_with_map_reduce and search_with_regex, which serve different purposes.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description includes a crucial usage constraint ('Exactly one of context_path or context_text must be provided. Do NOT provide both.'), but it does not explicitly discuss when to use this tool versus alternatives. Usage is implied by the description's clarity about what it does, but no explicit when-to-use or when-not-to-use guidance is given.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
search_with_regexA
Searches a document for a regex pattern and returns matching snippets.
Exactly one of context_path or context_text must be provided. Do NOT provide both.
Args:
context_path (str, optional): The path to the context file.
context_text (str, optional): The text content to search.
regex_pattern (str, optional): The regex pattern to search for.
case_sensitive (bool, default=True): Whether to match case-sensitively.
Returns:
str: A string containing the matching snippets.
| Name | Required | Description | Default |
|---|---|---|---|
| context_path | No | ||
| context_text | No | ||
| regex_pattern | No | ||
| case_sensitive | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the burden. It discloses the exclusivity constraint and the return type, but does not explicitly state whether the operation is read-only or what happens if both inputs are provided, and error behaviors are undocumented.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is well-structured: a one-sentence summary, a constraint, a compact Args list, and a Returns line. No redundant fluff—every element contributes to understanding or correct usage.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The description covers the core purpose, all parameters, the exclusivity constraint, and the return type, which is sufficient for a straightforward regex search tool. It lacks only minor edge-case behavior like error handling and exact snippet formatting, but these are not essential for basic use.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, so the description fully compensates by documenting all four parameters with clear meanings, including the default for case_sensitive. It also specifies the mutual exclusivity of context_path and context_text, which is critical for correct invocation.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description uses a specific verb ('Searches') and resource ('a document for a regex pattern'), clearly distinguishing it from sibling tools that summarize or retrieve via RAG. It unambiguously conveys the tool's function.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description clearly states the tool is for regex searching, which distinguishes it from summarization and RAG siblings. However, it does not explicitly mention when not to use it or name alternatives. It provides strong parameter-level guidance ('Exactly one of context_path or context_text must be provided') but lacks tool-level exclusion criteria.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
summarize_with_map_reduceA
Summarizes a document or string using a map-reduce approach.
Exactly one of context_path or context_text must be provided. Do NOT provide both.
Note: This operation is resource-intensive and can be time-consuming.
Args:
context_path (str): The path to the context file.
context_text (str): The text content to summarize.
question (str): The question for each chunk to answer.
Returns:
str: A string containing the overall summary.
| Name | Required | Description | Default |
|---|---|---|---|
| question | No | ||
| context_path | No | ||
| context_text | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
The description discloses that the operation is resource-intensive and time-consuming, and sets a constraint on inputs, but lacks details on error behavior, side effects, or process specifics. Since no annotations are provided, this partial disclosure earns a 3.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is well-organized with clear sections (purpose, constraint, args, returns) and is not unnecessarily verbose, though the parameter list duplicates schema names but adds necessary detail.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The description covers the essential invocation details: purpose, parameters, return type, and a behavioral warning. However, it lacks explicit guidance on when to choose this tool over the sibling summarization tool, and it doesn't explain the map-reduce process or potential limitations, leaving some context gaps given the absence of annotations and output schema.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema provides no descriptions, but the description compensates fully by explaining each parameter (context_path, context_text, question) and adding the mutual exclusivity rule. This adds significant meaning beyond the schema.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's function with a specific verb ('Summarizes') and resource ('document or string'), and specifies the 'map-reduce approach' which distinguishes it from the sibling tool 'summarize_with_sequential_notes'. This meets the criteria for a 5.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides usage context by stating exactly one of context_path or context_text must be provided and warns about resource intensiveness, but it does not explicitly compare to alternatives like 'summarize_with_sequential_notes' or state when this approach is preferred. This is implied usage, not explicit guidance.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
summarize_with_sequential_notesA
Reads a document or string sequentially to synthesize query-aware notes.
Exactly one of context_path or context_text must be provided. Do NOT provide both.
Note: This operation is resource-intensive and can be time-consuming.
Args:
context_path (str): The path to the context file.
context_text (str): The text content to synthesize notes from.
question (str): The goal of the note-taking.
Returns:
str: A string containing the synthesized notes, focusing on the question.
| Name | Required | Description | Default |
|---|---|---|---|
| question | No | ||
| context_path | No | ||
| context_text | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the disclosure burden. It openly states the operation is 'resource-intensive' and 'time-consuming', and that it reads 'sequentially', which are useful behavioral traits beyond the simple action. It does not list side effects, but none are apparent for a note-taking tool.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is compact and well-structured: a one-sentence summary, a constraint note, a performance warning, an Args list, and a Returns line. Every sentence provides necessary information with no redundancy.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given no annotations and no output schema, the description provides adequate context: purpose, parameters, return type, and performance characteristics. It could better address relative usage against siblings, but overall it is sufficiently complete for an agent to invoke the tool correctly.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema has 0% description coverage, so the description must explain parameters. It lists all three arguments with brief meanings (context_path as file path, context_text as text content, question as goal) and clarifies the critical mutual exclusivity constraint. This goes well beyond the bare schema.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool reads a document or string sequentially to synthesize query-aware notes. The use of 'sequentially' distinguishes it from the sibling 'summarize_with_map_reduce', making its specific purpose clear.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description gives explicit constraints on parameter usage ('Exactly one of context_path or context_text must be provided. Do NOT provide both.') and a warning about resource intensity. However, it does not explicitly compare against sibling tools or state when to prefer this over them, so it misses the highest level of guidance.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
5 tool updates
v0.9.0- First observed
glance - First observed
retrieve_with_rag - First observed
search_with_regex - First observed
summarize_with_map_reduce - First observed
summarize_with_sequential_notes
TDQS
Each tool has a clearly distinct purpose: two different summarization strategies, a quick preview, regex search, and semantic retrieval. Even the two summarization tools are differentiated by their approach (map-reduce vs. sequential notes), so an agent can reliably select the right one.
Most tools follow a verb_with_modifier pattern (e.g., summarize_with_map_reduce, search_with_regex). 'glance' is a simple verb without a modifier, which is a minor deviation but still clear and consistent with the overall verb-first style.
With 5 tools, the server is well-scoped for a document reader/summarizer. Each tool serves a distinct function and none feel redundant or superfluous, making the count appropriate for the domain.
The core workflows of previewing, searching, retrieving, and summarizing are covered. A minor gap is the lack of a direct full-text extraction tool, but this is likely intentional for long-context handling and agents can work around it using glance or retrieval.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
- WauldoOAuthcom.wauldo
Stateless agentic tools over MCP: concept extraction, long-context, knowledge graph, planning.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Related MCP Servers
- AlicenseAqualityAmaintenanceA Model Context Protocol (MCP) server that helps large language models index, search, and analyze code repositories with minimal setup141,005MIT
- AlicenseAqualityCmaintenancedistill-mcp-v2 is a high-performance, network-dependency-free Python FastMCP server designed to aggressively optimize Large Language Model (LLM) context windows. It provides specialized tools for compressing and analyzing massive AI-agent payloads without losing critical semantic information.8MIT
- FlicenseNot gradedqualityCmaintenanceAn MCP server for document parsing, ingestion, query (including multimodal), and lightweight knowledge graph inspection, enabling RAG workflows via the Model Context Protocol.-
- AlicenseNot gradedqualityAmaintenanceA local MCP server that ingests entire repositories into a large context window (GLM-5.2 1M tokens) for coding agents, bypassing file limits and reducing query costs.1MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/yuplin2333/mcp-long-context-reader'
If you have feedback or need assistance with the MCP directory API, please join our Discord server