
mcp_demo
展示如何使用模型上下文协议 (MCP) 创建工具和资源,用于大型语言模型。
Repository Info
About This Server
展示如何使用模型上下文协议 (MCP) 创建工具和资源,用于大型语言模型。
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
MCP Demo Project
A demonstration of the Model Context Protocol (MCP) with multiple services, including math operations and notes information retrieval mcp servers.
Overview
This project showcases how to use the Model Context Protocol (MCP) to create tools & resources that can be utilized by large language models (LLMs). It includes:
- Math Operations Service: A Python-based Stdio & SSE MCP server implemented in
src/server/mcp_math_server.py. - Notes Service: A Node.js-based service using Server-Sent Events (SSE) for notes retrieval. Server is implemented in
src/index.js - MCP Client: A Python client (
src/client/mcp_client.py) that connects to mcp_math_server queries llm and utlizes server tools and resources.
Requirements
- Python: Version 3.9+ (developed with Python 3.13)
- Node.js: Version 18+ (for Node.js-based services)
- npm: For managing Node.js dependencies
Installation
Getting Started
Clone the Repository
First, clone the repository to your local machine:
# Clone the repository
git clone https://github.com/dheerajsn/mcp_demo.git
#or you can fork from above repo and clone it from your forked repo.
# Navigate to the project directory
cd mcp_demo
Add the Project to PYTHONPATH
# On macOS/Linux (add to your .bashrc or .zshrc for permanence)
export PYTHONPATH=$PYTHONPATH:/path/to/mcp_demo
# On Windows (Command Prompt)
set PYTHONPATH=%PYTHONPATH%;C:\path\to\mcp_demo
# On Windows (PowerShell)
$env:PYTHONPATH += ";C:\path\to\mcp_demo"
Python Virtual Environment
First, create and activate a Python virtual environment:
# Create a virtual environment
# On macOS/Linux:
python -m venv .venv
# On Windows:
python -m venv .venv
# or if you have multiple Python versions:
py -3 -m venv .venv
Activate the virtual environment:
# On macOS/Linux:
source .venv/bin/activate
# On Windows (Command Prompt):
.venv\Scripts\activate.bat
# On Windows (PowerShell):
.venv\Scripts\Activate.ps1
Python Dependencies
Install the required Python packages:
pip install -r requirements.txt
Node.js Dependencies
Install the required Node.js packages:
npm install
Usage
1. Running the Node.js MCP Notes Server (SSEServerTransport)
For the Node.js-based service (e.g.,notes service), follow these steps:
-
Install Node.js dependencies:
npm install -
Run the notes server in development mode (with live reloading):
npm run dev -
Run the MCP Inspector for debugging:
npm run inspect
2. Running SSE (src/server/mcp_math_server.py) server. After running, you can test it through MCP inspector (port 8000)
We need to first run below script which starts MCP server with Sse Transport.
python src/server/mcp_math_server.py
Running single MCP Client
The MCP client (src/client/mcp_client.py) connects to the Stdio & SSE MCP (src/server/mcp_math_server.py) server and provides tools, resources for math operations. To run the client:
python src/client/mcp_client.py
Running the Multi-Server MCP Client
The multi-server MCP client (src/client/mcp_multiserver_client.py) connects to both the Python (Stdio) and Node.js (SSE) servers, invokes the LLM with prompts, and uses tools/resources supported by both MCP servers. To run it:
python src/client/mcp_multiserver_client.py
Environment Variables
Ensure the following environment variables are set in the .env file:
OPENAI_API_KEY=your_openai_api_key
GROQ_API_KEY=your_groq_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key
Replace your_openai_api_key, your_groq_api_key, and your_anthropic_api_key with your actual API keys.
Quick Start
Clone the repository
git clone https://github.com/dheerajsn/mcp_demoInstall dependencies
cd mcp_demo
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.