
alejandro-ao/mcp-client-python 是从 https://github.com/alejandro-ao/mcp-client-python. 导入的 MCP 服务器候选
概览
alejandro-ao/mcp-client-python 是从 https://github.com/alejandro-ao/mcp-client-python. 导入的 MCP 服务器候选
概述(AI 翻译)
该仓库包含了关于如何使用 FastAPI 在 Python 创建 MCP(模块化计算平台)客户端的完整教程。该教程灵感来源于 Claude Desktop 应用程序,演示如何让大型语言模型(LLM)从 MCP 服务器调用 MCP 工具并显示结果。
特色
- 使用 Python 和 FastAPI 构建 MCP 客户端。
- 集成大型语言模型以与MCP工具交互。
- 从MCP服务器获取并显示结果。
- 逐步指导客户端的设置和运行。
先修条件
- Python 3.8 或更高版本
- 具备FastAPI和REST API的基础知识
- MCP服务器设置
开始
-
克隆仓库:
-
安装依赖系统:
-
设置环境变量: 在根目录创建一个
.env文件,并添加你的 API 密钥。在这个示例中,我添加了SERPER_API_KEY,因为它被用在 MCP 服务器文件中,我们之前的教程中构建了这个文件。而且由于我们所有内容都本地运行,我们可以在同一个文件中设置所有环境变量(服务器和客户端的)。
本页由 AI 翻译,技术细节请以原文为准。
README
MCP Client in Python with FastAPI
This repository contains a complete tutorial on how to create an MCP (Modular Computational Platform) client in Python using FastAPI. The tutorial is inspired by the Claude Desktop application and demonstrates how to make an LLM (Large Language Model) call MCP tools from an MCP server and display the results.
Features
- Build an MCP client using Python and FastAPI.
- Integrate LLMs to interact with MCP tools.
- Fetch and display results from an MCP server.
- Step-by-step guidance for setting up and running the client.
Prerequisites
- Python 3.8 or higher
- Basic knowledge of FastAPI and REST APIs
- An MCP server setup
Getting Started
- Clone the Repository:
git clone [email protected]:alejandro-ao/mcp-client-python.git
cd mcp-client-python
- Install Dependencies:
pip install -r requirements.txt
- Set Up Environment Variables:
Create a
.envfile in the root directory and add your API keys. In this example, I added theSERPER_API_KEYbecause it is used in the MCP server file, which we built in the previous tutorial. And since we are running everything locally, we can set all the environment variables (for both serverand client) in the same file. In a more complex setup, you would deploy your MCP server separately and set the environment variables accordingly.
ANTHROPIC_API_KEY=
SERPER_API_KEY=
- Run the Application:
uvicorn main:app --reload
- Access the API:
Open your browser and navigate to
http://127.0.0.1:8000/docsto explore the API documentation.
Tutorial Overview
-
Setting Up FastAPI: Learn how to create a FastAPI application and define endpoints.
-
Connecting to the MCP Server: Understand how to make requests to the MCP server and handle responses.
-
Integrating LLMs: Explore how to use an LLM to call MCP tools dynamically.
-
Displaying Results: Implement logic to process and display results from the MCP tools.
Resources
- FastAPI Documentation
- MCP Documentation (for inspiration)
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
Special thanks to the creators of FastAPI and the Claude Desktop application for their inspiration.
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →