代理构建模板

Bheem平台的代理构建模板,包含持久内存、作用域技能、远程服务器操作和按代理访问控制。

  • by Bheem-Platform
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 Bheem-Platform/bheem-mcp-sdk

使用说明

Bheem MCP服务器模板

Bheem平台上构建代理的入门模板。包括持久内存、作用域技能、远程服务器操作和每个代理的访问控制。

快速开始

# 1. Clone this template
git clone https://github.com/Bheem-Platform/bheem-mcp-sdk.git my-module-mcp
cd my-module-mcp

# 2. Configure
cp .env.example .env
# → set MCP_PORT, MCP_EXTERNAL_URL, BACKEND_API_URL, ORCHESTRATOR_URL

# 3. Install & run
npm install
npm run dev

# 4. Verify
curl http://<YOUR_SERVER_IP>:9012/health

您的MCP服务器正在运行。模板在启动时自动向编排器注册。

包含什么

功能 描述 文件
域名工具 每个域一个工具,带有操作路由(items, analytics) src/tools/items.ts, src/tools/analytics.ts
工作空间内存 跨会话的持久键值事实,按模块/用户/代理确定范围 src/memory/
远程操作 基于SSH访问所有9台Bheem服务器,并具有每个代理的权限 src/tools/remote-ops.ts
范围技能 每个代理只注入相关的平台技能(并非全部50+) src/templates/index.ts
代理模板 具有技能、内存和远程操作的自注册模板 src/templates/index.ts

建筑

┌────────────────────────────────────────────────────────────┐
│              Your MCP Server (:9012)                        │
│                                                             │
│  Domain Tools (3-5)     Memory Tools (4)    Remote Ops (6) │
│  ┌────────────────┐    ┌──────────────┐    ┌─────────────┐ │
│  │ items           │    │ memory_set    │    │ remote_exec │ │
│  │ analytics       │    │ memory_get    │    │ remote_read │ │
│  │ [your domain]   │    │ memory_list   │    │ remote_write│ │
│  │                 │    │ memory_delete │    │ remote_edit │ │
│  └────────────────┘    └──────────────┘    │ remote_ls   │ │
│                              │              │ remote_health│ │
│                         ┌────┴────┐        └──────┬──────┘ │
│                         │ Cache + │              SSH│        │
│                         │ Postgres│                │        │
│                         └─────────┘         ┌──────┴──────┐ │
│                                             │ 9 Servers   │ │
│  Agent Templates (auto-register on boot)    │ Access Ctrl │ │
│  ┌───────────────────────────────────────┐  └─────────────┘ │
│  │ my-module-assistant  (SDK, free)       │                  │
│  │ my-module-deep-agent (PEV, pro)        │                  │
│  │ devops-engineer      (SDK, pro)        │                  │
│  └───────────────────────────────────────┘                  │
└────────────────────────────────────────────────────────────┘
         │                              │
    auto-register                  MCP calls
         ▼                              ▼
  Bheem Orchestrator            Any Bheem Agent

三个工具层

图层 工具 用途 何时使用
SDK工具 (allowedTools) bash, read, write, edit 通用本地操作 Shell命令、文件I/O、git、npm
MCP域工具 (mcpServers) items, analytics, memory_* 结构化后端API CRUD、业务逻辑、持久性
远程操作 (MCP) remote_exec/read/write/edit/ls/health SSH到远程服务器 跨服务器操作、基础设施管理

创建代理(3个步骤)

步骤1:创建域工具

// src/tools/orders.ts — ONE tool, multiple actions
export const orderTools: McpToolDefinition[] = [{
  name: 'orders',
  description: `Order management. Actions: list, get, create, cancel, refund`,
  inputSchema: {
    type: 'object',
    properties: {
      action: { type: 'string', enum: ['list', 'get', 'create', 'cancel', 'refund'] },
      params: { type: 'object' },
    },
    required: ['action'],
  },
  execute: async (input, context) => {
    const scope = getUserScope(context);
    // ... switch on input.action
  },
}];

步骤2:创建模板

// src/templates/index.ts
{
  id: 'order-assistant',
  name: 'Order Assistant',
  orchestrator: 'sdk',
  model: 'auto',
  mcpServers: { orders: { type: 'http', url: MCP_URL } },
  allowedTools: [],
  skills: ['slack', 'trello'],
  systemPrompt: `You are an order management assistant.
## Tools
- orders({ action: 'list' }) — List orders
- memory_set({ key: 'x', value: 'y' }) — Store a fact
NEVER use curl or raw HTTP calls.`,
}

步骤3:部署

npm run build
pm2 start dist/index.js --name my-module-mcp
# Templates auto-register. Agent is immediately available.

文件结构

src/
├── index.ts                    # Server + memory + remote ops + template registration
├── tools/
│   ├── items.ts                # Domain tool (example)
│   ├── analytics.ts            # Domain tool (example)
│   └── remote-ops.ts           # Remote server operations (6 tools, SSH, access control)
├── memory/
│   ├── index.ts                # Barrel exports
│   ├── workspace-memory-store.ts  # Cache + PostgreSQL write-through
│   ├── memory-tools.ts         # 4 MCP tools (set/get/list/delete)
│   ├── schema.ts               # TypeScript types
│   └── schema.sql              # PostgreSQL migration
├── templates/
│   └── index.ts                # Agent templates with skills (auto-register on boot)
└── utils/
    ├── api-client.ts           # Axios client for your backend
    └── scope.ts                # Auth helpers (role, userId, module, templateId)

环境变量

变量 默认值 描述
MCP_PORT 9012 服务器端口
MCP_EXTERNAL_URL — 必修的。 可访问的URL(例如。 http://10.0.0.5:9012/mcp)
BACKEND_API_URL — 必修的。 您的后端API基础URL
ORCHESTRATOR_URL https://agents.agentbheem.com 模板注册的编排器
DATABASE_URL -- 可选。PostgreSQL用于持久内存
SSH_KEY_PATH ~/.ssh/sundeep 用于远程操作的SSH密钥
SSH_USER root 远程连接的SSH用户
MCP_AUTH_TOKEN -- MCP端点的可选身份验证令牌

开发者规则

  1. 每个模块最多5个域工具 --使用 action 路由参数
  2. 系统提示中没有URL --仅参考工具名称和操作
  3. 不 Bash/curl 用于API调用 --使用MCP域工具
  4. 每个工具都检查身份验证 — getUserScope(context) 每次执行
  5. 模板自行注册 --via registerTemplatesWithOrchestrator()
  6. 每个代理的范围技能 — skills: [...] 避免代币浪费
  7. 包括记忆工具 --接线 WorkspaceMemoryStore 在 index.ts
  8. 使用 model: 'auto' --让平台选择最佳模型

端口分配

端口 MCP服务器 状态
9006 学院 建成
9008 社交销售 跑步
9009 交易 建成
9010 云 正在运行
9011 工作区 运行
9012+ 您的新MCP 可用
9015 远程操作 计划

延伸阅读