Generic ERP Analytics MCP Server

Generic ERP Analytics MCP Server

Read-only MCP server for MongoDB ERP analytics with catalog-driven collection allowlist and safe find/aggregate tools.

Category
访问服务器

README

Generic ERP Analytics MCP Server

Reusable Node.js + TypeScript MCP server for safe, read-only analytics over MongoDB-backed ERP databases.

The server is intentionally not ERP-specific. To use it with a different ERP database, change only:

  • .env
  • src/catalog/schema-catalog.json
  • src/catalog/relationship-map.json

Features

  • MCP stdio server for LangGraph or other MCP clients
  • MongoDB official driver with one reusable connection pool
  • Zod validation for environment, catalog, and tool inputs
  • Catalog-driven collection allowlist
  • Read-only find and aggregate tools only
  • Blocks system collections and write-like/dangerous operators
  • Enforces DEFAULT_QUERY_LIMIT, MAX_QUERY_LIMIT, and MAX_TIME_MS
  • Applies catalog default projections and rejects sensitive/non-analytics projected fields
  • Structured JSON responses without raw stack traces

Install

npm install

Configure

Create a local .env from the example:

cp .env.example .env

Required variables:

MONGO_URI=mongodb://readonly_user:change_me@localhost:27017/?authSource=admin
MONGO_DB_NAME=erp_database
MCP_SERVER_NAME=generic-erp-analytics
MCP_SERVER_VERSION=1.0.0
DEFAULT_QUERY_LIMIT=50
MAX_QUERY_LIMIT=500
MAX_TIME_MS=10000

Create a Read-Only MongoDB User

Use a MongoDB account with permission to create users, then create a dedicated read-only user:

use erp_database

db.createUser({
  user: "readonly_user",
  pwd: "change_me",
  roles: [
    { role: "read", db: "erp_database" }
  ]
})

Use that user in MONGO_URI. The application also enforces read-only access, but database-level read-only credentials are still required.

Run

Development:

npm run dev

Build:

npm run build

Start compiled server:

npm start

Typecheck:

npm run typecheck

MCP Tools

list_collections

Returns only collection names defined in schema-catalog.json.

describe_collection

Input:

{
  "collectionName": "example_records"
}

Returns catalog metadata, fields, allowed operations, default projection, and relations.

get_schema_catalog

Returns the full schema catalog.

get_relationship_map

Returns all catalog-defined relationships.

run_find_query

Input:

{
  "collectionName": "example_records",
  "filter": {},
  "projection": {},
  "sort": {},
  "limit": 50
}

run_aggregation_query

Input:

{
  "collectionName": "example_records",
  "pipeline": [],
  "limit": 50
}

The server automatically appends a safe $project when no aggregation projection is present and appends $limit when no $limit exists.

Add a New ERP Schema

Edit src/catalog/schema-catalog.json:

{
  "collections": {
    "collection_name": {
      "description": "What this collection stores",
      "primaryKey": "_id",
      "fields": {
        "fieldName": {
          "type": "string",
          "description": "Meaning of this field",
          "sensitive": false,
          "analytics": true
        }
      },
      "allowedOperations": ["find", "aggregate"],
      "defaultProjection": {},
      "relations": [
        {
          "targetCollection": "other_collection",
          "localField": "fieldName",
          "foreignField": "_id",
          "type": "many-to-one",
          "description": "How these records are connected"
        }
      ]
    }
  }
}

Edit src/catalog/relationship-map.json:

{
  "relations": [
    {
      "fromCollection": "collection_a",
      "toCollection": "collection_b",
      "localField": "fieldName",
      "foreignField": "_id",
      "type": "many-to-one",
      "description": "Business meaning of relation"
    }
  ]
}

Restart the MCP server after changing the catalog. No TypeScript code changes are needed.

FastAPI LangGraph MCP Client

This server starts with stdio transport. A FastAPI LangGraph process can launch it as a subprocess and connect through an MCP stdio client.

Conceptually:

from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

server_params = StdioServerParameters(
    command="node",
    args=["dist/server.js"],
    env={
        "MONGO_URI": "...",
        "MONGO_DB_NAME": "...",
        "MCP_SERVER_NAME": "generic-erp-analytics",
        "MCP_SERVER_VERSION": "1.0.0",
        "DEFAULT_QUERY_LIMIT": "50",
        "MAX_QUERY_LIMIT": "500",
        "MAX_TIME_MS": "10000"
    }
)

async with stdio_client(server_params) as (read, write):
    async with ClientSession(read, write) as session:
        await session.initialize()
        tools = await session.list_tools()

HTTP transport can be added later in src/mcp/mcp.server.ts without changing the tool or service layers.

Security Notes

  • Never use an admin MongoDB user for this server.
  • Keep every collection allowlisted in schema-catalog.json.
  • Mark sensitive fields with "sensitive": true and "analytics": false.
  • Do not add write operations to allowedOperations; only find and aggregate are supported.
  • Blocked operators include $out, $merge, $function, $where, and $accumulator.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选