MCP 入门教程

这是一份面向初学者的模型上下文协议(MCP)教程,演示如何使用 Python、LangChain 和 Cerebras Cloud 构建并连接本地 Stdio 与远程 SSE 两种 MCP 服务端,实现与 PDF 文档进行对话交互。

  • by hereandnowai
  • Python
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 hereandnowai/model-context-protocol-tutorial-for-beginners

使用说明

Model Context Protocol (MCP) Tutorial for Beginners 🚀

Welcome to the Ultimate Beginner's Guide to Model Context Protocol (MCP). This tutorial demonstrates how to build and connect MCP servers to chat with PDF documents using Python, LangChain, and Cerebras Cloud.


🏢 About HERE AND NOW AI

"AI is Good"

HERE AND NOW AI is dedicated to making artificial intelligence accessible and impactful. We specialize in cutting-edge AI research and development.


📘 Project Overview

This repository contains two types of MCP servers designed to serve a professional PDF profile:

  1. Stdio Server: For local usage (works with Claude Desktop).
  2. SSE Server: For remote usage via Web Browsers or Google Colab (using Server-Sent Events).

📁 Project Structure

  • stdio-server/: Local MCP server implementation (Line-by-line explanation).
  • sse-server/: Web-capable MCP server implementation.
  • mcp-client/: A Python client using LangChain and Cerebras (Line-by-line explanation).
  • simple-bot/: A minimalist 8-line chatbot example.

🛠️ Setup Instructions

1. Prerequisites

2. Installation

git clone https://github.com/hereandnowai/model-context-protocol-tutorial-for-beginners.git
cd model-context-protocol-tutorial-for-beginners
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

3. Environment Variables

Rename .env.example to .env and add your keys:

CEREBRAS_API_KEY=your_api_key_here

🚀 Running the Servers

Local Stdio Server

python stdio-server/main.py

Remote SSE Server

Start the server on port 3001:

python sse-server/main.py

To expose it to the internet (for Google Colab):

# Option: Localtunnel
lt --port 3001

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.


© 2026 HERE AND NOW AI. All rights reserved.