合金MCP示例
一系列全面的示例,演示如何在各种应用程序和框架中集成和使用Alloy的模型上下文协议(MCP)服务器。
🚀 快速开始```bash
Clone the repository
git clone https://github.com/alloy-automation/mcp-examples
cd mcp-examples
Install dependencies
pnpm install
Copy environment variables (already pre-configured!)
cp .env.example .env
All examples use a single .env file from the root
## 📚 例子
### 1. 基础TypeScript
一个展示如何使用TypeScript连接到Alloy MCP服务器的最小示例。
**特征:**
- 基本服务器连接
- 工具发现和调用
- 错误处理
- 响应流```bash
pnpm run example:basic
2. Next.js聊天应用程序
使用Next.js和Alloy MCP构建的功能齐全的聊天应用程序。
特征:
- 实时聊天界面
- 多MCP服务器支持
- 工具执行可视化```bash
cd examples/nextjs-chat
pnpm install
pnpm dev
### 3. 开发包
Alloy MCP集成的Python实现。
**特征:**
- Python MCP客户端
- 异步/等待支持
- 工具发现
- 工作流执行```bash
cd examples/python-sdk
pip install -r requirements.txt
python main.py
🏗️ 建筑```mermaid
graph TB
A[Client Application] --> B[Alloy MCP Client]
B --> C[MCP Server 1]
B --> D[MCP Server 2]
B --> E[MCP Server N]
C --> F[Tools & Resources]
D --> G[Workflows]
E --> H[Integrations]
F --> I[External APIs]
G --> J[Business Logic]
H --> K[Third-party Services]
## 🔧 配置
所有示例均使用a **集中式配置** 从根开始 `.env` 文件。这简化了设置,并确保了所有示例的一致性。
### 环境变量
该项目使用这些预先配置的值:```bash
# Root .env file (used by all examples)
# MCP Server Configuration
NEXT_PUBLIC_ALLOY_API_KEY=
NEXT_PUBLIC_MCP_SERVER_URL=
NEXT_PUBLIC_MCP_ACCESS_TOKEN=
🤝 贡献
我们欢迎捐款!
- 分叉存储库
- 创建功能分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
📝 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🔗 资源
- 合金文件
- MCP规范
💬 支持
- 问题: GitHub问题
内置于❤️ Alloy团队