MCP 加密货币协议是一个高效的应用协议,它借助 FastMCP 实现模型上下文协议的服务器端接口。该协议融合了 TimescaleDB 时间序列数据库和 CCXT 加密货币交易库的强大功能,为加密货币市场数据、新闻分析和 AI 驱动的洞见搭建了统一平台。
使用 pip 一键安装:
pip install mcp-crypto
启动 MCP 加密货币服务器:
python -m mcp.crypto serve --host localhost --port 8000
symbols://list:获取所有支持的加密货币符号。market_data://{symbol}:获取特定符号的实时市场数据。historical_data://{symbol}?timeframe={timeframe}&start={start}&end={end}:按时间段查询历史数据。news://recent:获取最新的新闻摘要。news://{source}:通过来源获取新闻。news://by-coin/{symbol}:按加密货币符号获取相关新闻。pip install mcp-crypto
python -m mcp.crypto serve --host localhost --port 8000
创建自定义 MCP 服务器:
from mcp.crypto.server import MCPServer
# 创建一个简单的 MCP 服务器
server = MCPServer(host="localhost", port=8000)
# 定义一个新的资源
@server.resource("example://test")
def get_example_resource():
return {"message": "Hello, MCP!"}
# 启动服务器
if __name__ == "__main__":
server.start()
通过 MCP 客户端访问资源和工具:
from mcp import Client
# 连接本地服务器
client = Client("http://localhost:8000")
# 请求市场数据
market_data_response = await client.query(
inputs=["BTC/USD"],
resources=["market_data:BTC/USD"]
)
print(market_data_response.outputs)
# 使用新闻分析工具
news_analysis_response = await client.query(
inputs=["BTC/USD"],
tools=["news_analysis"]
)
print(news_analysis_response.outputs)
from mcp.crypto.server import MCPServer
# 创建一个自定义资源
class ExampleResource:
def get(self, symbol):
return f"Example data for {symbol}"
# 注册资源到服务器
server.add_resource("example://custom", ExampleResource())
from mcp.crypto.tools import NewsAnalyzer
# 初始化新闻分析工具
news_analyzer = NewsAnalyzer()
# 分析新闻并生成策略
analysis = news_analyzer.analyze("latest BTC news")
print(analysis.strategy)
get 方法,并注册到服务器。analyze 方法,并注册到服务器。Client 类连接 MCP 服务器。query 方法获取所需数据和分析结果。from mcp import Client
# 连接本地服务器
client = Client("http://localhost:8000")
# 请求实时市场数据
market_data_response = await client.query(
inputs=["BTC/USD"],
resources=["market_data:BTC/USD"]
)
print(market_data_response.outputs)
# 使用新闻分析工具获取洞见
news_insight = await client.query(
inputs=["ETH/USD"],
tools=["news_analysis"]
)
print(news_insight.outputs)
启动服务器:
python -m mcp.crypto serve --host localhost --port 8000
运行客户端脚本:
python client_script.py
# 添加新依赖
uv add package_name
# 同步所有依赖
uv pip sync
# 生成依赖锁文件
uv pip compile -o uv.lock
使用 uv 管理项目依赖:
# 初始化 uv 配置文件
uv init
# 安装所有依赖
uv install
该项目采用 MIT 许可证,具体内容如下:
MIT License
Copyright (c) 2023 MCP-Crypto Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
欢迎社区贡献代码!请参考 CONTRIBUTING.md 获取更多信息。
感谢所有贡献者和社区成员,是你们的支持使得 MCP 加密货币协议更加完善。