MCP协议实现

一个基于FastMCP库的生产级MCP(Model Context Protocol)服务器和客户端实现,支持Python 3.13和现代异步模式,包含天气、新闻和金融三个生产服务器及智能客户端。

  • by Kumarjit-Pathak
  • HTML
  • 本地部署
  • 更新于
在 GitHub 查看 Kumarjit-Pathak/MCP-Model-Context-Protocol

使用说明

FastMCP实施

使用FastMCP、Python 3.13和现代异步模式的生产就绪MCP(模型上下文协议)服务器和客户端实现。

这是什么?

此项目演示了如何构建 干净、可读的MCP服务器和客户端 使用FastMCP库。它包括:

  • 3台生产MCP服务器 (天气、新闻、财经)
  • 智能MCP客户端 与LLM集成(Anthropic/OpenAI)
  • 交互式聊天界面 用于测试
  • 自动化测试套件 用于验证

=€快速入门

1.安装依赖项

cd fastmcp-implementation
uv sync

2.配置API密钥

编辑 .env 使用API密钥文件:

# LLM Provider (required)
OPENAI_API_KEY=your_key_here
ANTHROPIC_API_KEY=your_key_here

# External APIs (optional - servers will work with test keys)
OPENWEATHER_API_KEY=your_key_here
NEWS_API_KEY=your_key_here
EXCHANGERATE_API_KEY=your_key_here

3.运行自动测试

uv run python examples/test_demo.py

预期产量:

======================================================================
TEST SUMMARY
======================================================================
[PASS] Weather Server
[PASS] News Server
[PASS] Finance Server

Total: 3/3 tests passed
======================================================================

4.尝试互动模式

uv run python examples/interactive_client.py

=Á项目结构

fastmcp-implementation/
�� server/           # MCP servers (Weather, News, Finance)
�� client/           # MCP client with LLM integration
�� examples/         # Interactive demo and tests
�� .env             # API keys (gitignored)
�� pyproject.toml   # UV dependencies

=à Tech Stack

  • Python 3.13.1 - Latest Python release
  • UV - Fast package manager
  • MCP SDK 1.19.0 - Model Context Protocol
  • Anthropic/OpenAI - LLM providers
  • httpx - Async HTTP client

 Success - All Tests Passed!

[PASS] Weather Server - 2 tools discovered
[PASS] News Server - 2 tools discovered
[PASS] Finance Server - 3 tools discovered

Total: 3/3 tests passed

See full documentation in FASTMCP_IMPLEMENTATION_PLAN.md