@bheemverse/erp-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ERP_AGENT_DEVELOPER_GUIDE.md +649 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1106 -0
- package/package.json +50 -0
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
# Bheem Core ERP — Agent Developer Guide
|
|
2
|
+
|
|
3
|
+
> Build, register, deploy, and customize AI agents for the Bheem ERP system.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Architecture
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
erp.agentbheem.com (FastAPI, port 8000)
|
|
11
|
+
┌─────────────────────────────────────────────┐
|
|
12
|
+
│ HR, Accounting, CRM, Sales, Projects, │
|
|
13
|
+
│ Inventory, Purchase │
|
|
14
|
+
│ 200+ REST API endpoints │
|
|
15
|
+
│ Multi-tenant (company_id) │
|
|
16
|
+
└─────────────────────────────────────────────┘
|
|
17
|
+
▲ ▲
|
|
18
|
+
│ REST calls │ Template registration
|
|
19
|
+
┌──────────────────────┐ ┌──────────────────────┐
|
|
20
|
+
│ erp-mcp │───►│ Orchestrator │
|
|
21
|
+
│ (port 9013) │ │ (port 8009) │
|
|
22
|
+
│ 5 MCP tools │ │ Runs agents │
|
|
23
|
+
│ 6 agent templates │ │ DO NOT MODIFY │
|
|
24
|
+
│ YOU BUILD THIS │ └──────────────────────┘
|
|
25
|
+
└──────────────────────┘
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**What you work on:**
|
|
29
|
+
- `packages/@bheem/erp-mcp/` — MCP tools and agent templates
|
|
30
|
+
- `modules/bheem-core/` — ERP backend (FastAPI)
|
|
31
|
+
|
|
32
|
+
**What you do NOT touch:**
|
|
33
|
+
- `orchestrator` — Agent execution engine (port 8009). Protected, platform team only.
|
|
34
|
+
|
|
35
|
+
### SDK & Package
|
|
36
|
+
|
|
37
|
+
| Resource | URL |
|
|
38
|
+
|----------|-----|
|
|
39
|
+
| **MCP SDK (starter template)** | `git clone https://github.com/Bheem-Platform/bheem-mcp-sdk.git` |
|
|
40
|
+
| **MCP Server Core (npm)** | `npm install @bheemverse/mcp-server-core` |
|
|
41
|
+
| **Full SDK Developer Guide** | `DEVELOPER_GUIDE.md` inside the SDK repo |
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Table of Contents
|
|
46
|
+
|
|
47
|
+
1. [ERP Module Overview](#1-erp-module-overview)
|
|
48
|
+
2. [Available Agents](#2-available-agents)
|
|
49
|
+
3. [MCP Tools Reference](#3-mcp-tools-reference)
|
|
50
|
+
4. [Creating New Agents](#4-creating-new-agents)
|
|
51
|
+
5. [Customizing Existing Agents](#5-customizing-existing-agents)
|
|
52
|
+
6. [Template Config Reference](#6-template-config-reference)
|
|
53
|
+
7. [Authentication & Multi-Tenancy](#7-authentication--multi-tenancy)
|
|
54
|
+
8. [Build & Deploy](#8-build--deploy)
|
|
55
|
+
9. [Testing](#9-testing)
|
|
56
|
+
10. [Possible Agent Ideas](#10-possible-agent-ideas)
|
|
57
|
+
11. [Troubleshooting](#11-troubleshooting)
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 1. ERP Module Overview
|
|
62
|
+
|
|
63
|
+
Bheem Core ERP has 7 modules with 200+ API endpoints:
|
|
64
|
+
|
|
65
|
+
| Module | API Base | Key Entities |
|
|
66
|
+
|--------|----------|-------------|
|
|
67
|
+
| **HR** | `/api/hr/` | Employees, departments, attendance, leave, payroll, recruitment, expenses |
|
|
68
|
+
| **Accounting** | `/api/accounting/` | Chart of accounts, journal entries, invoices, budgets, fiscal years, reports, fixed assets |
|
|
69
|
+
| **CRM** | `/api/crm/` | Contacts, accounts, opportunities, leads, activities, campaigns, support tickets |
|
|
70
|
+
| **Sales** | `/api/sales/` | Customers, vendors, quotes, orders, invoices, payments |
|
|
71
|
+
| **Inventory** | `/api/inventory/` | Warehouses, stock levels, stock movements, adjustments |
|
|
72
|
+
| **Project Management** | `/project-management/api/v1/` | Projects, tasks, milestones, team members, time logs, budget, risks, documents |
|
|
73
|
+
| **Purchase** | `/api/purchase/` | Purchase orders, vendor bills (extend via new MCP tool) |
|
|
74
|
+
|
|
75
|
+
**Tech Stack:** FastAPI + SQLAlchemy async + PostgreSQL (multi-schema) + Redis event bus
|
|
76
|
+
**Production:** `https://erp.agentbheem.com` (server `37.27.89.140`)
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 2. Available Agents
|
|
81
|
+
|
|
82
|
+
### erp-hr-agent — HR Manager
|
|
83
|
+
**20 actions** covering the full HR lifecycle.
|
|
84
|
+
|
|
85
|
+
| Action | Params | Permission |
|
|
86
|
+
|--------|--------|-----------|
|
|
87
|
+
| `dashboard` | — | read |
|
|
88
|
+
| `list_employees` | `department_id?, status?, limit?` | read |
|
|
89
|
+
| `get_employee` | `employee_id` | read |
|
|
90
|
+
| `create_employee` | `first_name, last_name, email, department_id, position?` | write |
|
|
91
|
+
| `update_employee` | `employee_id, ...fields` | write |
|
|
92
|
+
| `list_departments` | — | read |
|
|
93
|
+
| `create_department` | `name, parent_id?` | admin |
|
|
94
|
+
| `list_attendance` | `employee_id?, date_from?, date_to?, limit?` | read |
|
|
95
|
+
| `mark_attendance` | `employee_id, date, check_in, check_out?` | write |
|
|
96
|
+
| `list_leave_requests` | `employee_id?, status?, limit?` | read |
|
|
97
|
+
| `create_leave_request` | `employee_id, leave_type, start_date, end_date, reason?` | write |
|
|
98
|
+
| `approve_leave` | `leave_request_id, status, remarks?` | admin |
|
|
99
|
+
| `list_candidates` | `status?, limit?` | read |
|
|
100
|
+
| `create_candidate` | `first_name, last_name, email, position, resume_url?` | write |
|
|
101
|
+
| `list_payroll_runs` | `month?, year?, limit?` | read |
|
|
102
|
+
| `get_payslip` | `payslip_id` | read |
|
|
103
|
+
| `run_payroll` | `month, year, department_id?` | admin |
|
|
104
|
+
| `list_expenses` | `employee_id?, status?, limit?` | read |
|
|
105
|
+
| `create_expense` | `employee_id, amount, category, description, receipt_url?` | write |
|
|
106
|
+
| `approve_expense` | `expense_id, status, remarks?` | admin |
|
|
107
|
+
|
|
108
|
+
### erp-accounting-agent — Accounting Manager
|
|
109
|
+
**17 actions** for financial management.
|
|
110
|
+
|
|
111
|
+
| Action | Params | Permission |
|
|
112
|
+
|--------|--------|-----------|
|
|
113
|
+
| `dashboard` | — | read |
|
|
114
|
+
| `list_accounts` | `account_type?, limit?` | read |
|
|
115
|
+
| `get_account` | `account_id` | read |
|
|
116
|
+
| `create_account` | `name, account_type, code, parent_id?` | write |
|
|
117
|
+
| `list_journal_entries` | `date_from?, date_to?, status?, limit?` | read |
|
|
118
|
+
| `create_journal_entry` | `date, description, lines[{account_id, debit, credit}]` | write |
|
|
119
|
+
| `list_invoices` | `status?, customer_id?, date_from?, date_to?, limit?` | read |
|
|
120
|
+
| `get_invoice` | `invoice_id` | read |
|
|
121
|
+
| `create_invoice` | `customer_id, due_date, lines[{description, quantity, unit_price}]` | write |
|
|
122
|
+
| `list_budgets` | `fiscal_year?, limit?` | read |
|
|
123
|
+
| `create_budget` | `name, fiscal_year_id, lines[{account_id, amount}]` | admin |
|
|
124
|
+
| `list_fiscal_years` | — | read |
|
|
125
|
+
| `financial_report` | `report_type, date_from, date_to` | read |
|
|
126
|
+
| `list_cost_centers` | — | read |
|
|
127
|
+
| `list_profit_centers` | — | read |
|
|
128
|
+
| `list_fixed_assets` | `status?, limit?` | read |
|
|
129
|
+
| `ar_ap_summary` | — | read |
|
|
130
|
+
|
|
131
|
+
**Report types:** `trial_balance`, `income_statement`, `balance_sheet`
|
|
132
|
+
|
|
133
|
+
### erp-crm-agent — CRM Manager
|
|
134
|
+
**22 actions** for customer relationship management.
|
|
135
|
+
|
|
136
|
+
| Action | Params | Permission |
|
|
137
|
+
|--------|--------|-----------|
|
|
138
|
+
| `analytics` | — | read |
|
|
139
|
+
| `list_contacts` | `limit?` | read |
|
|
140
|
+
| `get_contact` | `contact_id` | read |
|
|
141
|
+
| `create_contact` | `first_name, last_name, email?, phone?, company?` | write |
|
|
142
|
+
| `list_accounts` | `limit?` | read |
|
|
143
|
+
| `get_account` | `account_id` | read |
|
|
144
|
+
| `create_account` | `name, industry?, website?` | write |
|
|
145
|
+
| `list_opportunities` | `stage?, owner_id?, limit?` | read |
|
|
146
|
+
| `get_opportunity` | `opportunity_id` | read |
|
|
147
|
+
| `create_opportunity` | `name, account_id, stage, value?, close_date?` | write |
|
|
148
|
+
| `update_opportunity` | `opportunity_id, stage?, value?, close_date?` | write |
|
|
149
|
+
| `list_leads` | `status?, source?, limit?` | read |
|
|
150
|
+
| `get_lead` | `lead_id` | read |
|
|
151
|
+
| `create_lead` | `name, email?, phone?, source?, campaign_id?` | write |
|
|
152
|
+
| `update_lead` | `lead_id, status?, assigned_to?` | write |
|
|
153
|
+
| `list_activities` | `contact_id?, type?, limit?` | read |
|
|
154
|
+
| `create_activity` | `type[call|email|meeting|note], contact_id?, subject, description?` | write |
|
|
155
|
+
| `list_campaigns` | `status?, limit?` | read |
|
|
156
|
+
| `create_campaign` | `name, type, start_date?, end_date?, budget?` | write |
|
|
157
|
+
| `list_tickets` | `status?, priority?, limit?` | read |
|
|
158
|
+
| `create_ticket` | `subject, description, contact_id?, priority?` | write |
|
|
159
|
+
| `update_ticket` | `ticket_id, status?, priority?, assigned_to?` | write |
|
|
160
|
+
|
|
161
|
+
### erp-sales-agent — Sales & Inventory Manager
|
|
162
|
+
**20 actions** for the full sales cycle + inventory.
|
|
163
|
+
|
|
164
|
+
| Action | Params | Permission |
|
|
165
|
+
|--------|--------|-----------|
|
|
166
|
+
| `dashboard` | — | read |
|
|
167
|
+
| `list_customers` | `limit?` | read |
|
|
168
|
+
| `get_customer` | `customer_id` | read |
|
|
169
|
+
| `create_customer` | `name, email?, phone?, company?` | write |
|
|
170
|
+
| `list_vendors` | `limit?` | read |
|
|
171
|
+
| `create_vendor` | `name, email?, phone?` | write |
|
|
172
|
+
| `list_quotes` | `status?, customer_id?, limit?` | read |
|
|
173
|
+
| `get_quote` | `quote_id` | read |
|
|
174
|
+
| `create_quote` | `customer_id, items[{sku_id, quantity, unit_price}], valid_until?` | write |
|
|
175
|
+
| `list_orders` | `status?, customer_id?, limit?` | read |
|
|
176
|
+
| `get_order` | `order_id` | read |
|
|
177
|
+
| `create_order` | `customer_id, items[{sku_id, quantity, unit_price}]` | write |
|
|
178
|
+
| `list_invoices` | `status?, customer_id?, limit?` | read |
|
|
179
|
+
| `create_invoice` | `order_id` | write |
|
|
180
|
+
| `record_payment` | `invoice_id, amount, payment_method, reference?` | write |
|
|
181
|
+
| `list_warehouses` | — | read |
|
|
182
|
+
| `get_stock_levels` | `warehouse_id?, sku_id?, limit?` | read |
|
|
183
|
+
| `list_stock_movements` | `warehouse_id?, sku_id?, limit?` | read |
|
|
184
|
+
| `create_stock_movement` | `sku_id, warehouse_id, quantity, movement_type[in|out|transfer], reason?` | write |
|
|
185
|
+
| `adjust_inventory` | `warehouse_id, sku_id, new_quantity, reason` | admin |
|
|
186
|
+
|
|
187
|
+
**Sales Cycle:** Customer → Quote → Order → Invoice → Payment
|
|
188
|
+
|
|
189
|
+
### erp-projects-agent — Project Manager
|
|
190
|
+
**21 actions** for project management.
|
|
191
|
+
|
|
192
|
+
| Action | Params | Permission |
|
|
193
|
+
|--------|--------|-----------|
|
|
194
|
+
| `analytics` | — | read |
|
|
195
|
+
| `list_projects` | `status?, limit?` | read |
|
|
196
|
+
| `get_project` | `project_id` | read |
|
|
197
|
+
| `create_project` | `name, description?, start_date?, end_date?, budget?` | write |
|
|
198
|
+
| `update_project` | `project_id, ...fields` | write |
|
|
199
|
+
| `list_tasks` | `project_id?, assignee_id?, status?, priority?, limit?` | read |
|
|
200
|
+
| `get_task` | `task_id` | read |
|
|
201
|
+
| `create_task` | `project_id, title, description?, assignee_id?, priority?, due_date?` | write |
|
|
202
|
+
| `update_task` | `task_id, status?, priority?, assignee_id?, due_date?` | write |
|
|
203
|
+
| `list_milestones` | `project_id?, limit?` | read |
|
|
204
|
+
| `create_milestone` | `project_id, name, due_date, description?` | write |
|
|
205
|
+
| `list_team_members` | `project_id` | read |
|
|
206
|
+
| `add_team_member` | `project_id, employee_id, role?` | write |
|
|
207
|
+
| `list_time_logs` | `project_id?, task_id?, employee_id?, date_from?, date_to?, limit?` | read |
|
|
208
|
+
| `log_time` | `task_id, hours, date, description?` | write |
|
|
209
|
+
| `get_budget` | `project_id` | read |
|
|
210
|
+
| `list_comments` | `task_id, limit?` | read |
|
|
211
|
+
| `add_comment` | `task_id, content` | write |
|
|
212
|
+
| `list_documents` | `project_id, limit?` | read |
|
|
213
|
+
| `list_risks` | `project_id, limit?` | read |
|
|
214
|
+
| `create_risk` | `project_id, title, description?, probability?, impact?` | write |
|
|
215
|
+
|
|
216
|
+
### erp-router — ERP Assistant
|
|
217
|
+
Routes user queries to the right specialist agent. Understands natural language:
|
|
218
|
+
- "Show me employee list" → erp-hr-agent
|
|
219
|
+
- "What's our AR/AP status?" → erp-accounting-agent
|
|
220
|
+
- "Update lead status" → erp-crm-agent
|
|
221
|
+
- "Create a sales order" → erp-sales-agent
|
|
222
|
+
- "How's the project going?" → erp-projects-agent
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## 3. MCP Tools Reference
|
|
227
|
+
|
|
228
|
+
The ERP MCP server exposes 5 domain tools. Each tool uses action routing — one tool handles many operations via the `action` field.
|
|
229
|
+
|
|
230
|
+
### Tool: `hr`
|
|
231
|
+
```json
|
|
232
|
+
{
|
|
233
|
+
"action": "list_employees",
|
|
234
|
+
"params": { "department_id": "dept-123", "limit": 10 }
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Tool: `accounting`
|
|
239
|
+
```json
|
|
240
|
+
{
|
|
241
|
+
"action": "financial_report",
|
|
242
|
+
"params": { "report_type": "income_statement", "date_from": "2026-01-01", "date_to": "2026-01-31" }
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Tool: `crm`
|
|
247
|
+
```json
|
|
248
|
+
{
|
|
249
|
+
"action": "create_lead",
|
|
250
|
+
"params": { "name": "John Doe", "email": "john@example.com", "source": "website" }
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Tool: `sales`
|
|
255
|
+
```json
|
|
256
|
+
{
|
|
257
|
+
"action": "create_order",
|
|
258
|
+
"params": { "customer_id": "cust-456", "items": [{"sku_id": "SKU-001", "quantity": 5, "unit_price": 100}] }
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Tool: `projects`
|
|
263
|
+
```json
|
|
264
|
+
{
|
|
265
|
+
"action": "create_task",
|
|
266
|
+
"params": { "project_id": "proj-789", "title": "Design review", "priority": "high", "due_date": "2026-03-01" }
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## 4. Creating New Agents
|
|
273
|
+
|
|
274
|
+
### Step 1: Add a template to `src/templates/index.ts`
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
// Add to the erpTemplates array:
|
|
278
|
+
{
|
|
279
|
+
id: 'erp-payroll-specialist',
|
|
280
|
+
name: 'Payroll Specialist',
|
|
281
|
+
version: '1.0.0',
|
|
282
|
+
description: 'Dedicated payroll agent — runs payroll, generates payslips, tracks expenses',
|
|
283
|
+
icon: 'credit-card',
|
|
284
|
+
category: 'hr',
|
|
285
|
+
executionMode: 'channel',
|
|
286
|
+
orchestrator: 'sdk',
|
|
287
|
+
model: 'auto',
|
|
288
|
+
mcpServers: ERP_MCP,
|
|
289
|
+
allowedTools: [],
|
|
290
|
+
maxTurns: 10,
|
|
291
|
+
maxBudgetUsd: 1.0,
|
|
292
|
+
tierRequired: 'free',
|
|
293
|
+
triggers: ['manual', 'schedule', 'channel'],
|
|
294
|
+
connectedServices: ['erp'],
|
|
295
|
+
systemPrompt: `You are a payroll specialist for Bheem ERP.
|
|
296
|
+
|
|
297
|
+
## Tools
|
|
298
|
+
- hr({ action: 'list_payroll_runs', params: { month?, year? } })
|
|
299
|
+
- hr({ action: 'get_payslip', params: { payslip_id } })
|
|
300
|
+
- hr({ action: 'run_payroll', params: { month, year, department_id? } })
|
|
301
|
+
- hr({ action: 'list_expenses', params: { employee_id?, status? } })
|
|
302
|
+
- hr({ action: 'approve_expense', params: { expense_id, status, remarks? } })
|
|
303
|
+
- hr({ action: 'list_employees', params: { department_id? } })
|
|
304
|
+
|
|
305
|
+
## Workflow
|
|
306
|
+
1. Check existing payroll runs for the period
|
|
307
|
+
2. List employees in target department
|
|
308
|
+
3. Run payroll (requires admin access)
|
|
309
|
+
4. Review generated payslips
|
|
310
|
+
5. Handle pending expenses
|
|
311
|
+
|
|
312
|
+
NEVER use curl or raw HTTP calls — use MCP tools only.
|
|
313
|
+
${COMMUNICATION_STYLE}`,
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Step 2: Build and restart
|
|
318
|
+
|
|
319
|
+
```bash
|
|
320
|
+
cd packages/@bheem/erp-mcp
|
|
321
|
+
npm run build
|
|
322
|
+
pm2 restart erp-mcp
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Templates self-register with the orchestrator on boot. No orchestrator changes needed.
|
|
326
|
+
|
|
327
|
+
### Step 3: Add a new MCP tool (if needed)
|
|
328
|
+
|
|
329
|
+
Create `src/tools/purchase.ts`:
|
|
330
|
+
```typescript
|
|
331
|
+
import type { McpToolDefinition } from '@bheem/mcp-server-core';
|
|
332
|
+
import { erpClient } from '../utils/erp-client.js';
|
|
333
|
+
import { getUserScope, authHeaders } from '../utils/scope.js';
|
|
334
|
+
|
|
335
|
+
export const purchaseTools: McpToolDefinition[] = [
|
|
336
|
+
{
|
|
337
|
+
name: 'purchase',
|
|
338
|
+
description: `Purchase operations. Available actions:
|
|
339
|
+
- list_purchase_orders: List POs (params: status?, vendor_id?, limit?)
|
|
340
|
+
- create_purchase_order: Create PO (params: vendor_id, items[{sku_id, quantity, unit_price}])
|
|
341
|
+
- list_vendor_bills: List vendor bills (params: status?, limit?)`,
|
|
342
|
+
inputSchema: {
|
|
343
|
+
type: 'object',
|
|
344
|
+
properties: {
|
|
345
|
+
action: {
|
|
346
|
+
type: 'string',
|
|
347
|
+
enum: ['list_purchase_orders', 'create_purchase_order', 'list_vendor_bills'],
|
|
348
|
+
},
|
|
349
|
+
params: { type: 'object' },
|
|
350
|
+
},
|
|
351
|
+
required: ['action'],
|
|
352
|
+
},
|
|
353
|
+
execute: async (input, context) => {
|
|
354
|
+
const scope = getUserScope(context);
|
|
355
|
+
const p = (input.params || {}) as Record<string, any>;
|
|
356
|
+
const headers = authHeaders(scope);
|
|
357
|
+
|
|
358
|
+
if (scope.role === 'visitor') return { error: 'Please log in.' };
|
|
359
|
+
|
|
360
|
+
try {
|
|
361
|
+
switch (input.action) {
|
|
362
|
+
case 'list_purchase_orders':
|
|
363
|
+
return (await erpClient.get('/api/purchase/orders/', {
|
|
364
|
+
params: { status: p.status, vendor_id: p.vendor_id, limit: p.limit ?? 50 },
|
|
365
|
+
headers,
|
|
366
|
+
})).data;
|
|
367
|
+
case 'create_purchase_order': {
|
|
368
|
+
if (!scope.canWrite) return { error: 'Write access required.' };
|
|
369
|
+
return (await erpClient.post('/api/purchase/orders/', p, { headers })).data;
|
|
370
|
+
}
|
|
371
|
+
case 'list_vendor_bills':
|
|
372
|
+
return (await erpClient.get('/api/purchase/vendor-bills/', {
|
|
373
|
+
params: { status: p.status, limit: p.limit ?? 50 },
|
|
374
|
+
headers,
|
|
375
|
+
})).data;
|
|
376
|
+
default:
|
|
377
|
+
return { error: `Unknown action: ${input.action}` };
|
|
378
|
+
}
|
|
379
|
+
} catch (error: any) {
|
|
380
|
+
return { error: `Purchase ${input.action} failed`, details: error.response?.data?.detail || error.message };
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
];
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Then add it to `src/index.ts`:
|
|
388
|
+
```typescript
|
|
389
|
+
import { purchaseTools } from './tools/purchase.js';
|
|
390
|
+
// ... in tools array:
|
|
391
|
+
...purchaseTools,
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
---
|
|
395
|
+
|
|
396
|
+
## 5. Customizing Existing Agents
|
|
397
|
+
|
|
398
|
+
### Change the system prompt
|
|
399
|
+
Edit the agent's `systemPrompt` in `src/templates/index.ts`. The prompt controls:
|
|
400
|
+
- Which tools the agent knows about
|
|
401
|
+
- Workflow steps
|
|
402
|
+
- Communication style
|
|
403
|
+
- Permission awareness
|
|
404
|
+
|
|
405
|
+
### Limit tool access
|
|
406
|
+
Use `allowedTools` to restrict which MCP tools an agent can call:
|
|
407
|
+
```typescript
|
|
408
|
+
allowedTools: ['mcp__erp__hr', 'mcp__erp__accounting'], // Only HR + accounting
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
### Add subagents
|
|
412
|
+
For complex multi-step workflows, add subagents:
|
|
413
|
+
```typescript
|
|
414
|
+
subagents: {
|
|
415
|
+
'data-gatherer': {
|
|
416
|
+
description: 'Collects financial data from multiple sources.',
|
|
417
|
+
tools: ['mcp__erp__*'],
|
|
418
|
+
prompt: 'Gather accounting data: dashboard, AR/AP summary, recent journal entries.',
|
|
419
|
+
model: 'haiku',
|
|
420
|
+
},
|
|
421
|
+
'report-writer': {
|
|
422
|
+
description: 'Writes executive summaries from collected data.',
|
|
423
|
+
tools: ['mcp__erp__*'],
|
|
424
|
+
prompt: 'Analyze financial data and write a concise executive summary.',
|
|
425
|
+
model: 'sonnet',
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
---
|
|
431
|
+
|
|
432
|
+
## 6. Template Config Reference
|
|
433
|
+
|
|
434
|
+
| Field | Type | Required | Description |
|
|
435
|
+
|-------|------|----------|-------------|
|
|
436
|
+
| `id` | string | yes | Unique template ID (prefix with `erp-`) |
|
|
437
|
+
| `name` | string | yes | Display name |
|
|
438
|
+
| `version` | string | yes | Semver version |
|
|
439
|
+
| `description` | string | yes | Short description for UI |
|
|
440
|
+
| `icon` | string | no | Lucide icon name |
|
|
441
|
+
| `category` | string | no | `hr`, `finance`, `sales`, `projects`, `general` |
|
|
442
|
+
| `executionMode` | string | yes | `channel` (chat), `sandbox` (code exec), `client` (container) |
|
|
443
|
+
| `orchestrator` | string | yes | `sdk` (recommended) |
|
|
444
|
+
| `model` | string | yes | `auto`, `sonnet`, `haiku`, `opus` |
|
|
445
|
+
| `mcpServers` | object | yes | MCP server connections |
|
|
446
|
+
| `allowedTools` | string[] | yes | Tool filter (empty = all) |
|
|
447
|
+
| `maxTurns` | number | yes | Max agent turns per conversation |
|
|
448
|
+
| `maxBudgetUsd` | number | yes | Max spend per conversation |
|
|
449
|
+
| `tierRequired` | string | yes | `free`, `pro`, `enterprise` |
|
|
450
|
+
| `triggers` | string[] | yes | `manual`, `webhook`, `schedule`, `channel` |
|
|
451
|
+
| `connectedServices` | string[] | no | Service dependencies |
|
|
452
|
+
| `systemPrompt` | string | yes | Agent instructions |
|
|
453
|
+
| `skills` | string[] | no | Platform skills to inject (omit = all skills) |
|
|
454
|
+
| `subagents` | object | no | Sub-agent definitions for complex workflows |
|
|
455
|
+
| `pevConfig` | object | no | Plan-Execute-Verify config for advanced agents |
|
|
456
|
+
|
|
457
|
+
---
|
|
458
|
+
|
|
459
|
+
## 7. Authentication & Multi-Tenancy
|
|
460
|
+
|
|
461
|
+
### How auth works
|
|
462
|
+
The ERP uses JWT tokens via Bheem Passport. The MCP server extracts user context from the orchestrator's claims:
|
|
463
|
+
|
|
464
|
+
```typescript
|
|
465
|
+
// src/utils/scope.ts
|
|
466
|
+
export function getUserScope(context: any) {
|
|
467
|
+
const claims = context?.claims || {};
|
|
468
|
+
return {
|
|
469
|
+
userId: claims.user_id,
|
|
470
|
+
companyId: claims.company_id, // Multi-tenant scoping
|
|
471
|
+
role: claims.role || 'visitor',
|
|
472
|
+
token: claims.access_token,
|
|
473
|
+
canWrite: ['admin', 'manager', 'editor', 'SuperAdmin'].includes(claims.role),
|
|
474
|
+
canAccessAll: ['admin', 'SuperAdmin'].includes(claims.role),
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
### Permission levels
|
|
480
|
+
| Level | Roles | Can Do |
|
|
481
|
+
|-------|-------|--------|
|
|
482
|
+
| **Read** | Any authenticated user | List, get, dashboards, reports |
|
|
483
|
+
| **Write** | admin, manager, editor, SuperAdmin | Create, update |
|
|
484
|
+
| **Admin** | admin, SuperAdmin | Approve leave/expenses, run payroll, create departments, adjust inventory, create budgets |
|
|
485
|
+
|
|
486
|
+
### Multi-tenancy
|
|
487
|
+
All API calls include `company_id` from the JWT. The ERP backend scopes data automatically — agents only see data for their company.
|
|
488
|
+
|
|
489
|
+
---
|
|
490
|
+
|
|
491
|
+
## 8. Build & Deploy
|
|
492
|
+
|
|
493
|
+
### First time setup
|
|
494
|
+
```bash
|
|
495
|
+
cd packages/@bheem/erp-mcp
|
|
496
|
+
npm install
|
|
497
|
+
npm run build
|
|
498
|
+
pm2 start dist/index.js --name erp-mcp \
|
|
499
|
+
--env ERP_MCP_PORT=9013 \
|
|
500
|
+
--env ORCHESTRATOR_URL=http://localhost:8009 \
|
|
501
|
+
--env ERP_API_URL=https://erp.agentbheem.com
|
|
502
|
+
pm2 save
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
### After changes
|
|
506
|
+
```bash
|
|
507
|
+
cd packages/@bheem/erp-mcp
|
|
508
|
+
npm run build && pm2 restart erp-mcp
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
### Verify
|
|
512
|
+
```bash
|
|
513
|
+
# Health check
|
|
514
|
+
curl http://localhost:9013/health
|
|
515
|
+
|
|
516
|
+
# Verify templates registered
|
|
517
|
+
curl http://localhost:8009/api/v1/templates | python3 -c "
|
|
518
|
+
import sys, json
|
|
519
|
+
data = json.load(sys.stdin)
|
|
520
|
+
erp = [t['id'] for t in data['templates'] if t['id'].startswith('erp')]
|
|
521
|
+
print(f'{len(erp)} ERP templates:', erp)
|
|
522
|
+
"
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
### Environment variables
|
|
526
|
+
| Variable | Default | Description |
|
|
527
|
+
|----------|---------|-------------|
|
|
528
|
+
| `ERP_MCP_PORT` | `9013` | MCP server port |
|
|
529
|
+
| `ERP_MCP_AUTH_TOKEN` | — | Optional auth token |
|
|
530
|
+
| `ERP_MCP_EXTERNAL_URL` | `http://localhost:9013/mcp` | URL for agent access |
|
|
531
|
+
| `ERP_API_URL` | `https://erp.agentbheem.com` | ERP backend URL |
|
|
532
|
+
| `ORCHESTRATOR_URL` | `http://localhost:8009` | Orchestrator for template registration |
|
|
533
|
+
|
|
534
|
+
---
|
|
535
|
+
|
|
536
|
+
## 9. Testing
|
|
537
|
+
|
|
538
|
+
### Test a tool directly
|
|
539
|
+
```bash
|
|
540
|
+
curl -X POST http://localhost:9013/mcp \
|
|
541
|
+
-H "Content-Type: application/json" \
|
|
542
|
+
-d '{
|
|
543
|
+
"jsonrpc": "2.0",
|
|
544
|
+
"id": 1,
|
|
545
|
+
"method": "tools/call",
|
|
546
|
+
"params": {
|
|
547
|
+
"name": "hr",
|
|
548
|
+
"arguments": {
|
|
549
|
+
"action": "dashboard"
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}'
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
### Test via orchestrator
|
|
556
|
+
```bash
|
|
557
|
+
curl -X POST http://localhost:8009/api/v1/messages \
|
|
558
|
+
-H "Content-Type: application/json" \
|
|
559
|
+
-d '{
|
|
560
|
+
"templateId": "erp-hr-agent",
|
|
561
|
+
"messages": [{"role": "user", "content": "Show me the employee list"}],
|
|
562
|
+
"claims": {"user_id": "test", "role": "admin", "company_id": "1"}
|
|
563
|
+
}'
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
---
|
|
567
|
+
|
|
568
|
+
## 10. Possible Agent Ideas
|
|
569
|
+
|
|
570
|
+
Here are agents you can build using the existing tools (or by adding new ones):
|
|
571
|
+
|
|
572
|
+
### Cross-Module Agents
|
|
573
|
+
|
|
574
|
+
| Agent | Description | Tools Used |
|
|
575
|
+
|-------|-------------|-----------|
|
|
576
|
+
| **Financial Controller** | Monthly close: verify journal entries, reconcile AR/AP, generate reports | `accounting`, `sales` |
|
|
577
|
+
| **Workforce Planner** | Match project staffing with HR data, identify capacity gaps | `hr`, `projects` |
|
|
578
|
+
| **Sales-to-Project Converter** | When a sales order is won, auto-create a project with tasks | `sales`, `projects` |
|
|
579
|
+
| **Expense Auditor** | Review employee expenses against project budgets | `hr`, `projects` |
|
|
580
|
+
| **Customer 360** | Unified view: CRM contact + sales history + support tickets | `crm`, `sales` |
|
|
581
|
+
|
|
582
|
+
### Specialized Agents
|
|
583
|
+
|
|
584
|
+
| Agent | Description | Tools Used |
|
|
585
|
+
|-------|-------------|-----------|
|
|
586
|
+
| **Payroll Specialist** | Run payroll, generate payslips, handle expense approvals | `hr` |
|
|
587
|
+
| **Recruitment Assistant** | Track candidates, schedule interviews, manage offers | `hr` |
|
|
588
|
+
| **Leave Manager** | Handle leave requests, check balances, approve/reject | `hr` |
|
|
589
|
+
| **Invoice Collector** | Track overdue invoices, send reminders, record payments | `accounting`, `sales` |
|
|
590
|
+
| **Budget Watchdog** | Alert on budget overruns across projects and departments | `accounting`, `projects` |
|
|
591
|
+
| **Inventory Optimizer** | Track stock levels, predict reorder points, suggest movements | `sales` (inventory) |
|
|
592
|
+
| **Pipeline Coach** | Analyze CRM pipeline, suggest next actions for stale deals | `crm` |
|
|
593
|
+
| **Campaign ROI Analyzer** | Track campaign spend vs. converted opportunities | `crm` |
|
|
594
|
+
| **Time Tracker** | Log time, generate utilization reports, flag overtime | `projects`, `hr` |
|
|
595
|
+
| **Risk Monitor** | Track project risks, escalate high-probability items | `projects` |
|
|
596
|
+
|
|
597
|
+
### Adding Purchase Module (not yet exposed)
|
|
598
|
+
|
|
599
|
+
The ERP has a Purchase module (`/api/purchase/`) not yet wrapped as an MCP tool. To add it:
|
|
600
|
+
1. Create `src/tools/purchase.ts` (see [Section 4](#4-creating-new-agents))
|
|
601
|
+
2. Register in `src/index.ts`
|
|
602
|
+
3. Build new agents like **Procurement Manager** or **Vendor Payment Tracker**
|
|
603
|
+
|
|
604
|
+
---
|
|
605
|
+
|
|
606
|
+
## 11. Troubleshooting
|
|
607
|
+
|
|
608
|
+
| Issue | Cause | Fix |
|
|
609
|
+
|-------|-------|-----|
|
|
610
|
+
| `Please log in.` | No JWT claims in context | Ensure orchestrator passes claims |
|
|
611
|
+
| `Write access required.` | User role is read-only | User needs admin/manager/editor role |
|
|
612
|
+
| `Admin access required.` | Action requires admin | User needs admin or SuperAdmin role |
|
|
613
|
+
| `Unknown action: X` | Typo in action name | Check the tool's action enum |
|
|
614
|
+
| Templates not appearing | Registration failed on boot | Check `pm2 logs erp-mcp` for errors |
|
|
615
|
+
| `ECONNREFUSED :9013` | MCP server not running | `pm2 restart erp-mcp` |
|
|
616
|
+
| `ERP API timeout` | ERP backend slow/down | Check `https://erp.agentbheem.com/health` |
|
|
617
|
+
| `404 from ERP API` | Wrong endpoint path | Verify against ERP FastAPI docs |
|
|
618
|
+
|
|
619
|
+
### Useful commands
|
|
620
|
+
```bash
|
|
621
|
+
pm2 logs erp-mcp --lines 50 # View logs
|
|
622
|
+
pm2 restart erp-mcp # Restart
|
|
623
|
+
curl http://localhost:9013/health # Health check
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
---
|
|
627
|
+
|
|
628
|
+
## File Structure
|
|
629
|
+
|
|
630
|
+
```
|
|
631
|
+
packages/@bheem/erp-mcp/
|
|
632
|
+
├── package.json
|
|
633
|
+
├── tsconfig.json
|
|
634
|
+
├── ERP_AGENT_DEVELOPER_GUIDE.md ← This file
|
|
635
|
+
├── src/
|
|
636
|
+
│ ├── index.ts ← Server entry (port 9013)
|
|
637
|
+
│ ├── templates/
|
|
638
|
+
│ │ └── index.ts ← 6 agent templates
|
|
639
|
+
│ ├── tools/
|
|
640
|
+
│ │ ├── hr.ts ← 20 HR actions
|
|
641
|
+
│ │ ├── accounting.ts ← 17 Accounting actions
|
|
642
|
+
│ │ ├── crm.ts ← 22 CRM actions
|
|
643
|
+
│ │ ├── sales.ts ← 20 Sales + Inventory actions
|
|
644
|
+
│ │ └── projects.ts ← 21 Project Management actions
|
|
645
|
+
│ └── utils/
|
|
646
|
+
│ ├── erp-client.ts ← Axios client → erp.agentbheem.com
|
|
647
|
+
│ └── scope.ts ← Auth + multi-tenancy
|
|
648
|
+
└── dist/ ← Built output
|
|
649
|
+
```
|
package/dist/index.d.ts
ADDED