第5天:来自远程MCP的API
学习目标
Day4的,之Local MCP打开服务器Remote MCP部署为服务器Claude Web即使…也Google Docs使操作成为可能
今天要学习的东西
- Local MCP vs Remote MCP 区别
- HTTP/WebSocket基本MCP服务器实施
- Claude Web Custom Connectors 与集成
- 可伸缩的API统一体系结构
- 真正的EpisodicRAG系统基础建设
项目结构
Day5_APIsFromRemoteMCP/
├── README.md # このファイル
├── package.json # Node.js プロジェクト設定
├── tsconfig.json # TypeScript設定
├── .env.example # 環境変数のサンプル
├── .gitignore # Git除外ファイル
├── vercel.json # Vercel デプロイ設定(オプション)
├── src/
│ ├── server.ts # Remote MCPサーバー本体
│ ├── routes/
│ │ ├── mcp.ts # MCP protocol endpoints
│ │ └── health.ts # ヘルスチェック
│ ├── services/
│ │ └── google-docs-remote.ts # Remote用Google Docsサービス
│ ├── middleware/
│ │ ├── auth.ts # 認証ミドルウェア
│ │ ├── cors.ts # CORS設定
│ │ └── error.ts # エラーハンドリング
│ └── utils/
│ ├── mcp-protocol.ts # MCPプロトコル実装
│ └── websocket.ts # WebSocket管理
├── deployment/
│ ├── vercel/ # Vercel用設定
│ ├── railway/ # Railway用設定
│ └── docker/ # Docker用設定
└── dist/ # コンパイル後のJavaScriptDay1-4从上一步
以前的学习→Day5的发展
- Day1: Python関数 → 可伸缩的API函数
- 第二天:本地MCP → 远程MCP服务器
- Day3: 认证学习 → 服务器端认证管理
- Day4: Claude Desktop统合 → Claude Web+定制连接器
本地MCP与远程MCP
本地MCP(第4天)
Claude Desktop ←→ Node.js Process ←→ Google APIs
(stdio) (localhost) (OAuth2)特徴:
- Claude Desktop専用
- Stdio通信(标准入出力)
- 本地进程
- OAuth2验证(用户权限)
远程MCP(第5天)
Claude Web ←→ HTTP Server ←→ Google APIs
(HTTPS) (Remote Host) (Service Account)特徴:
- 克劳德网络+桌面両対応
- HTTP/WebSocket通信
- 远程服务器
- 服务帐户认证(服务器权限)
体系结构设计
核心组件
1. 远程MCP服务器
// HTTP endpoint for MCP protocol
app.post('/mcp', handleMCPRequest);
// WebSocket for real-time updates
app.ws('/ws', handleWebSocket);2. 身份验证策略
// Day3で学んだサービスアカウント認証を活用
const auth = new GoogleServiceAccount({
keyFile: process.env.GOOGLE_SERVICE_ACCOUNT_KEY,
scopes: ['docs', 'drive']
});3. Claude Web集成
// Custom Connector 設定
{
"name": "EpisodicRAG Remote",
"url": "https://your-server.vercel.app/mcp",
"description": "Remote Google Docs operations"
}技术栈
后端
- Express.js: HTTP 服务器
- 操作系统: WebSocket 支持
- 谷歌API: Day3・4的知识活用
- 萨德:架构验证(与第4天相同)
部署选项
- 维塞尔:无服务器函数(推荐)
- 铁路:全栈主机
- 码头工人:容器部署
安全
- API Key认证:用于自定义连接器
- 速率限制: DDoS防止
- CORS:交叉原始控制
- 输入验证: Zod 验证
Day5创新点
1. 通用访问
Claude Desktop (Day4) → Local MCP
Claude Web (Day5) → Remote MCP
Mobile Apps (Future) → Same Remote MCP2. 可扩展体系结构
Single Remote Server → Multiple Client Types
→ Multiple Google Accounts
→ Multiple API Integrations3. EpiodicRAG基金会
- 集中的知识:所有客户端都相同EpisodicRAG访问文件夹
- 统一API:一致Google Docs操作
- 多用户支持:未来的多用户支持
MCP协议实现
HTTP端点设计
// MCP tools/list
GET /mcp/tools
// MCP tools/call
POST /mcp/tools/call
{
"name": "create_document",
"arguments": {
"title": "Remote Test Document"
}
}WebSocket实时更新
// Document creation notifications
ws.send({
"type": "document_created",
"data": {
"id": "doc_id",
"url": "https://docs.google.com/..."
}
});安全注意事项
1. API密钥管理
- 环境变量で秘密鍵管理
- Rotation 可能的API 键设计
- 按客户端访问控制
2. 速率限制
// Per IP, Per API Key limits
const rateLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100 // requests per window
});3. 输入消毒
// Zod schema validation
const CreateDocSchema = z.object({
title: z.string().max(200).min(1),
content: z.string().max(10000).optional()
});部署策略
第1阶段:基本远程MCP
- Express 服务器实施
- 第4天工具の HTTP 版変換
- Vercel 部署
- Claude Web 测试
第二阶段:高级功能
- WebSocket 实时更新
- 多用户支持
- 高级错误处理
- 监控和记录
第三阶段:EpiodicRAG整合
- 知识图连接
- 高级文档关系
- 基于人工智能的内容建议
- 自动化知识管理
🎉 部署成功!
Railway.app 中的部署
- 公共URL: https://testday5-production.up.railway.app
- 健康检查: https://testday5-production.up.railway.app/health
- MCP端点: https://testday5-production.up.railway.app/mcp
Claude Web自定义连接器設定
Name: Railway MCP Server
URL: https://testday5-production.up.railway.app/mcp
Description: Simple MCP server hosted on Railway可用工具
get_time-获取当前时间echo-回显消息calculate-简单的公式计算
成功基准
- \[x\] Remote MCP服务器HTTP运行✅
- \[x\] Claude Web单击功能区上Custom Connector可设置✅
- \[x\] Railway.app成功部署✅
- \[ \] Day4等值Google Docs可远程操作
- \[x\] 可扩展体系结构的基础完成✅
Day4兼容
共享工具
create_document→ HTTP POST/mcp/工具/调用write_to_document→ 同上list_loop_documents→ 同上create_learning_log→ 同上
迁移路径
Day4 Local MCP → Day5 Remote MCP → Hybrid Usage
Claude Desktop Claude Web Both Platforms下一步(第6天以后展望)
- 高级EpiodicRAG: AI基本解说
- 多API集成: Slack, Notion, GitHub等的合并
- 实时协作:实时协同编辑
- AI助手集成: GPT-4, Claude等直接合并
