LangChain MCP Demo
Enables grounding AI responses in a local document corpus by exposing MCP tools to list, search, and summarize documents, and generating answers using OpenAI.
README
LangChain MCP Demo
This repository demonstrates a small Model Context Protocol style workflow in Python.
It shows how to:
- expose reusable tools through MCP
- keep a local document corpus in the repo
- retrieve grounded context from those documents
- generate a short OpenAI-backed answer from the retrieved context
- run the same project as a CLI for quick checks
What’s Inside
- MCP tools for listing, searching, and summarizing local documents
- a CLI mode for quick smoke testing
- a small local knowledge base in
docs/ - a test suite for non-network logic
- project docs that cover architecture, configuration, testing, and security
Setup
cd C:\Projects\MCP
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
pip install -r requirements-dev.txt
Copy-Item .env.example .env
Set OPENAI_API_KEY in your environment or .env.
Run
python app.py
The demo starts a local MCP server on stdin/stdout for tool use by default and also provides a CLI mode for quick testing.
To run the HTTP transport instead:
python app.py --transport streamable-http
Architecture
flowchart LR
User[User or Client] --> MCP[MCP Server]
MCP --> Docs[(Local Markdown Docs)]
MCP --> List[list_docs]
MCP --> Search[search_docs]
MCP --> Summary[summarize_docs]
User --> CLI[CLI Question]
CLI --> Retriever[Document Scoring]
Retriever --> Context[Top Matching Context]
Context --> LLM[OpenAI Chat Model]
LLM --> Answer[Grounded Answer]
Request Flow
- A client or CLI user asks a question.
- The project loads the local documents from
docs/. - The document scorer ranks the best matches.
- The selected context is passed to OpenAI with a grounding instruction.
- The response is returned with the retrieved source set.
Project Structure
app.py: MCP server and CLI entry pointdocs/: architecture, configuration, security, and sample knowledgetests/: unit tests for non-network logicrequirements.txt: runtime dependenciesrequirements-dev.txt: test dependencies.env.example: required environment variables
Configuration
Required:
OPENAI_API_KEY
Optional:
OPENAI_MODEL: defaults togpt-4o-miniMCP_HOST: defaults to127.0.0.1MCP_PORT: defaults to8000MCP_TRANSPORT: defaults tostdio
Run Modes
CLI mode
python app.py --cli "What does this demo project do?"
MCP stdio mode
python app.py
MCP HTTP mode
python app.py --transport streamable-http
Transport Modes
stdio: default and best for local agent connectionsstreamable-http: useful when a client connects over HTTPsse: available for compatibility with older MCP clients
Testing
python -m pytest
The unit tests cover scoring and preview logic without network access. The CLI mode can be used for a live smoke test when OPENAI_API_KEY is set.
Security
Do not commit .env, logs, caches, or API keys. This project uses the same OPENAI_API_KEY environment variable as the earlier AI projects.
If a secret ever appears in a commit or pushed log, rotate it immediately and rewrite the affected history before treating the repo as clean.
Troubleshooting
- If
OPENAI_API_KEYis missing, the CLI will stop before calling the API. - If the MCP SDK is not installed, install dependencies from
requirements.txt. - If a client needs HTTP, use
--transport streamable-httpand the configured host and port. - If the GitHub About box still looks empty, set the repository description, website, and topics in GitHub settings. README content does not populate that panel automatically.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。