Compare commits
92 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40af398f68 | ||
|
|
4726f00a22 | ||
|
|
77f64b7b98 | ||
|
|
d9cbc5381a | ||
|
|
56c6447469 | ||
|
|
f8149c4b0b | ||
|
|
e259f30539 | ||
|
|
3a421bc476 | ||
|
|
503b60edb7 | ||
|
|
4039a85ee1 | ||
|
|
3a83b83a9e | ||
|
|
c1621805de | ||
|
|
ecf79eaef3 | ||
|
|
e2cb5fa467 | ||
|
|
7193ca4cdc | ||
|
|
9675cd8533 | ||
|
|
65c95aaa0b | ||
|
|
d2bbadea83 | ||
|
|
394945bbc5 | ||
|
|
bfc184afc6 | ||
|
|
1acacfab88 | ||
|
|
63c55875b5 | ||
|
|
80c6aae116 | ||
|
|
e2c5cc8ed1 | ||
|
|
b0a65cc6d0 | ||
|
|
e019c9e8b3 | ||
|
|
39b69bf550 | ||
|
|
a1047321d1 | ||
|
|
268ce5cce6 | ||
|
|
37bb3414c8 | ||
|
|
c3e1fa1eee | ||
|
|
edfbdb7123 | ||
|
|
9e5c2b5525 | ||
|
|
27b7e766af | ||
|
|
9c55f63bb1 | ||
|
|
b1674cc630 | ||
|
|
3570232ccc | ||
|
|
f50bb08816 | ||
|
|
721674e7eb | ||
|
|
1337eeed84 | ||
|
|
b14be9955b | ||
|
|
da45d49a5e | ||
|
|
f46e2c22fc | ||
|
|
ae3fe1c6f1 | ||
|
|
76a27a454e | ||
|
|
b15b71f407 | ||
|
|
298d96d593 | ||
|
|
d44886b81b | ||
|
|
bbe44fc540 | ||
|
|
c60b98e3d6 | ||
|
|
a447fe5b41 | ||
|
|
94d51fa03a | ||
|
|
b88a7240c6 | ||
|
|
3c875590ce | ||
|
|
26fa61fcfc | ||
|
|
d689541fc4 | ||
|
|
30895c4b9a | ||
|
|
37c3fd9e06 | ||
|
|
59454ca250 | ||
|
|
63efa0038c | ||
|
|
040782da8d | ||
|
|
f1a5f692cc | ||
|
|
5d798cfe6a | ||
|
|
0490d98c9e | ||
|
|
7af3c8a2ba | ||
|
|
7c43ca359e | ||
|
|
2bb6302cbc | ||
|
|
3a3f6c984c | ||
|
|
e8bc053788 | ||
|
|
bb674236c7 | ||
|
|
0f5dfbe419 | ||
|
|
74d1ca6a87 | ||
|
|
eab421c753 | ||
|
|
886ca44681 | ||
|
|
3d4baeef1a | ||
|
|
4379513a35 | ||
|
|
9a06bae225 | ||
|
|
e5aaae466f | ||
|
|
9b1338a356 | ||
|
|
10d4616601 | ||
|
|
9ca242a0e4 | ||
|
|
0a6259decf | ||
|
|
7887a3a5f9 | ||
|
|
7f33615161 | ||
|
|
c9ec3b77ce | ||
|
|
142c3f628a | ||
|
|
bbb99b6f17 | ||
|
|
c1eabb5607 | ||
|
|
afd1ee7a50 | ||
|
|
6bf22025e1 | ||
|
|
2c00f1d606 | ||
|
|
3d49c652ad |
@@ -20,6 +20,6 @@
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"no-undef": "off",
|
||||
"no-undef": "off"
|
||||
}
|
||||
}
|
||||
|
||||
15
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: samanhappy
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
polar: # Replace with a single Polar username
|
||||
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
|
||||
thanks_dev: # Replace with a single thanks.dev username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
29
.github/ISSUE_TEMPLATE/bug-report---bug-报告.md
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
name: Bug Report / Bug 报告
|
||||
about: Create a report to help us improve / 报告问题以帮助改进
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Bug Description / 问题描述**
|
||||
What happened? / 发生了什么?
|
||||
|
||||
**Steps to Reproduce / 复现步骤**
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
**Expected Behavior / 预期行为**
|
||||
What should happen? / 应该发生什么?
|
||||
|
||||
**Environment / 运行环境**
|
||||
- Running on / 运行方式: [docker/npx/local / docker/npx/本地]
|
||||
- Version / 版本: [e.g. 1.0.0]
|
||||
|
||||
**Screenshots / 截图**
|
||||
If relevant, add screenshots / 如果有帮助的话,请添加截图
|
||||
|
||||
**Additional Info / 补充信息**
|
||||
Any other details? / 还有其他信息吗?
|
||||
20
.github/ISSUE_TEMPLATE/feature-request---功能请求.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request / 功能请求
|
||||
about: Suggest an idea for this project / 为项目提出新想法
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Current Problem / 当前问题**
|
||||
What problem are you trying to solve? / 您想要解决什么问题?
|
||||
|
||||
**Proposed Solution / 建议方案**
|
||||
How would you like this to work? / 您期望的解决方案是什么?
|
||||
|
||||
**Alternatives / 替代方案**
|
||||
Have you considered any alternatives? / 您是否考虑过其他解决方案?
|
||||
|
||||
**Additional Context / 补充说明**
|
||||
Any screenshots, mockups, or relevant information? / 有任何截图、设计图或相关信息吗?
|
||||
11
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
12
.github/workflows/build.yml
vendored
@@ -16,6 +16,16 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Update version from tag
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
run: |
|
||||
VERSION=${GITHUB_REF#refs/tags/v}
|
||||
echo "Updating package.json version to $VERSION"
|
||||
jq ".version = \"$VERSION\"" package.json > package.json.tmp
|
||||
mv package.json.tmp package.json
|
||||
echo "Updated version in package.json:"
|
||||
grep -m 1 "version" package.json
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
@@ -36,7 +46,7 @@ jobs:
|
||||
type=raw,value=latest${{ matrix.variant == 'full' && '-full' || '' }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
|
||||
flavor: |
|
||||
latest=false
|
||||
|
||||
|
||||
- name: Build and Push Docker Image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
|
||||
58
.github/workflows/npm-publish.yml
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
name: Publish to NPM
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: ['v*.*.*']
|
||||
|
||||
jobs:
|
||||
publish-npm:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: 10
|
||||
run_install: false
|
||||
|
||||
- name: Get pnpm store directory
|
||||
id: pnpm-cache
|
||||
shell: bash
|
||||
run: |
|
||||
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Setup pnpm cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
|
||||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pnpm-store-
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Update version from tag
|
||||
run: |
|
||||
VERSION=${GITHUB_REF#refs/tags/v}
|
||||
echo "Updating package.json version to $VERSION"
|
||||
jq ".version = \"$VERSION\"" package.json > package.json.tmp
|
||||
mv package.json.tmp package.json
|
||||
echo "Updated version in package.json:"
|
||||
grep -m 1 "version" package.json
|
||||
|
||||
- name: Build package
|
||||
run: pnpm build
|
||||
|
||||
- name: Publish to NPM
|
||||
run: pnpm publish --no-git-checks --access public
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
1
.github/workflows/release.yml
vendored
@@ -13,6 +13,7 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
|
||||
31
Dockerfile
@@ -2,7 +2,13 @@ FROM python:3.13-slim-bookworm AS base
|
||||
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
||||
|
||||
RUN apt-get update && apt-get install -y curl gnupg \
|
||||
# 添加 HTTP_PROXY 和 HTTPS_PROXY 环境变量
|
||||
ARG HTTP_PROXY=""
|
||||
ARG HTTPS_PROXY=""
|
||||
ENV HTTP_PROXY=$HTTP_PROXY
|
||||
ENV HTTPS_PROXY=$HTTPS_PROXY
|
||||
|
||||
RUN apt-get update && apt-get install -y curl gnupg git \
|
||||
&& curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
|
||||
&& apt-get install -y nodejs \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
@@ -12,23 +18,25 @@ RUN npm install -g pnpm
|
||||
ARG REQUEST_TIMEOUT=60000
|
||||
ENV REQUEST_TIMEOUT=$REQUEST_TIMEOUT
|
||||
|
||||
ARG BASE_PATH=""
|
||||
ENV BASE_PATH=$BASE_PATH
|
||||
|
||||
ENV PNPM_HOME=/usr/local/share/pnpm
|
||||
ENV PATH=$PNPM_HOME:$PATH
|
||||
RUN mkdir -p $PNPM_HOME && \
|
||||
pnpm add -g @amap/amap-maps-mcp-server @playwright/mcp@latest tavily-mcp@latest @modelcontextprotocol/server-github @modelcontextprotocol/server-slack
|
||||
pnpm add -g @amap/amap-maps-mcp-server @playwright/mcp@latest tavily-mcp@latest @modelcontextprotocol/server-github @modelcontextprotocol/server-slack
|
||||
|
||||
ARG INSTALL_EXT=false
|
||||
RUN if [ "$INSTALL_EXT" = "true" ]; then \
|
||||
ARCH=$(uname -m); \
|
||||
if [ "$ARCH" = "x86_64" ]; then \
|
||||
npx -y playwright install --with-deps chrome; \
|
||||
else \
|
||||
echo "Skipping Chrome installation on non-amd64 architecture: $ARCH"; \
|
||||
fi; \
|
||||
fi
|
||||
ARCH=$(uname -m); \
|
||||
if [ "$ARCH" = "x86_64" ]; then \
|
||||
npx -y playwright install --with-deps chrome; \
|
||||
else \
|
||||
echo "Skipping Chrome installation on non-amd64 architecture: $ARCH"; \
|
||||
fi; \
|
||||
fi
|
||||
|
||||
RUN uv tool install mcp-server-fetch
|
||||
ENV UV_PYTHON_INSTALL_MIRROR="http://mirrors.aliyun.com/pypi/simple/"
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
@@ -37,6 +45,9 @@ RUN pnpm install
|
||||
|
||||
COPY . .
|
||||
|
||||
# Download the latest servers.json from mcpm.sh and replace the existing file
|
||||
RUN curl -s -f --connect-timeout 10 https://mcpm.sh/api/servers.json -o servers.json || echo "Failed to download servers.json, using bundled version"
|
||||
|
||||
RUN pnpm frontend:build && pnpm build
|
||||
|
||||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
|
||||
147
README.md
@@ -1,14 +1,14 @@
|
||||
# MCPHub: Your Ultimate MCP Server Hub
|
||||
# MCPHub: The Unified Hub for Model Context Protocol (MCP) Servers
|
||||
|
||||
English | [中文版](README.zh.md)
|
||||
|
||||
MCPHub is a unified management platform that aggregates multiple MCP (Model Context Protocol) servers into separate SSE endpoints for different scenarios by group. It streamlines your AI tool integrations through an intuitive interface and robust protocol handling.
|
||||
MCPHub makes it easy to manage and scale multiple MCP (Model Context Protocol) servers by organizing them into flexible Streamable HTTP (SSE) endpoints—supporting access to all servers, individual servers, or logical server groups.
|
||||
|
||||

|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- **Out-of-the-Box MCP Server Support**: Seamlessly integrate popular servers like `amap-maps`, `playwright`, `fetch`, `slack`, and more.
|
||||
- **Broadened MCP Server Support**: Seamlessly integrate any MCP server with minimal configuration.
|
||||
- **Centralized Dashboard**: Monitor real-time status and performance metrics from one sleek web UI.
|
||||
- **Flexible Protocol Handling**: Full compatibility with both stdio and SSE MCP protocols.
|
||||
- **Hot-Swappable Configuration**: Add, remove, or update MCP servers on the fly — no downtime required.
|
||||
@@ -18,14 +18,14 @@ MCPHub is a unified management platform that aggregates multiple MCP (Model Cont
|
||||
|
||||
## 🔧 Quick Start
|
||||
|
||||
### Optional Configuration
|
||||
### Configuration
|
||||
|
||||
Create a `mcp_settings.json` file to customize your server settings:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"amap-maps": {
|
||||
"amap": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@amap/amap-maps-mcp-server"],
|
||||
"env": {
|
||||
@@ -48,31 +48,20 @@ Create a `mcp_settings.json` file to customize your server settings:
|
||||
"SLACK_TEAM_ID": "your-team-id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"users": [
|
||||
{
|
||||
"username": "admin",
|
||||
"password": "$2b$10$Vt7krIvjNgyN67LXqly0uOcTpN0LI55cYRbcKC71pUDAP0nJ7RPa.",
|
||||
"isAdmin": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> **Note**: Default credentials are `admin` / `admin123`. Passwords are securely hashed with bcrypt. Generate a new hash with:
|
||||
>
|
||||
> ```bash
|
||||
> npx bcryptjs your-password
|
||||
> ```
|
||||
|
||||
### Docker Deployment
|
||||
|
||||
**Recommended**: Mount your custom config:
|
||||
|
||||
```bash
|
||||
docker run -p 3000:3000 -v $(pwd)/mcp_settings.json:/app/mcp_settings.json samanhappy/mcphub
|
||||
```
|
||||
|
||||
or run with default settings:
|
||||
|
||||
```bash
|
||||
docker run -p 3000:3000 samanhappy/mcphub
|
||||
```
|
||||
@@ -80,34 +69,110 @@ docker run -p 3000:3000 samanhappy/mcphub
|
||||
### Access the Dashboard
|
||||
|
||||
Open `http://localhost:3000` and log in with your credentials.
|
||||
|
||||
> **Note**: Default credentials are `admin` / `admin123`.
|
||||
|
||||
**Dashboard Overview**:
|
||||
|
||||
- Live status of all MCP servers
|
||||
- Enable/disable or reconfigure servers
|
||||
- Group management for organizing servers
|
||||
- User administration for access control
|
||||
|
||||
### SSE Endpoint
|
||||
### Streamable HTTP Endpoint
|
||||
|
||||
> As of now, support for streaming HTTP endpoints varies across different AI clients. If you encounter issues, you can use the SSE endpoint or wait for future updates.
|
||||
|
||||
Connect AI clients (e.g., Claude Desktop, Cursor, DeepChat, etc.) via:
|
||||
|
||||
```
|
||||
http://localhost:3000/mcp
|
||||
```
|
||||
|
||||
This endpoint provides a unified streamable HTTP interface for all your MCP servers. It allows you to:
|
||||
|
||||
- Send requests to any configured MCP server
|
||||
- Receive responses in real-time
|
||||
- Easily integrate with various AI clients and tools
|
||||
- Use the same endpoint for all servers, simplifying your integration process
|
||||
|
||||
**Smart Routing (Experimental)**:
|
||||
|
||||
Smart Routing is MCPHub's intelligent tool discovery system that uses vector semantic search to automatically find the most relevant tools for any given task.
|
||||
|
||||
```
|
||||
http://localhost:3000/mcp/$smart
|
||||
```
|
||||
|
||||
**How it Works:**
|
||||
|
||||
1. **Tool Indexing**: All MCP tools are automatically converted to vector embeddings and stored in PostgreSQL with pgvector
|
||||
2. **Semantic Search**: User queries are converted to vectors and matched against tool embeddings using cosine similarity
|
||||
3. **Intelligent Filtering**: Dynamic thresholds ensure relevant results without noise
|
||||
4. **Precise Execution**: Found tools can be directly executed with proper parameter validation
|
||||
|
||||
**Setup Requirements:**
|
||||
|
||||

|
||||
|
||||
To enable Smart Routing, you need:
|
||||
|
||||
- PostgreSQL with pgvector extension
|
||||
- OpenAI API key (or compatible embedding service)
|
||||
- Enable Smart Routing in MCPHub settings
|
||||
|
||||
**Group-Specific Endpoints (Recommended)**:
|
||||
|
||||

|
||||
|
||||
For targeted access to specific server groups, use the group-based HTTP endpoint:
|
||||
|
||||
```
|
||||
http://localhost:3000/mcp/{group}
|
||||
```
|
||||
|
||||
Where `{group}` is the ID or name of the group you created in the dashboard. This allows you to:
|
||||
|
||||
- Connect to a specific subset of MCP servers organized by use case
|
||||
- Isolate different AI tools to access only relevant servers
|
||||
- Implement more granular access control for different environments or teams
|
||||
|
||||
**Server-Specific Endpoints**:
|
||||
For direct access to individual servers, use the server-specific HTTP endpoint:
|
||||
|
||||
```
|
||||
http://localhost:3000/mcp/{server}
|
||||
```
|
||||
|
||||
Where `{server}` is the name of the server you want to connect to. This allows you to access a specific MCP server directly.
|
||||
|
||||
> **Note**: If the server name and group name are the same, the group name will take precedence.
|
||||
|
||||
### SSE Endpoint (Deprecated in Future)
|
||||
|
||||
Connect AI clients (e.g., Claude Desktop, Cursor, DeepChat, etc.) via:
|
||||
|
||||
Connect AI clients (e.g., Claude Desktop, Cursor, Cherry Studio) via:
|
||||
```
|
||||
http://localhost:3000/sse
|
||||
```
|
||||
|
||||
**Group-Specific Endpoints (Recommended)**:
|
||||
For smart routing, use:
|
||||
|
||||

|
||||
```
|
||||
http://localhost:3000/sse/$smart
|
||||
```
|
||||
|
||||
For targeted access to specific server groups, use the group-based SSE endpoint:
|
||||
|
||||
```
|
||||
http://localhost:3000/sse/{groupId}
|
||||
http://localhost:3000/sse/{group}
|
||||
```
|
||||
|
||||
Where `{groupId}` is the ID of the group you created in the dashboard. This allows you to:
|
||||
- Connect to a specific subset of MCP servers organized by use case
|
||||
- Isolate different AI tools to access only relevant servers
|
||||
- Implement more granular access control for different environments or teams
|
||||
For direct access to individual servers, use the server-specific SSE endpoint:
|
||||
|
||||
```
|
||||
http://localhost:3000/sse/{server}
|
||||
```
|
||||
|
||||
## 🧑💻 Local Development
|
||||
|
||||
@@ -120,6 +185,18 @@ pnpm dev
|
||||
|
||||
This starts both frontend and backend in development mode with hot-reloading.
|
||||
|
||||
> For windows users, you may need to start the backend server and frontend separately: `pnpm backend:dev`, `pnpm frontend:dev`.
|
||||
|
||||
## 🛠️ Common Issues
|
||||
|
||||
### Using Nginx as a Reverse Proxy
|
||||
|
||||
If you are using Nginx to reverse proxy MCPHub, please make sure to add the following configuration in your Nginx setup:
|
||||
|
||||
```nginx
|
||||
proxy_buffering off
|
||||
```
|
||||
|
||||
## 🔍 Tech Stack
|
||||
|
||||
- **Backend**: Node.js, Express, TypeScript
|
||||
@@ -129,13 +206,25 @@ This starts both frontend and backend in development mode with hot-reloading.
|
||||
|
||||
## 👥 Contributing
|
||||
|
||||
Contributions are welcome!
|
||||
Contributions of any kind are welcome!
|
||||
|
||||
- New features & optimizations
|
||||
- Documentation improvements
|
||||
- Bug reports & fixes
|
||||
- Translations & suggestions
|
||||
|
||||
Welcome to join our [Discord community](https://discord.gg/qMKNsn5Q) for discussions and support.
|
||||
|
||||
## ❤️ Sponsor
|
||||
|
||||
If you like this project, maybe you can consider:
|
||||
|
||||
[](https://ko-fi.com/samanhappy)
|
||||
|
||||
## 🌟 Star History
|
||||
|
||||
[](https://www.star-history.com/#samanhappy/mcphub&Date)
|
||||
|
||||
## 📄 License
|
||||
|
||||
Licensed under the [Apache 2.0 License](LICENSE).
|
||||
|
||||
147
README.zh.md
@@ -2,13 +2,13 @@
|
||||
|
||||
[English Version](README.md) | 中文版
|
||||
|
||||
MCPHub 是一个统一的 MCP(Model Context Protocol,模型上下文协议)服务器聚合平台,可以根据场景将多个服务器聚合到不同的 SSE 端点。它通过直观的界面和强大的协议处理能力,简化了您的 AI 工具集成流程。
|
||||
MCPHub 通过将多个 MCP(Model Context Protocol)服务器组织为灵活的流式 HTTP(SSE)端点,简化了管理与扩展工作。系统支持按需访问全部服务器、单个服务器或按场景分组的服务器集合。
|
||||
|
||||

|
||||
|
||||
## 🚀 功能亮点
|
||||
|
||||
- **开箱即用的 MCP 服务器支持**:无缝集成 `amap-maps`、`playwright`、`fetch`、`slack` 等常见服务器。
|
||||
- **广泛的 MCP 服务器支持**:无缝集成任何 MCP 服务器,配置简单。
|
||||
- **集中式管理控制台**:在一个简洁的 Web UI 中实时监控所有服务器的状态和性能指标。
|
||||
- **灵活的协议兼容**:完全支持 stdio 和 SSE 两种 MCP 协议。
|
||||
- **热插拔式配置**:在运行时动态添加、移除或更新服务器配置,无需停机。
|
||||
@@ -18,14 +18,14 @@ MCPHub 是一个统一的 MCP(Model Context Protocol,模型上下文协议
|
||||
|
||||
## 🔧 快速开始
|
||||
|
||||
### 可选配置
|
||||
### 配置
|
||||
|
||||
通过创建 `mcp_settings.json` 自定义服务器设置:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"amap-maps": {
|
||||
"amap": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@amap/amap-maps-mcp-server"],
|
||||
"env": {
|
||||
@@ -48,31 +48,20 @@ MCPHub 是一个统一的 MCP(Model Context Protocol,模型上下文协议
|
||||
"SLACK_TEAM_ID": "your-team-id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"users": [
|
||||
{
|
||||
"username": "admin",
|
||||
"password": "$2b$10$Vt7krIvjNgyN67LXqly0uOcTpN0LI55cYRbcKC71pUDAP0nJ7RPa.",
|
||||
"isAdmin": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> **提示**:默认用户名/密码为 `admin` / `admin123`。密码已通过 bcrypt 安全哈希。生成新密码哈希:
|
||||
>
|
||||
> ```bash
|
||||
> npx bcryptjs your-password
|
||||
> ```
|
||||
|
||||
### Docker 部署
|
||||
|
||||
**推荐**:挂载自定义配置:
|
||||
|
||||
```bash
|
||||
docker run -p 3000:3000 -v $(pwd)/mcp_settings.json:/app/mcp_settings.json samanhappy/mcphub
|
||||
```
|
||||
|
||||
或使用默认配置运行:
|
||||
|
||||
```bash
|
||||
docker run -p 3000:3000 samanhappy/mcphub
|
||||
```
|
||||
@@ -80,34 +69,110 @@ docker run -p 3000:3000 samanhappy/mcphub
|
||||
### 访问控制台
|
||||
|
||||
打开 `http://localhost:3000`,使用您的账号登录。
|
||||
|
||||
> **提示**:默认用户名/密码为 `admin` / `admin123`。
|
||||
|
||||
**控制台功能**:
|
||||
|
||||
- 实时监控所有 MCP 服务器状态
|
||||
- 启用/禁用或重新配置服务器
|
||||
- 分组管理,组织服务器访问
|
||||
- 用户管理,设定权限
|
||||
|
||||
### SSE 端点集成
|
||||
### 支持流式的 HTTP 端点
|
||||
|
||||
> 截至目前,各家 AI 客户端对流式的 HTTP 端点支持不一,如果遇到问题,可以使用 SSE 端点或者等待更新。
|
||||
|
||||
通过以下地址连接 AI 客户端(如 Claude Desktop、Cursor、DeepChat 等):
|
||||
|
||||
```
|
||||
http://localhost:3000/mcp
|
||||
```
|
||||
|
||||
这个端点为所有 MCP 服务器提供统一的流式 HTTP 接口。它允许您:
|
||||
|
||||
- 向任何配置的 MCP 服务器发送请求
|
||||
- 实时接收响应
|
||||
- 轻松与各种 AI 客户端和工具集成
|
||||
- 对所有服务器使用相同的端点,简化集成过程
|
||||
|
||||
**智能路由(实验性功能)**:
|
||||
|
||||
智能路由是 MCPHub 的智能工具发现系统,使用向量语义搜索自动为任何给定任务找到最相关的工具。
|
||||
|
||||
```
|
||||
http://localhost:3000/mcp/$smart
|
||||
```
|
||||
|
||||
**工作原理:**
|
||||
|
||||
1. **工具索引**:所有 MCP 工具自动转换为向量嵌入并存储在 PostgreSQL 与 pgvector 中
|
||||
2. **语义搜索**:用户查询转换为向量并使用余弦相似度与工具嵌入匹配
|
||||
3. **智能筛选**:动态阈值确保相关结果且无噪声
|
||||
4. **精确执行**:找到的工具可以直接执行并进行适当的参数验证
|
||||
|
||||
**设置要求:**
|
||||
|
||||

|
||||
|
||||
为了启用智能路由,您需要:
|
||||
|
||||
- 支持 pgvector 扩展的 PostgreSQL
|
||||
- OpenAI API 密钥(或兼容的嵌入服务)
|
||||
- 在 MCPHub 设置中启用智能路由
|
||||
|
||||
**基于分组的 HTTP 端点(推荐)**:
|
||||

|
||||
要针对特定服务器分组进行访问,请使用基于分组的 HTTP 端点:
|
||||
|
||||
```
|
||||
http://localhost:3000/mcp/{group}
|
||||
```
|
||||
|
||||
其中 `{group}` 是您在控制面板中创建的分组 ID 或名称。这样做可以:
|
||||
|
||||
- 连接到按用例组织的特定 MCP 服务器子集
|
||||
- 隔离不同的 AI 工具,使其只能访问相关服务器
|
||||
- 为不同环境或团队实现更精细的访问控制
|
||||
- 通过分组名称轻松识别和管理服务器
|
||||
- 允许不同的 AI 客户端使用相同的端点,简化集成过程
|
||||
|
||||
**针对特定服务器的 HTTP 端点**:
|
||||
要针对特定服务器进行访问,请使用以下格式:
|
||||
|
||||
```
|
||||
http://localhost:3000/mcp/{server}
|
||||
```
|
||||
|
||||
其中 `{server}` 是您要连接的服务器名称。这样做可以直接访问特定的 MCP 服务器。
|
||||
|
||||
> **提示**:如果服务器名称和分组名称相同,则分组名称优先。
|
||||
|
||||
### SSE 端点集成 (未来可能废弃)
|
||||
|
||||
通过以下地址连接 AI 客户端(如 Claude Desktop、Cursor、DeepChat 等):
|
||||
|
||||
通过以下地址连接 AI 客户端(如 Claude Desktop、Cursor、Cherry Studio 等):
|
||||
```
|
||||
http://localhost:3000/sse
|
||||
```
|
||||
|
||||
**基于分组的 SSE 端点(推荐)**:
|
||||
要启用智能路由,请使用:
|
||||
|
||||

|
||||
```
|
||||
http://localhost:3000/sse/$smart
|
||||
```
|
||||
|
||||
要针对特定服务器分组进行访问,请使用基于分组的 SSE 端点:
|
||||
|
||||
```
|
||||
http://localhost:3000/sse/{groupId}
|
||||
http://localhost:3000/sse/{group}
|
||||
```
|
||||
|
||||
其中 `{groupId}` 是您在控制面板中创建的分组 ID。这样做可以:
|
||||
- 连接到按用例组织的特定 MCP 服务器子集
|
||||
- 隔离不同的 AI 工具,使其只能访问相关服务器
|
||||
- 为不同环境或团队实现更精细的访问控制
|
||||
要针对特定服务器进行访问,请使用以下格式:
|
||||
|
||||
```
|
||||
http://localhost:3000/sse/{server}
|
||||
```
|
||||
|
||||
## 🧑💻 本地开发
|
||||
|
||||
@@ -120,6 +185,18 @@ pnpm dev
|
||||
|
||||
此命令将在开发模式下启动前后端,并启用热重载。
|
||||
|
||||
> 针对 Windows 用户,可能需要分别启动后端服务器和前端:`pnpm backend:dev`,`pnpm frontend:dev`。
|
||||
|
||||
## 🛠️ 常见问题
|
||||
|
||||
### 使用 nginx 反向代理
|
||||
|
||||
如果您在使用 nginx 反向代理 MCPHub,请确保在 nginx 配置中添加以下内容:
|
||||
|
||||
```nginx
|
||||
proxy_buffering off
|
||||
```
|
||||
|
||||
## 🔍 技术栈
|
||||
|
||||
- **后端**:Node.js、Express、TypeScript
|
||||
@@ -136,9 +213,21 @@ pnpm dev
|
||||
- Bug 报告与修复
|
||||
- 翻译与建议
|
||||
|
||||
欢迎加入企微交流共建群
|
||||
欢迎加入企微交流共建群,由于群人数限制,有兴趣的同学可以扫码添加管理员为好友后拉入群聊。
|
||||
|
||||
<img src="assets/wegroup.png" width="500">
|
||||
<img src="assets/wexin.png" width="350">
|
||||
|
||||
如果觉得项目有帮助,不妨请我喝杯咖啡 ☕️
|
||||
|
||||
<img src="assets/reward.png" width="350">
|
||||
|
||||
## 致谢
|
||||
|
||||
感谢以下人员的赞赏:小白、琛。你们的支持是我继续前进的动力!
|
||||
|
||||
## 🌟 Star 历史趋势
|
||||
|
||||
[](https://www.star-history.com/#samanhappy/mcphub&Date)
|
||||
|
||||
## 📄 许可证
|
||||
|
||||
|
||||
BIN
articals/assets/sr-conf.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
articals/assets/sr-dc.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
articals/assets/sr-map-call.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
articals/assets/sr-map-result.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
articals/assets/sr-map-search.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
articals/assets/sr-servers.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
articals/assets/sr-time.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
articals/assets/sr-tools.png
Normal file
|
After Width: | Height: | Size: 57 KiB |
BIN
articals/assets/sr-web.png
Normal file
|
After Width: | Height: | Size: 44 KiB |
232
articals/intro2.md
Normal file
@@ -0,0 +1,232 @@
|
||||
# 本地部署、一键安装、分组路由:MCPHub 重塑 MCP 服务器体验
|
||||
|
||||
## 概述
|
||||
|
||||
现代 AI 应用场景中,将大模型(LLM)与各种数据源和工具无缝对接,往往需要手动编写大量胶水代码,并且无法快速复用。MCP(Model Context Protocol)协议由 Anthropic 在 2024 年开源,旨在提供类似“USB‑C”接口般的标准化通信方式,简化 AI 助手与内容仓库、业务系统等的集成流程。然而,MCP 服务器部署常常需要大量环境依赖、手动配置及持续运行,开发者常因安装和配置耗费大量时间和精力。MCPHub 作为一款开源的一站式聚合平台,通过直观的 Web UI、Docker 镜像和热插拔配置,实现本地或容器里的“一键安装”与“分组路由”,大幅降低 MCP 服务器的使用门槛和运维成本。
|
||||
|
||||
## MCPHub 是什么
|
||||
|
||||
### MCP 协议简介
|
||||
|
||||
Model Context Protocol(MCP)是一种开放标准,类似“USB‑C”接口,为 AI 助手与内容仓库、业务系统和第三方服务之间提供统一通信协议。它支持 stdio 与 SSE(最新协议中被 Streamable HTTP 取代)两种通信方式,既能满足实时流式数据交换,也可用于批量任务。2024 年由 Anthropic 团队开源发布后,MCP 已在各类 AI 客户端(如 Claude Desktop)中得到应用,成功实现与 GitHub、Slack、网页自动化工具等的无缝对接。
|
||||
|
||||
### MCPHub 项目概览
|
||||
|
||||
MCPHub 是一个统一的 MCP 服务器聚合平台,内置 MCP 服务器市场实现一键安装。前端基于 React、Vite 和 Tailwind CSS 构建,后端兼容任意使用 npx 或 uvx 命令启动的 MCP 服务器。它通过一个集中式 Dashboard 实时展示各服务器的运行状态,并支持在运行时热插拔增删改服务器配置,无需停机维护。支持分组式访问控制,可以通过独立的 SSE 端点访问不同的 MCP 服务器组合,管理员可灵活定义不同团队或环境的权限策略。官方提供 Docker 镜像,仅需一条命令即可快速启动本地或云端服务。
|
||||
|
||||

|
||||
|
||||
## 为什么要使用 MCPHub
|
||||
|
||||
### 1. 复杂的环境依赖与配置
|
||||
|
||||
- MCP 服务器常依赖 Node.js、Python 等多种运行时,需手动维护大量命令、参数和环境变量。
|
||||
- MCPHub 内置 MCP 服务器市场,包含众多常用 MCP 服务器,支持一键安装和自动配置,简化了环境搭建过程。
|
||||
- 通过 Docker 部署,MCPHub 可在任何支持 Docker 的平台上运行,避免了环境不一致的问题。
|
||||
|
||||

|
||||
|
||||
### 2. 持续运行的服务压力
|
||||
|
||||
- MCP 要求长连接服务常驻内存,重启或升级时需要人工干预,缺乏弹性。
|
||||
- 借助 Docker 容器化部署,MCPHub 可快速重建环境,享受容器带来的弹性与隔离优势。
|
||||
|
||||
### 3. 路由与分组管理缺乏统一视图
|
||||
|
||||
- 传统方式下,很难可视化地将不同 MCP 服务按场景分类,容易造成 token 浪费和工具选择精度下降。
|
||||
- MCPHub 支持动态创建分组(如“地图检索”、“网页自动化”、“聊天”等),为每个分组生成独立的 SSE 端点,实现各类用例的隔离与优化。
|
||||
|
||||

|
||||
|
||||
## 如何使用 MCPHub
|
||||
|
||||
### 快速部署
|
||||
|
||||
```bash
|
||||
docker run -p 3000:3000 samanhappy/mcphub
|
||||
```
|
||||
|
||||
一条命令就可以在本地快速启动 MCPHub,默认监听 3000 端口。
|
||||
|
||||
MCPHub 使用`mcp_settings.json`保存所有服务器、分组和用户的配置。你可以创建一个 `mcp_settings.json` 文件,并将其挂载到 Docker 容器中,以便在重启时保留配置。
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"amap": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@amap/amap-maps-mcp-server"],
|
||||
"env": {
|
||||
"AMAP_MAPS_API_KEY": "your-api-key"
|
||||
}
|
||||
},
|
||||
"time-mcp": {
|
||||
"command": "npx",
|
||||
"args": [
|
||||
"-y",
|
||||
"time-mcp"
|
||||
]
|
||||
},
|
||||
"sequential-thinking": {
|
||||
"command": "npx",
|
||||
"args": [
|
||||
"-y",
|
||||
"@modelcontextprotocol/server-sequential-thinking"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
然后挂载配置文件启动:
|
||||
|
||||
```bash
|
||||
docker run -p 3000:3000 -v $(pwd)/mcp_settings.json:/app/mcp_settings.json samanhappy/mcphub
|
||||
```
|
||||
|
||||
> 注意:首次运行时,MCPHub 会自动下载并安装所需的依赖包,可能需要一些时间。
|
||||
|
||||
### 访问控制台
|
||||
|
||||
启动后访问 `http://localhost:3000` 即可进入控制台。
|
||||
|
||||
> 默认登录用户名和密码为 `admin`/`admin123`,登录后可以修改密码以确保安全。
|
||||
|
||||
控制台提供了服务器管理、分组管理和市场管理等功能,你可以在这里查看所有已安装的 MCP 服务器、创建新的分组、添加或删除服务器等。
|
||||
|
||||
### 分组路由 & SSE 端点
|
||||
|
||||
#### 全局 SSE 端点
|
||||
|
||||
```
|
||||
http://localhost:3000/sse
|
||||
```
|
||||
|
||||
通过全局 SSE 端点可以访问所有已启用的 MCP 服务器。
|
||||
|
||||
#### 基于分组的 SSE 端点
|
||||
|
||||
除了全局 SSE 端点,MCPHub 还支持基于分组的 SSE 端点。你可以为每个分组创建独立的 SSE 端点,以便更好地管理和路由请求。
|
||||
分组的 SSE 端点格式如下:
|
||||
|
||||
```
|
||||
http://localhost:3000/sse/{groupId}
|
||||
```
|
||||
|
||||
其中 `{groupId}` 是分组的唯一标识符,可以从控制台获取。比如我在上面的截图中创建了一个名为 `map` 的分组,选择了 `amap` 和 `sequential-thinking` 两个服务器,那么可以通过以下 URL 访问这个分组的 SSE 端点:
|
||||
|
||||
```
|
||||
http://localhost:3000/sse/a800bef7-c4c1-4460-9557-5f4404cdd0bd
|
||||
```
|
||||
|
||||
#### 使用分组路由
|
||||
|
||||
创建了路由分组后,我们就可以在任意支持 MCP 的客户端中使用这个分组的 SSE 端点了。比如在 `Cursor` 中,我们可以在配置文件中指定分组的 SSE 端点:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"mcphub": {
|
||||
"url": "http://localhost:3000/sse/a800bef7-c4c1-4460-9557-5f4404cdd0bd"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
配置完成后,可以从 `Cursor` 中看到所有可用的 MCP 服务器工具列表。
|
||||
|
||||

|
||||
|
||||
然后,我们可以测试一下,比如输入:深度思考一下,帮我制定一个五一假期从南京出发的自驾行出游计划,要求避开拥堵路线,结合天气情况,并且可以体验到不同的自然风光。
|
||||
|
||||

|
||||
|
||||
接着可以看到,`Cursor` 在运行过程中调用了多个工具。
|
||||
|
||||

|
||||
|
||||
最终生成结果如下:
|
||||
|
||||
```markdown
|
||||
基于对路线和天气的全面分析,我为你制定了一个四天的五一自驾游行程方案:
|
||||
|
||||
### 第一天(4月29日):南京→黄山
|
||||
- 出发时间:建议早上8点出发
|
||||
- 行驶路线:G42沪蓉高速 → S11巢黄高速
|
||||
- 行驶时间:约4.5小时(282公里)
|
||||
- 住宿地点:黄山风景区附近
|
||||
- 特别提醒:
|
||||
* 路线多隧道,注意安全
|
||||
* 天气较好,适合出行
|
||||
* 建议提前订好黄山景区附近酒店
|
||||
|
||||
### 第二天(4月30日):黄山→婺源
|
||||
- 游览时间:上午游览黄山景区
|
||||
- 下午出发前往婺源
|
||||
- 行驶路线:G3京台高速 → G56杭瑞高速
|
||||
- 行驶时间:约2.5小时(139公里)
|
||||
- 住宿地点:婺源县城或特色古村落
|
||||
- 特别提醒:
|
||||
* 注意天气可能有阵雨
|
||||
* 建议游览篁岭、李坑等著名古村落
|
||||
|
||||
### 第三天(5月1日):婺源→景德镇
|
||||
- 上午游览婺源景点
|
||||
- 中午后出发前往景德镇
|
||||
- 行驶路线:G56杭瑞高速
|
||||
- 行驶时间:约1.5小时(77公里)
|
||||
- 住宿地点:景德镇市区
|
||||
- 特别提醒:
|
||||
* 可能遇到阵雨天气
|
||||
* 建议参观陶瓷博物馆和古窑址
|
||||
|
||||
### 第四天(5月2日):景德镇→南京
|
||||
- 建议上午游览景德镇景点
|
||||
- 中午后出发返回南京
|
||||
- 行驶路线:G35济广高速 → G4211宁芜高速
|
||||
- 行驶时间:约5小时(429公里)
|
||||
- 特别提醒:
|
||||
* 路程较长,建议做好休息安排
|
||||
* 注意途中加油站分布
|
||||
* 建议错峰返程,避免拥堵
|
||||
|
||||
### 整体建议:
|
||||
1. 避堵建议:
|
||||
- 选择错峰出行时间
|
||||
- 提前查看实时路况
|
||||
- 准备备选绕行路线
|
||||
|
||||
2. 安全建议:
|
||||
- 全程多雨,注意雨天行车安全
|
||||
- 保持车距,谨慎驾驶
|
||||
- 途经隧道较多,注意灯光使用
|
||||
|
||||
3. 行程准备:
|
||||
- 提前预订住宿
|
||||
- 准备雨具和应急用品
|
||||
- 建议下载离线地图
|
||||
- 检查车况,特别是雨刮和轮胎
|
||||
|
||||
4. 景点安排:
|
||||
- 黄山:建议游览迎客松、光明顶等
|
||||
- 婺源:篁岭、李坑、江岭等
|
||||
- 景德镇:陶瓷博物馆、古窑民俗博览区
|
||||
|
||||
这条路线可以让你体验到:
|
||||
- 黄山的壮丽山景
|
||||
- 婺源的田园风光
|
||||
- 景德镇的人文历史
|
||||
既避开了主要拥堵路段,又能欣赏到不同的自然风光。
|
||||
```
|
||||
|
||||
可以看到,`Cursor` 通过调用 `amap` 和 `sequential-thinking` 两个服务器,成功生成了一个五一假期的自驾游行程方案,并且避开了拥堵路线,结合了天气情况。但是细心的同学可能发现,计划中的开始时间是 4 月 29 日,而今年的五一假期是 5 月 1 日开始的,产生偏差的原因是 `sequential-thinking` 使用了错误的假期时间。如何解决这个问题呢?我们可以尝试在分组中添加支持搜索的 MCP 服务器,这样就可以在查询时自动纠正错误的假期时间了,具体就不在这里展开了。
|
||||
|
||||
## 结语
|
||||
|
||||
MCPHub 将本地部署、一键安装、分组路由和可视化管理融为一体,以简洁而强大的设计,彻底解决了 MCP 服务器的部署、配置与运维难题。无论是追求快速验证的开发者,还是需要稳定可靠 AI 工具链的企业用户,都能通过 MCPHub 专注于核心业务与创新,而无需被底层细节所困扰。
|
||||
|
||||
尽管目前各家平台都在陆续推出各类 MCP 云服务,但在数据隐私、合规性和定制化需求日益增长的背景下,MCPHub 仍然是一个值得关注的本地部署解决方案。
|
||||
|
||||
MCPHub 只是我一时兴起开发的小项目,没想到竟收获了这么多关注,非常感谢大家的支持!目前 MCPHub 还有不少地方需要优化和完善,我也专门建了个交流群,方便大家交流反馈。如果你也对这个项目感兴趣,欢迎一起参与建设!项目地址为:https://github.com/samanhappy/mcphub。
|
||||
|
||||

|
||||
177
articals/smart-routing.md
Normal file
@@ -0,0 +1,177 @@
|
||||
# 无限工具,智能路由:MCPHub 引领 AI 工具使用新范式
|
||||
|
||||
## 概述
|
||||
|
||||
在现代 AI 应用中,随着 MCP 服务器数量的快速增长和工具种类的不断丰富,如何从数百个可用工具中快速定位最适合当前任务的工具,成为开发者和 AI 助手面临的一项重要挑战。
|
||||
|
||||
传统做法要么将所有工具暴露给 AI 助手处理,导致 token 消耗巨大、响应延迟严重;要么依赖开发者手动分组配置,灵活性和智能性不足。
|
||||
|
||||
MCPHub 推出的智能路由功能,基于向量语义搜索技术,实现了自然语言驱动的工具发现与精准推荐。它让 AI 助手能够像人类专家一样,根据任务描述自动选择最优工具组合,大幅提升了系统效率和用户体验。
|
||||
|
||||
## 什么是智能路由
|
||||
|
||||
### 技术原理
|
||||
|
||||
智能路由是 MCPHub 的核心功能之一。它将每个 MCP 工具的名称和描述嵌入为高维语义向量。当用户发起自然语言任务请求时,系统会将该请求也转换为向量,通过计算相似度,快速返回最相关的工具列表。
|
||||
|
||||
这一过程摒弃了传统的关键词匹配,具备更强的语义理解能力,能够处理自然语言的模糊性和多样性。
|
||||
|
||||
### 核心组件
|
||||
|
||||
- **向量嵌入引擎**:支持如 `text-embedding-3-small`、`bge-m3` 等主流模型,将文本描述转为语义向量。
|
||||
- **PostgreSQL + pgvector**:使用开源向量数据库方案,支持高效的向量索引和搜索。
|
||||
- **两步工作流分离**:
|
||||
- `search_tools`:负责语义工具发现
|
||||
- `call_tool`:执行实际工具调用逻辑
|
||||
|
||||
## 为什么需要智能路由
|
||||
|
||||
### 1. 减少认知负荷
|
||||
|
||||
- 当工具数量超过 100 个,AI 模型难以处理所有工具上下文。
|
||||
- 智能路由通过语义压缩,将候选工具缩小至 5~10 个,提高决策效率。
|
||||
|
||||
### 2. 显著降低 token 消耗
|
||||
|
||||
- 传统做法传入全量工具描述,可能消耗上千 token。
|
||||
- 使用智能路由,通常可将 token 使用降低 70~90%。
|
||||
|
||||
### 3. 提升调用准确率
|
||||
|
||||
- 理解任务语义:如“图片增强”→选择图像处理工具,而不是依赖命名关键词。
|
||||
- 上下文感知:考虑输入/输出格式和工具组合能力,匹配更合理的执行链路。
|
||||
|
||||
## 智能路由配置指南
|
||||
|
||||
### 1. 启动支持 `pgvector` 的 PostgreSQL 数据库
|
||||
|
||||
```bash
|
||||
docker run --name mcphub-postgres \
|
||||
-e POSTGRES_DB=mcphub \
|
||||
-e POSTGRES_USER=mcphub \
|
||||
-e POSTGRES_PASSWORD=your_password \
|
||||
-p 5432:5432 \
|
||||
-d pgvector/pgvector:pg17
|
||||
```
|
||||
|
||||
如已部署 PostgreSQL,可直接创建数据库并启用 `pgvector` 扩展:
|
||||
|
||||
```sql
|
||||
CREATE DATABASE mcphub;
|
||||
CREATE EXTENSION vector;
|
||||
```
|
||||
|
||||
### 2. 获取 embedding 模型的 API Key
|
||||
|
||||
前往 OpenAI 或其他提供商获取嵌入模型的 API Key。国内用户推荐使用硅基流动 `bge-m3` 免费模型,没有注册过的用户可以使用我的邀请链接:[https://cloud.siliconflow.cn/i/TQhVYBvA](https://cloud.siliconflow.cn/i/TQhVYBvA)。
|
||||
|
||||
### 3. 控制台配置
|
||||
|
||||

|
||||
|
||||
在 MCPHub 控制台中,进入「智能路由」配置页面,填写以下信息:
|
||||
|
||||
- **数据库 URL**:`postgresql://mcphub:your_password@localhost:5432/mcphub`
|
||||
- **OpenAI API Key** :填写你获取的嵌入模型 API Key
|
||||
- **OpenAI 基础 URL**:`https://api.siliconflow.cn/v1`
|
||||
- **嵌入模型**:推荐使用 `BAAI/bge-m3`
|
||||
|
||||
开启「启用智能路由」后系统会自动:
|
||||
|
||||
- 对所有工具生成向量嵌入
|
||||
- 构建向量索引
|
||||
- 自动监听新增工具,更新索引
|
||||
|
||||
## 工具定义
|
||||
|
||||
### search_tools - 工具搜索
|
||||
|
||||
```ts
|
||||
{
|
||||
"name": "search_tools",
|
||||
"arguments": {
|
||||
"query": "help me resize and convert images",
|
||||
"limit": 10
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### call_tool - 工具执行
|
||||
|
||||
```ts
|
||||
{
|
||||
"name": "call_tool",
|
||||
"arguments": {
|
||||
"toolName": "image_resizer",
|
||||
"arguments": {
|
||||
"input_path": "/path/to/image.png",
|
||||
"width": 800,
|
||||
"height": 600
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 演示
|
||||
|
||||
下面我将通过几个示例来展示如何使用智能路由。
|
||||
|
||||
首先,我们需要在 mcphub 添加几个不同类型的 MCP 服务器:`amap`、`time-map`、`fetch`。
|
||||
|
||||

|
||||
|
||||
然后我们需要选择一个支持 MCP 的客户端,这里选择国产的 DeepChat,聊天模型选择 `Qwen3-14B`。
|
||||
|
||||
接着,在 DeepChat 中添加 mcphub 的智能路由端点:
|
||||
|
||||

|
||||
|
||||
添加成功后,就可以在工具中看到 `search_tools` 和 `call_tool` 两个工具了:
|
||||
|
||||

|
||||
|
||||
### 示例 1:地图导航
|
||||
|
||||
输入:从北京如何导航到上海。
|
||||
|
||||
结果:
|
||||
|
||||

|
||||
|
||||
可以看到,DeepChat 先调用了 `search_tools` 工具:
|
||||
|
||||

|
||||
|
||||
然后再调用 `call_tool` 查询具体的导航信息:
|
||||
|
||||

|
||||
|
||||
### 示例 2:查询时间
|
||||
|
||||
输入:使用工具查询美国现在的时间是几点
|
||||
|
||||
结果:
|
||||
|
||||

|
||||
|
||||
需要说明的是,由于不同的模型对工具调用的支持程度不同,可能会出现一些差异。比如在这个例子中,为了提高准确性,我在输入中明确提到了“使用工具”。
|
||||
|
||||
### 示例 3:查看网页
|
||||
|
||||
输入:打开 baidu.com 看看有什么
|
||||
|
||||
结果:
|
||||
|
||||

|
||||
|
||||
可以看到,DeepChat 成功调用了工具,不过由于百度的 robots.txt 限制,无法获取到具体内容。
|
||||
|
||||
## 结语
|
||||
|
||||
借助 MCPHub 的智能路由功能,AI 助手能够更高效地处理复杂任务,显著减少不必要的 token 消耗,同时提升工具调用的准确性与灵活性。作为面向未来的 AI 工具发现与调用基础设施,智能路由不仅使 AI 更聪明地选择和组合工具,还为多 Agent 协同提供了清晰、可控且可扩展的底层能力支撑。
|
||||
|
||||
> MCPHub 只是我一时兴起开发的小项目,没想到收获了这么多关注,非常感谢大家的支持!目前 MCPHub 还有不少地方需要优化和完善,我也专门建了个交流群,感兴趣的可以添加下面的微信。
|
||||
|
||||

|
||||
|
||||
> 同时,欢迎大家一起参与建设!项目地址为:[https://github.com/samanhappy/mcphub](https://github.com/samanhappy/mcphub)。
|
||||
BIN
assets/cursor-mcp.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
assets/cursor-query.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
assets/cursor-tools.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
BIN
assets/group.png
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 16 KiB |
BIN
assets/market.zh.png
Normal file
|
After Width: | Height: | Size: 74 KiB |
BIN
assets/reward.png
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
assets/smart-routing.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
assets/smart-routing.zh.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
assets/wegroup.jpg
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
assets/wexin.png
Normal file
|
After Width: | Height: | Size: 92 KiB |
96
bin/cli.js
Executable file
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { execSync } from 'child_process';
|
||||
import fs from 'fs';
|
||||
|
||||
// Enable debug logging if needed
|
||||
// process.env.DEBUG = 'true';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
// Start with more debug information
|
||||
console.log('📋 MCPHub CLI');
|
||||
console.log(`📁 CLI script location: ${__dirname}`);
|
||||
|
||||
// The npm package directory structure when installed is:
|
||||
// node_modules/@samanhappy/mcphub/
|
||||
// - dist/
|
||||
// - bin/
|
||||
// - frontend/dist/
|
||||
|
||||
// Get the package root - this is where package.json is located
|
||||
function findPackageRoot() {
|
||||
const isDebug = process.env.DEBUG === 'true';
|
||||
|
||||
// Possible locations for package.json
|
||||
const possibleRoots = [
|
||||
// Standard npm package location
|
||||
path.resolve(__dirname, '..'),
|
||||
// When installed via npx
|
||||
path.resolve(__dirname, '..', '..', '..')
|
||||
];
|
||||
|
||||
// Special handling for npx
|
||||
if (process.argv[1] && process.argv[1].includes('_npx')) {
|
||||
const npxDir = path.dirname(process.argv[1]);
|
||||
possibleRoots.unshift(path.resolve(npxDir, '..'));
|
||||
}
|
||||
|
||||
if (isDebug) {
|
||||
console.log('DEBUG: Checking for package.json in:', possibleRoots);
|
||||
}
|
||||
|
||||
for (const root of possibleRoots) {
|
||||
const packageJsonPath = path.join(root, 'package.json');
|
||||
if (fs.existsSync(packageJsonPath)) {
|
||||
try {
|
||||
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||
if (pkg.name === 'mcphub' || pkg.name === '@samanhappy/mcphub') {
|
||||
if (isDebug) {
|
||||
console.log(`DEBUG: Found package.json at ${packageJsonPath}`);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
} catch (e) {
|
||||
// Continue to the next potential root
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('⚠️ Could not find package.json, using default path');
|
||||
return path.resolve(__dirname, '..');
|
||||
}
|
||||
|
||||
// Locate and check the frontend distribution
|
||||
function checkFrontend(packageRoot) {
|
||||
const isDebug = process.env.DEBUG === 'true';
|
||||
const frontendDistPath = path.join(packageRoot, 'frontend', 'dist');
|
||||
|
||||
if (isDebug) {
|
||||
console.log(`DEBUG: Checking frontend at: ${frontendDistPath}`);
|
||||
}
|
||||
|
||||
if (fs.existsSync(frontendDistPath) && fs.existsSync(path.join(frontendDistPath, 'index.html'))) {
|
||||
console.log('✅ Frontend distribution found');
|
||||
return true;
|
||||
} else {
|
||||
console.log('⚠️ Frontend distribution not found at', frontendDistPath);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const projectRoot = findPackageRoot();
|
||||
console.log(`📦 Using package root: ${projectRoot}`);
|
||||
|
||||
// Check if frontend exists
|
||||
checkFrontend(projectRoot);
|
||||
|
||||
// Start the server
|
||||
console.log('🚀 Starting MCPHub server...');
|
||||
import(path.join(projectRoot, 'dist', 'index.js')).catch(err => {
|
||||
console.error('Failed to start MCPHub:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
32
docs/README.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Mintlify Starter Kit
|
||||
|
||||
Click on `Use this template` to copy the Mintlify starter kit. The starter kit contains examples including
|
||||
|
||||
- Guide pages
|
||||
- Navigation
|
||||
- Customizations
|
||||
- API Reference pages
|
||||
- Use of popular components
|
||||
|
||||
### Development
|
||||
|
||||
Install the [Mintlify CLI](https://www.npmjs.com/package/mintlify) to preview the documentation changes locally. To install, use the following command
|
||||
|
||||
```
|
||||
npm i -g mintlify
|
||||
```
|
||||
|
||||
Run the following command at the root of your documentation (where docs.json is)
|
||||
|
||||
```
|
||||
mintlify dev
|
||||
```
|
||||
|
||||
### Publishing Changes
|
||||
|
||||
Install our Github App to auto propagate changes from your repo to your deployment. Changes will be deployed to production automatically after pushing to the default branch. Find the link to install on your dashboard.
|
||||
|
||||
#### Troubleshooting
|
||||
|
||||
- Mintlify dev isn't running - Run `mintlify install` it'll re-install dependencies.
|
||||
- Page loads as a 404 - Make sure you are running in a folder with `docs.json`
|
||||
4
docs/api-reference/endpoint/create.mdx
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
title: 'Create Plant'
|
||||
openapi: 'POST /plants'
|
||||
---
|
||||
4
docs/api-reference/endpoint/delete.mdx
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
title: 'Delete Plant'
|
||||
openapi: 'DELETE /plants/{id}'
|
||||
---
|
||||
4
docs/api-reference/endpoint/get.mdx
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
title: 'Get Plants'
|
||||
openapi: 'GET /plants'
|
||||
---
|
||||
4
docs/api-reference/endpoint/webhook.mdx
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
title: 'New Plant'
|
||||
openapi: 'WEBHOOK /plant/webhook'
|
||||
---
|
||||
33
docs/api-reference/introduction.mdx
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
title: 'Introduction'
|
||||
description: 'Example section for showcasing API endpoints'
|
||||
---
|
||||
|
||||
<Note>
|
||||
If you're not looking to build API reference documentation, you can delete
|
||||
this section by removing the api-reference folder.
|
||||
</Note>
|
||||
|
||||
## Welcome
|
||||
|
||||
There are two ways to build API documentation: [OpenAPI](https://mintlify.com/docs/api-playground/openapi/setup) and [MDX components](https://mintlify.com/docs/api-playground/mdx/configuration). For the starter kit, we are using the following OpenAPI specification.
|
||||
|
||||
<Card
|
||||
title="Plant Store Endpoints"
|
||||
icon="leaf"
|
||||
href="https://github.com/mintlify/starter/blob/main/api-reference/openapi.json"
|
||||
>
|
||||
View the OpenAPI specification file
|
||||
</Card>
|
||||
|
||||
## Authentication
|
||||
|
||||
All API endpoints are authenticated using Bearer tokens and picked up from the specification file.
|
||||
|
||||
```json
|
||||
"security": [
|
||||
{
|
||||
"bearerAuth": []
|
||||
}
|
||||
]
|
||||
```
|
||||
217
docs/api-reference/openapi.json
Normal file
@@ -0,0 +1,217 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "OpenAPI Plant Store",
|
||||
"description": "A sample API that uses a plant store as an example to demonstrate features in the OpenAPI specification",
|
||||
"license": {
|
||||
"name": "MIT"
|
||||
},
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "http://sandbox.mintlify.com"
|
||||
}
|
||||
],
|
||||
"security": [
|
||||
{
|
||||
"bearerAuth": []
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/plants": {
|
||||
"get": {
|
||||
"description": "Returns all plants from the system that the user has access to",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"description": "The maximum number of results to return",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Plant response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/Plant"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Unexpected error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "Creates a new plant in the store",
|
||||
"requestBody": {
|
||||
"description": "Plant to add to the store",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/NewPlant"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "plant response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Plant"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "unexpected error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/plants/{id}": {
|
||||
"delete": {
|
||||
"description": "Deletes a single plant based on the ID supplied",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"description": "ID of plant to delete",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "Plant deleted",
|
||||
"content": {}
|
||||
},
|
||||
"400": {
|
||||
"description": "unexpected error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"webhooks": {
|
||||
"/plant/webhook": {
|
||||
"post": {
|
||||
"description": "Information about a new plant added to the store",
|
||||
"requestBody": {
|
||||
"description": "Plant added to the store",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/NewPlant"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Return a 200 status to indicate that the data was received successfully"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"Plant": {
|
||||
"required": [
|
||||
"name"
|
||||
],
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "The name of the plant",
|
||||
"type": "string"
|
||||
},
|
||||
"tag": {
|
||||
"description": "Tag to specify the type",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"NewPlant": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/Plant"
|
||||
},
|
||||
{
|
||||
"required": [
|
||||
"id"
|
||||
],
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"description": "Identification number of the plant",
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"Error": {
|
||||
"required": [
|
||||
"error",
|
||||
"message"
|
||||
],
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"error": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securitySchemes": {
|
||||
"bearerAuth": {
|
||||
"type": "http",
|
||||
"scheme": "bearer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
539
docs/configuration/docker-setup.mdx
Normal file
@@ -0,0 +1,539 @@
|
||||
---
|
||||
title: 'Docker Setup'
|
||||
description: 'Deploy MCPHub using Docker and Docker Compose'
|
||||
---
|
||||
|
||||
# Docker Setup
|
||||
|
||||
This guide covers deploying MCPHub using Docker, including development and production configurations.
|
||||
|
||||
## Quick Start with Docker
|
||||
|
||||
### Using Pre-built Image
|
||||
|
||||
```bash
|
||||
# Pull the latest image
|
||||
docker pull mcphub/mcphub:latest
|
||||
|
||||
# Run with default configuration
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
-p 3000:3000 \
|
||||
-v $(pwd)/mcp_settings.json:/app/mcp_settings.json \
|
||||
mcphub/mcphub:latest
|
||||
```
|
||||
|
||||
### Building from Source
|
||||
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://github.com/your-username/mcphub.git
|
||||
cd mcphub
|
||||
|
||||
# Build the Docker image
|
||||
docker build -t mcphub:local .
|
||||
|
||||
# Run the container
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
-p 3000:3000 \
|
||||
-v $(pwd)/mcp_settings.json:/app/mcp_settings.json \
|
||||
mcphub:local
|
||||
```
|
||||
|
||||
## Docker Compose Setup
|
||||
|
||||
### Basic Configuration
|
||||
|
||||
Create a `docker-compose.yml` file:
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
mcphub:
|
||||
image: mcphub/mcphub:latest
|
||||
# For local development, use:
|
||||
# build: .
|
||||
container_name: mcphub
|
||||
ports:
|
||||
- '3000:3000'
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- PORT=3000
|
||||
- JWT_SECRET=${JWT_SECRET:-your-jwt-secret}
|
||||
- DATABASE_URL=postgresql://mcphub:password@postgres:5432/mcphub
|
||||
volumes:
|
||||
- ./mcp_settings.json:/app/mcp_settings.json:ro
|
||||
- ./servers.json:/app/servers.json:ro
|
||||
- mcphub_data:/app/data
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mcphub-network
|
||||
|
||||
postgres:
|
||||
image: postgres:15-alpine
|
||||
container_name: mcphub-postgres
|
||||
environment:
|
||||
- POSTGRES_DB=mcphub
|
||||
- POSTGRES_USER=mcphub
|
||||
- POSTGRES_PASSWORD=password
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- ./scripts/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql:ro
|
||||
ports:
|
||||
- '5432:5432'
|
||||
healthcheck:
|
||||
test: ['CMD-SHELL', 'pg_isready -U mcphub -d mcphub']
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mcphub-network
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
mcphub_data:
|
||||
|
||||
networks:
|
||||
mcphub-network:
|
||||
driver: bridge
|
||||
```
|
||||
|
||||
### Production Configuration with Nginx
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
container_name: mcphub-nginx
|
||||
ports:
|
||||
- '80:80'
|
||||
- '443:443'
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
- ./ssl:/etc/nginx/ssl:ro
|
||||
- nginx_logs:/var/log/nginx
|
||||
depends_on:
|
||||
- mcphub
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mcphub-network
|
||||
|
||||
mcphub:
|
||||
image: mcphub/mcphub:latest
|
||||
container_name: mcphub-app
|
||||
expose:
|
||||
- '3000'
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- PORT=3000
|
||||
- JWT_SECRET=${JWT_SECRET}
|
||||
- JWT_EXPIRES_IN=${JWT_EXPIRES_IN:-24h}
|
||||
- DATABASE_URL=postgresql://mcphub:${POSTGRES_PASSWORD}@postgres:5432/mcphub
|
||||
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
||||
- REDIS_URL=redis://redis:6379
|
||||
volumes:
|
||||
- ./mcp_settings.json:/app/mcp_settings.json:ro
|
||||
- ./servers.json:/app/servers.json:ro
|
||||
- mcphub_data:/app/data
|
||||
- mcphub_logs:/app/logs
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mcphub-network
|
||||
healthcheck:
|
||||
test: ['CMD', 'wget', '--quiet', '--tries=1', '--spider', 'http://localhost:3000/health']
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
postgres:
|
||||
image: postgres:15-alpine
|
||||
container_name: mcphub-postgres
|
||||
environment:
|
||||
- POSTGRES_DB=mcphub
|
||||
- POSTGRES_USER=mcphub
|
||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- ./backups:/backups
|
||||
healthcheck:
|
||||
test: ['CMD-SHELL', 'pg_isready -U mcphub -d mcphub']
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mcphub-network
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: mcphub-redis
|
||||
command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD}
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ['CMD', 'redis-cli', 'ping']
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mcphub-network
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
redis_data:
|
||||
mcphub_data:
|
||||
mcphub_logs:
|
||||
nginx_logs:
|
||||
|
||||
networks:
|
||||
mcphub-network:
|
||||
driver: bridge
|
||||
```
|
||||
|
||||
### Environment Variables
|
||||
|
||||
Create a `.env` file for Docker Compose:
|
||||
|
||||
```env
|
||||
# Application
|
||||
NODE_ENV=production
|
||||
JWT_SECRET=your-super-secret-jwt-key-change-this
|
||||
JWT_EXPIRES_IN=24h
|
||||
|
||||
# Database
|
||||
POSTGRES_PASSWORD=your-secure-database-password
|
||||
|
||||
# Redis
|
||||
REDIS_PASSWORD=your-secure-redis-password
|
||||
|
||||
# External APIs
|
||||
OPENAI_API_KEY=your-openai-api-key
|
||||
|
||||
# Optional: Custom port
|
||||
# PORT=3000
|
||||
```
|
||||
|
||||
## Development Setup
|
||||
|
||||
### Development Docker Compose
|
||||
|
||||
Create `docker-compose.dev.yml`:
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
mcphub-dev:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.dev
|
||||
container_name: mcphub-dev
|
||||
ports:
|
||||
- '3000:3000'
|
||||
- '5173:5173' # Frontend dev server
|
||||
- '9229:9229' # Debug port
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
- PORT=3000
|
||||
- DATABASE_URL=postgresql://mcphub:password@postgres:5432/mcphub
|
||||
volumes:
|
||||
- .:/app
|
||||
- /app/node_modules
|
||||
- /app/frontend/node_modules
|
||||
depends_on:
|
||||
- postgres
|
||||
command: pnpm dev
|
||||
networks:
|
||||
- mcphub-dev
|
||||
|
||||
postgres:
|
||||
image: postgres:15-alpine
|
||||
container_name: mcphub-postgres-dev
|
||||
environment:
|
||||
- POSTGRES_DB=mcphub
|
||||
- POSTGRES_USER=mcphub
|
||||
- POSTGRES_PASSWORD=password
|
||||
ports:
|
||||
- '5432:5432'
|
||||
volumes:
|
||||
- postgres_dev_data:/var/lib/postgresql/data
|
||||
networks:
|
||||
- mcphub-dev
|
||||
|
||||
volumes:
|
||||
postgres_dev_data:
|
||||
|
||||
networks:
|
||||
mcphub-dev:
|
||||
driver: bridge
|
||||
```
|
||||
|
||||
### Development Dockerfile
|
||||
|
||||
Create `Dockerfile.dev`:
|
||||
|
||||
```dockerfile
|
||||
FROM node:20-alpine
|
||||
|
||||
# Install pnpm
|
||||
RUN npm install -g pnpm
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
COPY frontend/package.json ./frontend/
|
||||
|
||||
# Install dependencies
|
||||
RUN pnpm install
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Expose ports
|
||||
EXPOSE 3000 5173 9229
|
||||
|
||||
# Start development server
|
||||
CMD ["pnpm", "dev"]
|
||||
```
|
||||
|
||||
## Running the Application
|
||||
|
||||
### Development Mode
|
||||
|
||||
```bash
|
||||
# Start development environment
|
||||
docker-compose -f docker-compose.dev.yml up -d
|
||||
|
||||
# View logs
|
||||
docker-compose -f docker-compose.dev.yml logs -f mcphub-dev
|
||||
|
||||
# Stop development environment
|
||||
docker-compose -f docker-compose.dev.yml down
|
||||
```
|
||||
|
||||
### Production Mode
|
||||
|
||||
```bash
|
||||
# Start production environment
|
||||
docker-compose up -d
|
||||
|
||||
# View logs
|
||||
docker-compose logs -f mcphub
|
||||
|
||||
# Stop production environment
|
||||
docker-compose down
|
||||
```
|
||||
|
||||
## Configuration Management
|
||||
|
||||
### MCP Settings Volume Mount
|
||||
|
||||
Create your `mcp_settings.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"]
|
||||
},
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"]
|
||||
},
|
||||
"amap": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@amap/amap-maps-mcp-server"],
|
||||
"env": {
|
||||
"AMAP_MAPS_API_KEY": "your-api-key"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Secrets Management
|
||||
|
||||
For production, use Docker secrets:
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
mcphub:
|
||||
image: mcphub/mcphub:latest
|
||||
environment:
|
||||
- JWT_SECRET_FILE=/run/secrets/jwt_secret
|
||||
- DATABASE_PASSWORD_FILE=/run/secrets/db_password
|
||||
secrets:
|
||||
- jwt_secret
|
||||
- db_password
|
||||
|
||||
secrets:
|
||||
jwt_secret:
|
||||
file: ./secrets/jwt_secret.txt
|
||||
db_password:
|
||||
file: ./secrets/db_password.txt
|
||||
```
|
||||
|
||||
## Data Persistence
|
||||
|
||||
### Database Backups
|
||||
|
||||
Add backup service to your `docker-compose.yml`:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
backup:
|
||||
image: postgres:15-alpine
|
||||
container_name: mcphub-backup
|
||||
environment:
|
||||
- PGPASSWORD=${POSTGRES_PASSWORD}
|
||||
volumes:
|
||||
- ./backups:/backups
|
||||
- ./scripts/backup.sh:/backup.sh:ro
|
||||
command: /bin/sh -c "chmod +x /backup.sh && /backup.sh"
|
||||
depends_on:
|
||||
- postgres
|
||||
profiles:
|
||||
- backup
|
||||
networks:
|
||||
- mcphub-network
|
||||
```
|
||||
|
||||
Create `scripts/backup.sh`:
|
||||
|
||||
```bash
|
||||
#!/bin/sh
|
||||
BACKUP_FILE="/backups/mcphub_$(date +%Y%m%d_%H%M%S).sql"
|
||||
pg_dump -h postgres -U mcphub -d mcphub > "$BACKUP_FILE"
|
||||
echo "Backup created: $BACKUP_FILE"
|
||||
|
||||
# Keep only last 7 days of backups
|
||||
find /backups -name "mcphub_*.sql" -mtime +7 -delete
|
||||
```
|
||||
|
||||
Run backup:
|
||||
|
||||
```bash
|
||||
docker-compose --profile backup run --rm backup
|
||||
```
|
||||
|
||||
## Monitoring and Health Checks
|
||||
|
||||
### Health Check Endpoint
|
||||
|
||||
Add to your application:
|
||||
|
||||
```javascript
|
||||
// In your Express app
|
||||
app.get('/health', (req, res) => {
|
||||
res.json({
|
||||
status: 'healthy',
|
||||
timestamp: new Date().toISOString(),
|
||||
uptime: process.uptime(),
|
||||
memory: process.memoryUsage(),
|
||||
version: process.env.npm_package_version,
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### Docker Health Checks
|
||||
|
||||
```yaml
|
||||
services:
|
||||
mcphub:
|
||||
# ... other config
|
||||
healthcheck:
|
||||
test: ['CMD', 'wget', '--quiet', '--tries=1', '--spider', 'http://localhost:3000/health']
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 60s
|
||||
```
|
||||
|
||||
### Monitoring with Watchtower
|
||||
|
||||
Add automatic updates:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
watchtower:
|
||||
image: containrrr/watchtower
|
||||
container_name: mcphub-watchtower
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
environment:
|
||||
- WATCHTOWER_CLEANUP=true
|
||||
- WATCHTOWER_POLL_INTERVAL=3600
|
||||
- WATCHTOWER_INCLUDE_STOPPED=true
|
||||
restart: unless-stopped
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
**Container fails to start**: Check logs with `docker-compose logs mcphub`
|
||||
|
||||
**Database connection errors**: Ensure PostgreSQL is healthy and accessible
|
||||
|
||||
**Port conflicts**: Check if ports 3000/5432 are already in use
|
||||
|
||||
**Volume mount issues**: Verify file paths and permissions
|
||||
|
||||
### Debug Commands
|
||||
|
||||
```bash
|
||||
# Check container status
|
||||
docker-compose ps
|
||||
|
||||
# View logs
|
||||
docker-compose logs -f [service_name]
|
||||
|
||||
# Execute commands in container
|
||||
docker-compose exec mcphub sh
|
||||
|
||||
# Check database connection
|
||||
docker-compose exec postgres psql -U mcphub -d mcphub
|
||||
|
||||
# Restart specific service
|
||||
docker-compose restart mcphub
|
||||
|
||||
# Rebuild and restart
|
||||
docker-compose up --build -d
|
||||
```
|
||||
|
||||
### Performance Optimization
|
||||
|
||||
```yaml
|
||||
services:
|
||||
mcphub:
|
||||
# ... other config
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 512M
|
||||
cpus: '0.5'
|
||||
reservations:
|
||||
memory: 256M
|
||||
cpus: '0.25'
|
||||
```
|
||||
|
||||
This Docker setup provides a complete containerized environment for MCPHub with development and production configurations.
|
||||
389
docs/configuration/environment-variables.mdx
Normal file
@@ -0,0 +1,389 @@
|
||||
---
|
||||
title: 'Environment Variables'
|
||||
description: 'Configure MCPHub using environment variables'
|
||||
---
|
||||
|
||||
# Environment Variables
|
||||
|
||||
MCPHub uses environment variables for configuration. This guide covers all available variables and their usage.
|
||||
|
||||
## Core Application Settings
|
||||
|
||||
### Server Configuration
|
||||
|
||||
| Variable | Default | Description |
|
||||
| ----------- | ------------- | ------------------------------------------------------------- |
|
||||
| `PORT` | `3000` | Port number for the HTTP server |
|
||||
| `HOST` | `0.0.0.0` | Host address to bind the server |
|
||||
| `NODE_ENV` | `development` | Application environment (`development`, `production`, `test`) |
|
||||
| `LOG_LEVEL` | `info` | Logging level (`error`, `warn`, `info`, `debug`) |
|
||||
|
||||
```env
|
||||
PORT=3000
|
||||
HOST=0.0.0.0
|
||||
NODE_ENV=production
|
||||
LOG_LEVEL=info
|
||||
```
|
||||
|
||||
### Database Configuration
|
||||
|
||||
| Variable | Default | Description |
|
||||
| -------------- | ----------- | ---------------------------------- |
|
||||
| `DATABASE_URL` | - | PostgreSQL connection string |
|
||||
| `DB_HOST` | `localhost` | Database host |
|
||||
| `DB_PORT` | `5432` | Database port |
|
||||
| `DB_NAME` | `mcphub` | Database name |
|
||||
| `DB_USER` | `mcphub` | Database username |
|
||||
| `DB_PASSWORD` | - | Database password |
|
||||
| `DB_SSL` | `false` | Enable SSL for database connection |
|
||||
| `DB_POOL_MIN` | `2` | Minimum database pool size |
|
||||
| `DB_POOL_MAX` | `10` | Maximum database pool size |
|
||||
|
||||
```env
|
||||
# Option 1: Full connection string
|
||||
DATABASE_URL=postgresql://username:password@localhost:5432/mcphub
|
||||
|
||||
# Option 2: Individual components
|
||||
DB_HOST=localhost
|
||||
DB_PORT=5432
|
||||
DB_NAME=mcphub
|
||||
DB_USER=mcphub
|
||||
DB_PASSWORD=your-password
|
||||
DB_SSL=false
|
||||
```
|
||||
|
||||
## Authentication & Security
|
||||
|
||||
### JWT Configuration
|
||||
|
||||
| Variable | Default | Description |
|
||||
| ------------------------ | ------- | ------------------------------------------- |
|
||||
| `JWT_SECRET` | - | Secret key for JWT token signing (required) |
|
||||
| `JWT_EXPIRES_IN` | `24h` | JWT token expiration time |
|
||||
| `JWT_REFRESH_EXPIRES_IN` | `7d` | Refresh token expiration time |
|
||||
| `JWT_ALGORITHM` | `HS256` | JWT signing algorithm |
|
||||
|
||||
```env
|
||||
JWT_SECRET=your-super-secret-key-change-this-in-production
|
||||
JWT_EXPIRES_IN=24h
|
||||
JWT_REFRESH_EXPIRES_IN=7d
|
||||
```
|
||||
|
||||
### Session & Security
|
||||
|
||||
| Variable | Default | Description |
|
||||
| ------------------- | ------- | ------------------------------- |
|
||||
| `SESSION_SECRET` | - | Session encryption secret |
|
||||
| `BCRYPT_ROUNDS` | `12` | bcrypt hashing rounds |
|
||||
| `RATE_LIMIT_WINDOW` | `15` | Rate limiting window in minutes |
|
||||
| `RATE_LIMIT_MAX` | `100` | Maximum requests per window |
|
||||
| `CORS_ORIGIN` | `*` | Allowed CORS origins |
|
||||
|
||||
```env
|
||||
SESSION_SECRET=your-session-secret
|
||||
BCRYPT_ROUNDS=12
|
||||
RATE_LIMIT_WINDOW=15
|
||||
RATE_LIMIT_MAX=100
|
||||
CORS_ORIGIN=https://your-domain.com,https://admin.your-domain.com
|
||||
```
|
||||
|
||||
## External Services
|
||||
|
||||
### OpenAI Configuration
|
||||
|
||||
| Variable | Default | Description |
|
||||
| ------------------------ | ------------------------ | -------------------------------- |
|
||||
| `OPENAI_API_KEY` | - | OpenAI API key for smart routing |
|
||||
| `OPENAI_MODEL` | `gpt-3.5-turbo` | OpenAI model for embeddings |
|
||||
| `OPENAI_EMBEDDING_MODEL` | `text-embedding-ada-002` | Model for vector embeddings |
|
||||
| `OPENAI_MAX_TOKENS` | `1000` | Maximum tokens per request |
|
||||
| `OPENAI_TEMPERATURE` | `0.1` | Temperature for AI responses |
|
||||
|
||||
```env
|
||||
OPENAI_API_KEY=sk-your-openai-api-key
|
||||
OPENAI_MODEL=gpt-3.5-turbo
|
||||
OPENAI_EMBEDDING_MODEL=text-embedding-ada-002
|
||||
OPENAI_MAX_TOKENS=1000
|
||||
OPENAI_TEMPERATURE=0.1
|
||||
```
|
||||
|
||||
### Redis Configuration (Optional)
|
||||
|
||||
| Variable | Default | Description |
|
||||
| ---------------- | ----------- | ----------------------- |
|
||||
| `REDIS_URL` | - | Redis connection string |
|
||||
| `REDIS_HOST` | `localhost` | Redis host |
|
||||
| `REDIS_PORT` | `6379` | Redis port |
|
||||
| `REDIS_PASSWORD` | - | Redis password |
|
||||
| `REDIS_DB` | `0` | Redis database number |
|
||||
| `REDIS_PREFIX` | `mcphub:` | Key prefix for Redis |
|
||||
|
||||
```env
|
||||
# Option 1: Full connection string
|
||||
REDIS_URL=redis://username:password@localhost:6379/0
|
||||
|
||||
# Option 2: Individual components
|
||||
REDIS_HOST=localhost
|
||||
REDIS_PORT=6379
|
||||
REDIS_PASSWORD=your-redis-password
|
||||
REDIS_DB=0
|
||||
REDIS_PREFIX=mcphub:
|
||||
```
|
||||
|
||||
## MCP Server Configuration
|
||||
|
||||
### Default Settings
|
||||
|
||||
| Variable | Default | Description |
|
||||
| ------------------- | ------------------- | -------------------------------------------- |
|
||||
| `MCP_SETTINGS_FILE` | `mcp_settings.json` | Path to MCP settings file |
|
||||
| `MCP_SERVERS_FILE` | `servers.json` | Path to servers configuration |
|
||||
| `MCP_TIMEOUT` | `30000` | Default timeout for MCP operations (ms) |
|
||||
| `MCP_MAX_RETRIES` | `3` | Maximum retry attempts for failed operations |
|
||||
| `MCP_RESTART_DELAY` | `5000` | Delay before restarting failed servers (ms) |
|
||||
|
||||
```env
|
||||
MCP_SETTINGS_FILE=./config/mcp_settings.json
|
||||
MCP_SERVERS_FILE=./config/servers.json
|
||||
MCP_TIMEOUT=30000
|
||||
MCP_MAX_RETRIES=3
|
||||
MCP_RESTART_DELAY=5000
|
||||
```
|
||||
|
||||
### Smart Routing
|
||||
|
||||
| Variable | Default | Description |
|
||||
| --------------------------- | ------- | -------------------------------- |
|
||||
| `SMART_ROUTING_ENABLED` | `true` | Enable AI-powered smart routing |
|
||||
| `SMART_ROUTING_THRESHOLD` | `0.7` | Similarity threshold for routing |
|
||||
| `SMART_ROUTING_MAX_RESULTS` | `5` | Maximum tools to return |
|
||||
| `VECTOR_CACHE_TTL` | `3600` | Vector cache TTL in seconds |
|
||||
|
||||
```env
|
||||
SMART_ROUTING_ENABLED=true
|
||||
SMART_ROUTING_THRESHOLD=0.7
|
||||
SMART_ROUTING_MAX_RESULTS=5
|
||||
VECTOR_CACHE_TTL=3600
|
||||
```
|
||||
|
||||
## File Storage & Uploads
|
||||
|
||||
| Variable | Default | Description |
|
||||
| -------------------- | ---------------- | ----------------------------------- |
|
||||
| `UPLOAD_DIR` | `./uploads` | Directory for file uploads |
|
||||
| `MAX_FILE_SIZE` | `10485760` | Maximum file size in bytes (10MB) |
|
||||
| `ALLOWED_FILE_TYPES` | `image/*,text/*` | Allowed MIME types |
|
||||
| `STORAGE_TYPE` | `local` | Storage type (`local`, `s3`, `gcs`) |
|
||||
|
||||
```env
|
||||
UPLOAD_DIR=./data/uploads
|
||||
MAX_FILE_SIZE=10485760
|
||||
ALLOWED_FILE_TYPES=image/*,text/*,application/json
|
||||
STORAGE_TYPE=local
|
||||
```
|
||||
|
||||
### S3 Storage (Optional)
|
||||
|
||||
| Variable | Default | Description |
|
||||
| ---------------------- | ----------- | ------------------ |
|
||||
| `S3_BUCKET` | - | S3 bucket name |
|
||||
| `S3_REGION` | `us-east-1` | S3 region |
|
||||
| `S3_ACCESS_KEY_ID` | - | S3 access key |
|
||||
| `S3_SECRET_ACCESS_KEY` | - | S3 secret key |
|
||||
| `S3_ENDPOINT` | - | Custom S3 endpoint |
|
||||
|
||||
```env
|
||||
S3_BUCKET=mcphub-uploads
|
||||
S3_REGION=us-east-1
|
||||
S3_ACCESS_KEY_ID=your-access-key
|
||||
S3_SECRET_ACCESS_KEY=your-secret-key
|
||||
```
|
||||
|
||||
## Monitoring & Logging
|
||||
|
||||
### Application Monitoring
|
||||
|
||||
| Variable | Default | Description |
|
||||
| ------------------------ | ------- | ----------------------------- |
|
||||
| `METRICS_ENABLED` | `true` | Enable metrics collection |
|
||||
| `METRICS_PORT` | `9090` | Port for metrics endpoint |
|
||||
| `HEALTH_CHECK_INTERVAL` | `30000` | Health check interval (ms) |
|
||||
| `PERFORMANCE_MONITORING` | `false` | Enable performance monitoring |
|
||||
|
||||
```env
|
||||
METRICS_ENABLED=true
|
||||
METRICS_PORT=9090
|
||||
HEALTH_CHECK_INTERVAL=30000
|
||||
PERFORMANCE_MONITORING=true
|
||||
```
|
||||
|
||||
### Logging Configuration
|
||||
|
||||
| Variable | Default | Description |
|
||||
| ------------------ | ------------ | --------------------------------------- |
|
||||
| `LOG_FORMAT` | `json` | Log format (`json`, `text`) |
|
||||
| `LOG_FILE` | - | Log file path (if file logging enabled) |
|
||||
| `LOG_MAX_SIZE` | `10m` | Maximum log file size |
|
||||
| `LOG_MAX_FILES` | `5` | Maximum number of log files |
|
||||
| `LOG_DATE_PATTERN` | `YYYY-MM-DD` | Date pattern for log rotation |
|
||||
|
||||
```env
|
||||
LOG_FORMAT=json
|
||||
LOG_FILE=./logs/mcphub.log
|
||||
LOG_MAX_SIZE=10m
|
||||
LOG_MAX_FILES=5
|
||||
LOG_DATE_PATTERN=YYYY-MM-DD
|
||||
```
|
||||
|
||||
## Development & Debug
|
||||
|
||||
| Variable | Default | Description |
|
||||
| ------------------------ | ------- | ----------------------------------- |
|
||||
| `DEBUG` | - | Debug namespaces (e.g., `mcphub:*`) |
|
||||
| `DEV_TOOLS_ENABLED` | `false` | Enable development tools |
|
||||
| `HOT_RELOAD` | `true` | Enable hot reload in development |
|
||||
| `MOCK_EXTERNAL_SERVICES` | `false` | Mock external API calls |
|
||||
|
||||
```env
|
||||
DEBUG=mcphub:*
|
||||
DEV_TOOLS_ENABLED=true
|
||||
HOT_RELOAD=true
|
||||
MOCK_EXTERNAL_SERVICES=false
|
||||
```
|
||||
|
||||
## Production Optimization
|
||||
|
||||
| Variable | Default | Description |
|
||||
| ------------------ | ------- | -------------------------------------- |
|
||||
| `CLUSTER_MODE` | `false` | Enable cluster mode |
|
||||
| `WORKER_PROCESSES` | `0` | Number of worker processes (0 = auto) |
|
||||
| `MEMORY_LIMIT` | - | Memory limit per process |
|
||||
| `CPU_LIMIT` | - | CPU limit per process |
|
||||
| `GC_OPTIMIZE` | `false` | Enable garbage collection optimization |
|
||||
|
||||
```env
|
||||
CLUSTER_MODE=true
|
||||
WORKER_PROCESSES=4
|
||||
MEMORY_LIMIT=512M
|
||||
GC_OPTIMIZE=true
|
||||
```
|
||||
|
||||
## Configuration Examples
|
||||
|
||||
### Development Environment
|
||||
|
||||
```env
|
||||
# .env.development
|
||||
NODE_ENV=development
|
||||
PORT=3000
|
||||
LOG_LEVEL=debug
|
||||
|
||||
# Database
|
||||
DATABASE_URL=postgresql://mcphub:password@localhost:5432/mcphub_dev
|
||||
|
||||
# Auth
|
||||
JWT_SECRET=dev-secret-key
|
||||
JWT_EXPIRES_IN=24h
|
||||
|
||||
# OpenAI (optional for development)
|
||||
# OPENAI_API_KEY=your-dev-key
|
||||
|
||||
# Debug
|
||||
DEBUG=mcphub:*
|
||||
DEV_TOOLS_ENABLED=true
|
||||
HOT_RELOAD=true
|
||||
```
|
||||
|
||||
### Production Environment
|
||||
|
||||
```env
|
||||
# .env.production
|
||||
NODE_ENV=production
|
||||
PORT=3000
|
||||
LOG_LEVEL=info
|
||||
LOG_FORMAT=json
|
||||
|
||||
# Database
|
||||
DATABASE_URL=postgresql://mcphub:secure-password@db.example.com:5432/mcphub
|
||||
DB_SSL=true
|
||||
DB_POOL_MAX=20
|
||||
|
||||
# Security
|
||||
JWT_SECRET=your-super-secure-production-secret
|
||||
SESSION_SECRET=your-session-secret
|
||||
BCRYPT_ROUNDS=14
|
||||
|
||||
# External Services
|
||||
OPENAI_API_KEY=your-production-openai-key
|
||||
REDIS_URL=redis://redis.example.com:6379
|
||||
|
||||
# Monitoring
|
||||
METRICS_ENABLED=true
|
||||
PERFORMANCE_MONITORING=true
|
||||
|
||||
# Optimization
|
||||
CLUSTER_MODE=true
|
||||
GC_OPTIMIZE=true
|
||||
```
|
||||
|
||||
### Docker Environment
|
||||
|
||||
```env
|
||||
# .env.docker
|
||||
NODE_ENV=production
|
||||
HOST=0.0.0.0
|
||||
PORT=3000
|
||||
|
||||
# Use service names for Docker networking
|
||||
DATABASE_URL=postgresql://mcphub:password@postgres:5432/mcphub
|
||||
REDIS_URL=redis://redis:6379
|
||||
|
||||
# Security
|
||||
JWT_SECRET_FILE=/run/secrets/jwt_secret
|
||||
DB_PASSWORD_FILE=/run/secrets/db_password
|
||||
|
||||
# File paths in container
|
||||
MCP_SETTINGS_FILE=/app/mcp_settings.json
|
||||
UPLOAD_DIR=/app/data/uploads
|
||||
LOG_FILE=/app/logs/mcphub.log
|
||||
```
|
||||
|
||||
## Environment Variable Loading
|
||||
|
||||
MCPHub loads environment variables in the following order:
|
||||
|
||||
1. System environment variables
|
||||
2. `.env.local` (ignored by git)
|
||||
3. `.env.{NODE_ENV}` (e.g., `.env.production`)
|
||||
4. `.env`
|
||||
|
||||
### Using dotenv-expand
|
||||
|
||||
MCPHub supports variable expansion:
|
||||
|
||||
```env
|
||||
BASE_URL=https://api.example.com
|
||||
API_ENDPOINT=${BASE_URL}/v1
|
||||
DATABASE_URL=postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
|
||||
```
|
||||
|
||||
## Security Best Practices
|
||||
|
||||
1. **Never commit secrets** to version control
|
||||
2. **Use strong, unique secrets** for production
|
||||
3. **Rotate secrets regularly**
|
||||
4. **Use environment-specific files**
|
||||
5. **Validate all environment variables** at startup
|
||||
6. **Use Docker secrets** for container deployments
|
||||
|
||||
## Validation
|
||||
|
||||
MCPHub validates environment variables at startup. Invalid configurations will prevent the application from starting with helpful error messages.
|
||||
|
||||
Required variables for production:
|
||||
|
||||
- `JWT_SECRET`
|
||||
- `DATABASE_URL` or individual DB components
|
||||
- `OPENAI_API_KEY` (if smart routing is enabled)
|
||||
|
||||
This comprehensive environment configuration ensures MCPHub can be properly configured for any deployment scenario.
|
||||
564
docs/configuration/mcp-settings.mdx
Normal file
@@ -0,0 +1,564 @@
|
||||
---
|
||||
title: 'MCP Settings Configuration'
|
||||
description: 'Configure MCP servers and their settings for MCPHub'
|
||||
---
|
||||
|
||||
# MCP Settings Configuration
|
||||
|
||||
This guide explains how to configure MCP servers in MCPHub using the `mcp_settings.json` file and related configurations.
|
||||
|
||||
## Configuration Files Overview
|
||||
|
||||
MCPHub uses several configuration files:
|
||||
|
||||
- **`mcp_settings.json`**: Main MCP server configurations
|
||||
- **`servers.json`**: Server metadata and grouping
|
||||
- **`.env`**: Environment variables and secrets
|
||||
|
||||
## Basic MCP Settings Structure
|
||||
|
||||
### mcp_settings.json
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"server-name": {
|
||||
"command": "command-to-run",
|
||||
"args": ["arg1", "arg2"],
|
||||
"env": {
|
||||
"ENV_VAR": "value"
|
||||
},
|
||||
"cwd": "/working/directory",
|
||||
"timeout": 30000,
|
||||
"restart": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Example Configuration
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"],
|
||||
"env": {
|
||||
"USER_AGENT": "MCPHub/1.0"
|
||||
}
|
||||
},
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"],
|
||||
"timeout": 60000
|
||||
},
|
||||
"slack": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-slack"],
|
||||
"env": {
|
||||
"SLACK_BOT_TOKEN": "${SLACK_BOT_TOKEN}",
|
||||
"SLACK_TEAM_ID": "${SLACK_TEAM_ID}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Server Configuration Options
|
||||
|
||||
### Required Fields
|
||||
|
||||
| Field | Type | Description |
|
||||
| --------- | ------ | -------------------------- |
|
||||
| `command` | string | Executable command or path |
|
||||
| `args` | array | Command-line arguments |
|
||||
|
||||
### Optional Fields
|
||||
|
||||
| Field | Type | Default | Description |
|
||||
| -------------- | ------- | --------------- | --------------------------- |
|
||||
| `env` | object | `{}` | Environment variables |
|
||||
| `cwd` | string | `process.cwd()` | Working directory |
|
||||
| `timeout` | number | `30000` | Startup timeout (ms) |
|
||||
| `restart` | boolean | `true` | Auto-restart on failure |
|
||||
| `maxRestarts` | number | `5` | Maximum restart attempts |
|
||||
| `restartDelay` | number | `5000` | Delay between restarts (ms) |
|
||||
| `stdio` | string | `pipe` | stdio configuration |
|
||||
|
||||
## Common MCP Server Examples
|
||||
|
||||
### Web and API Servers
|
||||
|
||||
#### Fetch Server
|
||||
|
||||
```json
|
||||
{
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"],
|
||||
"env": {
|
||||
"USER_AGENT": "MCPHub/1.0",
|
||||
"MAX_REDIRECTS": "10"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Web Scraping with Playwright
|
||||
|
||||
```json
|
||||
{
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"],
|
||||
"timeout": 60000,
|
||||
"env": {
|
||||
"PLAYWRIGHT_BROWSERS_PATH": "/tmp/browsers"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### File and System Servers
|
||||
|
||||
#### Filesystem Server
|
||||
|
||||
```json
|
||||
{
|
||||
"filesystem": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/allowed/path"],
|
||||
"env": {
|
||||
"ALLOWED_OPERATIONS": "read,write,list"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### SQLite Server
|
||||
|
||||
```json
|
||||
{
|
||||
"sqlite": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-sqlite", "--db-path", "/path/to/database.db"],
|
||||
"env": {
|
||||
"SQLITE_READONLY": "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Communication Servers
|
||||
|
||||
#### Slack Server
|
||||
|
||||
```json
|
||||
{
|
||||
"slack": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-slack"],
|
||||
"env": {
|
||||
"SLACK_BOT_TOKEN": "${SLACK_BOT_TOKEN}",
|
||||
"SLACK_TEAM_ID": "${SLACK_TEAM_ID}",
|
||||
"SLACK_APP_TOKEN": "${SLACK_APP_TOKEN}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Email Server
|
||||
|
||||
```json
|
||||
{
|
||||
"email": {
|
||||
"command": "python",
|
||||
"args": ["-m", "mcp_server_email"],
|
||||
"env": {
|
||||
"SMTP_HOST": "smtp.gmail.com",
|
||||
"SMTP_PORT": "587",
|
||||
"EMAIL_USER": "${EMAIL_USER}",
|
||||
"EMAIL_PASSWORD": "${EMAIL_PASSWORD}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Development and API Servers
|
||||
|
||||
#### GitHub Server
|
||||
|
||||
```json
|
||||
{
|
||||
"github": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-github"],
|
||||
"env": {
|
||||
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Google Drive Server
|
||||
|
||||
```json
|
||||
{
|
||||
"gdrive": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@google/mcp-server-gdrive"],
|
||||
"env": {
|
||||
"GOOGLE_CLIENT_ID": "${GOOGLE_CLIENT_ID}",
|
||||
"GOOGLE_CLIENT_SECRET": "${GOOGLE_CLIENT_SECRET}",
|
||||
"GOOGLE_REFRESH_TOKEN": "${GOOGLE_REFRESH_TOKEN}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Map and Location Services
|
||||
|
||||
#### Amap (高德地图) Server
|
||||
|
||||
```json
|
||||
{
|
||||
"amap": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@amap/amap-maps-mcp-server"],
|
||||
"env": {
|
||||
"AMAP_MAPS_API_KEY": "${AMAP_API_KEY}",
|
||||
"AMAP_LANGUAGE": "zh-cn"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### OpenStreetMap Server
|
||||
|
||||
```json
|
||||
{
|
||||
"osm": {
|
||||
"command": "python",
|
||||
"args": ["-m", "mcp_server_osm"],
|
||||
"env": {
|
||||
"OSM_USER_AGENT": "MCPHub/1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Advanced Configuration
|
||||
|
||||
### Environment Variable Substitution
|
||||
|
||||
MCPHub supports environment variable substitution using `${VAR_NAME}` syntax:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"api-server": {
|
||||
"command": "python",
|
||||
"args": ["-m", "api_server"],
|
||||
"env": {
|
||||
"API_KEY": "${API_KEY}",
|
||||
"API_URL": "${API_BASE_URL}/v1",
|
||||
"DEBUG": "${NODE_ENV:development}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Default values can be specified with `${VAR_NAME:default}`:
|
||||
|
||||
```json
|
||||
{
|
||||
"timeout": "${MCP_TIMEOUT:30000}",
|
||||
"maxRestarts": "${MCP_MAX_RESTARTS:5}"
|
||||
}
|
||||
```
|
||||
|
||||
### Conditional Configuration
|
||||
|
||||
Use different configurations based on environment:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"database": {
|
||||
"command": "python",
|
||||
"args": ["-m", "db_server"],
|
||||
"env": {
|
||||
"DB_URL": "${NODE_ENV:development == 'production' ? DATABASE_URL : DEV_DATABASE_URL}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Custom Server Scripts
|
||||
|
||||
#### Local Python Server
|
||||
|
||||
```json
|
||||
{
|
||||
"custom-python": {
|
||||
"command": "python",
|
||||
"args": ["./servers/custom_server.py"],
|
||||
"cwd": "/app/custom-servers",
|
||||
"env": {
|
||||
"PYTHONPATH": "/app/custom-servers",
|
||||
"CONFIG_FILE": "./config.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Local Node.js Server
|
||||
|
||||
```json
|
||||
{
|
||||
"custom-node": {
|
||||
"command": "node",
|
||||
"args": ["./servers/custom-server.js"],
|
||||
"cwd": "/app/custom-servers",
|
||||
"env": {
|
||||
"NODE_ENV": "production"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Server Metadata Configuration
|
||||
|
||||
### servers.json
|
||||
|
||||
Complement `mcp_settings.json` with server metadata:
|
||||
|
||||
```json
|
||||
{
|
||||
"servers": {
|
||||
"fetch": {
|
||||
"name": "Fetch Server",
|
||||
"description": "HTTP client for web requests",
|
||||
"category": "web",
|
||||
"tags": ["http", "api", "web"],
|
||||
"version": "1.0.0",
|
||||
"author": "MCPHub Team",
|
||||
"documentation": "https://docs.mcphub.com/servers/fetch",
|
||||
"enabled": true
|
||||
},
|
||||
"playwright": {
|
||||
"name": "Playwright Browser",
|
||||
"description": "Web automation and scraping",
|
||||
"category": "automation",
|
||||
"tags": ["browser", "scraping", "automation"],
|
||||
"version": "2.0.0",
|
||||
"enabled": true
|
||||
}
|
||||
},
|
||||
"groups": {
|
||||
"web-tools": {
|
||||
"name": "Web Tools",
|
||||
"description": "Tools for web interaction",
|
||||
"servers": ["fetch", "playwright"],
|
||||
"access": "public"
|
||||
},
|
||||
"admin-tools": {
|
||||
"name": "Admin Tools",
|
||||
"description": "Administrative utilities",
|
||||
"servers": ["filesystem", "database"],
|
||||
"access": "admin"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Group Management
|
||||
|
||||
### Group Configuration
|
||||
|
||||
```json
|
||||
{
|
||||
"groups": {
|
||||
"production": {
|
||||
"name": "Production Tools",
|
||||
"description": "Stable production servers",
|
||||
"servers": ["fetch", "slack", "github"],
|
||||
"access": "authenticated",
|
||||
"rateLimit": {
|
||||
"requestsPerMinute": 100,
|
||||
"burstLimit": 20
|
||||
}
|
||||
},
|
||||
"experimental": {
|
||||
"name": "Experimental Features",
|
||||
"description": "Beta and experimental servers",
|
||||
"servers": ["experimental-ai", "beta-search"],
|
||||
"access": "admin",
|
||||
"enabled": false
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Access Control
|
||||
|
||||
| Access Level | Description |
|
||||
| --------------- | -------------------------- |
|
||||
| `public` | No authentication required |
|
||||
| `authenticated` | Valid JWT token required |
|
||||
| `admin` | Admin role required |
|
||||
| `custom` | Custom permission logic |
|
||||
|
||||
## Dynamic Configuration
|
||||
|
||||
### Hot Reloading
|
||||
|
||||
MCPHub supports hot reloading of configurations:
|
||||
|
||||
```bash
|
||||
# Reload configurations without restart
|
||||
curl -X POST http://localhost:3000/api/admin/reload-config \
|
||||
-H "Authorization: Bearer your-admin-token"
|
||||
```
|
||||
|
||||
### Configuration Validation
|
||||
|
||||
MCPHub validates configurations on startup and reload:
|
||||
|
||||
```json
|
||||
{
|
||||
"validation": {
|
||||
"strict": true,
|
||||
"allowUnknownServers": false,
|
||||
"requireDocumentation": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Security
|
||||
|
||||
1. **Use environment variables** for sensitive data:
|
||||
|
||||
```json
|
||||
{
|
||||
"env": {
|
||||
"API_KEY": "${API_KEY}",
|
||||
"DATABASE_PASSWORD": "${DB_PASSWORD}"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. **Limit server permissions**:
|
||||
```json
|
||||
{
|
||||
"filesystem": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/restricted/path"],
|
||||
"env": {
|
||||
"READONLY": "true"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Performance
|
||||
|
||||
1. **Set appropriate timeouts**:
|
||||
|
||||
```json
|
||||
{
|
||||
"timeout": 30000,
|
||||
"maxRestarts": 3,
|
||||
"restartDelay": 5000
|
||||
}
|
||||
```
|
||||
|
||||
2. **Resource limits**:
|
||||
```json
|
||||
{
|
||||
"env": {
|
||||
"NODE_OPTIONS": "--max-old-space-size=512",
|
||||
"MEMORY_LIMIT": "512MB"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Monitoring
|
||||
|
||||
1. **Enable health checks**:
|
||||
|
||||
```json
|
||||
{
|
||||
"healthCheck": {
|
||||
"enabled": true,
|
||||
"interval": 30000,
|
||||
"timeout": 5000
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. **Logging configuration**:
|
||||
```json
|
||||
{
|
||||
"env": {
|
||||
"LOG_LEVEL": "info",
|
||||
"LOG_FORMAT": "json"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
**Server won't start**: Check command and arguments
|
||||
|
||||
```bash
|
||||
# Test command manually
|
||||
uvx mcp-server-fetch
|
||||
```
|
||||
|
||||
**Environment variables not found**: Verify `.env` file
|
||||
|
||||
```bash
|
||||
# Check environment
|
||||
printenv | grep API_KEY
|
||||
```
|
||||
|
||||
**Permission errors**: Check file permissions and paths
|
||||
|
||||
```bash
|
||||
# Verify executable permissions
|
||||
ls -la /path/to/server
|
||||
```
|
||||
|
||||
### Debug Configuration
|
||||
|
||||
Enable debug mode for detailed logging:
|
||||
|
||||
```json
|
||||
{
|
||||
"debug": {
|
||||
"enabled": true,
|
||||
"logLevel": "debug",
|
||||
"includeEnv": false,
|
||||
"logStartup": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Validation Errors
|
||||
|
||||
Common validation errors and solutions:
|
||||
|
||||
1. **Missing required fields**: Add `command` and `args`
|
||||
2. **Invalid timeout**: Use number, not string
|
||||
3. **Environment variable not found**: Check `.env` file
|
||||
4. **Command not found**: Verify installation and PATH
|
||||
|
||||
This comprehensive guide covers all aspects of configuring MCP servers in MCPHub for various use cases and environments.
|
||||
373
docs/configuration/nginx.mdx
Normal file
@@ -0,0 +1,373 @@
|
||||
---
|
||||
title: 'Nginx Configuration'
|
||||
description: 'Configure Nginx as a reverse proxy for MCPHub'
|
||||
---
|
||||
|
||||
# Nginx Configuration
|
||||
|
||||
This guide explains how to configure Nginx as a reverse proxy for MCPHub, including SSL termination, load balancing, and caching strategies.
|
||||
|
||||
## Basic Reverse Proxy Setup
|
||||
|
||||
### Configuration File
|
||||
|
||||
Create or update your Nginx configuration file (`/etc/nginx/sites-available/mcphub`):
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name your-domain.com;
|
||||
|
||||
# Redirect HTTP to HTTPS
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name your-domain.com;
|
||||
|
||||
# SSL Configuration
|
||||
ssl_certificate /path/to/your/certificate.crt;
|
||||
ssl_certificate_key /path/to/your/private.key;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384;
|
||||
ssl_prefer_server_ciphers off;
|
||||
|
||||
# Security Headers
|
||||
add_header X-Frame-Options DENY;
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
|
||||
# Gzip Compression
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_types
|
||||
text/plain
|
||||
text/css
|
||||
text/xml
|
||||
text/javascript
|
||||
application/json
|
||||
application/javascript
|
||||
application/xml+rss
|
||||
application/atom+xml
|
||||
image/svg+xml;
|
||||
|
||||
# Main application
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
# API endpoints with longer timeout for MCP operations
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_read_timeout 300;
|
||||
proxy_connect_timeout 60;
|
||||
proxy_send_timeout 60;
|
||||
}
|
||||
|
||||
# Static assets caching
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_cache_valid 200 1d;
|
||||
proxy_cache_valid 404 1m;
|
||||
add_header Cache-Control "public, immutable";
|
||||
expires 1y;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Enable the Configuration
|
||||
|
||||
```bash
|
||||
# Create symbolic link to enable the site
|
||||
sudo ln -s /etc/nginx/sites-available/mcphub /etc/nginx/sites-enabled/
|
||||
|
||||
# Test configuration
|
||||
sudo nginx -t
|
||||
|
||||
# Reload Nginx
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
## Load Balancing Configuration
|
||||
|
||||
For high-availability setups with multiple MCPHub instances:
|
||||
|
||||
```nginx
|
||||
upstream mcphub_backend {
|
||||
least_conn;
|
||||
server 127.0.0.1:3000 weight=1 max_fails=3 fail_timeout=30s;
|
||||
server 127.0.0.1:3001 weight=1 max_fails=3 fail_timeout=30s;
|
||||
server 127.0.0.1:3002 weight=1 max_fails=3 fail_timeout=30s;
|
||||
|
||||
# Health check (Nginx Plus feature)
|
||||
# health_check interval=5s fails=3 passes=2;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name your-domain.com;
|
||||
|
||||
# SSL and other configurations...
|
||||
|
||||
location / {
|
||||
proxy_pass http://mcphub_backend;
|
||||
# Other proxy settings...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Caching Configuration
|
||||
|
||||
### Browser Caching
|
||||
|
||||
```nginx
|
||||
# Cache static assets
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Cache API responses (be careful with dynamic content)
|
||||
location /api/public/ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_cache mcphub_cache;
|
||||
proxy_cache_valid 200 5m;
|
||||
proxy_cache_key "$scheme$request_method$host$request_uri";
|
||||
add_header X-Cache-Status $upstream_cache_status;
|
||||
}
|
||||
```
|
||||
|
||||
### Nginx Proxy Cache
|
||||
|
||||
Add to the `http` block in `nginx.conf`:
|
||||
|
||||
```nginx
|
||||
http {
|
||||
# Proxy cache configuration
|
||||
proxy_cache_path /var/cache/nginx/mcphub
|
||||
levels=1:2
|
||||
keys_zone=mcphub_cache:10m
|
||||
max_size=1g
|
||||
inactive=60m
|
||||
use_temp_path=off;
|
||||
|
||||
# Other configurations...
|
||||
}
|
||||
```
|
||||
|
||||
## WebSocket Support
|
||||
|
||||
For real-time features and SSE (Server-Sent Events):
|
||||
|
||||
```nginx
|
||||
location /api/stream {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# Disable buffering for real-time responses
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
|
||||
# Timeouts for long-lived connections
|
||||
proxy_read_timeout 24h;
|
||||
proxy_send_timeout 24h;
|
||||
}
|
||||
```
|
||||
|
||||
## Security Configuration
|
||||
|
||||
### Rate Limiting
|
||||
|
||||
```nginx
|
||||
http {
|
||||
# Define rate limiting zones
|
||||
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
|
||||
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
|
||||
|
||||
server {
|
||||
# Apply rate limiting to API endpoints
|
||||
location /api/ {
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
# Other configurations...
|
||||
}
|
||||
|
||||
# Strict rate limiting for login endpoints
|
||||
location /api/auth/login {
|
||||
limit_req zone=login burst=5;
|
||||
# Other configurations...
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### IP Whitelisting
|
||||
|
||||
```nginx
|
||||
# Allow specific IPs for admin endpoints
|
||||
location /api/admin/ {
|
||||
allow 192.168.1.0/24;
|
||||
allow 10.0.0.0/8;
|
||||
deny all;
|
||||
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
# Other proxy settings...
|
||||
}
|
||||
```
|
||||
|
||||
## Monitoring and Logging
|
||||
|
||||
### Access Logs
|
||||
|
||||
```nginx
|
||||
http {
|
||||
# Custom log format
|
||||
log_format mcphub_format '$remote_addr - $remote_user [$time_local] '
|
||||
'"$request" $status $body_bytes_sent '
|
||||
'"$http_referer" "$http_user_agent" '
|
||||
'$request_time $upstream_response_time';
|
||||
|
||||
server {
|
||||
# Enable access logging
|
||||
access_log /var/log/nginx/mcphub_access.log mcphub_format;
|
||||
error_log /var/log/nginx/mcphub_error.log;
|
||||
|
||||
# Other configurations...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Status Page
|
||||
|
||||
```nginx
|
||||
location /nginx_status {
|
||||
stub_status;
|
||||
allow 127.0.0.1;
|
||||
deny all;
|
||||
}
|
||||
```
|
||||
|
||||
## Docker Integration
|
||||
|
||||
When running MCPHub in Docker, update the proxy configuration:
|
||||
|
||||
```nginx
|
||||
upstream mcphub_docker {
|
||||
server mcphub:3000; # Docker service name
|
||||
}
|
||||
|
||||
server {
|
||||
location / {
|
||||
proxy_pass http://mcphub_docker;
|
||||
# Other proxy settings...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Complete Example Configuration
|
||||
|
||||
Here's a production-ready example using the provided `nginx.conf.example`:
|
||||
|
||||
```bash
|
||||
# Copy the example configuration
|
||||
cp nginx.conf.example /etc/nginx/sites-available/mcphub
|
||||
|
||||
# Update the configuration with your domain and paths
|
||||
sudo nano /etc/nginx/sites-available/mcphub
|
||||
|
||||
# Enable the site
|
||||
sudo ln -s /etc/nginx/sites-available/mcphub /etc/nginx/sites-enabled/
|
||||
|
||||
# Test and reload
|
||||
sudo nginx -t && sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
**502 Bad Gateway**: Check if MCPHub is running and accessible
|
||||
|
||||
**504 Gateway Timeout**: Increase `proxy_read_timeout` for long-running operations
|
||||
|
||||
**WebSocket connection failures**: Ensure proper `Upgrade` and `Connection` headers
|
||||
|
||||
**Cache issues**: Clear proxy cache or disable for development
|
||||
|
||||
### Debug Commands
|
||||
|
||||
```bash
|
||||
# Test Nginx configuration
|
||||
sudo nginx -t
|
||||
|
||||
# Check Nginx status
|
||||
sudo systemctl status nginx
|
||||
|
||||
# View error logs
|
||||
sudo tail -f /var/log/nginx/error.log
|
||||
|
||||
# Check if MCPHub is responding
|
||||
curl -I http://localhost:3000
|
||||
```
|
||||
|
||||
## Performance Optimization
|
||||
|
||||
### Worker Processes
|
||||
|
||||
```nginx
|
||||
# In nginx.conf
|
||||
worker_processes auto;
|
||||
worker_connections 1024;
|
||||
```
|
||||
|
||||
### Buffer Sizes
|
||||
|
||||
```nginx
|
||||
proxy_buffering on;
|
||||
proxy_buffer_size 128k;
|
||||
proxy_buffers 4 256k;
|
||||
proxy_busy_buffers_size 256k;
|
||||
```
|
||||
|
||||
### Keep-Alive
|
||||
|
||||
```nginx
|
||||
upstream mcphub_backend {
|
||||
server 127.0.0.1:3000;
|
||||
keepalive 32;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://mcphub_backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
}
|
||||
```
|
||||
|
||||
This configuration provides a solid foundation for running MCPHub behind Nginx with proper security, performance, and reliability features.
|
||||
107
docs/development.mdx
Normal file
@@ -0,0 +1,107 @@
|
||||
---
|
||||
title: 'Development'
|
||||
description: 'Preview changes locally to update your docs'
|
||||
---
|
||||
|
||||
<Info>
|
||||
**Prerequisite**: Please install Node.js (version 19 or higher) before proceeding. <br />
|
||||
Please upgrade to ```docs.json``` before proceeding and delete the legacy ```mint.json``` file.
|
||||
</Info>
|
||||
|
||||
Follow these steps to install and run Mintlify on your operating system:
|
||||
|
||||
**Step 1**: Install Mintlify:
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash npm
|
||||
npm i -g mintlify
|
||||
```
|
||||
|
||||
```bash yarn
|
||||
yarn global add mintlify
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
**Step 2**: Navigate to the docs directory (where the `docs.json` file is located) and execute the following command:
|
||||
|
||||
```bash
|
||||
mintlify dev
|
||||
```
|
||||
|
||||
A local preview of your documentation will be available at `http://localhost:3000`.
|
||||
|
||||
### Custom Ports
|
||||
|
||||
By default, Mintlify uses port 3000. You can customize the port Mintlify runs on by using the `--port` flag. To run Mintlify on port 3333, for instance, use this command:
|
||||
|
||||
```bash
|
||||
mintlify dev --port 3333
|
||||
```
|
||||
|
||||
If you attempt to run Mintlify on a port that's already in use, it will use the next available port:
|
||||
|
||||
```md
|
||||
Port 3000 is already in use. Trying 3001 instead.
|
||||
```
|
||||
|
||||
## Mintlify Versions
|
||||
|
||||
Please note that each CLI release is associated with a specific version of Mintlify. If your local website doesn't align with the production version, please update the CLI:
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash npm
|
||||
npm i -g mintlify@latest
|
||||
```
|
||||
|
||||
```bash yarn
|
||||
yarn global upgrade mintlify
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
## Validating Links
|
||||
|
||||
The CLI can assist with validating reference links made in your documentation. To identify any broken links, use the following command:
|
||||
|
||||
```bash
|
||||
mintlify broken-links
|
||||
```
|
||||
|
||||
## Deployment
|
||||
|
||||
<Tip>
|
||||
Unlimited editors available under the [Pro
|
||||
Plan](https://mintlify.com/pricing) and above.
|
||||
</Tip>
|
||||
|
||||
If the deployment is successful, you should see the following:
|
||||
|
||||
<Frame>
|
||||
<img src="/images/checks-passed.png" style={{ borderRadius: '0.5rem' }} />
|
||||
</Frame>
|
||||
|
||||
## Code Formatting
|
||||
|
||||
We suggest using extensions on your IDE to recognize and format MDX. If you're a VSCode user, consider the [MDX VSCode extension](https://marketplace.visualstudio.com/items?itemName=unifiedjs.vscode-mdx) for syntax highlighting, and [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) for code formatting.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title='Error: Could not load the "sharp" module using the darwin-arm64 runtime'>
|
||||
|
||||
This may be due to an outdated version of node. Try the following:
|
||||
1. Remove the currently-installed version of mintlify: `npm remove -g mintlify`
|
||||
2. Upgrade to Node v19 or higher.
|
||||
3. Reinstall mintlify: `npm install -g mintlify`
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Issue: Encountering an unknown error">
|
||||
|
||||
Solution: Go to the root of your device and delete the \~/.mintlify folder. Afterwards, run `mintlify dev` again.
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
Curious about what changed in the CLI version? [Check out the CLI changelog.](https://www.npmjs.com/package/mintlify?activeTab=versions)
|
||||
724
docs/development/architecture.mdx
Normal file
@@ -0,0 +1,724 @@
|
||||
---
|
||||
title: 'Architecture Overview'
|
||||
description: "Understand MCPHub's system architecture and design principles"
|
||||
---
|
||||
|
||||
## System Overview
|
||||
|
||||
MCPHub is designed as a scalable, modular platform for managing Model Context Protocol (MCP) servers. The architecture follows modern web application patterns with clear separation of concerns, microservices-ready design, and extensibility in mind.
|
||||
|
||||
## High-Level Architecture
|
||||
|
||||
```mermaid
|
||||
graph TB
|
||||
subgraph "Client Layer"
|
||||
WEB[Web Dashboard]
|
||||
API[External APIs]
|
||||
CLI[CLI Tools]
|
||||
end
|
||||
|
||||
subgraph "Application Layer"
|
||||
LB[Load Balancer/Nginx]
|
||||
APP[MCPHub Server]
|
||||
WS[WebSocket Server]
|
||||
end
|
||||
|
||||
subgraph "Service Layer"
|
||||
MCP[MCP Service]
|
||||
AUTH[Auth Service]
|
||||
ROUTE[Smart Routing]
|
||||
MON[Monitoring Service]
|
||||
end
|
||||
|
||||
subgraph "Data Layer"
|
||||
PG[(PostgreSQL)]
|
||||
REDIS[(Redis)]
|
||||
VECTOR[(Vector Store)]
|
||||
end
|
||||
|
||||
subgraph "MCP Servers"
|
||||
GITHUB[GitHub MCP]
|
||||
FS[Filesystem MCP]
|
||||
DB[Database MCP]
|
||||
CUSTOM[Custom MCP]
|
||||
end
|
||||
|
||||
WEB --> LB
|
||||
API --> LB
|
||||
CLI --> LB
|
||||
LB --> APP
|
||||
APP --> WS
|
||||
APP --> MCP
|
||||
APP --> AUTH
|
||||
APP --> ROUTE
|
||||
APP --> MON
|
||||
|
||||
MCP --> GITHUB
|
||||
MCP --> FS
|
||||
MCP --> DB
|
||||
MCP --> CUSTOM
|
||||
|
||||
AUTH --> PG
|
||||
AUTH --> REDIS
|
||||
ROUTE --> VECTOR
|
||||
MON --> PG
|
||||
MON --> REDIS
|
||||
```
|
||||
|
||||
## Core Components
|
||||
|
||||
### 1. Application Server
|
||||
|
||||
The main Node.js/Express application that handles all HTTP requests and coordinates between services.
|
||||
|
||||
```typescript
|
||||
// src/server.ts - Main application entry point
|
||||
class MCPHubServer {
|
||||
private app: Express;
|
||||
private httpServer: Server;
|
||||
private wsServer: WebSocketServer;
|
||||
|
||||
async start(): Promise<void> {
|
||||
await this.initializeDatabase();
|
||||
await this.initializeServices();
|
||||
await this.setupRoutes();
|
||||
await this.startServer();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Key Responsibilities:**
|
||||
|
||||
- HTTP request handling
|
||||
- WebSocket connections for real-time features
|
||||
- Service coordination
|
||||
- Middleware chain management
|
||||
- Error handling and logging
|
||||
|
||||
### 2. MCP Service Layer
|
||||
|
||||
Manages the lifecycle and communication with MCP servers.
|
||||
|
||||
```typescript
|
||||
// src/services/mcpService.ts
|
||||
class MCPService {
|
||||
private servers: Map<string, MCPServerInstance> = new Map();
|
||||
private processManager: ProcessManager;
|
||||
|
||||
async startServer(config: MCPServerConfig): Promise<void> {
|
||||
const instance = await this.processManager.spawn(config);
|
||||
this.servers.set(config.name, instance);
|
||||
await this.waitForHealthy(instance);
|
||||
}
|
||||
|
||||
async executeRequest(serverName: string, request: MCPRequest): Promise<MCPResponse> {
|
||||
const server = this.servers.get(serverName);
|
||||
return await server.sendRequest(request);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Key Features:**
|
||||
|
||||
- Process lifecycle management
|
||||
- Health monitoring
|
||||
- Request routing
|
||||
- Error recovery
|
||||
- Resource management
|
||||
|
||||
### 3. Smart Routing Engine
|
||||
|
||||
Provides AI-powered tool discovery and routing using vector embeddings.
|
||||
|
||||
```typescript
|
||||
// src/services/smartRouting.ts
|
||||
class SmartRoutingService {
|
||||
private vectorStore: VectorStore;
|
||||
private embeddingService: EmbeddingService;
|
||||
|
||||
async findRelevantTools(query: string): Promise<ToolMatch[]> {
|
||||
const queryEmbedding = await this.embeddingService.embed(query);
|
||||
const matches = await this.vectorStore.similaritySearch(queryEmbedding);
|
||||
return this.rankResults(matches, query);
|
||||
}
|
||||
|
||||
async indexTool(tool: ToolDefinition): Promise<void> {
|
||||
const embedding = await this.embeddingService.embed(tool.description);
|
||||
await this.vectorStore.upsert(tool.id, embedding, tool);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Components:**
|
||||
|
||||
- Vector embedding generation
|
||||
- Similarity search
|
||||
- Result ranking and filtering
|
||||
- Tool metadata management
|
||||
|
||||
### 4. Authentication & Authorization
|
||||
|
||||
Handles user authentication, session management, and access control.
|
||||
|
||||
```typescript
|
||||
// src/services/authService.ts
|
||||
class AuthService {
|
||||
async authenticate(credentials: Credentials): Promise<User> {
|
||||
const user = await this.validateCredentials(credentials);
|
||||
const token = await this.generateJWT(user);
|
||||
await this.createSession(user, token);
|
||||
return user;
|
||||
}
|
||||
|
||||
async authorize(user: User, resource: string, action: string): Promise<boolean> {
|
||||
const permissions = await this.getUserPermissions(user);
|
||||
return this.checkPermission(permissions, resource, action);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Features:**
|
||||
|
||||
- JWT-based authentication
|
||||
- Role-based access control (RBAC)
|
||||
- Session management
|
||||
- API key authentication
|
||||
- Group-based permissions
|
||||
|
||||
### 5. Monitoring & Logging
|
||||
|
||||
Provides comprehensive monitoring, metrics collection, and logging.
|
||||
|
||||
```typescript
|
||||
// src/services/monitoringService.ts
|
||||
class MonitoringService {
|
||||
private metricsCollector: MetricsCollector;
|
||||
private alertManager: AlertManager;
|
||||
|
||||
async collectMetrics(): Promise<void> {
|
||||
const systemMetrics = await this.getSystemMetrics();
|
||||
const serverMetrics = await this.getMCPServerMetrics();
|
||||
await this.metricsCollector.record(systemMetrics, serverMetrics);
|
||||
await this.checkAlerts(systemMetrics, serverMetrics);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Capabilities:**
|
||||
|
||||
- Real-time metrics collection
|
||||
- Performance monitoring
|
||||
- Error tracking
|
||||
- Alert management
|
||||
- Audit logging
|
||||
|
||||
## Data Architecture
|
||||
|
||||
### Database Schema
|
||||
|
||||
```sql
|
||||
-- Core entities
|
||||
CREATE TABLE users (
|
||||
id UUID PRIMARY KEY,
|
||||
username VARCHAR UNIQUE NOT NULL,
|
||||
email VARCHAR UNIQUE NOT NULL,
|
||||
password_hash VARCHAR NOT NULL,
|
||||
role VARCHAR NOT NULL DEFAULT 'user',
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE servers (
|
||||
id UUID PRIMARY KEY,
|
||||
name VARCHAR UNIQUE NOT NULL,
|
||||
command VARCHAR NOT NULL,
|
||||
args JSONB NOT NULL DEFAULT '[]',
|
||||
env JSONB DEFAULT '{}',
|
||||
group_name VARCHAR,
|
||||
status VARCHAR DEFAULT 'stopped',
|
||||
config JSONB DEFAULT '{}',
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
updated_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE groups (
|
||||
id UUID PRIMARY KEY,
|
||||
name VARCHAR UNIQUE NOT NULL,
|
||||
description TEXT,
|
||||
config JSONB DEFAULT '{}',
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Vector search for smart routing
|
||||
CREATE TABLE tool_embeddings (
|
||||
id UUID PRIMARY KEY,
|
||||
server_name VARCHAR NOT NULL,
|
||||
tool_name VARCHAR NOT NULL,
|
||||
description TEXT,
|
||||
embedding vector(1536),
|
||||
metadata JSONB DEFAULT '{}',
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
updated_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Monitoring and logging
|
||||
CREATE TABLE request_logs (
|
||||
id UUID PRIMARY KEY,
|
||||
user_id UUID REFERENCES users(id),
|
||||
server_name VARCHAR NOT NULL,
|
||||
tool_name VARCHAR,
|
||||
request_data JSONB,
|
||||
response_data JSONB,
|
||||
status VARCHAR NOT NULL,
|
||||
duration_ms INTEGER,
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
```
|
||||
|
||||
### Caching Strategy
|
||||
|
||||
```typescript
|
||||
// src/services/cacheService.ts
|
||||
class CacheService {
|
||||
// Multi-layer caching strategy
|
||||
private memoryCache: Map<string, CacheEntry> = new Map();
|
||||
private redisCache: Redis;
|
||||
|
||||
async get<T>(key: string): Promise<T | null> {
|
||||
// L1: Memory cache
|
||||
const memoryEntry = this.memoryCache.get(key);
|
||||
if (memoryEntry && !this.isExpired(memoryEntry)) {
|
||||
return memoryEntry.value;
|
||||
}
|
||||
|
||||
// L2: Redis cache
|
||||
const redisValue = await this.redisCache.get(key);
|
||||
if (redisValue) {
|
||||
const value = JSON.parse(redisValue);
|
||||
this.memoryCache.set(key, { value, expiry: Date.now() + 60000 });
|
||||
return value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Cache Layers:**
|
||||
|
||||
- **L1 (Memory)**: Fast access for frequently used data
|
||||
- **L2 (Redis)**: Shared cache across instances
|
||||
- **L3 (Database)**: Persistent storage with query optimization
|
||||
|
||||
## Communication Patterns
|
||||
|
||||
### Request Flow
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant Client
|
||||
participant API
|
||||
participant Auth
|
||||
participant Router
|
||||
participant MCP
|
||||
participant Server
|
||||
|
||||
Client->>API: HTTP Request
|
||||
API->>Auth: Validate Token
|
||||
Auth-->>API: User Context
|
||||
API->>Router: Route Request
|
||||
Router->>Router: Find Target Server
|
||||
Router->>MCP: Execute Request
|
||||
MCP->>Server: MCP Protocol
|
||||
Server-->>MCP: MCP Response
|
||||
MCP-->>Router: Formatted Response
|
||||
Router-->>API: Response Data
|
||||
API-->>Client: HTTP Response
|
||||
```
|
||||
|
||||
### WebSocket Communication
|
||||
|
||||
```typescript
|
||||
// src/services/websocketService.ts
|
||||
class WebSocketService {
|
||||
private connections: Map<string, WebSocket> = new Map();
|
||||
|
||||
handleConnection(ws: WebSocket, userId: string): void {
|
||||
this.connections.set(userId, ws);
|
||||
|
||||
ws.on('message', async (data) => {
|
||||
const message = JSON.parse(data.toString());
|
||||
await this.handleMessage(userId, message);
|
||||
});
|
||||
|
||||
ws.on('close', () => {
|
||||
this.connections.delete(userId);
|
||||
});
|
||||
}
|
||||
|
||||
broadcast(event: string, data: any): void {
|
||||
this.connections.forEach((ws) => {
|
||||
ws.send(JSON.stringify({ event, data }));
|
||||
});
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Event-Driven Architecture
|
||||
|
||||
```typescript
|
||||
// src/events/eventBus.ts
|
||||
class EventBus {
|
||||
private listeners: Map<string, EventListener[]> = new Map();
|
||||
|
||||
emit(event: string, data: any): void {
|
||||
const handlers = this.listeners.get(event) || [];
|
||||
handlers.forEach((handler) => handler(data));
|
||||
}
|
||||
|
||||
on(event: string, handler: EventListener): void {
|
||||
const handlers = this.listeners.get(event) || [];
|
||||
handlers.push(handler);
|
||||
this.listeners.set(event, handlers);
|
||||
}
|
||||
}
|
||||
|
||||
// Usage
|
||||
eventBus.on('server.started', (data) => {
|
||||
logger.info(`Server ${data.name} started`);
|
||||
monitoringService.updateServerStatus(data.name, 'running');
|
||||
});
|
||||
```
|
||||
|
||||
## Security Architecture
|
||||
|
||||
### Authentication Flow
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
A[Client] --> B[Login Request]
|
||||
B --> C[Validate Credentials]
|
||||
C --> D[Generate JWT]
|
||||
D --> E[Create Session]
|
||||
E --> F[Return Token]
|
||||
F --> G[Store in Cookie/Header]
|
||||
G --> H[Subsequent Requests]
|
||||
H --> I[Validate Token]
|
||||
I --> J[Check Permissions]
|
||||
J --> K[Allow/Deny Access]
|
||||
```
|
||||
|
||||
### Authorization Model
|
||||
|
||||
```typescript
|
||||
// Role-Based Access Control (RBAC)
|
||||
interface Permission {
|
||||
resource: string; // e.g., 'servers', 'groups', 'users'
|
||||
action: string; // e.g., 'create', 'read', 'update', 'delete'
|
||||
scope?: string; // e.g., 'own', 'group', 'all'
|
||||
}
|
||||
|
||||
interface Role {
|
||||
name: string;
|
||||
permissions: Permission[];
|
||||
}
|
||||
|
||||
const roles: Role[] = [
|
||||
{
|
||||
name: 'admin',
|
||||
permissions: [{ resource: '*', action: '*', scope: 'all' }],
|
||||
},
|
||||
{
|
||||
name: 'manager',
|
||||
permissions: [
|
||||
{ resource: 'servers', action: '*', scope: 'group' },
|
||||
{ resource: 'groups', action: 'read', scope: 'all' },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'user',
|
||||
permissions: [
|
||||
{ resource: 'servers', action: 'read', scope: 'group' },
|
||||
{ resource: 'tools', action: 'execute', scope: 'group' },
|
||||
],
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
## Scalability Considerations
|
||||
|
||||
### Horizontal Scaling
|
||||
|
||||
```yaml
|
||||
# Kubernetes deployment for scaling
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mcphub
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mcphub
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: mcphub
|
||||
image: mcphub:latest
|
||||
resources:
|
||||
requests:
|
||||
memory: '256Mi'
|
||||
cpu: '200m'
|
||||
limits:
|
||||
memory: '512Mi'
|
||||
cpu: '500m'
|
||||
```
|
||||
|
||||
### Load Balancing Strategy
|
||||
|
||||
```typescript
|
||||
// src/services/loadBalancer.ts
|
||||
class LoadBalancer {
|
||||
private servers: ServerInstance[] = [];
|
||||
private algorithm: 'round-robin' | 'least-connections' | 'weighted';
|
||||
|
||||
selectServer(): ServerInstance {
|
||||
switch (this.algorithm) {
|
||||
case 'round-robin':
|
||||
return this.roundRobin();
|
||||
case 'least-connections':
|
||||
return this.leastConnections();
|
||||
case 'weighted':
|
||||
return this.weighted();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Database Scaling
|
||||
|
||||
```typescript
|
||||
// Database connection management
|
||||
class DatabaseManager {
|
||||
private readPool: Pool; // Read replicas
|
||||
private writePool: Pool; // Primary database
|
||||
|
||||
async query(sql: string, params: any[]): Promise<any> {
|
||||
if (this.isReadOperation(sql)) {
|
||||
return this.readPool.query(sql, params);
|
||||
} else {
|
||||
return this.writePool.query(sql, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Performance Optimization
|
||||
|
||||
### Query Optimization
|
||||
|
||||
```sql
|
||||
-- Optimized queries with proper indexing
|
||||
CREATE INDEX CONCURRENTLY idx_servers_status_group
|
||||
ON servers(status, group_name)
|
||||
WHERE status IN ('running', 'starting');
|
||||
|
||||
CREATE INDEX CONCURRENTLY idx_tool_embeddings_similarity
|
||||
ON tool_embeddings USING ivfflat (embedding vector_cosine_ops)
|
||||
WITH (lists = 100);
|
||||
|
||||
CREATE INDEX CONCURRENTLY idx_request_logs_performance
|
||||
ON request_logs(created_at, status, duration_ms)
|
||||
WHERE created_at > NOW() - INTERVAL '30 days';
|
||||
```
|
||||
|
||||
### Caching Strategy
|
||||
|
||||
```typescript
|
||||
// Multi-level caching
|
||||
class CacheManager {
|
||||
// Cache server configurations
|
||||
@Cache({ ttl: 300, key: 'server-config' })
|
||||
async getServerConfig(name: string): Promise<ServerConfig> {
|
||||
return this.database.getServerConfig(name);
|
||||
}
|
||||
|
||||
// Cache tool metadata for smart routing
|
||||
@Cache({ ttl: 3600, key: 'tool-metadata' })
|
||||
async getToolMetadata(): Promise<ToolMetadata[]> {
|
||||
return this.database.getToolMetadata();
|
||||
}
|
||||
|
||||
// Cache user permissions
|
||||
@Cache({ ttl: 600, key: 'user-permissions' })
|
||||
async getUserPermissions(userId: string): Promise<Permission[]> {
|
||||
return this.authService.getUserPermissions(userId);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Monitoring & Observability
|
||||
|
||||
### Metrics Collection
|
||||
|
||||
```typescript
|
||||
// src/services/metricsService.ts
|
||||
class MetricsService {
|
||||
private prometheus: PrometheusRegistry;
|
||||
|
||||
constructor() {
|
||||
this.initializeMetrics();
|
||||
}
|
||||
|
||||
private initializeMetrics(): void {
|
||||
// Request metrics
|
||||
this.requestCount = new Counter({
|
||||
name: 'mcphub_requests_total',
|
||||
help: 'Total number of requests',
|
||||
labelNames: ['method', 'route', 'status'],
|
||||
});
|
||||
|
||||
// Server metrics
|
||||
this.serverStatus = new Gauge({
|
||||
name: 'mcphub_server_status',
|
||||
help: 'Status of MCP servers',
|
||||
labelNames: ['server_name', 'status'],
|
||||
});
|
||||
|
||||
// Performance metrics
|
||||
this.responseTime = new Histogram({
|
||||
name: 'mcphub_response_time_seconds',
|
||||
help: 'Response time in seconds',
|
||||
labelNames: ['route'],
|
||||
});
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Distributed Tracing
|
||||
|
||||
```typescript
|
||||
// OpenTelemetry integration
|
||||
import { trace } from '@opentelemetry/api';
|
||||
|
||||
class MCPService {
|
||||
async executeRequest(serverName: string, request: MCPRequest): Promise<MCPResponse> {
|
||||
const span = trace.getActiveSpan();
|
||||
span?.setAttributes({
|
||||
'mcp.server': serverName,
|
||||
'mcp.tool': request.tool,
|
||||
'mcp.request_id': request.id,
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await this.sendRequest(serverName, request);
|
||||
span?.setStatus({ code: SpanStatusCode.OK });
|
||||
return response;
|
||||
} catch (error) {
|
||||
span?.setStatus({
|
||||
code: SpanStatusCode.ERROR,
|
||||
message: error.message,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Extension Points
|
||||
|
||||
### Plugin Architecture
|
||||
|
||||
```typescript
|
||||
// Plugin interface
|
||||
interface MCPHubPlugin {
|
||||
name: string;
|
||||
version: string;
|
||||
init(context: PluginContext): Promise<void>;
|
||||
destroy(): Promise<void>;
|
||||
}
|
||||
|
||||
// Plugin manager
|
||||
class PluginManager {
|
||||
private plugins: Map<string, MCPHubPlugin> = new Map();
|
||||
|
||||
async loadPlugin(plugin: MCPHubPlugin): Promise<void> {
|
||||
await plugin.init(this.createContext());
|
||||
this.plugins.set(plugin.name, plugin);
|
||||
}
|
||||
|
||||
private createContext(): PluginContext {
|
||||
return {
|
||||
eventBus: this.eventBus,
|
||||
logger: this.logger,
|
||||
database: this.database,
|
||||
// ... other services
|
||||
};
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Custom Middleware
|
||||
|
||||
```typescript
|
||||
// Custom middleware registration
|
||||
class MiddlewareManager {
|
||||
register(middleware: Middleware): void {
|
||||
this.app.use(middleware);
|
||||
}
|
||||
|
||||
registerRoute(path: string, middleware: Middleware): void {
|
||||
this.app.use(path, middleware);
|
||||
}
|
||||
}
|
||||
|
||||
// Example custom middleware
|
||||
const customAuthMiddleware: Middleware = (req, res, next) => {
|
||||
// Custom authentication logic
|
||||
next();
|
||||
};
|
||||
```
|
||||
|
||||
## Deployment Architecture
|
||||
|
||||
### Container Strategy
|
||||
|
||||
```dockerfile
|
||||
# Multi-stage build for optimized images
|
||||
FROM node:18-alpine AS builder
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm ci --only=production
|
||||
|
||||
FROM node:18-alpine AS runtime
|
||||
RUN addgroup -g 1001 -S nodejs
|
||||
RUN adduser -S mcphub -u 1001
|
||||
WORKDIR /app
|
||||
COPY --from=builder --chown=mcphub:nodejs /app .
|
||||
USER mcphub
|
||||
EXPOSE 3000
|
||||
CMD ["node", "dist/server.js"]
|
||||
```
|
||||
|
||||
### Infrastructure as Code
|
||||
|
||||
```terraform
|
||||
# Terraform configuration for AWS deployment
|
||||
resource "aws_ecs_cluster" "mcphub" {
|
||||
name = "mcphub-cluster"
|
||||
}
|
||||
|
||||
resource "aws_ecs_service" "mcphub" {
|
||||
name = "mcphub"
|
||||
cluster = aws_ecs_cluster.mcphub.id
|
||||
task_definition = aws_ecs_task_definition.mcphub.arn
|
||||
desired_count = 3
|
||||
|
||||
load_balancer {
|
||||
target_group_arn = aws_lb_target_group.mcphub.arn
|
||||
container_name = "mcphub"
|
||||
container_port = 3000
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This architecture provides a solid foundation for building a scalable, maintainable, and extensible MCP server management platform while following modern software development best practices.
|
||||
597
docs/development/contributing.mdx
Normal file
@@ -0,0 +1,597 @@
|
||||
---
|
||||
title: 'Contributing to MCPHub'
|
||||
description: 'Learn how to contribute to the MCPHub project'
|
||||
---
|
||||
|
||||
## Welcome Contributors! 🎉
|
||||
|
||||
Thank you for your interest in contributing to MCPHub! This guide will help you get started with contributing to the project, whether you're fixing bugs, adding features, improving documentation, or helping with testing.
|
||||
|
||||
## Quick Start
|
||||
|
||||
1. **Fork the repository** on GitHub
|
||||
2. **Clone your fork** locally
|
||||
3. **Create a branch** for your changes
|
||||
4. **Make your changes** following our guidelines
|
||||
5. **Test your changes** thoroughly
|
||||
6. **Submit a pull request**
|
||||
|
||||
## Ways to Contribute
|
||||
|
||||
### 🐛 Bug Reports
|
||||
|
||||
Help us improve MCPHub by reporting bugs:
|
||||
|
||||
- **Search existing issues** first to avoid duplicates
|
||||
- **Use the bug report template** when creating issues
|
||||
- **Provide detailed information** including steps to reproduce
|
||||
- **Include system information** (OS, Node.js version, etc.)
|
||||
|
||||
```markdown
|
||||
## Bug Report Template
|
||||
|
||||
**Description**
|
||||
A clear description of what the bug is.
|
||||
|
||||
**Steps to Reproduce**
|
||||
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected Behavior**
|
||||
What you expected to happen.
|
||||
|
||||
**Actual Behavior**
|
||||
What actually happened.
|
||||
|
||||
**Environment**
|
||||
|
||||
- OS: [e.g. macOS 12.0]
|
||||
- Node.js: [e.g. 18.17.0]
|
||||
- MCPHub Version: [e.g. 1.2.3]
|
||||
- Browser: [e.g. Chrome 91.0]
|
||||
|
||||
**Additional Context**
|
||||
Any other context about the problem.
|
||||
```
|
||||
|
||||
### ✨ Feature Requests
|
||||
|
||||
We welcome feature suggestions:
|
||||
|
||||
- **Check existing feature requests** to avoid duplicates
|
||||
- **Use the feature request template**
|
||||
- **Explain the use case** and why it would be valuable
|
||||
- **Consider implementation complexity**
|
||||
|
||||
### 🔧 Code Contributions
|
||||
|
||||
Ready to write some code? Here's how:
|
||||
|
||||
#### Setting Up Development Environment
|
||||
|
||||
```bash
|
||||
# 1. Fork and clone the repository
|
||||
git clone https://github.com/YOUR_USERNAME/mcphub.git
|
||||
cd mcphub
|
||||
|
||||
# 2. Add upstream remote
|
||||
git remote add upstream https://github.com/mcphub/mcphub.git
|
||||
|
||||
# 3. Install dependencies
|
||||
pnpm install
|
||||
|
||||
# 4. Set up environment
|
||||
cp .env.example .env.development
|
||||
|
||||
# 5. Start development environment
|
||||
docker-compose -f docker-compose.dev.yml up -d
|
||||
pnpm run migrate
|
||||
pnpm run seed
|
||||
|
||||
# 6. Start development server
|
||||
pnpm run dev
|
||||
```
|
||||
|
||||
#### Branch Naming Convention
|
||||
|
||||
Use descriptive branch names with prefixes:
|
||||
|
||||
```bash
|
||||
# Features
|
||||
git checkout -b feature/smart-routing-improvements
|
||||
git checkout -b feature/user-authentication
|
||||
|
||||
# Bug fixes
|
||||
git checkout -b fix/server-startup-error
|
||||
git checkout -b fix/memory-leak-in-cache
|
||||
|
||||
# Documentation
|
||||
git checkout -b docs/api-reference-update
|
||||
git checkout -b docs/deployment-guide
|
||||
|
||||
# Refactoring
|
||||
git checkout -b refactor/auth-service-cleanup
|
||||
git checkout -b refactor/database-queries
|
||||
```
|
||||
|
||||
### 📚 Documentation
|
||||
|
||||
Help improve our documentation:
|
||||
|
||||
- **Fix typos and grammar**
|
||||
- **Improve existing guides**
|
||||
- **Add missing documentation**
|
||||
- **Create tutorials and examples**
|
||||
- **Translate documentation**
|
||||
|
||||
## Development Guidelines
|
||||
|
||||
### Code Style
|
||||
|
||||
We use ESLint and Prettier to maintain code quality:
|
||||
|
||||
```bash
|
||||
# Check code style
|
||||
pnpm run lint
|
||||
|
||||
# Fix automatically fixable issues
|
||||
pnpm run lint:fix
|
||||
|
||||
# Format code
|
||||
pnpm run format
|
||||
|
||||
# Type check
|
||||
pnpm run type-check
|
||||
```
|
||||
|
||||
#### TypeScript Best Practices
|
||||
|
||||
```typescript
|
||||
// ✅ Good: Use proper types
|
||||
interface MCPServerConfig {
|
||||
name: string;
|
||||
command: string;
|
||||
args: string[];
|
||||
env?: Record<string, string>;
|
||||
}
|
||||
|
||||
// ✅ Good: Use async/await
|
||||
async function startServer(config: MCPServerConfig): Promise<void> {
|
||||
try {
|
||||
await mcpService.start(config);
|
||||
} catch (error) {
|
||||
logger.error('Failed to start server', { error, config });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// ❌ Bad: Using any type
|
||||
function processData(data: any): any {
|
||||
return data.something();
|
||||
}
|
||||
|
||||
// ❌ Bad: Not handling errors
|
||||
async function riskyOperation(): Promise<void> {
|
||||
await dangerousFunction(); // Could throw
|
||||
}
|
||||
```
|
||||
|
||||
#### React/Frontend Guidelines
|
||||
|
||||
```tsx
|
||||
// ✅ Good: Functional components with proper typing
|
||||
interface ServerCardProps {
|
||||
server: MCPServer;
|
||||
onStart: (serverId: string) => void;
|
||||
onStop: (serverId: string) => void;
|
||||
}
|
||||
|
||||
const ServerCard: React.FC<ServerCardProps> = ({ server, onStart, onStop }) => {
|
||||
const handleStart = useCallback(() => {
|
||||
onStart(server.id);
|
||||
}, [server.id, onStart]);
|
||||
|
||||
return (
|
||||
<Card data-testid={`server-card-${server.id}`}>
|
||||
<CardHeader>
|
||||
<CardTitle>{server.name}</CardTitle>
|
||||
<Badge variant={server.status === 'running' ? 'success' : 'secondary'}>
|
||||
{server.status}
|
||||
</Badge>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p>{server.description}</p>
|
||||
</CardContent>
|
||||
<CardActions>
|
||||
{server.status === 'stopped' ? (
|
||||
<Button onClick={handleStart}>Start</Button>
|
||||
) : (
|
||||
<Button onClick={() => onStop(server.id)}>Stop</Button>
|
||||
)}
|
||||
</CardActions>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
### Testing Requirements
|
||||
|
||||
All contributions must include appropriate tests:
|
||||
|
||||
#### Unit Tests
|
||||
|
||||
```typescript
|
||||
// src/services/__tests__/mcpService.test.ts
|
||||
import { MCPService } from '../mcpService';
|
||||
import { mockLogger, mockDatabase } from '../../__mocks__';
|
||||
|
||||
describe('MCPService', () => {
|
||||
let service: MCPService;
|
||||
|
||||
beforeEach(() => {
|
||||
service = new MCPService(mockLogger, mockDatabase);
|
||||
});
|
||||
|
||||
describe('startServer', () => {
|
||||
it('should start a server successfully', async () => {
|
||||
const config = {
|
||||
name: 'test-server',
|
||||
command: 'node',
|
||||
args: ['server.js'],
|
||||
};
|
||||
|
||||
await service.startServer(config);
|
||||
|
||||
expect(service.getServerStatus('test-server')).toBe('running');
|
||||
});
|
||||
|
||||
it('should handle server startup failures', async () => {
|
||||
const invalidConfig = {
|
||||
name: 'invalid-server',
|
||||
command: 'invalid-command',
|
||||
args: [],
|
||||
};
|
||||
|
||||
await expect(service.startServer(invalidConfig)).rejects.toThrow(
|
||||
'Failed to start server: Command not found',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
#### Integration Tests
|
||||
|
||||
```typescript
|
||||
// src/__tests__/integration/server-api.test.ts
|
||||
import request from 'supertest';
|
||||
import { app } from '../../app';
|
||||
import { setupTestDatabase, teardownTestDatabase } from '../helpers/database';
|
||||
|
||||
describe('Server API Integration', () => {
|
||||
beforeAll(async () => {
|
||||
await setupTestDatabase();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await teardownTestDatabase();
|
||||
});
|
||||
|
||||
describe('POST /api/servers', () => {
|
||||
it('should create a new server', async () => {
|
||||
const serverData = {
|
||||
name: 'test-server',
|
||||
command: 'node',
|
||||
args: ['server.js'],
|
||||
group: 'development',
|
||||
};
|
||||
|
||||
const response = await request(app).post('/api/servers').send(serverData).expect(201);
|
||||
|
||||
expect(response.body).toMatchObject({
|
||||
name: 'test-server',
|
||||
status: 'stopped',
|
||||
group: 'development',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
#### End-to-End Tests
|
||||
|
||||
```typescript
|
||||
// tests/e2e/server-management.spec.ts
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('Server Management', () => {
|
||||
test('should create and manage MCP servers', async ({ page }) => {
|
||||
await page.goto('/dashboard');
|
||||
|
||||
// Create new server
|
||||
await page.click('[data-testid="add-server-button"]');
|
||||
await page.fill('[data-testid="server-name-input"]', 'test-server');
|
||||
await page.fill('[data-testid="server-command-input"]', 'node server.js');
|
||||
await page.click('[data-testid="save-server-button"]');
|
||||
|
||||
// Verify server appears in list
|
||||
await expect(page.locator('[data-testid="server-list"]')).toContainText('test-server');
|
||||
|
||||
// Start the server
|
||||
await page.click('[data-testid="start-server-test-server"]');
|
||||
|
||||
// Verify server is running
|
||||
await expect(page.locator('[data-testid="server-status-test-server"]')).toContainText(
|
||||
'running',
|
||||
);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### Commit Guidelines
|
||||
|
||||
We follow [Conventional Commits](https://www.conventionalcommits.org/):
|
||||
|
||||
```bash
|
||||
# Format: <type>[optional scope]: <description>
|
||||
|
||||
# Features
|
||||
git commit -m "feat(auth): add JWT token refresh functionality"
|
||||
git commit -m "feat(ui): implement server status dashboard"
|
||||
|
||||
# Bug fixes
|
||||
git commit -m "fix(api): resolve memory leak in server manager"
|
||||
git commit -m "fix(db): handle connection timeout gracefully"
|
||||
|
||||
# Documentation
|
||||
git commit -m "docs(api): add examples for server endpoints"
|
||||
git commit -m "docs(readme): update installation instructions"
|
||||
|
||||
# Refactoring
|
||||
git commit -m "refactor(services): extract auth logic into separate module"
|
||||
|
||||
# Tests
|
||||
git commit -m "test(api): add integration tests for server management"
|
||||
|
||||
# Chores
|
||||
git commit -m "chore(deps): update dependencies to latest versions"
|
||||
```
|
||||
|
||||
#### Commit Types
|
||||
|
||||
- **feat**: New feature
|
||||
- **fix**: Bug fix
|
||||
- **docs**: Documentation changes
|
||||
- **style**: Code style changes (formatting, etc.)
|
||||
- **refactor**: Code refactoring
|
||||
- **test**: Adding or updating tests
|
||||
- **chore**: Maintenance tasks
|
||||
- **perf**: Performance improvements
|
||||
- **ci**: CI/CD changes
|
||||
|
||||
### Pull Request Process
|
||||
|
||||
#### Before Submitting
|
||||
|
||||
```bash
|
||||
# 1. Sync with upstream
|
||||
git fetch upstream
|
||||
git checkout main
|
||||
git merge upstream/main
|
||||
|
||||
# 2. Rebase your feature branch
|
||||
git checkout feature/your-feature
|
||||
git rebase main
|
||||
|
||||
# 3. Run all checks
|
||||
pnpm run lint
|
||||
pnpm run type-check
|
||||
pnpm run test
|
||||
pnpm run build
|
||||
|
||||
# 4. Update documentation if needed
|
||||
# 5. Add/update tests for your changes
|
||||
```
|
||||
|
||||
#### Pull Request Template
|
||||
|
||||
```markdown
|
||||
## Description
|
||||
|
||||
Brief description of the changes and motivation.
|
||||
|
||||
## Type of Change
|
||||
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
||||
- [ ] Documentation update
|
||||
|
||||
## Testing
|
||||
|
||||
- [ ] Unit tests pass
|
||||
- [ ] Integration tests pass
|
||||
- [ ] E2E tests pass (if applicable)
|
||||
- [ ] Manual testing completed
|
||||
|
||||
## Documentation
|
||||
|
||||
- [ ] Code is self-documenting
|
||||
- [ ] API documentation updated
|
||||
- [ ] User documentation updated
|
||||
- [ ] README updated (if needed)
|
||||
|
||||
## Checklist
|
||||
|
||||
- [ ] My code follows the project's style guidelines
|
||||
- [ ] I have performed a self-review of my code
|
||||
- [ ] I have commented my code, particularly in hard-to-understand areas
|
||||
- [ ] I have made corresponding changes to the documentation
|
||||
- [ ] My changes generate no new warnings
|
||||
- [ ] I have added tests that prove my fix is effective or that my feature works
|
||||
- [ ] New and existing unit tests pass locally with my changes
|
||||
|
||||
## Screenshots (if applicable)
|
||||
|
||||
Add screenshots to help explain your changes.
|
||||
|
||||
## Additional Notes
|
||||
|
||||
Any additional information that reviewers should know.
|
||||
```
|
||||
|
||||
### Code Review Process
|
||||
|
||||
#### For Contributors
|
||||
|
||||
- **Be patient**: Reviews take time, and reviewers may have questions
|
||||
- **Be responsive**: Address feedback promptly and clearly
|
||||
- **Be open**: Accept constructive criticism and suggestions
|
||||
- **Ask questions**: If feedback is unclear, ask for clarification
|
||||
|
||||
#### For Reviewers
|
||||
|
||||
- **Be constructive**: Provide helpful suggestions, not just criticism
|
||||
- **Be specific**: Point out exact issues and suggest solutions
|
||||
- **Be timely**: Review PRs within a reasonable timeframe
|
||||
- **Be encouraging**: Recognize good work and improvements
|
||||
|
||||
## Community Guidelines
|
||||
|
||||
### Code of Conduct
|
||||
|
||||
We are committed to providing a welcoming and inspiring community for all:
|
||||
|
||||
- **Be respectful**: Treat everyone with respect and kindness
|
||||
- **Be inclusive**: Welcome people of all backgrounds and skill levels
|
||||
- **Be collaborative**: Work together towards common goals
|
||||
- **Be patient**: Help others learn and grow
|
||||
- **Be professional**: Maintain professional communication
|
||||
|
||||
### Communication Channels
|
||||
|
||||
- **GitHub Issues**: Bug reports and feature requests
|
||||
- **GitHub Discussions**: General questions and community chat
|
||||
- **Discord**: Real-time community chat (link in README)
|
||||
- **Email**: Security issues and private matters
|
||||
|
||||
## Getting Help
|
||||
|
||||
### Documentation
|
||||
|
||||
- [Getting Started Guide](./getting-started.mdx)
|
||||
- [Architecture Overview](./architecture.mdx)
|
||||
- [API Reference](../api-reference/introduction.mdx)
|
||||
- [Configuration Guide](../configuration/mcp-settings.mdx)
|
||||
|
||||
### Common Issues
|
||||
|
||||
**Build Failures**
|
||||
|
||||
```bash
|
||||
# Clear and reinstall dependencies
|
||||
rm -rf node_modules pnpm-lock.yaml
|
||||
pnpm install
|
||||
|
||||
# Clear build cache
|
||||
rm -rf dist/
|
||||
pnpm run build
|
||||
```
|
||||
|
||||
**Test Failures**
|
||||
|
||||
```bash
|
||||
# Run tests with verbose output
|
||||
pnpm run test -- --verbose
|
||||
|
||||
# Run specific test file
|
||||
pnpm test src/services/mcpService.test.ts
|
||||
|
||||
# Debug tests
|
||||
pnpm run test:debug
|
||||
```
|
||||
|
||||
**Database Issues**
|
||||
|
||||
```bash
|
||||
# Reset database
|
||||
pnpm run db:reset
|
||||
|
||||
# Run migrations
|
||||
pnpm run migrate
|
||||
|
||||
# Seed development data
|
||||
pnpm run seed
|
||||
```
|
||||
|
||||
### Getting Support
|
||||
|
||||
If you need help:
|
||||
|
||||
1. **Check the documentation** first
|
||||
2. **Search existing issues** on GitHub
|
||||
3. **Ask in GitHub Discussions** for general questions
|
||||
4. **Create an issue** if you found a bug
|
||||
5. **Join our Discord** for real-time help
|
||||
|
||||
## Recognition
|
||||
|
||||
Contributors will be recognized in several ways:
|
||||
|
||||
- **Contributors file**: All contributors are listed in CONTRIBUTORS.md
|
||||
- **Release notes**: Significant contributions are mentioned in release notes
|
||||
- **GitHub badges**: Active contributors receive special recognition
|
||||
- **Community showcase**: Outstanding contributions are featured in our blog
|
||||
|
||||
## Advanced Topics
|
||||
|
||||
### Maintainer Guidelines
|
||||
|
||||
For project maintainers:
|
||||
|
||||
#### Release Process
|
||||
|
||||
```bash
|
||||
# 1. Create release branch
|
||||
git checkout -b release/v1.2.0
|
||||
|
||||
# 2. Update version
|
||||
npm version 1.2.0 --no-git-tag-version
|
||||
|
||||
# 3. Update changelog
|
||||
# Edit CHANGELOG.md
|
||||
|
||||
# 4. Commit changes
|
||||
git add .
|
||||
git commit -m "chore(release): prepare v1.2.0"
|
||||
|
||||
# 5. Create PR for review
|
||||
# 6. After merge, tag release
|
||||
git tag v1.2.0
|
||||
git push origin v1.2.0
|
||||
```
|
||||
|
||||
#### Security Handling
|
||||
|
||||
For security issues:
|
||||
|
||||
1. **Do not** create public issues
|
||||
2. **Email** security@mcphub.dev
|
||||
3. **Wait** for response before disclosure
|
||||
4. **Coordinate** with maintainers on fixes
|
||||
|
||||
### Architectural Decisions
|
||||
|
||||
When making significant changes:
|
||||
|
||||
1. **Create an RFC** (Request for Comments) issue
|
||||
2. **Discuss** with the community
|
||||
3. **Get approval** from maintainers
|
||||
4. **Document** decisions in ADR (Architecture Decision Records)
|
||||
|
||||
## Thank You! 🙏
|
||||
|
||||
Thank you for taking the time to contribute to MCPHub! Every contribution, no matter how small, helps make the project better for everyone. We look forward to collaborating with you!
|
||||
244
docs/development/getting-started.mdx
Normal file
@@ -0,0 +1,244 @@
|
||||
---
|
||||
title: 'Getting Started with Development'
|
||||
description: 'Learn how to set up your development environment for MCPHub'
|
||||
---
|
||||
|
||||
# Getting Started with Development
|
||||
|
||||
This guide will help you set up your development environment for contributing to MCPHub.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before you begin, ensure you have the following installed:
|
||||
|
||||
- **Node.js** (version 18 or higher)
|
||||
- **pnpm** (recommended package manager)
|
||||
- **Git**
|
||||
- **Docker** (optional, for containerized development)
|
||||
|
||||
## Setting Up the Development Environment
|
||||
|
||||
### 1. Clone the Repository
|
||||
|
||||
```bash
|
||||
git clone https://github.com/your-username/mcphub.git
|
||||
cd mcphub
|
||||
```
|
||||
|
||||
### 2. Install Dependencies
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
```
|
||||
|
||||
### 3. Environment Configuration
|
||||
|
||||
Create a `.env` file in the root directory:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
Configure the following environment variables:
|
||||
|
||||
```env
|
||||
# Server Configuration
|
||||
PORT=3000
|
||||
NODE_ENV=development
|
||||
|
||||
# Database Configuration
|
||||
DATABASE_URL=postgresql://username:password@localhost:5432/mcphub
|
||||
|
||||
# JWT Configuration
|
||||
JWT_SECRET=your-secret-key
|
||||
JWT_EXPIRES_IN=24h
|
||||
|
||||
# OpenAI Configuration (for smart routing)
|
||||
OPENAI_API_KEY=your-openai-api-key
|
||||
```
|
||||
|
||||
### 4. Database Setup
|
||||
|
||||
If using PostgreSQL, create a database:
|
||||
|
||||
```bash
|
||||
createdb mcphub
|
||||
```
|
||||
|
||||
### 5. MCP Server Configuration
|
||||
|
||||
Create or modify `mcp_settings.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"]
|
||||
},
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Development Workflow
|
||||
|
||||
### Running the Development Server
|
||||
|
||||
Start both backend and frontend in development mode:
|
||||
|
||||
```bash
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
This will start:
|
||||
|
||||
- Backend server on `http://localhost:3000`
|
||||
- Frontend development server on `http://localhost:5173`
|
||||
|
||||
### Running Backend Only
|
||||
|
||||
```bash
|
||||
pnpm backend:dev
|
||||
```
|
||||
|
||||
### Running Frontend Only
|
||||
|
||||
```bash
|
||||
pnpm frontend:dev
|
||||
```
|
||||
|
||||
### Building the Project
|
||||
|
||||
Build both backend and frontend:
|
||||
|
||||
```bash
|
||||
pnpm build
|
||||
```
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
mcphub/
|
||||
├── src/ # Backend source code
|
||||
│ ├── controllers/ # Express controllers
|
||||
│ ├── routes/ # API routes
|
||||
│ ├── services/ # Business logic
|
||||
│ ├── models/ # Database models
|
||||
│ └── utils/ # Utility functions
|
||||
├── frontend/ # Frontend React application
|
||||
│ ├── src/
|
||||
│ │ ├── components/ # React components
|
||||
│ │ ├── pages/ # Page components
|
||||
│ │ ├── services/ # API services
|
||||
│ │ └── utils/ # Frontend utilities
|
||||
├── docs/ # Documentation
|
||||
├── bin/ # CLI scripts
|
||||
└── scripts/ # Build and utility scripts
|
||||
```
|
||||
|
||||
## Development Tools
|
||||
|
||||
### Linting and Formatting
|
||||
|
||||
```bash
|
||||
# Run ESLint
|
||||
pnpm lint
|
||||
|
||||
# Format code with Prettier
|
||||
pnpm format
|
||||
```
|
||||
|
||||
### Testing
|
||||
|
||||
```bash
|
||||
# Run tests
|
||||
pnpm test
|
||||
|
||||
# Run tests in watch mode
|
||||
pnpm test --watch
|
||||
```
|
||||
|
||||
### Debugging
|
||||
|
||||
To debug the backend with Node.js inspector:
|
||||
|
||||
```bash
|
||||
pnpm backend:debug
|
||||
```
|
||||
|
||||
Then attach your debugger to `http://localhost:9229`.
|
||||
|
||||
## Making Changes
|
||||
|
||||
### Backend Development
|
||||
|
||||
1. **Controllers**: Handle HTTP requests and responses
|
||||
2. **Services**: Implement business logic
|
||||
3. **Models**: Define database schemas
|
||||
4. **Routes**: Define API endpoints
|
||||
|
||||
### Frontend Development
|
||||
|
||||
1. **Components**: Reusable React components
|
||||
2. **Pages**: Route-specific components
|
||||
3. **Services**: API communication
|
||||
4. **Hooks**: Custom React hooks
|
||||
|
||||
### Adding New MCP Servers
|
||||
|
||||
1. Update `mcp_settings.json` with the new server configuration
|
||||
2. Test the server integration
|
||||
3. Update documentation if needed
|
||||
|
||||
## Common Development Tasks
|
||||
|
||||
### Adding a New API Endpoint
|
||||
|
||||
1. Create a controller in `src/controllers/`
|
||||
2. Define the route in `src/routes/`
|
||||
3. Add any necessary middleware
|
||||
4. Write tests for the new endpoint
|
||||
|
||||
### Adding a New Frontend Feature
|
||||
|
||||
1. Create components in `frontend/src/components/`
|
||||
2. Add routes if needed
|
||||
3. Implement API integration
|
||||
4. Style with Tailwind CSS
|
||||
|
||||
### Database Migrations
|
||||
|
||||
When modifying database schemas:
|
||||
|
||||
1. Update models in `src/models/`
|
||||
2. Create migration scripts if using TypeORM
|
||||
3. Test migrations locally
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
**Port conflicts**: Ensure ports 3000 and 5173 are available
|
||||
|
||||
**Database connection**: Verify PostgreSQL is running and credentials are correct
|
||||
|
||||
**MCP server startup**: Check server configurations in `mcp_settings.json`
|
||||
|
||||
**Permission issues**: Ensure MCP servers have necessary permissions
|
||||
|
||||
### Getting Help
|
||||
|
||||
- Check the [Contributing Guide](/development/contributing)
|
||||
- Review [Architecture Documentation](/development/architecture)
|
||||
- Open an issue on GitHub for bugs
|
||||
- Join our community discussions
|
||||
|
||||
## Next Steps
|
||||
|
||||
- Read the [Architecture Overview](/development/architecture)
|
||||
- Learn about [Contributing Guidelines](/development/contributing)
|
||||
- Explore [Configuration Options](/configuration/environment-variables)
|
||||
162
docs/docs.json
Normal file
@@ -0,0 +1,162 @@
|
||||
{
|
||||
"$schema": "https://mintlify.com/docs.json",
|
||||
"theme": "mint",
|
||||
"name": "MCPHub Documentation",
|
||||
"description": "The Unified Hub for Model Context Protocol (MCP) Servers",
|
||||
"colors": {
|
||||
"primary": "#16A34A",
|
||||
"light": "#07C983",
|
||||
"dark": "#15803D"
|
||||
},
|
||||
"favicon": "/favicon.ico",
|
||||
"navigation": {
|
||||
"tabs": [
|
||||
{
|
||||
"tab": "English",
|
||||
"groups": [
|
||||
{
|
||||
"group": "Get Started",
|
||||
"pages": [
|
||||
"index",
|
||||
"quickstart",
|
||||
"installation"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "Core Features",
|
||||
"pages": [
|
||||
"features/server-management",
|
||||
"features/group-management",
|
||||
"features/smart-routing",
|
||||
"features/authentication",
|
||||
"features/monitoring"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "Configuration",
|
||||
"pages": [
|
||||
"configuration/mcp-settings",
|
||||
"configuration/environment-variables",
|
||||
"configuration/docker-setup",
|
||||
"configuration/nginx"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "Development",
|
||||
"pages": [
|
||||
"development/getting-started",
|
||||
"development/architecture",
|
||||
"development/contributing"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tab": "中文",
|
||||
"groups": [
|
||||
{
|
||||
"group": "开始使用",
|
||||
"pages": [
|
||||
"zh/index",
|
||||
"zh/quickstart",
|
||||
"zh/installation"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "核心功能",
|
||||
"pages": [
|
||||
"zh/features/server-management",
|
||||
"zh/features/group-management",
|
||||
"zh/features/smart-routing",
|
||||
"zh/features/authentication",
|
||||
"zh/features/monitoring"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "配置指南",
|
||||
"pages": [
|
||||
"zh/configuration/mcp-settings",
|
||||
"zh/configuration/environment-variables",
|
||||
"zh/configuration/docker-setup",
|
||||
"zh/configuration/nginx"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "开发指南",
|
||||
"pages": [
|
||||
"zh/development/getting-started",
|
||||
"zh/development/architecture",
|
||||
"zh/development/contributing"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tab": "API Reference",
|
||||
"groups": [
|
||||
{
|
||||
"group": "MCP Endpoints",
|
||||
"pages": [
|
||||
"api-reference/introduction",
|
||||
"api-reference/mcp-http",
|
||||
"api-reference/mcp-sse",
|
||||
"api-reference/smart-routing"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "Management API",
|
||||
"pages": [
|
||||
"api-reference/servers",
|
||||
"api-reference/groups",
|
||||
"api-reference/auth",
|
||||
"api-reference/logs",
|
||||
"api-reference/config"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"global": {
|
||||
"anchors": [
|
||||
{
|
||||
"anchor": "GitHub",
|
||||
"href": "https://github.com/samanhappy/mcphub",
|
||||
"icon": "github"
|
||||
},
|
||||
{
|
||||
"anchor": "Discord",
|
||||
"href": "https://discord.gg/qMKNsn5Q",
|
||||
"icon": "discord"
|
||||
},
|
||||
{
|
||||
"anchor": "Sponsor",
|
||||
"href": "https://ko-fi.com/samanhappy",
|
||||
"icon": "heart"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"logo": {
|
||||
"light": "/logo/light.svg",
|
||||
"dark": "/logo/dark.svg"
|
||||
},
|
||||
"navbar": {
|
||||
"links": [
|
||||
{
|
||||
"label": "Demo",
|
||||
"href": "http://localhost:3000"
|
||||
}
|
||||
],
|
||||
"primary": {
|
||||
"type": "button",
|
||||
"label": "Get Started",
|
||||
"href": "https://docs.hubmcp.dev/quickstart"
|
||||
}
|
||||
},
|
||||
"footer": {
|
||||
"socials": {
|
||||
"github": "https://github.com/samanhappy/mcphub",
|
||||
"discord": "https://discord.gg/qMKNsn5Q"
|
||||
}
|
||||
}
|
||||
}
|
||||
37
docs/essentials/code.mdx
Normal file
@@ -0,0 +1,37 @@
|
||||
---
|
||||
title: 'Code Blocks'
|
||||
description: 'Display inline code and code blocks'
|
||||
icon: 'code'
|
||||
---
|
||||
|
||||
## Basic
|
||||
|
||||
### Inline Code
|
||||
|
||||
To denote a `word` or `phrase` as code, enclose it in backticks (`).
|
||||
|
||||
```
|
||||
To denote a `word` or `phrase` as code, enclose it in backticks (`).
|
||||
```
|
||||
|
||||
### Code Block
|
||||
|
||||
Use [fenced code blocks](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks) by enclosing code in three backticks and follow the leading ticks with the programming language of your snippet to get syntax highlighting. Optionally, you can also write the name of your code after the programming language.
|
||||
|
||||
```java HelloWorld.java
|
||||
class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
````md
|
||||
```java HelloWorld.java
|
||||
class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
||||
```
|
||||
````
|
||||
59
docs/essentials/images.mdx
Normal file
@@ -0,0 +1,59 @@
|
||||
---
|
||||
title: 'Images and Embeds'
|
||||
description: 'Add image, video, and other HTML elements'
|
||||
icon: 'image'
|
||||
---
|
||||
|
||||
<img
|
||||
style={{ borderRadius: '0.5rem' }}
|
||||
src="https://mintlify-assets.b-cdn.net/bigbend.jpg"
|
||||
/>
|
||||
|
||||
## Image
|
||||
|
||||
### Using Markdown
|
||||
|
||||
The [markdown syntax](https://www.markdownguide.org/basic-syntax/#images) lets you add images using the following code
|
||||
|
||||
```md
|
||||

|
||||
```
|
||||
|
||||
Note that the image file size must be less than 5MB. Otherwise, we recommend hosting on a service like [Cloudinary](https://cloudinary.com/) or [S3](https://aws.amazon.com/s3/). You can then use that URL and embed.
|
||||
|
||||
### Using Embeds
|
||||
|
||||
To get more customizability with images, you can also use [embeds](/writing-content/embed) to add images
|
||||
|
||||
```html
|
||||
<img height="200" src="/path/image.jpg" />
|
||||
```
|
||||
|
||||
## Embeds and HTML elements
|
||||
|
||||
<iframe
|
||||
width="560"
|
||||
height="315"
|
||||
src="https://www.youtube.com/embed/4KzFe50RQkQ"
|
||||
title="YouTube video player"
|
||||
frameBorder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowFullScreen
|
||||
style={{ width: '100%', borderRadius: '0.5rem' }}
|
||||
></iframe>
|
||||
|
||||
<br />
|
||||
|
||||
<Tip>
|
||||
|
||||
Mintlify supports [HTML tags in Markdown](https://www.markdownguide.org/basic-syntax/#html). This is helpful if you prefer HTML tags to Markdown syntax, and lets you create documentation with infinite flexibility.
|
||||
|
||||
</Tip>
|
||||
|
||||
### iFrames
|
||||
|
||||
Loads another HTML page within the document. Most commonly used for embedding videos.
|
||||
|
||||
```html
|
||||
<iframe src="https://www.youtube.com/embed/4KzFe50RQkQ"> </iframe>
|
||||
```
|
||||
88
docs/essentials/markdown.mdx
Normal file
@@ -0,0 +1,88 @@
|
||||
---
|
||||
title: 'Markdown Syntax'
|
||||
description: 'Text, title, and styling in standard markdown'
|
||||
icon: 'text-size'
|
||||
---
|
||||
|
||||
## Titles
|
||||
|
||||
Best used for section headers.
|
||||
|
||||
```md
|
||||
## Titles
|
||||
```
|
||||
|
||||
### Subtitles
|
||||
|
||||
Best use to subsection headers.
|
||||
|
||||
```md
|
||||
### Subtitles
|
||||
```
|
||||
|
||||
<Tip>
|
||||
|
||||
Each **title** and **subtitle** creates an anchor and also shows up on the table of contents on the right.
|
||||
|
||||
</Tip>
|
||||
|
||||
## Text Formatting
|
||||
|
||||
We support most markdown formatting. Simply add `**`, `_`, or `~` around text to format it.
|
||||
|
||||
| Style | How to write it | Result |
|
||||
| ------------- | ----------------- | --------------- |
|
||||
| Bold | `**bold**` | **bold** |
|
||||
| Italic | `_italic_` | _italic_ |
|
||||
| Strikethrough | `~strikethrough~` | ~strikethrough~ |
|
||||
|
||||
You can combine these. For example, write `**_bold and italic_**` to get **_bold and italic_** text.
|
||||
|
||||
You need to use HTML to write superscript and subscript text. That is, add `<sup>` or `<sub>` around your text.
|
||||
|
||||
| Text Size | How to write it | Result |
|
||||
| ----------- | ------------------------ | ---------------------- |
|
||||
| Superscript | `<sup>superscript</sup>` | <sup>superscript</sup> |
|
||||
| Subscript | `<sub>subscript</sub>` | <sub>subscript</sub> |
|
||||
|
||||
## Linking to Pages
|
||||
|
||||
You can add a link by wrapping text in `[]()`. You would write `[link to google](https://google.com)` to [link to google](https://google.com).
|
||||
|
||||
Links to pages in your docs need to be root-relative. Basically, you should include the entire folder path. For example, `[link to text](/writing-content/text)` links to the page "Text" in our components section.
|
||||
|
||||
Relative links like `[link to text](../text)` will open slower because we cannot optimize them as easily.
|
||||
|
||||
## Blockquotes
|
||||
|
||||
### Singleline
|
||||
|
||||
To create a blockquote, add a `>` in front of a paragraph.
|
||||
|
||||
> Dorothy followed her through many of the beautiful rooms in her castle.
|
||||
|
||||
```md
|
||||
> Dorothy followed her through many of the beautiful rooms in her castle.
|
||||
```
|
||||
|
||||
### Multiline
|
||||
|
||||
> Dorothy followed her through many of the beautiful rooms in her castle.
|
||||
>
|
||||
> The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.
|
||||
|
||||
```md
|
||||
> Dorothy followed her through many of the beautiful rooms in her castle.
|
||||
>
|
||||
> The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.
|
||||
```
|
||||
|
||||
### LaTeX
|
||||
|
||||
Mintlify supports [LaTeX](https://www.latex-project.org) through the Latex component.
|
||||
|
||||
<Latex>8 x (vk x H1 - H2) = (0,1)</Latex>
|
||||
|
||||
```md
|
||||
<Latex>8 x (vk x H1 - H2) = (0,1)</Latex>
|
||||
```
|
||||
87
docs/essentials/navigation.mdx
Normal file
@@ -0,0 +1,87 @@
|
||||
---
|
||||
title: 'Navigation'
|
||||
description: 'The navigation field in docs.json defines the pages that go in the navigation menu'
|
||||
icon: 'map'
|
||||
---
|
||||
|
||||
The navigation menu is the list of links on every website.
|
||||
|
||||
You will likely update `docs.json` every time you add a new page. Pages do not show up automatically.
|
||||
|
||||
## Navigation syntax
|
||||
|
||||
Our navigation syntax is recursive which means you can make nested navigation groups. You don't need to include `.mdx` in page names.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```json Regular Navigation
|
||||
"navigation": {
|
||||
"tabs": [
|
||||
{
|
||||
"tab": "Docs",
|
||||
"groups": [
|
||||
{
|
||||
"group": "Getting Started",
|
||||
"pages": ["quickstart"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
```json Nested Navigation
|
||||
"navigation": {
|
||||
"tabs": [
|
||||
{
|
||||
"tab": "Docs",
|
||||
"groups": [
|
||||
{
|
||||
"group": "Getting Started",
|
||||
"pages": [
|
||||
"quickstart",
|
||||
{
|
||||
"group": "Nested Reference Pages",
|
||||
"pages": ["nested-reference-page"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
## Folders
|
||||
|
||||
Simply put your MDX files in folders and update the paths in `docs.json`.
|
||||
|
||||
For example, to have a page at `https://yoursite.com/your-folder/your-page` you would make a folder called `your-folder` containing an MDX file called `your-page.mdx`.
|
||||
|
||||
<Warning>
|
||||
|
||||
You cannot use `api` for the name of a folder unless you nest it inside another folder. Mintlify uses Next.js which reserves the top-level `api` folder for internal server calls. A folder name such as `api-reference` would be accepted.
|
||||
|
||||
</Warning>
|
||||
|
||||
```json Navigation With Folder
|
||||
"navigation": {
|
||||
"tabs": [
|
||||
{
|
||||
"tab": "Docs",
|
||||
"groups": [
|
||||
{
|
||||
"group": "Group Name",
|
||||
"pages": ["your-folder/your-page"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Hidden Pages
|
||||
|
||||
MDX files not included in `docs.json` will not show up in the sidebar but are accessible through the search bar and by linking directly to them.
|
||||
110
docs/essentials/reusable-snippets.mdx
Normal file
@@ -0,0 +1,110 @@
|
||||
---
|
||||
title: Reusable Snippets
|
||||
description: Reusable, custom snippets to keep content in sync
|
||||
icon: 'recycle'
|
||||
---
|
||||
|
||||
import SnippetIntro from '/snippets/snippet-intro.mdx';
|
||||
|
||||
<SnippetIntro />
|
||||
|
||||
## Creating a custom snippet
|
||||
|
||||
**Pre-condition**: You must create your snippet file in the `snippets` directory.
|
||||
|
||||
<Note>
|
||||
Any page in the `snippets` directory will be treated as a snippet and will not
|
||||
be rendered into a standalone page. If you want to create a standalone page
|
||||
from the snippet, import the snippet into another file and call it as a
|
||||
component.
|
||||
</Note>
|
||||
|
||||
### Default export
|
||||
|
||||
1. Add content to your snippet file that you want to re-use across multiple
|
||||
locations. Optionally, you can add variables that can be filled in via props
|
||||
when you import the snippet.
|
||||
|
||||
```mdx snippets/my-snippet.mdx
|
||||
Hello world! This is my content I want to reuse across pages. My keyword of the
|
||||
day is {word}.
|
||||
```
|
||||
|
||||
<Warning>
|
||||
The content that you want to reuse must be inside the `snippets` directory in
|
||||
order for the import to work.
|
||||
</Warning>
|
||||
|
||||
2. Import the snippet into your destination file.
|
||||
|
||||
```mdx destination-file.mdx
|
||||
---
|
||||
title: My title
|
||||
description: My Description
|
||||
---
|
||||
|
||||
import MySnippet from '/snippets/path/to/my-snippet.mdx';
|
||||
|
||||
## Header
|
||||
|
||||
Lorem impsum dolor sit amet.
|
||||
|
||||
<MySnippet word="bananas" />
|
||||
```
|
||||
|
||||
### Reusable variables
|
||||
|
||||
1. Export a variable from your snippet file:
|
||||
|
||||
```mdx snippets/path/to/custom-variables.mdx
|
||||
export const myName = 'my name';
|
||||
|
||||
export const myObject = { fruit: 'strawberries' };
|
||||
```
|
||||
|
||||
2. Import the snippet from your destination file and use the variable:
|
||||
|
||||
```mdx destination-file.mdx
|
||||
---
|
||||
title: My title
|
||||
description: My Description
|
||||
---
|
||||
|
||||
import { myName, myObject } from '/snippets/path/to/custom-variables.mdx';
|
||||
|
||||
Hello, my name is {myName} and I like {myObject.fruit}.
|
||||
```
|
||||
|
||||
### Reusable components
|
||||
|
||||
1. Inside your snippet file, create a component that takes in props by exporting
|
||||
your component in the form of an arrow function.
|
||||
|
||||
```mdx snippets/custom-component.mdx
|
||||
export const MyComponent = ({ title }) => (
|
||||
<div>
|
||||
<h1>{title}</h1>
|
||||
<p>... snippet content ...</p>
|
||||
</div>
|
||||
);
|
||||
```
|
||||
|
||||
<Warning>
|
||||
MDX does not compile inside the body of an arrow function. Stick to HTML
|
||||
syntax when you can or use a default export if you need to use MDX.
|
||||
</Warning>
|
||||
|
||||
2. Import the snippet into your destination file and pass in the props
|
||||
|
||||
```mdx destination-file.mdx
|
||||
---
|
||||
title: My title
|
||||
description: My Description
|
||||
---
|
||||
|
||||
import { MyComponent } from '/snippets/custom-component.mdx';
|
||||
|
||||
Lorem ipsum dolor sit amet.
|
||||
|
||||
<MyComponent title={'Custom title'} />
|
||||
```
|
||||
318
docs/essentials/settings.mdx
Normal file
@@ -0,0 +1,318 @@
|
||||
---
|
||||
title: 'Global Settings'
|
||||
description: 'Mintlify gives you complete control over the look and feel of your documentation using the docs.json file'
|
||||
icon: 'gear'
|
||||
---
|
||||
|
||||
Every Mintlify site needs a `docs.json` file with the core configuration settings. Learn more about the [properties](#properties) below.
|
||||
|
||||
## Properties
|
||||
|
||||
<ResponseField name="name" type="string" required>
|
||||
Name of your project. Used for the global title.
|
||||
|
||||
Example: `mintlify`
|
||||
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="navigation" type="Navigation[]" required>
|
||||
An array of groups with all the pages within that group
|
||||
<Expandable title="Navigation">
|
||||
<ResponseField name="group" type="string">
|
||||
The name of the group.
|
||||
|
||||
Example: `Settings`
|
||||
|
||||
</ResponseField>
|
||||
<ResponseField name="pages" type="string[]">
|
||||
The relative paths to the markdown files that will serve as pages.
|
||||
|
||||
Example: `["customization", "page"]`
|
||||
|
||||
</ResponseField>
|
||||
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="logo" type="string or object">
|
||||
Path to logo image or object with path to "light" and "dark" mode logo images
|
||||
<Expandable title="Logo">
|
||||
<ResponseField name="light" type="string">
|
||||
Path to the logo in light mode
|
||||
</ResponseField>
|
||||
<ResponseField name="dark" type="string">
|
||||
Path to the logo in dark mode
|
||||
</ResponseField>
|
||||
<ResponseField name="href" type="string" default="/">
|
||||
Where clicking on the logo links you to
|
||||
</ResponseField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="favicon" type="string">
|
||||
Path to the favicon image
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="colors" type="Colors">
|
||||
Hex color codes for your global theme
|
||||
<Expandable title="Colors">
|
||||
<ResponseField name="primary" type="string" required>
|
||||
The primary color. Used for most often for highlighted content, section
|
||||
headers, accents, in light mode
|
||||
</ResponseField>
|
||||
<ResponseField name="light" type="string">
|
||||
The primary color for dark mode. Used for most often for highlighted
|
||||
content, section headers, accents, in dark mode
|
||||
</ResponseField>
|
||||
<ResponseField name="dark" type="string">
|
||||
The primary color for important buttons
|
||||
</ResponseField>
|
||||
<ResponseField name="background" type="object">
|
||||
The color of the background in both light and dark mode
|
||||
<Expandable title="Object">
|
||||
<ResponseField name="light" type="string" required>
|
||||
The hex color code of the background in light mode
|
||||
</ResponseField>
|
||||
<ResponseField name="dark" type="string" required>
|
||||
The hex color code of the background in dark mode
|
||||
</ResponseField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="topbarLinks" type="TopbarLink[]">
|
||||
Array of `name`s and `url`s of links you want to include in the topbar
|
||||
<Expandable title="TopbarLink">
|
||||
<ResponseField name="name" type="string">
|
||||
The name of the button.
|
||||
|
||||
Example: `Contact us`
|
||||
</ResponseField>
|
||||
<ResponseField name="url" type="string">
|
||||
The url once you click on the button. Example: `https://mintlify.com/docs`
|
||||
</ResponseField>
|
||||
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="topbarCtaButton" type="Call to Action">
|
||||
<Expandable title="Topbar Call to Action">
|
||||
<ResponseField name="type" type={'"link" or "github"'} default="link">
|
||||
Link shows a button. GitHub shows the repo information at the url provided including the number of GitHub stars.
|
||||
</ResponseField>
|
||||
<ResponseField name="url" type="string">
|
||||
If `link`: What the button links to.
|
||||
|
||||
If `github`: Link to the repository to load GitHub information from.
|
||||
</ResponseField>
|
||||
<ResponseField name="name" type="string">
|
||||
Text inside the button. Only required if `type` is a `link`.
|
||||
</ResponseField>
|
||||
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="versions" type="string[]">
|
||||
Array of version names. Only use this if you want to show different versions
|
||||
of docs with a dropdown in the navigation bar.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="anchors" type="Anchor[]">
|
||||
An array of the anchors, includes the `icon`, `color`, and `url`.
|
||||
<Expandable title="Anchor">
|
||||
<ResponseField name="icon" type="string">
|
||||
The [Font Awesome](https://fontawesome.com/search?q=heart) icon used to feature the anchor.
|
||||
|
||||
Example: `comments`
|
||||
</ResponseField>
|
||||
<ResponseField name="name" type="string">
|
||||
The name of the anchor label.
|
||||
|
||||
Example: `Community`
|
||||
</ResponseField>
|
||||
<ResponseField name="url" type="string">
|
||||
The start of the URL that marks what pages go in the anchor. Generally, this is the name of the folder you put your pages in.
|
||||
</ResponseField>
|
||||
<ResponseField name="color" type="string">
|
||||
The hex color of the anchor icon background. Can also be a gradient if you pass an object with the properties `from` and `to` that are each a hex color.
|
||||
</ResponseField>
|
||||
<ResponseField name="version" type="string">
|
||||
Used if you want to hide an anchor until the correct docs version is selected.
|
||||
</ResponseField>
|
||||
<ResponseField name="isDefaultHidden" type="boolean" default="false">
|
||||
Pass `true` if you want to hide the anchor until you directly link someone to docs inside it.
|
||||
</ResponseField>
|
||||
<ResponseField name="iconType" default="duotone" type="string">
|
||||
One of: "brands", "duotone", "light", "sharp-solid", "solid", or "thin"
|
||||
</ResponseField>
|
||||
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="topAnchor" type="Object">
|
||||
Override the default configurations for the top-most anchor.
|
||||
<Expandable title="Object">
|
||||
<ResponseField name="name" default="Documentation" type="string">
|
||||
The name of the top-most anchor
|
||||
</ResponseField>
|
||||
<ResponseField name="icon" default="book-open" type="string">
|
||||
Font Awesome icon.
|
||||
</ResponseField>
|
||||
<ResponseField name="iconType" default="duotone" type="string">
|
||||
One of: "brands", "duotone", "light", "sharp-solid", "solid", or "thin"
|
||||
</ResponseField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="tabs" type="Tabs[]">
|
||||
An array of navigational tabs.
|
||||
<Expandable title="Tabs">
|
||||
<ResponseField name="name" type="string">
|
||||
The name of the tab label.
|
||||
</ResponseField>
|
||||
<ResponseField name="url" type="string">
|
||||
The start of the URL that marks what pages go in the tab. Generally, this
|
||||
is the name of the folder you put your pages in.
|
||||
</ResponseField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="api" type="API">
|
||||
Configuration for API settings. Learn more about API pages at [API Components](/api-playground/demo).
|
||||
<Expandable title="API">
|
||||
<ResponseField name="baseUrl" type="string">
|
||||
The base url for all API endpoints. If `baseUrl` is an array, it will enable for multiple base url
|
||||
options that the user can toggle.
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="auth" type="Auth">
|
||||
<Expandable title="Auth">
|
||||
<ResponseField name="method" type='"bearer" | "basic" | "key"'>
|
||||
The authentication strategy used for all API endpoints.
|
||||
</ResponseField>
|
||||
<ResponseField name="name" type="string">
|
||||
The name of the authentication parameter used in the API playground.
|
||||
|
||||
If method is `basic`, the format should be `[usernameName]:[passwordName]`
|
||||
</ResponseField>
|
||||
<ResponseField name="inputPrefix" type="string">
|
||||
The default value that's designed to be a prefix for the authentication input field.
|
||||
|
||||
E.g. If an `inputPrefix` of `AuthKey` would inherit the default input result of the authentication field as `AuthKey`.
|
||||
</ResponseField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="playground" type="Playground">
|
||||
Configurations for the API playground
|
||||
|
||||
<Expandable title="Playground">
|
||||
<ResponseField name="mode" default="show" type='"show" | "simple" | "hide"'>
|
||||
Whether the playground is showing, hidden, or only displaying the endpoint with no added user interactivity `simple`
|
||||
|
||||
Learn more at the [playground guides](/api-playground/demo)
|
||||
</ResponseField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="maintainOrder" type="boolean">
|
||||
Enabling this flag ensures that key ordering in OpenAPI pages matches the key ordering defined in the OpenAPI file.
|
||||
|
||||
<Warning>This behavior will soon be enabled by default, at which point this field will be deprecated.</Warning>
|
||||
</ResponseField>
|
||||
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="openapi" type="string | string[]">
|
||||
A string or an array of strings of URL(s) or relative path(s) pointing to your
|
||||
OpenAPI file.
|
||||
|
||||
Examples:
|
||||
<CodeGroup>
|
||||
```json Absolute
|
||||
"openapi": "https://example.com/openapi.json"
|
||||
```
|
||||
```json Relative
|
||||
"openapi": "/openapi.json"
|
||||
```
|
||||
```json Multiple
|
||||
"openapi": ["https://example.com/openapi1.json", "/openapi2.json", "/openapi3.json"]
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="footerSocials" type="FooterSocials">
|
||||
An object of social media accounts where the key:property pair represents the social media platform and the account url.
|
||||
|
||||
Example:
|
||||
```json
|
||||
{
|
||||
"x": "https://x.com/mintlify",
|
||||
"website": "https://mintlify.com"
|
||||
}
|
||||
```
|
||||
<Expandable title="FooterSocials">
|
||||
<ResponseField name="[key]" type="string">
|
||||
One of the following values `website`, `facebook`, `x`, `discord`, `slack`, `github`, `linkedin`, `instagram`, `hacker-news`
|
||||
|
||||
Example: `x`
|
||||
</ResponseField>
|
||||
<ResponseField name="property" type="string">
|
||||
The URL to the social platform.
|
||||
|
||||
Example: `https://x.com/mintlify`
|
||||
</ResponseField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="feedback" type="Feedback">
|
||||
Configurations to enable feedback buttons
|
||||
|
||||
<Expandable title="Feedback">
|
||||
<ResponseField name="suggestEdit" type="boolean" default="false">
|
||||
Enables a button to allow users to suggest edits via pull requests
|
||||
</ResponseField>
|
||||
<ResponseField name="raiseIssue" type="boolean" default="false">
|
||||
Enables a button to allow users to raise an issue about the documentation
|
||||
</ResponseField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="modeToggle" type="ModeToggle">
|
||||
Customize the dark mode toggle.
|
||||
<Expandable title="ModeToggle">
|
||||
<ResponseField name="default" type={'"light" or "dark"'}>
|
||||
Set if you always want to show light or dark mode for new users. When not
|
||||
set, we default to the same mode as the user's operating system.
|
||||
</ResponseField>
|
||||
<ResponseField name="isHidden" type="boolean" default="false">
|
||||
Set to true to hide the dark/light mode toggle. You can combine `isHidden` with `default` to force your docs to only use light or dark mode. For example:
|
||||
|
||||
<CodeGroup>
|
||||
```json Only Dark Mode
|
||||
"modeToggle": {
|
||||
"default": "dark",
|
||||
"isHidden": true
|
||||
}
|
||||
```
|
||||
|
||||
```json Only Light Mode
|
||||
"modeToggle": {
|
||||
"default": "light",
|
||||
"isHidden": true
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
</ResponseField>
|
||||
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
|
||||
<ResponseField name="backgroundImage" type="string">
|
||||
A background image to be displayed behind every page. See example with
|
||||
[Infisical](https://infisical.com/docs) and [FRPC](https://frpc.io).
|
||||
</ResponseField>
|
||||
BIN
docs/favicon.ico
Executable file
|
After Width: | Height: | Size: 5.1 KiB |
19
docs/favicon.svg
Normal file
@@ -0,0 +1,19 @@
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M9.06145 23.1079C5.26816 22.3769 -3.39077 20.6274 1.4173 5.06384C9.6344 6.09939 16.9728 14.0644 9.06145 23.1079Z" fill="url(#paint0_linear_17557_2021)"/>
|
||||
<path d="M8.91928 23.0939C5.27642 21.2223 0.78371 4.20891 17.0071 0C20.7569 7.19341 19.6212 16.5452 8.91928 23.0939Z" fill="url(#paint1_linear_17557_2021)"/>
|
||||
<path d="M8.91388 23.0788C8.73534 19.8817 10.1585 9.08525 23.5699 13.1107C23.1812 20.1229 18.984 26.4182 8.91388 23.0788Z" fill="url(#paint2_linear_17557_2021)"/>
|
||||
<defs>
|
||||
<linearGradient id="paint0_linear_17557_2021" x1="3.77557" y1="5.91571" x2="5.23185" y2="21.5589" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#18E299"/>
|
||||
<stop offset="1" stop-color="#15803D"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="paint1_linear_17557_2021" x1="12.1711" y1="-0.718425" x2="10.1897" y2="22.9832" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#16A34A"/>
|
||||
<stop offset="1" stop-color="#4ADE80"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="paint2_linear_17557_2021" x1="23.1327" y1="15.353" x2="9.33841" y2="18.5196" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#4ADE80"/>
|
||||
<stop offset="1" stop-color="#0D9373"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
338
docs/features/authentication.mdx
Normal file
@@ -0,0 +1,338 @@
|
||||
---
|
||||
title: 'Authentication & Security'
|
||||
description: 'Configure authentication and security settings for MCPHub'
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
MCPHub provides flexible authentication mechanisms to secure your MCP server management platform. The system supports multiple authentication methods and role-based access control.
|
||||
|
||||
## Authentication Methods
|
||||
|
||||
### Environment-based Authentication
|
||||
|
||||
Configure basic authentication using environment variables:
|
||||
|
||||
```bash
|
||||
# Basic auth credentials
|
||||
AUTH_USERNAME=admin
|
||||
AUTH_PASSWORD=your-secure-password
|
||||
|
||||
# JWT settings
|
||||
JWT_SECRET=your-jwt-secret-key
|
||||
JWT_EXPIRES_IN=24h
|
||||
```
|
||||
|
||||
### Database Authentication
|
||||
|
||||
For production deployments, enable database-backed user management:
|
||||
|
||||
```json
|
||||
{
|
||||
"auth": {
|
||||
"provider": "database",
|
||||
"database": {
|
||||
"url": "postgresql://user:pass@localhost:5432/mcphub",
|
||||
"userTable": "users"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## User Management
|
||||
|
||||
### Creating Users
|
||||
|
||||
Create users via the admin interface or API:
|
||||
|
||||
```bash
|
||||
# Via API
|
||||
curl -X POST http://localhost:3000/api/auth/users \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $ADMIN_TOKEN" \
|
||||
-d '{
|
||||
"username": "newuser",
|
||||
"email": "user@example.com",
|
||||
"password": "securepassword",
|
||||
"role": "user"
|
||||
}'
|
||||
```
|
||||
|
||||
### User Roles
|
||||
|
||||
MCPHub supports role-based access control:
|
||||
|
||||
- **Admin**: Full system access, user management, server configuration
|
||||
- **Manager**: Server management, group management, monitoring
|
||||
- **User**: Basic server access within assigned groups
|
||||
- **Viewer**: Read-only access to assigned resources
|
||||
|
||||
## Group-based Access Control
|
||||
|
||||
### Assigning Users to Groups
|
||||
|
||||
```bash
|
||||
# Add user to group
|
||||
curl -X POST http://localhost:3000/api/groups/{groupId}/users \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{"userId": "user123"}'
|
||||
```
|
||||
|
||||
### Group Permissions
|
||||
|
||||
Configure group-level permissions:
|
||||
|
||||
```json
|
||||
{
|
||||
"groupId": "dev-team",
|
||||
"permissions": {
|
||||
"servers": ["read", "write", "execute"],
|
||||
"tools": ["read", "execute"],
|
||||
"logs": ["read"],
|
||||
"config": ["read"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## API Authentication
|
||||
|
||||
### JWT Token Authentication
|
||||
|
||||
```javascript
|
||||
// Login to get token
|
||||
const response = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
username: 'your-username',
|
||||
password: 'your-password',
|
||||
}),
|
||||
});
|
||||
|
||||
const { token } = await response.json();
|
||||
|
||||
// Use token for authenticated requests
|
||||
const serversResponse = await fetch('/api/servers', {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
```
|
||||
|
||||
### API Key Authentication
|
||||
|
||||
For service-to-service communication:
|
||||
|
||||
```bash
|
||||
# Generate API key
|
||||
curl -X POST http://localhost:3000/api/auth/api-keys \
|
||||
-H "Authorization: Bearer $ADMIN_TOKEN" \
|
||||
-d '{
|
||||
"name": "my-service",
|
||||
"permissions": ["servers:read", "tools:execute"]
|
||||
}'
|
||||
|
||||
# Use API key
|
||||
curl -H "X-API-Key: your-api-key" \
|
||||
http://localhost:3000/api/servers
|
||||
```
|
||||
|
||||
## Security Configuration
|
||||
|
||||
### HTTPS Setup
|
||||
|
||||
Configure HTTPS for production:
|
||||
|
||||
```yaml
|
||||
# docker-compose.yml
|
||||
services:
|
||||
mcphub:
|
||||
environment:
|
||||
- HTTPS_ENABLED=true
|
||||
- SSL_CERT_PATH=/certs/cert.pem
|
||||
- SSL_KEY_PATH=/certs/key.pem
|
||||
volumes:
|
||||
- ./certs:/certs:ro
|
||||
```
|
||||
|
||||
### CORS Configuration
|
||||
|
||||
Configure CORS for web applications:
|
||||
|
||||
```json
|
||||
{
|
||||
"cors": {
|
||||
"origin": ["https://your-frontend.com"],
|
||||
"credentials": true,
|
||||
"methods": ["GET", "POST", "PUT", "DELETE"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Rate Limiting
|
||||
|
||||
Protect against abuse with rate limiting:
|
||||
|
||||
```json
|
||||
{
|
||||
"rateLimit": {
|
||||
"windowMs": 900000,
|
||||
"max": 100,
|
||||
"message": "Too many requests from this IP"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Session Management
|
||||
|
||||
### Session Configuration
|
||||
|
||||
```json
|
||||
{
|
||||
"session": {
|
||||
"secret": "your-session-secret",
|
||||
"cookie": {
|
||||
"secure": true,
|
||||
"httpOnly": true,
|
||||
"maxAge": 86400000
|
||||
},
|
||||
"store": "redis",
|
||||
"redis": {
|
||||
"host": "localhost",
|
||||
"port": 6379
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Logout and Session Cleanup
|
||||
|
||||
```javascript
|
||||
// Logout endpoint
|
||||
app.post('/api/auth/logout', (req, res) => {
|
||||
req.session.destroy();
|
||||
res.json({ message: 'Logged out successfully' });
|
||||
});
|
||||
```
|
||||
|
||||
## Security Best Practices
|
||||
|
||||
### Password Security
|
||||
|
||||
- Use strong password requirements
|
||||
- Implement password hashing with bcrypt
|
||||
- Support password reset functionality
|
||||
- Enable two-factor authentication (2FA)
|
||||
|
||||
### Token Security
|
||||
|
||||
- Use secure JWT secrets
|
||||
- Implement token rotation
|
||||
- Set appropriate expiration times
|
||||
- Store tokens securely in httpOnly cookies
|
||||
|
||||
### Network Security
|
||||
|
||||
- Use HTTPS in production
|
||||
- Implement proper CORS policies
|
||||
- Enable request validation
|
||||
- Use security headers (helmet.js)
|
||||
|
||||
### Monitoring Security Events
|
||||
|
||||
```javascript
|
||||
// Log security events
|
||||
const auditLog = {
|
||||
event: 'login_attempt',
|
||||
user: username,
|
||||
ip: req.ip,
|
||||
userAgent: req.headers['user-agent'],
|
||||
success: true,
|
||||
timestamp: new Date(),
|
||||
};
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Authentication Issues
|
||||
|
||||
**Invalid Credentials**
|
||||
|
||||
```bash
|
||||
# Check user exists and password is correct
|
||||
curl -X POST http://localhost:3000/api/auth/verify \
|
||||
-d '{"username": "user", "password": "pass"}'
|
||||
```
|
||||
|
||||
**Token Expiration**
|
||||
|
||||
```javascript
|
||||
// Handle token refresh
|
||||
if (response.status === 401) {
|
||||
const newToken = await refreshToken();
|
||||
// Retry request with new token
|
||||
}
|
||||
```
|
||||
|
||||
**Permission Denied**
|
||||
|
||||
```bash
|
||||
# Check user permissions
|
||||
curl -H "Authorization: Bearer $TOKEN" \
|
||||
http://localhost:3000/api/auth/permissions
|
||||
```
|
||||
|
||||
### Debug Authentication
|
||||
|
||||
Enable authentication debugging:
|
||||
|
||||
```bash
|
||||
DEBUG=mcphub:auth npm start
|
||||
```
|
||||
|
||||
## Integration Examples
|
||||
|
||||
### Frontend Integration
|
||||
|
||||
```javascript
|
||||
// React authentication hook
|
||||
const useAuth = () => {
|
||||
const [user, setUser] = useState(null);
|
||||
|
||||
const login = async (credentials) => {
|
||||
const response = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(credentials),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const userData = await response.json();
|
||||
setUser(userData.user);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
return { user, login };
|
||||
};
|
||||
```
|
||||
|
||||
### Middleware Integration
|
||||
|
||||
```javascript
|
||||
// Express middleware
|
||||
const authMiddleware = (req, res, next) => {
|
||||
const token = req.headers.authorization?.split(' ')[1];
|
||||
|
||||
if (!token) {
|
||||
return res.status(401).json({ error: 'No token provided' });
|
||||
}
|
||||
|
||||
try {
|
||||
const decoded = jwt.verify(token, process.env.JWT_SECRET);
|
||||
req.user = decoded;
|
||||
next();
|
||||
} catch (error) {
|
||||
res.status(401).json({ error: 'Invalid token' });
|
||||
}
|
||||
};
|
||||
```
|
||||
588
docs/features/group-management.mdx
Normal file
@@ -0,0 +1,588 @@
|
||||
---
|
||||
title: 'Group Management'
|
||||
description: 'Organize servers into logical groups for streamlined access control'
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
Group Management in MCPHub allows you to organize your MCP servers into logical collections based on functionality, use case, or access requirements. This enables fine-grained control over which tools are available to different AI clients and users.
|
||||
|
||||
## Core Concepts
|
||||
|
||||
### What are Groups?
|
||||
|
||||
Groups are named collections of MCP servers that can be accessed through dedicated endpoints. Instead of connecting to all servers at once, AI clients can connect to specific groups to access only relevant tools.
|
||||
|
||||
### Benefits of Groups
|
||||
|
||||
- **Focused Tool Access**: AI clients see only relevant tools for their use case
|
||||
- **Better Performance**: Reduced tool discovery overhead
|
||||
- **Enhanced Security**: Limit access to sensitive tools
|
||||
- **Improved Organization**: Logical separation of functionality
|
||||
- **Simplified Management**: Easier to manage related servers together
|
||||
|
||||
## Creating Groups
|
||||
|
||||
### Via Dashboard
|
||||
|
||||
1. **Navigate to Groups Section**: Click "Groups" in the main navigation
|
||||
2. **Click "Create Group"**: Start the group creation process
|
||||
3. **Fill Group Details**:
|
||||
|
||||
- **Name**: Unique identifier for the group
|
||||
- **Display Name**: Human-readable name
|
||||
- **Description**: Purpose and contents of the group
|
||||
- **Access Level**: Public, Private, or Restricted
|
||||
|
||||
4. **Add Servers**: Select servers to include in the group
|
||||
|
||||
### Via API
|
||||
|
||||
Create groups programmatically:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/api/groups \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
|
||||
-d '{
|
||||
"name": "web-automation",
|
||||
"displayName": "Web Automation Tools",
|
||||
"description": "Browser automation and web scraping tools",
|
||||
"servers": ["playwright", "fetch"],
|
||||
"accessLevel": "public"
|
||||
}'
|
||||
```
|
||||
|
||||
### Via Configuration File
|
||||
|
||||
Define groups in your `mcp_settings.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"fetch": { "command": "uvx", "args": ["mcp-server-fetch"] },
|
||||
"playwright": { "command": "npx", "args": ["@playwright/mcp@latest"] },
|
||||
"slack": { "command": "npx", "args": ["@modelcontextprotocol/server-slack"] }
|
||||
},
|
||||
"groups": {
|
||||
"web-tools": {
|
||||
"displayName": "Web Tools",
|
||||
"description": "Web scraping and browser automation",
|
||||
"servers": ["fetch", "playwright"],
|
||||
"accessLevel": "public"
|
||||
},
|
||||
"communication": {
|
||||
"displayName": "Communication Tools",
|
||||
"description": "Messaging and collaboration tools",
|
||||
"servers": ["slack"],
|
||||
"accessLevel": "private"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Group Types and Use Cases
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Web Automation Group">
|
||||
**Purpose**: Browser automation and web scraping
|
||||
|
||||
**Servers**:
|
||||
- `playwright`: Browser automation
|
||||
- `fetch`: HTTP requests and web scraping
|
||||
- `selenium`: Alternative browser automation
|
||||
|
||||
**Use Cases**:
|
||||
- Automated testing
|
||||
- Data collection
|
||||
- Web monitoring
|
||||
- Content analysis
|
||||
|
||||
**Endpoint**: `http://localhost:3000/mcp/web-automation`
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Data Processing Group">
|
||||
**Purpose**: Data manipulation and analysis
|
||||
|
||||
**Servers**:
|
||||
- `sqlite`: Database operations
|
||||
- `filesystem`: File operations
|
||||
- `spreadsheet`: Excel/CSV processing
|
||||
|
||||
**Use Cases**:
|
||||
- Data analysis
|
||||
- Report generation
|
||||
- File processing
|
||||
- Database queries
|
||||
|
||||
**Endpoint**: `http://localhost:3000/mcp/data-processing`
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Communication Group">
|
||||
**Purpose**: Messaging and collaboration
|
||||
|
||||
**Servers**:
|
||||
- `slack`: Slack integration
|
||||
- `discord`: Discord bot
|
||||
- `email`: Email sending
|
||||
- `sms`: SMS notifications
|
||||
|
||||
**Use Cases**:
|
||||
- Team notifications
|
||||
- Customer communication
|
||||
- Alert systems
|
||||
- Social media management
|
||||
|
||||
**Endpoint**: `http://localhost:3000/mcp/communication`
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Development Group">
|
||||
**Purpose**: Software development tools
|
||||
|
||||
**Servers**:
|
||||
- `github`: GitHub operations
|
||||
- `gitlab`: GitLab integration
|
||||
- `docker`: Container management
|
||||
- `kubernetes`: K8s operations
|
||||
|
||||
**Use Cases**:
|
||||
- Code deployment
|
||||
- Repository management
|
||||
- CI/CD operations
|
||||
- Infrastructure management
|
||||
|
||||
**Endpoint**: `http://localhost:3000/mcp/development`
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="AI/ML Group">
|
||||
**Purpose**: Machine learning and AI tools
|
||||
|
||||
**Servers**:
|
||||
- `openai`: OpenAI API integration
|
||||
- `huggingface`: Hugging Face models
|
||||
- `vector-db`: Vector database operations
|
||||
|
||||
**Use Cases**:
|
||||
- Model inference
|
||||
- Data embeddings
|
||||
- Natural language processing
|
||||
- Computer vision
|
||||
|
||||
**Endpoint**: `http://localhost:3000/mcp/ai-ml`
|
||||
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## Group Access Control
|
||||
|
||||
### Access Levels
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Public">
|
||||
**Public Groups**:
|
||||
- Accessible to all authenticated users
|
||||
- No additional permissions required
|
||||
- Visible in group listings
|
||||
- Default access level
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "public-tools",
|
||||
"accessLevel": "public",
|
||||
"servers": ["fetch", "calculator"]
|
||||
}
|
||||
```
|
||||
|
||||
</Tab>
|
||||
|
||||
<Tab title="Private">
|
||||
**Private Groups**:
|
||||
- Only visible to group members
|
||||
- Requires explicit user assignment
|
||||
- Hidden from public listings
|
||||
- Admin-controlled membership
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "internal-tools",
|
||||
"accessLevel": "private",
|
||||
"members": ["user1", "user2"],
|
||||
"servers": ["internal-api", "database"]
|
||||
}
|
||||
```
|
||||
|
||||
</Tab>
|
||||
|
||||
<Tab title="Restricted">
|
||||
**Restricted Groups**:
|
||||
- Role-based access control
|
||||
- Requires specific permissions
|
||||
- Audit logging enabled
|
||||
- Time-limited access
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "admin-tools",
|
||||
"accessLevel": "restricted",
|
||||
"requiredRoles": ["admin", "operator"],
|
||||
"servers": ["system-control", "user-management"]
|
||||
}
|
||||
```
|
||||
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### User Management
|
||||
|
||||
Assign users to groups:
|
||||
|
||||
```bash
|
||||
# Add user to group
|
||||
curl -X POST http://localhost:3000/api/groups/web-tools/members \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
|
||||
-d '{"userId": "user123"}'
|
||||
|
||||
# Remove user from group
|
||||
curl -X DELETE http://localhost:3000/api/groups/web-tools/members/user123 \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
|
||||
# List group members
|
||||
curl http://localhost:3000/api/groups/web-tools/members \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
```
|
||||
|
||||
## Group Endpoints
|
||||
|
||||
### Accessing Groups
|
||||
|
||||
Each group gets its own MCP endpoint:
|
||||
|
||||
<Tabs>
|
||||
<Tab title="HTTP MCP">
|
||||
```
|
||||
http://localhost:3000/mcp/{group-name}
|
||||
```
|
||||
|
||||
Examples:
|
||||
- `http://localhost:3000/mcp/web-tools`
|
||||
- `http://localhost:3000/mcp/data-processing`
|
||||
- `http://localhost:3000/mcp/communication`
|
||||
|
||||
</Tab>
|
||||
|
||||
<Tab title="SSE (Legacy)">
|
||||
```
|
||||
http://localhost:3000/sse/{group-name}
|
||||
```
|
||||
|
||||
Examples:
|
||||
- `http://localhost:3000/sse/web-tools`
|
||||
- `http://localhost:3000/sse/data-processing`
|
||||
- `http://localhost:3000/sse/communication`
|
||||
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### Group Tool Discovery
|
||||
|
||||
When connecting to a group endpoint, AI clients will only see tools from servers within that group:
|
||||
|
||||
```bash
|
||||
# List tools in web-tools group
|
||||
curl -X POST http://localhost:3000/mcp/web-tools \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "tools/list",
|
||||
"params": {}
|
||||
}'
|
||||
```
|
||||
|
||||
Response will only include tools from `fetch` and `playwright` servers.
|
||||
|
||||
## Dynamic Group Management
|
||||
|
||||
### Adding Servers to Groups
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Dashboard">
|
||||
1. Navigate to the group in the dashboard
|
||||
2. Click "Manage Servers"
|
||||
3. Select additional servers to add
|
||||
4. Click "Save Changes"
|
||||
</Tab>
|
||||
|
||||
<Tab title="API">
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/api/groups/web-tools/servers \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
|
||||
-d '{"serverId": "new-server"}'
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### Removing Servers from Groups
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Dashboard">
|
||||
1. Navigate to the group in the dashboard
|
||||
2. Click "Manage Servers"
|
||||
3. Unselect servers to remove
|
||||
4. Click "Save Changes"
|
||||
</Tab>
|
||||
|
||||
<Tab title="API">
|
||||
```bash
|
||||
curl -X DELETE http://localhost:3000/api/groups/web-tools/servers/server-name \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### Batch Server Updates
|
||||
|
||||
Update multiple servers at once:
|
||||
|
||||
```bash
|
||||
curl -X PUT http://localhost:3000/api/groups/web-tools/servers \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
|
||||
-d '{
|
||||
"servers": ["fetch", "playwright", "selenium"]
|
||||
}'
|
||||
```
|
||||
|
||||
## Group Monitoring
|
||||
|
||||
### Group Status
|
||||
|
||||
Monitor group health and activity:
|
||||
|
||||
```bash
|
||||
# Get group status
|
||||
curl http://localhost:3000/api/groups/web-tools/status \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
```
|
||||
|
||||
Response includes:
|
||||
|
||||
- Number of active servers
|
||||
- Tool count
|
||||
- Active connections
|
||||
- Recent activity
|
||||
|
||||
### Group Analytics
|
||||
|
||||
Track group usage:
|
||||
|
||||
```bash
|
||||
# Get group analytics
|
||||
curl http://localhost:3000/api/groups/web-tools/analytics \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
```
|
||||
|
||||
Metrics include:
|
||||
|
||||
- Request count by tool
|
||||
- Response times
|
||||
- Error rates
|
||||
- User activity
|
||||
|
||||
## Advanced Group Features
|
||||
|
||||
### Nested Groups
|
||||
|
||||
Create hierarchical group structures:
|
||||
|
||||
```json
|
||||
{
|
||||
"groups": {
|
||||
"development": {
|
||||
"displayName": "Development Tools",
|
||||
"subGroups": ["frontend-dev", "backend-dev", "devops"]
|
||||
},
|
||||
"frontend-dev": {
|
||||
"displayName": "Frontend Development",
|
||||
"servers": ["playwright", "webpack-server"],
|
||||
"parent": "development"
|
||||
},
|
||||
"backend-dev": {
|
||||
"displayName": "Backend Development",
|
||||
"servers": ["database", "api-server"],
|
||||
"parent": "development"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Group Templates
|
||||
|
||||
Use templates for quick group creation:
|
||||
|
||||
```json
|
||||
{
|
||||
"groupTemplates": {
|
||||
"web-project": {
|
||||
"description": "Standard web project toolset",
|
||||
"servers": ["fetch", "playwright", "filesystem"],
|
||||
"accessLevel": "public"
|
||||
},
|
||||
"data-science": {
|
||||
"description": "Data science and ML tools",
|
||||
"servers": ["python-tools", "jupyter", "vector-db"],
|
||||
"accessLevel": "private"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Apply template:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/api/groups/from-template \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
|
||||
-d '{
|
||||
"name": "my-web-project",
|
||||
"template": "web-project",
|
||||
"displayName": "My Web Project Tools"
|
||||
}'
|
||||
```
|
||||
|
||||
### Group Policies
|
||||
|
||||
Define policies for group behavior:
|
||||
|
||||
```json
|
||||
{
|
||||
"groupPolicies": {
|
||||
"web-tools": {
|
||||
"maxConcurrentConnections": 10,
|
||||
"requestTimeout": 30000,
|
||||
"rateLimiting": {
|
||||
"requestsPerMinute": 100,
|
||||
"burstLimit": 20
|
||||
},
|
||||
"allowedOrigins": ["localhost", "myapp.com"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Group Organization
|
||||
|
||||
<Tip>
|
||||
**Organize by Use Case**: Group servers based on what users want to accomplish, not just technical
|
||||
similarity.
|
||||
</Tip>
|
||||
|
||||
<Tip>
|
||||
**Keep Groups Focused**: Avoid creating groups with too many diverse tools. Smaller, focused
|
||||
groups are more useful.
|
||||
</Tip>
|
||||
|
||||
<Tip>
|
||||
**Use Descriptive Names**: Choose names that clearly indicate the group's purpose and contents.
|
||||
</Tip>
|
||||
|
||||
### Security Considerations
|
||||
|
||||
<Warning>
|
||||
**Principle of Least Privilege**: Only give users access to groups they actually need.
|
||||
</Warning>
|
||||
|
||||
<Warning>
|
||||
**Sensitive Tool Isolation**: Keep sensitive tools in restricted groups with proper access
|
||||
controls.
|
||||
</Warning>
|
||||
|
||||
<Warning>
|
||||
**Regular Access Reviews**: Periodically review group memberships and remove unnecessary access.
|
||||
</Warning>
|
||||
|
||||
### Performance Optimization
|
||||
|
||||
<Info>
|
||||
**Balance Group Size**: Very large groups may have slower tool discovery. Consider splitting into
|
||||
smaller groups.
|
||||
</Info>
|
||||
|
||||
<Info>
|
||||
**Monitor Usage**: Use analytics to identify which groups are heavily used and optimize
|
||||
accordingly.
|
||||
</Info>
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Group Not Accessible">
|
||||
**Check:**
|
||||
- User has proper permissions
|
||||
- Group exists and is active
|
||||
- Servers in group are running
|
||||
- Network connectivity
|
||||
|
||||
**Solutions:**
|
||||
1. Verify user group membership
|
||||
2. Check group configuration
|
||||
3. Test individual server connections
|
||||
4. Review access logs
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Tools Missing from Group">
|
||||
**Possible causes:**
|
||||
- Server not properly added to group
|
||||
- Server is not running
|
||||
- Tool discovery failed
|
||||
- Caching issues
|
||||
|
||||
**Debug steps:**
|
||||
1. Verify server is in group configuration
|
||||
2. Check server status
|
||||
3. Force refresh tool discovery
|
||||
4. Clear group cache
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Group Performance Issues">
|
||||
**Common issues:**
|
||||
- Too many servers in group
|
||||
- Slow server responses
|
||||
- Network latency
|
||||
- Resource constraints
|
||||
|
||||
**Optimizations:**
|
||||
1. Split large groups
|
||||
2. Monitor server performance
|
||||
3. Implement request caching
|
||||
4. Use connection pooling
|
||||
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## Next Steps
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Smart Routing" icon="route" href="/features/smart-routing">
|
||||
AI-powered tool discovery across groups
|
||||
</Card>
|
||||
<Card title="Authentication" icon="shield" href="/features/authentication">
|
||||
User management and access control
|
||||
</Card>
|
||||
<Card title="API Reference" icon="code" href="/api-reference/groups">
|
||||
Complete group management API
|
||||
</Card>
|
||||
<Card title="Configuration" icon="cog" href="/configuration/mcp-settings">
|
||||
Advanced group configuration options
|
||||
</Card>
|
||||
</CardGroup>
|
||||
526
docs/features/monitoring.mdx
Normal file
@@ -0,0 +1,526 @@
|
||||
---
|
||||
title: 'Monitoring & Logging'
|
||||
description: 'Monitor your MCP servers and analyze system logs with MCPHub'
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
MCPHub provides comprehensive monitoring and logging capabilities to help you track server performance, debug issues, and maintain system health.
|
||||
|
||||
## Real-time Monitoring
|
||||
|
||||
### Server Status Dashboard
|
||||
|
||||
The MCPHub dashboard provides real-time monitoring of all registered MCP servers:
|
||||
|
||||
- **Server Health**: Online/offline status with automatic health checks
|
||||
- **Response Times**: Average, min, max response times per server
|
||||
- **Request Volume**: Requests per second/minute/hour
|
||||
- **Error Rates**: Success/failure ratios and error trends
|
||||
- **Resource Usage**: Memory and CPU utilization (when available)
|
||||
|
||||
### Health Check Configuration
|
||||
|
||||
Configure health checks for your MCP servers:
|
||||
|
||||
```json
|
||||
{
|
||||
"healthCheck": {
|
||||
"enabled": true,
|
||||
"interval": 30000,
|
||||
"timeout": 5000,
|
||||
"retries": 3,
|
||||
"endpoints": {
|
||||
"ping": "/health",
|
||||
"tools": "/tools/list"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Monitoring API
|
||||
|
||||
Get monitoring data programmatically:
|
||||
|
||||
```bash
|
||||
# Get server health status
|
||||
curl http://localhost:3000/api/monitoring/health
|
||||
|
||||
# Get performance metrics
|
||||
curl http://localhost:3000/api/monitoring/metrics?server=my-server&range=1h
|
||||
|
||||
# Get system overview
|
||||
curl http://localhost:3000/api/monitoring/overview
|
||||
```
|
||||
|
||||
## Logging System
|
||||
|
||||
### Log Levels
|
||||
|
||||
MCPHub supports standard log levels:
|
||||
|
||||
- **ERROR**: Critical errors requiring immediate attention
|
||||
- **WARN**: Warning conditions that should be monitored
|
||||
- **INFO**: General operational messages
|
||||
- **DEBUG**: Detailed debugging information
|
||||
- **TRACE**: Very detailed trace information
|
||||
|
||||
### Log Configuration
|
||||
|
||||
Configure logging in your environment:
|
||||
|
||||
```bash
|
||||
# Set log level
|
||||
LOG_LEVEL=info
|
||||
|
||||
# Enable structured logging
|
||||
LOG_FORMAT=json
|
||||
|
||||
# Log file location
|
||||
LOG_FILE=/var/log/mcphub/app.log
|
||||
|
||||
# Enable request logging
|
||||
ENABLE_REQUEST_LOGS=true
|
||||
```
|
||||
|
||||
### Structured Logging
|
||||
|
||||
MCPHub uses structured logging for better analysis:
|
||||
|
||||
```json
|
||||
{
|
||||
"timestamp": "2024-01-20T10:30:00Z",
|
||||
"level": "info",
|
||||
"message": "MCP server request completed",
|
||||
"server": "github-mcp",
|
||||
"tool": "search_repositories",
|
||||
"duration": 245,
|
||||
"status": "success",
|
||||
"requestId": "req_123456",
|
||||
"userId": "user_789"
|
||||
}
|
||||
```
|
||||
|
||||
## Log Management
|
||||
|
||||
### Log Storage Options
|
||||
|
||||
#### File-based Logging
|
||||
|
||||
```yaml
|
||||
# docker-compose.yml
|
||||
services:
|
||||
mcphub:
|
||||
volumes:
|
||||
- ./logs:/app/logs
|
||||
environment:
|
||||
- LOG_FILE=/app/logs/mcphub.log
|
||||
- LOG_ROTATION=daily
|
||||
- LOG_MAX_SIZE=100MB
|
||||
- LOG_MAX_FILES=7
|
||||
```
|
||||
|
||||
#### Database Logging
|
||||
|
||||
```json
|
||||
{
|
||||
"logging": {
|
||||
"database": {
|
||||
"enabled": true,
|
||||
"table": "logs",
|
||||
"retention": "30d",
|
||||
"indexes": ["timestamp", "level", "server"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### External Log Services
|
||||
|
||||
```bash
|
||||
# Syslog integration
|
||||
SYSLOG_ENABLED=true
|
||||
SYSLOG_HOST=localhost
|
||||
SYSLOG_PORT=514
|
||||
SYSLOG_FACILITY=local0
|
||||
|
||||
# ELK Stack integration
|
||||
ELASTICSEARCH_URL=http://localhost:9200
|
||||
ELASTICSEARCH_INDEX=mcphub-logs
|
||||
```
|
||||
|
||||
### Log Rotation
|
||||
|
||||
Automatic log rotation configuration:
|
||||
|
||||
```json
|
||||
{
|
||||
"logRotation": {
|
||||
"enabled": true,
|
||||
"maxSize": "100MB",
|
||||
"maxFiles": 10,
|
||||
"compress": true,
|
||||
"interval": "daily"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Metrics Collection
|
||||
|
||||
### System Metrics
|
||||
|
||||
MCPHub collects various system metrics:
|
||||
|
||||
```javascript
|
||||
// Example metrics collected
|
||||
{
|
||||
"timestamp": "2024-01-20T10:30:00Z",
|
||||
"metrics": {
|
||||
"requests": {
|
||||
"total": 1547,
|
||||
"success": 1523,
|
||||
"errors": 24,
|
||||
"rate": 12.5
|
||||
},
|
||||
"servers": {
|
||||
"online": 8,
|
||||
"offline": 2,
|
||||
"total": 10
|
||||
},
|
||||
"performance": {
|
||||
"avgResponseTime": 156,
|
||||
"p95ResponseTime": 324,
|
||||
"p99ResponseTime": 567
|
||||
},
|
||||
"system": {
|
||||
"memoryUsage": "245MB",
|
||||
"cpuUsage": "15%",
|
||||
"uptime": "72h 35m"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Custom Metrics
|
||||
|
||||
Add custom metrics for your use case:
|
||||
|
||||
```javascript
|
||||
// Custom metric example
|
||||
const customMetric = {
|
||||
name: 'tool_usage',
|
||||
type: 'counter',
|
||||
tags: {
|
||||
server: 'github-mcp',
|
||||
tool: 'search_repositories',
|
||||
result: 'success',
|
||||
},
|
||||
value: 1,
|
||||
};
|
||||
|
||||
// Send to metrics endpoint
|
||||
await fetch('/api/monitoring/metrics', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(customMetric),
|
||||
});
|
||||
```
|
||||
|
||||
## Alerting
|
||||
|
||||
### Alert Configuration
|
||||
|
||||
Set up alerts for critical conditions:
|
||||
|
||||
```json
|
||||
{
|
||||
"alerts": {
|
||||
"serverDown": {
|
||||
"condition": "server.status == 'offline'",
|
||||
"duration": "5m",
|
||||
"severity": "critical",
|
||||
"channels": ["email", "slack"]
|
||||
},
|
||||
"highErrorRate": {
|
||||
"condition": "errors.rate > 0.1",
|
||||
"duration": "2m",
|
||||
"severity": "warning",
|
||||
"channels": ["slack"]
|
||||
},
|
||||
"slowResponse": {
|
||||
"condition": "response.p95 > 1000",
|
||||
"duration": "5m",
|
||||
"severity": "warning",
|
||||
"channels": ["email"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Notification Channels
|
||||
|
||||
#### Email Notifications
|
||||
|
||||
```bash
|
||||
# Email configuration
|
||||
SMTP_HOST=smtp.gmail.com
|
||||
SMTP_PORT=587
|
||||
SMTP_USER=alerts@yourcompany.com
|
||||
SMTP_PASS=your-app-password
|
||||
ALERT_EMAIL_TO=admin@yourcompany.com
|
||||
```
|
||||
|
||||
#### Slack Integration
|
||||
|
||||
```bash
|
||||
# Slack webhook
|
||||
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...
|
||||
SLACK_CHANNEL=#mcphub-alerts
|
||||
```
|
||||
|
||||
#### Webhook Notifications
|
||||
|
||||
```json
|
||||
{
|
||||
"webhooks": [
|
||||
{
|
||||
"url": "https://your-service.com/webhooks/mcphub",
|
||||
"events": ["server.down", "error.rate.high"],
|
||||
"headers": {
|
||||
"Authorization": "Bearer your-token"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Log Analysis
|
||||
|
||||
### Query Logs
|
||||
|
||||
Use the logs API to query and analyze logs:
|
||||
|
||||
```bash
|
||||
# Get recent errors
|
||||
curl "http://localhost:3000/api/logs?level=error&since=1h"
|
||||
|
||||
# Search logs by server
|
||||
curl "http://localhost:3000/api/logs?server=github-mcp&limit=100"
|
||||
|
||||
# Get logs for specific request
|
||||
curl "http://localhost:3000/api/logs?requestId=req_123456"
|
||||
|
||||
# Filter by time range
|
||||
curl "http://localhost:3000/api/logs?from=2024-01-20T00:00:00Z&to=2024-01-20T23:59:59Z"
|
||||
```
|
||||
|
||||
### Log Aggregation
|
||||
|
||||
Aggregate logs for insights:
|
||||
|
||||
```bash
|
||||
# Error summary by server
|
||||
curl "http://localhost:3000/api/logs/aggregate?groupBy=server&level=error&since=24h"
|
||||
|
||||
# Request volume over time
|
||||
curl "http://localhost:3000/api/logs/aggregate?groupBy=hour&type=request&since=7d"
|
||||
```
|
||||
|
||||
## Performance Monitoring
|
||||
|
||||
### Response Time Tracking
|
||||
|
||||
Monitor MCP server response times:
|
||||
|
||||
```javascript
|
||||
// Response time metrics
|
||||
{
|
||||
"server": "github-mcp",
|
||||
"tool": "search_repositories",
|
||||
"metrics": {
|
||||
"calls": 156,
|
||||
"avgTime": 234,
|
||||
"minTime": 89,
|
||||
"maxTime": 1205,
|
||||
"p50": 201,
|
||||
"p95": 567,
|
||||
"p99": 892
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Error Rate Monitoring
|
||||
|
||||
Track error rates and patterns:
|
||||
|
||||
```bash
|
||||
# Get error rates by server
|
||||
curl "http://localhost:3000/api/monitoring/errors?groupBy=server&since=1h"
|
||||
|
||||
# Get error details
|
||||
curl "http://localhost:3000/api/monitoring/errors?server=github-mcp&details=true"
|
||||
```
|
||||
|
||||
## Integration with External Tools
|
||||
|
||||
### Prometheus Integration
|
||||
|
||||
Export metrics to Prometheus:
|
||||
|
||||
```yaml
|
||||
# prometheus.yml
|
||||
scrape_configs:
|
||||
- job_name: 'mcphub'
|
||||
static_configs:
|
||||
- targets: ['localhost:3000']
|
||||
metrics_path: '/api/monitoring/prometheus'
|
||||
scrape_interval: 30s
|
||||
```
|
||||
|
||||
### Grafana Dashboards
|
||||
|
||||
Import MCPHub Grafana dashboard:
|
||||
|
||||
```json
|
||||
{
|
||||
"dashboard": {
|
||||
"title": "MCPHub Monitoring",
|
||||
"panels": [
|
||||
{
|
||||
"title": "Server Status",
|
||||
"type": "stat",
|
||||
"targets": [
|
||||
{
|
||||
"expr": "mcphub_servers_online",
|
||||
"legendFormat": "Online"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Request Rate",
|
||||
"type": "graph",
|
||||
"targets": [
|
||||
{
|
||||
"expr": "rate(mcphub_requests_total[5m])",
|
||||
"legendFormat": "Requests/sec"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### ELK Stack Integration
|
||||
|
||||
Configure Logstash for log processing:
|
||||
|
||||
```ruby
|
||||
# logstash.conf
|
||||
input {
|
||||
beats {
|
||||
port => 5044
|
||||
}
|
||||
}
|
||||
|
||||
filter {
|
||||
if [fields][service] == "mcphub" {
|
||||
json {
|
||||
source => "message"
|
||||
}
|
||||
|
||||
date {
|
||||
match => [ "timestamp", "ISO8601" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output {
|
||||
elasticsearch {
|
||||
hosts => ["localhost:9200"]
|
||||
index => "mcphub-logs-%{+YYYY.MM.dd}"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Monitoring Issues
|
||||
|
||||
**Missing Metrics**
|
||||
|
||||
```bash
|
||||
# Check metrics endpoint
|
||||
curl http://localhost:3000/api/monitoring/health
|
||||
|
||||
# Verify configuration
|
||||
grep -r "monitoring" /path/to/config/
|
||||
```
|
||||
|
||||
**Log File Issues**
|
||||
|
||||
```bash
|
||||
# Check log file permissions
|
||||
ls -la /var/log/mcphub/
|
||||
|
||||
# Verify disk space
|
||||
df -h /var/log/
|
||||
|
||||
# Check log rotation
|
||||
logrotate -d /etc/logrotate.d/mcphub
|
||||
```
|
||||
|
||||
**Performance Issues**
|
||||
|
||||
```bash
|
||||
# Monitor system resources
|
||||
top -p $(pgrep -f mcphub)
|
||||
|
||||
# Check database connections
|
||||
curl http://localhost:3000/api/monitoring/database
|
||||
|
||||
# Analyze slow queries
|
||||
curl http://localhost:3000/api/monitoring/slow-queries
|
||||
```
|
||||
|
||||
### Debug Mode
|
||||
|
||||
Enable debug logging for troubleshooting:
|
||||
|
||||
```bash
|
||||
# Enable debug mode
|
||||
DEBUG=mcphub:* npm start
|
||||
|
||||
# Or set environment variable
|
||||
export DEBUG=mcphub:monitoring,mcphub:logging
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Log Management
|
||||
|
||||
- Use structured logging with consistent formats
|
||||
- Implement proper log levels and filtering
|
||||
- Set up log rotation and retention policies
|
||||
- Monitor log file sizes and disk usage
|
||||
|
||||
### Monitoring Setup
|
||||
|
||||
- Configure appropriate health check intervals
|
||||
- Set up alerts for critical conditions
|
||||
- Monitor both system and application metrics
|
||||
- Use dashboards for visual monitoring
|
||||
|
||||
### Performance Optimization
|
||||
|
||||
- Index log database tables appropriately
|
||||
- Use log sampling for high-volume scenarios
|
||||
- Implement proper caching for metrics
|
||||
- Regular cleanup of old logs and metrics
|
||||
|
||||
### Security Considerations
|
||||
|
||||
- Sanitize sensitive data in logs
|
||||
- Secure access to monitoring endpoints
|
||||
- Use authentication for external integrations
|
||||
- Encrypt log transmission when using external services
|
||||
509
docs/features/server-management.mdx
Normal file
@@ -0,0 +1,509 @@
|
||||
---
|
||||
title: 'Server Management'
|
||||
description: 'Centrally manage multiple MCP servers with hot-swappable configuration'
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
MCPHub's server management system allows you to centrally configure, monitor, and control multiple MCP (Model Context Protocol) servers from a single dashboard. All changes are applied in real-time without requiring server restarts.
|
||||
|
||||
## Adding MCP Servers
|
||||
|
||||
### Via Dashboard
|
||||
|
||||
1. **Access the Dashboard**: Navigate to `http://localhost:3000` and log in
|
||||
2. **Click "Add Server"**: Located in the servers section
|
||||
3. **Fill Server Details**:
|
||||
- **Name**: Unique identifier for the server
|
||||
- **Command**: Executable command (e.g., `npx`, `uvx`, `python`)
|
||||
- **Arguments**: Array of command arguments
|
||||
- **Environment Variables**: Key-value pairs for environment setup
|
||||
- **Working Directory**: Optional working directory for the command
|
||||
|
||||
### Via Configuration File
|
||||
|
||||
Edit your `mcp_settings.json` file:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"server-name": {
|
||||
"command": "command-to-run",
|
||||
"args": ["arg1", "arg2"],
|
||||
"env": {
|
||||
"API_KEY": "your-api-key",
|
||||
"CONFIG_VALUE": "some-value"
|
||||
},
|
||||
"cwd": "/optional/working/directory"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Via API
|
||||
|
||||
Use the REST API to add servers programmatically:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/api/servers \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
|
||||
-d '{
|
||||
"name": "fetch-server",
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"],
|
||||
"env": {}
|
||||
}'
|
||||
```
|
||||
|
||||
## Popular MCP Server Examples
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Web Fetch Server">
|
||||
Provides web scraping and HTTP request capabilities:
|
||||
|
||||
```json
|
||||
{
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Available Tools:**
|
||||
- `fetch`: Make HTTP requests
|
||||
- `fetch_html`: Scrape web pages
|
||||
- `fetch_json`: Get JSON data from APIs
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Playwright Browser Automation">
|
||||
Browser automation for web interactions:
|
||||
|
||||
```json
|
||||
{
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Available Tools:**
|
||||
- `playwright_navigate`: Navigate to web pages
|
||||
- `playwright_screenshot`: Take screenshots
|
||||
- `playwright_click`: Click elements
|
||||
- `playwright_fill`: Fill forms
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="File System Operations">
|
||||
File and directory management:
|
||||
|
||||
```json
|
||||
{
|
||||
"filesystem": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/allowed/path"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Available Tools:**
|
||||
- `read_file`: Read file contents
|
||||
- `write_file`: Write to files
|
||||
- `create_directory`: Create directories
|
||||
- `list_directory`: List directory contents
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="SQLite Database">
|
||||
Database operations:
|
||||
|
||||
```json
|
||||
{
|
||||
"sqlite": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-sqlite", "/path/to/database.db"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Available Tools:**
|
||||
- `execute_query`: Execute SQL queries
|
||||
- `describe_tables`: Get table schemas
|
||||
- `create_table`: Create new tables
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Slack Integration">
|
||||
Slack workspace integration:
|
||||
|
||||
```json
|
||||
{
|
||||
"slack": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-slack"],
|
||||
"env": {
|
||||
"SLACK_BOT_TOKEN": "xoxb-your-bot-token",
|
||||
"SLACK_TEAM_ID": "T1234567890"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Available Tools:**
|
||||
- `send_slack_message`: Send messages to channels
|
||||
- `list_slack_channels`: List available channels
|
||||
- `get_slack_thread`: Get thread messages
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="GitHub Integration">
|
||||
GitHub repository operations:
|
||||
|
||||
```json
|
||||
{
|
||||
"github": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-github"],
|
||||
"env": {
|
||||
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_your_token"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Available Tools:**
|
||||
- `create_or_update_file`: Create/update repository files
|
||||
- `search_repositories`: Search GitHub repositories
|
||||
- `create_issue`: Create issues
|
||||
- `create_pull_request`: Create pull requests
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Google Drive">
|
||||
Google Drive file operations:
|
||||
|
||||
```json
|
||||
{
|
||||
"gdrive": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-gdrive"],
|
||||
"env": {
|
||||
"GDRIVE_CLIENT_ID": "your-client-id",
|
||||
"GDRIVE_CLIENT_SECRET": "your-client-secret",
|
||||
"GDRIVE_REDIRECT_URI": "your-redirect-uri"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Available Tools:**
|
||||
- `gdrive_search`: Search files and folders
|
||||
- `gdrive_read`: Read file contents
|
||||
- `gdrive_create`: Create new files
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Amap Maps (China)">
|
||||
Chinese mapping and location services:
|
||||
|
||||
```json
|
||||
{
|
||||
"amap": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@amap/amap-maps-mcp-server"],
|
||||
"env": {
|
||||
"AMAP_MAPS_API_KEY": "your-api-key"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Available Tools:**
|
||||
- `search_location`: Search for locations
|
||||
- `get_directions`: Get route directions
|
||||
- `reverse_geocode`: Convert coordinates to addresses
|
||||
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## Server Lifecycle Management
|
||||
|
||||
### Starting Servers
|
||||
|
||||
Servers are automatically started when:
|
||||
|
||||
- MCPHub boots up
|
||||
- A server is added via the dashboard or API
|
||||
- A server configuration is updated
|
||||
- A stopped server is manually restarted
|
||||
|
||||
### Stopping Servers
|
||||
|
||||
You can stop servers:
|
||||
|
||||
- **Via Dashboard**: Toggle the server status switch
|
||||
- **Via API**: Send a POST request to `/api/servers/{name}/toggle`
|
||||
- **Automatically**: Servers stop if they crash or encounter errors
|
||||
|
||||
### Restarting Servers
|
||||
|
||||
Servers are automatically restarted:
|
||||
|
||||
- When configuration changes are made
|
||||
- After environment variable updates
|
||||
- When manually triggered via dashboard or API
|
||||
|
||||
## Server Status Monitoring
|
||||
|
||||
### Status Indicators
|
||||
|
||||
Each server displays a status indicator:
|
||||
|
||||
- 🟢 **Running**: Server is active and responding
|
||||
- 🟡 **Starting**: Server is initializing
|
||||
- 🔴 **Stopped**: Server is not running
|
||||
- ⚠️ **Error**: Server encountered an error
|
||||
|
||||
### Real-time Logs
|
||||
|
||||
View server logs in real-time:
|
||||
|
||||
1. **Dashboard Logs**: Click on a server to view its logs
|
||||
2. **API Logs**: Access logs via `/api/logs` endpoint
|
||||
3. **Streaming Logs**: Subscribe to log streams via WebSocket
|
||||
|
||||
### Health Checks
|
||||
|
||||
MCPHub automatically performs health checks:
|
||||
|
||||
- **Initialization Check**: Verifies server starts successfully
|
||||
- **Tool Discovery**: Confirms available tools are detected
|
||||
- **Response Check**: Tests server responsiveness
|
||||
- **Resource Monitoring**: Tracks CPU and memory usage
|
||||
|
||||
## Configuration Management
|
||||
|
||||
### Environment Variables
|
||||
|
||||
Servers can use environment variables for configuration:
|
||||
|
||||
```json
|
||||
{
|
||||
"server-name": {
|
||||
"command": "python",
|
||||
"args": ["server.py"],
|
||||
"env": {
|
||||
"API_KEY": "${YOUR_API_KEY}",
|
||||
"DEBUG": "true",
|
||||
"MAX_CONNECTIONS": "10"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Environment Variable Expansion:**
|
||||
|
||||
- `${VAR_NAME}`: Expands to environment variable value
|
||||
- `${VAR_NAME:-default}`: Uses default if variable not set
|
||||
- `${VAR_NAME:+value}`: Uses value if variable is set
|
||||
|
||||
### Working Directory
|
||||
|
||||
Set the working directory for server execution:
|
||||
|
||||
```json
|
||||
{
|
||||
"server-name": {
|
||||
"command": "./local-script.sh",
|
||||
"args": [],
|
||||
"cwd": "/path/to/server/directory"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Command Variations
|
||||
|
||||
Different ways to specify server commands:
|
||||
|
||||
<Tabs>
|
||||
<Tab title="npm/npx">
|
||||
```json
|
||||
{
|
||||
"npm-server": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "package-name", "--option", "value"]
|
||||
}
|
||||
}
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="Python/uvx">
|
||||
```json
|
||||
{
|
||||
"python-server": {
|
||||
"command": "uvx",
|
||||
"args": ["package-name", "--config", "config.json"]
|
||||
}
|
||||
}
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="Direct Python">
|
||||
```json
|
||||
{
|
||||
"direct-python": {
|
||||
"command": "python",
|
||||
"args": ["-m", "module_name", "--arg", "value"]
|
||||
}
|
||||
}
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="Local Script">
|
||||
```json
|
||||
{
|
||||
"local-script": {
|
||||
"command": "./server.sh",
|
||||
"args": ["--port", "8080"],
|
||||
"cwd": "/path/to/script"
|
||||
}
|
||||
}
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
## Advanced Features
|
||||
|
||||
### Hot Reloading
|
||||
|
||||
MCPHub supports hot reloading of server configurations:
|
||||
|
||||
1. **Config File Changes**: Automatically detects changes to `mcp_settings.json`
|
||||
2. **Dashboard Updates**: Immediately applies changes made through the web interface
|
||||
3. **API Updates**: Real-time updates via REST API calls
|
||||
4. **Zero Downtime**: Graceful server restarts without affecting other servers
|
||||
|
||||
### Resource Limits
|
||||
|
||||
Control server resource usage:
|
||||
|
||||
```json
|
||||
{
|
||||
"resource-limited-server": {
|
||||
"command": "memory-intensive-server",
|
||||
"args": [],
|
||||
"limits": {
|
||||
"memory": "512MB",
|
||||
"cpu": "50%",
|
||||
"timeout": "30s"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Dependency Management
|
||||
|
||||
Handle server dependencies:
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Auto-installation">
|
||||
MCPHub can automatically install missing packages:
|
||||
|
||||
```json
|
||||
{
|
||||
"auto-install-server": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "package-that-might-not-exist"],
|
||||
"autoInstall": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Pre-installation Scripts">
|
||||
Run setup scripts before starting servers:
|
||||
|
||||
```json
|
||||
{
|
||||
"setup-server": {
|
||||
"preStart": ["npm install", "pip install -r requirements.txt"],
|
||||
"command": "python",
|
||||
"args": ["server.py"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Server Won't Start">
|
||||
**Check the following:**
|
||||
- Command is available in PATH
|
||||
- All required environment variables are set
|
||||
- Working directory exists and is accessible
|
||||
- Network ports are not blocked
|
||||
- Dependencies are installed
|
||||
|
||||
**Debug steps:**
|
||||
1. Check server logs in the dashboard
|
||||
2. Test command manually in terminal
|
||||
3. Verify environment variable expansion
|
||||
4. Check file permissions
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Server Keeps Crashing">
|
||||
**Common causes:**
|
||||
- Invalid configuration parameters
|
||||
- Missing API keys or credentials
|
||||
- Resource limits exceeded
|
||||
- Dependency conflicts
|
||||
|
||||
**Solutions:**
|
||||
1. Review server logs for error messages
|
||||
2. Test with minimal configuration
|
||||
3. Verify all credentials and API keys
|
||||
4. Check system resource availability
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Tools Not Appearing">
|
||||
**Possible issues:**
|
||||
- Server not fully initialized
|
||||
- Tool discovery timeout
|
||||
- Communication protocol mismatch
|
||||
- Server reporting errors
|
||||
|
||||
**Debug steps:**
|
||||
1. Wait for server initialization to complete
|
||||
2. Check server logs for tool registration messages
|
||||
3. Test direct communication with server
|
||||
4. Verify MCP protocol compatibility
|
||||
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## Next Steps
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Group Management" icon="users" href="/features/group-management">
|
||||
Organize servers into logical groups
|
||||
</Card>
|
||||
<Card title="Smart Routing" icon="route" href="/features/smart-routing">
|
||||
Set up AI-powered tool discovery
|
||||
</Card>
|
||||
<Card title="API Reference" icon="code" href="/api-reference/servers">
|
||||
Server management API documentation
|
||||
</Card>
|
||||
<Card title="Configuration Guide" icon="cog" href="/configuration/mcp-settings">
|
||||
Detailed configuration options
|
||||
</Card>
|
||||
</CardGroup>
|
||||
720
docs/features/smart-routing.mdx
Normal file
@@ -0,0 +1,720 @@
|
||||
---
|
||||
title: 'Smart Routing'
|
||||
description: 'AI-powered tool discovery using vector semantic search'
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
Smart Routing is MCPHub's intelligent tool discovery system that uses vector semantic search to automatically find the most relevant tools for any given task. Instead of manually specifying which tools to use, AI clients can describe what they want to accomplish, and Smart Routing will identify and provide access to the most appropriate tools.
|
||||
|
||||
## How Smart Routing Works
|
||||
|
||||
### 1. Tool Indexing
|
||||
|
||||
When servers start up, Smart Routing automatically:
|
||||
|
||||
- Discovers all available tools from MCP servers
|
||||
- Extracts tool metadata (names, descriptions, parameters)
|
||||
- Converts tool information to vector embeddings
|
||||
- Stores embeddings in PostgreSQL with pgvector
|
||||
|
||||
### 2. Semantic Search
|
||||
|
||||
When a query is made:
|
||||
|
||||
- User queries are converted to vector embeddings
|
||||
- Similarity search finds matching tools using cosine similarity
|
||||
- Dynamic thresholds filter out irrelevant results
|
||||
- Results are ranked by relevance score
|
||||
|
||||
### 3. Intelligent Filtering
|
||||
|
||||
Smart Routing applies several filters:
|
||||
|
||||
- **Relevance Threshold**: Only returns tools above similarity threshold
|
||||
- **Context Awareness**: Considers conversation context
|
||||
- **Tool Availability**: Ensures tools are currently accessible
|
||||
- **Permission Filtering**: Respects user access permissions
|
||||
|
||||
### 4. Tool Execution
|
||||
|
||||
Found tools can be directly executed:
|
||||
|
||||
- Parameter validation ensures correct tool usage
|
||||
- Error handling provides helpful feedback
|
||||
- Response formatting maintains consistency
|
||||
- Logging tracks tool usage for analytics
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Smart Routing requires additional setup compared to basic MCPHub usage:
|
||||
|
||||
### Required Components
|
||||
|
||||
1. **PostgreSQL with pgvector**: Vector database for embeddings storage
|
||||
2. **Embedding Service**: OpenAI API or compatible service
|
||||
3. **Environment Configuration**: Proper configuration variables
|
||||
|
||||
### Quick Setup
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Docker Compose">
|
||||
Use this `docker-compose.yml` for complete setup:
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
services:
|
||||
mcphub:
|
||||
image: samanhappy/mcphub:latest
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- DATABASE_URL=postgresql://mcphub:password@postgres:5432/mcphub
|
||||
- OPENAI_API_KEY=your_openai_api_key
|
||||
- ENABLE_SMART_ROUTING=true
|
||||
depends_on:
|
||||
- postgres
|
||||
volumes:
|
||||
- ./mcp_settings.json:/app/mcp_settings.json
|
||||
|
||||
postgres:
|
||||
image: pgvector/pgvector:pg16
|
||||
environment:
|
||||
- POSTGRES_DB=mcphub
|
||||
- POSTGRES_USER=mcphub
|
||||
- POSTGRES_PASSWORD=password
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "5432:5432"
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
```
|
||||
|
||||
Start with:
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
</Tab>
|
||||
|
||||
<Tab title="Manual Setup">
|
||||
1. **Install PostgreSQL with pgvector**:
|
||||
```bash
|
||||
# Using Docker
|
||||
docker run -d \
|
||||
--name mcphub-postgres \
|
||||
-e POSTGRES_DB=mcphub \
|
||||
-e POSTGRES_USER=mcphub \
|
||||
-e POSTGRES_PASSWORD=your_password \
|
||||
-p 5432:5432 \
|
||||
pgvector/pgvector:pg16
|
||||
```
|
||||
|
||||
2. **Set Environment Variables**:
|
||||
```bash
|
||||
export DATABASE_URL="postgresql://mcphub:your_password@localhost:5432/mcphub"
|
||||
export OPENAI_API_KEY="your_openai_api_key"
|
||||
export ENABLE_SMART_ROUTING="true"
|
||||
```
|
||||
|
||||
3. **Start MCPHub**:
|
||||
```bash
|
||||
mcphub
|
||||
```
|
||||
|
||||
</Tab>
|
||||
|
||||
<Tab title="Kubernetes">
|
||||
Deploy with these Kubernetes manifests:
|
||||
|
||||
```yaml
|
||||
# postgres-deployment.yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: postgres
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: postgres
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: postgres
|
||||
spec:
|
||||
containers:
|
||||
- name: postgres
|
||||
image: pgvector/pgvector:pg16
|
||||
env:
|
||||
- name: POSTGRES_DB
|
||||
value: mcphub
|
||||
- name: POSTGRES_USER
|
||||
value: mcphub
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-secret
|
||||
key: password
|
||||
ports:
|
||||
- containerPort: 5432
|
||||
---
|
||||
# mcphub-deployment.yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mcphub
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mcphub
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: mcphub
|
||||
spec:
|
||||
containers:
|
||||
- name: mcphub
|
||||
image: samanhappy/mcphub:latest
|
||||
env:
|
||||
- name: DATABASE_URL
|
||||
value: "postgresql://mcphub:password@postgres:5432/mcphub"
|
||||
- name: OPENAI_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: openai-secret
|
||||
key: api-key
|
||||
- name: ENABLE_SMART_ROUTING
|
||||
value: "true"
|
||||
ports:
|
||||
- containerPort: 3000
|
||||
```
|
||||
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
## Configuration
|
||||
|
||||
### Environment Variables
|
||||
|
||||
Configure Smart Routing with these environment variables:
|
||||
|
||||
```bash
|
||||
# Required
|
||||
DATABASE_URL=postgresql://user:password@host:5432/database
|
||||
OPENAI_API_KEY=your_openai_api_key
|
||||
|
||||
# Optional
|
||||
ENABLE_SMART_ROUTING=true
|
||||
EMBEDDING_MODEL=text-embedding-3-small
|
||||
SIMILARITY_THRESHOLD=0.7
|
||||
MAX_TOOLS_RETURNED=10
|
||||
EMBEDDING_BATCH_SIZE=100
|
||||
```
|
||||
|
||||
### Configuration Options
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Database Configuration">
|
||||
```bash
|
||||
# Full PostgreSQL connection string
|
||||
DATABASE_URL=postgresql://username:password@host:port/database?schema=public
|
||||
|
||||
# SSL configuration for cloud databases
|
||||
DATABASE_URL=postgresql://user:pass@host:5432/db?sslmode=require
|
||||
|
||||
# Connection pool settings
|
||||
DATABASE_POOL_SIZE=20
|
||||
DATABASE_TIMEOUT=30000
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Embedding Service">
|
||||
```bash
|
||||
# OpenAI (default)
|
||||
OPENAI_API_KEY=sk-your-api-key
|
||||
EMBEDDING_MODEL=text-embedding-3-small
|
||||
|
||||
# Azure OpenAI
|
||||
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
|
||||
AZURE_OPENAI_API_KEY=your-api-key
|
||||
AZURE_OPENAI_DEPLOYMENT=your-embedding-deployment
|
||||
|
||||
# Custom embedding service
|
||||
EMBEDDING_SERVICE_URL=https://your-embedding-service.com
|
||||
EMBEDDING_SERVICE_API_KEY=your-api-key
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Search Parameters">
|
||||
```bash
|
||||
# Similarity threshold (0.0 to 1.0)
|
||||
SIMILARITY_THRESHOLD=0.7
|
||||
|
||||
# Maximum tools to return
|
||||
MAX_TOOLS_RETURNED=10
|
||||
|
||||
# Minimum query length for smart routing
|
||||
MIN_QUERY_LENGTH=5
|
||||
|
||||
# Cache TTL for embeddings (seconds)
|
||||
EMBEDDING_CACHE_TTL=3600
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## Using Smart Routing
|
||||
|
||||
### Smart Routing Endpoint
|
||||
|
||||
Access Smart Routing through the special `$smart` endpoint:
|
||||
|
||||
<Tabs>
|
||||
<Tab title="HTTP MCP">
|
||||
```
|
||||
http://localhost:3000/mcp/$smart
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="SSE (Legacy)">
|
||||
```
|
||||
http://localhost:3000/sse/$smart
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### Basic Usage
|
||||
|
||||
Connect your AI client to the Smart Routing endpoint and make natural language requests:
|
||||
|
||||
```bash
|
||||
# Example: Find tools for web scraping
|
||||
curl -X POST http://localhost:3000/mcp/$smart \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "tools/search",
|
||||
"params": {
|
||||
"query": "scrape website content and extract text"
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
Response:
|
||||
|
||||
```json
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"result": {
|
||||
"tools": [
|
||||
{
|
||||
"name": "fetch_html",
|
||||
"server": "fetch",
|
||||
"description": "Fetch and parse HTML content from a URL",
|
||||
"relevanceScore": 0.92,
|
||||
"parameters": { ... }
|
||||
},
|
||||
{
|
||||
"name": "playwright_navigate",
|
||||
"server": "playwright",
|
||||
"description": "Navigate to a web page and extract content",
|
||||
"relevanceScore": 0.87,
|
||||
"parameters": { ... }
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Advanced Queries
|
||||
|
||||
Smart Routing supports various query types:
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Task-Based Queries">
|
||||
```bash
|
||||
# What you want to accomplish
|
||||
curl -X POST http://localhost:3000/mcp/$smart \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "tools/search",
|
||||
"params": {
|
||||
"query": "send a message to a slack channel"
|
||||
}
|
||||
}'
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Domain-Specific Queries">
|
||||
```bash
|
||||
# Specific domain or technology
|
||||
curl -X POST http://localhost:3000/mcp/$smart \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "tools/search",
|
||||
"params": {
|
||||
"query": "database operations SQL queries"
|
||||
}
|
||||
}'
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Action-Oriented Queries">
|
||||
```bash
|
||||
# Specific actions
|
||||
curl -X POST http://localhost:3000/mcp/$smart \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "tools/search",
|
||||
"params": {
|
||||
"query": "create file upload to github repository"
|
||||
}
|
||||
}'
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Context-Aware Queries">
|
||||
```bash
|
||||
# Include context for better results
|
||||
curl -X POST http://localhost:3000/mcp/$smart \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "tools/search",
|
||||
"params": {
|
||||
"query": "automated testing web application",
|
||||
"context": {
|
||||
"project": "e-commerce website",
|
||||
"technologies": ["React", "Node.js"],
|
||||
"environment": "staging"
|
||||
}
|
||||
}
|
||||
}'
|
||||
```
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
### Tool Execution
|
||||
|
||||
Once Smart Routing finds relevant tools, you can execute them directly:
|
||||
|
||||
```bash
|
||||
# Execute a found tool
|
||||
curl -X POST http://localhost:3000/mcp/$smart \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 2,
|
||||
"method": "tools/call",
|
||||
"params": {
|
||||
"name": "fetch_html",
|
||||
"arguments": {
|
||||
"url": "https://example.com"
|
||||
}
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
## Performance Optimization
|
||||
|
||||
### Embedding Cache
|
||||
|
||||
Smart Routing caches embeddings to improve performance:
|
||||
|
||||
```bash
|
||||
# Configure cache settings
|
||||
EMBEDDING_CACHE_TTL=3600 # Cache for 1 hour
|
||||
EMBEDDING_CACHE_SIZE=10000 # Cache up to 10k embeddings
|
||||
EMBEDDING_CACHE_CLEANUP=300 # Cleanup every 5 minutes
|
||||
```
|
||||
|
||||
### Batch Processing
|
||||
|
||||
Tools are indexed in batches for efficiency:
|
||||
|
||||
```bash
|
||||
# Batch size for embedding generation
|
||||
EMBEDDING_BATCH_SIZE=100
|
||||
|
||||
# Concurrent embedding requests
|
||||
EMBEDDING_CONCURRENCY=5
|
||||
|
||||
# Index update frequency
|
||||
INDEX_UPDATE_INTERVAL=3600 # Re-index every hour
|
||||
```
|
||||
|
||||
### Database Optimization
|
||||
|
||||
Optimize PostgreSQL for vector operations:
|
||||
|
||||
```sql
|
||||
-- Create indexes for better performance
|
||||
CREATE INDEX ON tool_embeddings USING hnsw (embedding vector_cosine_ops);
|
||||
|
||||
-- Adjust PostgreSQL settings
|
||||
ALTER SYSTEM SET shared_preload_libraries = 'vector';
|
||||
ALTER SYSTEM SET max_connections = 200;
|
||||
ALTER SYSTEM SET shared_buffers = '256MB';
|
||||
ALTER SYSTEM SET effective_cache_size = '1GB';
|
||||
```
|
||||
|
||||
## Monitoring and Analytics
|
||||
|
||||
### Smart Routing Metrics
|
||||
|
||||
Monitor Smart Routing performance:
|
||||
|
||||
```bash
|
||||
# Get Smart Routing statistics
|
||||
curl http://localhost:3000/api/smart-routing/stats \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
```
|
||||
|
||||
Response includes:
|
||||
|
||||
- Query count and frequency
|
||||
- Average response time
|
||||
- Embedding cache hit rate
|
||||
- Most popular tools
|
||||
- Query patterns
|
||||
|
||||
### Tool Usage Analytics
|
||||
|
||||
Track which tools are found and used:
|
||||
|
||||
```bash
|
||||
# Get tool usage analytics
|
||||
curl http://localhost:3000/api/smart-routing/analytics \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
```
|
||||
|
||||
Metrics include:
|
||||
|
||||
- Tool discovery rates
|
||||
- Execution success rates
|
||||
- User satisfaction scores
|
||||
- Query-to-execution conversion
|
||||
|
||||
### Performance Monitoring
|
||||
|
||||
Monitor system performance:
|
||||
|
||||
```bash
|
||||
# Database performance
|
||||
curl http://localhost:3000/api/smart-routing/db-stats \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
|
||||
# Embedding service status
|
||||
curl http://localhost:3000/api/smart-routing/embedding-stats \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
```
|
||||
|
||||
## Advanced Features
|
||||
|
||||
### Custom Embeddings
|
||||
|
||||
Use custom embedding models:
|
||||
|
||||
```bash
|
||||
# Hugging Face models
|
||||
EMBEDDING_SERVICE=huggingface
|
||||
HUGGINGFACE_MODEL=sentence-transformers/all-MiniLM-L6-v2
|
||||
HUGGINGFACE_API_KEY=your_api_key
|
||||
|
||||
# Local embedding service
|
||||
EMBEDDING_SERVICE=local
|
||||
EMBEDDING_SERVICE_URL=http://localhost:8080/embeddings
|
||||
```
|
||||
|
||||
### Query Enhancement
|
||||
|
||||
Enhance queries for better results:
|
||||
|
||||
```json
|
||||
{
|
||||
"queryEnhancement": {
|
||||
"enabled": true,
|
||||
"expandAcronyms": true,
|
||||
"addSynonyms": true,
|
||||
"contextualExpansion": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Result Filtering
|
||||
|
||||
Filter results based on criteria:
|
||||
|
||||
```json
|
||||
{
|
||||
"resultFiltering": {
|
||||
"minRelevanceScore": 0.7,
|
||||
"maxResults": 10,
|
||||
"preferredServers": ["fetch", "playwright"],
|
||||
"excludeServers": ["deprecated-server"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Feedback Learning
|
||||
|
||||
Improve results based on user feedback:
|
||||
|
||||
```bash
|
||||
# Provide feedback on search results
|
||||
curl -X POST http://localhost:3000/api/smart-routing/feedback \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
|
||||
-d '{
|
||||
"queryId": "search-123",
|
||||
"toolName": "fetch_html",
|
||||
"rating": 5,
|
||||
"successful": true,
|
||||
"comments": "Perfect tool for the task"
|
||||
}'
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Database Connection Issues">
|
||||
**Symptoms:**
|
||||
- Smart Routing not available
|
||||
- Database connection errors
|
||||
- Embedding storage failures
|
||||
|
||||
**Solutions:**
|
||||
1. Verify PostgreSQL is running
|
||||
2. Check DATABASE_URL format
|
||||
3. Ensure pgvector extension is installed
|
||||
4. Test connection manually:
|
||||
```bash
|
||||
psql $DATABASE_URL -c "SELECT 1;"
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Embedding Service Problems">
|
||||
**Symptoms:**
|
||||
- Tool indexing failures
|
||||
- Query processing errors
|
||||
- API rate limit errors
|
||||
|
||||
**Solutions:**
|
||||
1. Verify API key validity
|
||||
2. Check network connectivity
|
||||
3. Monitor rate limits
|
||||
4. Test embedding service:
|
||||
```bash
|
||||
curl -X POST https://api.openai.com/v1/embeddings \
|
||||
-H "Authorization: Bearer $OPENAI_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"input": "test", "model": "text-embedding-3-small"}'
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Poor Search Results">
|
||||
**Symptoms:**
|
||||
- Irrelevant tools returned
|
||||
- Low relevance scores
|
||||
- Missing expected tools
|
||||
|
||||
**Solutions:**
|
||||
1. Adjust similarity threshold
|
||||
2. Re-index tools with better descriptions
|
||||
3. Use more specific queries
|
||||
4. Check tool metadata quality
|
||||
```bash
|
||||
# Re-index all tools
|
||||
curl -X POST http://localhost:3000/api/smart-routing/reindex \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Performance Issues">
|
||||
**Symptoms:**
|
||||
- Slow query responses
|
||||
- High database load
|
||||
- Memory usage spikes
|
||||
|
||||
**Solutions:**
|
||||
1. Optimize database configuration
|
||||
2. Increase cache sizes
|
||||
3. Reduce batch sizes
|
||||
4. Monitor system resources
|
||||
```bash
|
||||
# Check system performance
|
||||
curl http://localhost:3000/api/smart-routing/performance \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Query Writing
|
||||
|
||||
<Tip>
|
||||
**Be Descriptive**: Use specific, descriptive language in queries for better tool matching.
|
||||
</Tip>
|
||||
|
||||
<Tip>
|
||||
**Include Context**: Provide relevant context about your task or domain for more accurate results.
|
||||
</Tip>
|
||||
|
||||
<Tip>**Use Natural Language**: Write queries as you would describe the task to a human.</Tip>
|
||||
|
||||
### Tool Descriptions
|
||||
|
||||
<Warning>
|
||||
**Quality Metadata**: Ensure MCP servers provide high-quality tool descriptions and metadata.
|
||||
</Warning>
|
||||
|
||||
<Warning>**Regular Updates**: Keep tool descriptions current as functionality evolves.</Warning>
|
||||
|
||||
<Warning>
|
||||
**Consistent Naming**: Use consistent naming conventions across tools and servers.
|
||||
</Warning>
|
||||
|
||||
### System Maintenance
|
||||
|
||||
<Info>**Regular Re-indexing**: Periodically re-index tools to ensure embedding quality.</Info>
|
||||
|
||||
<Info>**Monitor Performance**: Track query patterns and optimize based on usage.</Info>
|
||||
|
||||
<Info>
|
||||
**Update Models**: Consider updating to newer embedding models as they become available.
|
||||
</Info>
|
||||
|
||||
## Next Steps
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Authentication" icon="shield" href="/features/authentication">
|
||||
User management and access control
|
||||
</Card>
|
||||
<Card title="Monitoring" icon="chart-line" href="/features/monitoring">
|
||||
System monitoring and analytics
|
||||
</Card>
|
||||
<Card title="API Reference" icon="code" href="/api-reference/smart-routing">
|
||||
Complete Smart Routing API documentation
|
||||
</Card>
|
||||
<Card title="Configuration" icon="cog" href="/configuration/environment-variables">
|
||||
Advanced configuration options
|
||||
</Card>
|
||||
</CardGroup>
|
||||
BIN
docs/images/checks-passed.png
Normal file
|
After Width: | Height: | Size: 157 KiB |
BIN
docs/images/hero-dark.png
Normal file
|
After Width: | Height: | Size: 108 KiB |
BIN
docs/images/hero-light.png
Normal file
|
After Width: | Height: | Size: 102 KiB |
95
docs/index.mdx
Normal file
@@ -0,0 +1,95 @@
|
||||
---
|
||||
title: MCPHub Documentation
|
||||
description: 'The Unified Hub for Model Context Protocol (MCP) Servers'
|
||||
---
|
||||
|
||||
<img className="block dark:hidden" src="/images/hero-light.png" alt="Hero Light" />
|
||||
<img className="hidden dark:block" src="/images/hero-dark.png" alt="Hero Dark" />
|
||||
|
||||
# Welcome to MCPHub
|
||||
|
||||
MCPHub makes it easy to manage and scale multiple MCP (Model Context Protocol) servers by organizing them into flexible Streamable HTTP (SSE) endpoints—supporting access to all servers, individual servers, or logical server groups.
|
||||
|
||||
## Key Features
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Unified Management" icon="server" href="/features/server-management">
|
||||
Centrally manage multiple MCP servers with hot-swappable configuration
|
||||
</Card>
|
||||
<Card title="Smart Routing" icon="route" href="/features/smart-routing">
|
||||
AI-powered tool discovery using vector semantic search
|
||||
</Card>
|
||||
<Card title="Group Management" icon="users" href="/features/group-management">
|
||||
Organize servers into logical groups for streamlined access control
|
||||
</Card>
|
||||
<Card title="Real-time Monitoring" icon="chart-line" href="/features/monitoring">
|
||||
Monitor server status and performance from a unified dashboard
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Quick Start
|
||||
|
||||
Get MCPHub running in minutes with Docker:
|
||||
|
||||
```bash
|
||||
docker run -p 3000:3000 samanhappy/mcphub
|
||||
```
|
||||
|
||||
Or with custom configuration:
|
||||
|
||||
```bash
|
||||
docker run -p 3000:3000 -v $(pwd)/mcp_settings.json:/app/mcp_settings.json samanhappy/mcphub
|
||||
```
|
||||
|
||||
Access the dashboard at `http://localhost:3000` with default credentials:
|
||||
|
||||
- Username: `admin`
|
||||
- Password: `admin123`
|
||||
|
||||
## Core Concepts
|
||||
|
||||
### MCP Endpoints
|
||||
|
||||
MCPHub provides multiple ways to access your MCP servers:
|
||||
|
||||
- **Unified Access**: `http://localhost:3000/mcp` - Access all servers
|
||||
- **Group Access**: `http://localhost:3000/mcp/{group}` - Access specific groups
|
||||
- **Server Access**: `http://localhost:3000/mcp/{server}` - Access individual servers
|
||||
- **Smart Routing**: `http://localhost:3000/mcp/$smart` - AI-powered tool discovery
|
||||
|
||||
### Protocol Support
|
||||
|
||||
- **HTTP MCP**: Modern streamable HTTP interface (recommended)
|
||||
- **SSE**: Server-Sent Events for legacy compatibility
|
||||
- **stdio**: Native MCP protocol for server communication
|
||||
|
||||
## Getting Started
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Quick Start Guide" icon="rocket" href="/quickstart">
|
||||
Get MCPHub running in 5 minutes
|
||||
</Card>
|
||||
<Card title="Installation Guide" icon="download" href="/installation">
|
||||
Detailed installation instructions for all platforms
|
||||
</Card>
|
||||
<Card title="Configuration" icon="cog" href="/configuration/mcp-settings">
|
||||
Learn how to configure your MCP servers
|
||||
</Card>
|
||||
<Card title="API Reference" icon="code" href="/api-reference/introduction">
|
||||
Complete API documentation
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Community & Support
|
||||
|
||||
<CardGroup cols={3}>
|
||||
<Card title="GitHub" icon="github" href="https://github.com/samanhappy/mcphub">
|
||||
Source code and issue tracking
|
||||
</Card>
|
||||
<Card title="Discord" icon="discord" href="https://discord.gg/qMKNsn5Q">
|
||||
Join our community discussions
|
||||
</Card>
|
||||
<Card title="Sponsor" icon="heart" href="https://ko-fi.com/samanhappy">
|
||||
Support the project development
|
||||
</Card>
|
||||
</CardGroup>
|
||||
575
docs/installation.mdx
Normal file
@@ -0,0 +1,575 @@
|
||||
---
|
||||
title: 'Installation Guide'
|
||||
description: 'Detailed installation instructions for all platforms'
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before installing MCPHub, ensure you have the following prerequisites:
|
||||
|
||||
- **Node.js** 18+ (for local development)
|
||||
- **Docker** (recommended for production)
|
||||
- **pnpm** (for local development)
|
||||
|
||||
Optional for Smart Routing:
|
||||
|
||||
- **PostgreSQL** with pgvector extension
|
||||
- **OpenAI API Key** or compatible embedding service
|
||||
|
||||
## Installation Methods
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Docker (Recommended)">
|
||||
### Docker Installation
|
||||
|
||||
Docker is the recommended way to deploy MCPHub in production.
|
||||
|
||||
#### 1. Basic Installation
|
||||
|
||||
```bash
|
||||
# Pull the latest image
|
||||
docker pull samanhappy/mcphub:latest
|
||||
|
||||
# Run with default settings
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
-p 3000:3000 \
|
||||
samanhappy/mcphub:latest
|
||||
```
|
||||
|
||||
#### 2. With Custom Configuration
|
||||
|
||||
```bash
|
||||
# Create your configuration file
|
||||
cat > mcp_settings.json << 'EOF'
|
||||
{
|
||||
"mcpServers": {
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"]
|
||||
},
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"]
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Run with mounted config
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
-p 3000:3000 \
|
||||
-v $(pwd)/mcp_settings.json:/app/mcp_settings.json \
|
||||
samanhappy/mcphub:latest
|
||||
```
|
||||
|
||||
#### 3. With Environment Variables
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
-p 3000:3000 \
|
||||
-e PORT=3000 \
|
||||
-e BASE_PATH="" \
|
||||
-e REQUEST_TIMEOUT=60000 \
|
||||
samanhappy/mcphub:latest
|
||||
```
|
||||
|
||||
#### 4. Docker Compose
|
||||
|
||||
Create a `docker-compose.yml` file:
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
services:
|
||||
mcphub:
|
||||
image: samanhappy/mcphub:latest
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- ./mcp_settings.json:/app/mcp_settings.json
|
||||
environment:
|
||||
- PORT=3000
|
||||
- BASE_PATH=""
|
||||
- REQUEST_TIMEOUT=60000
|
||||
restart: unless-stopped
|
||||
|
||||
# Optional: PostgreSQL for Smart Routing
|
||||
postgres:
|
||||
image: pgvector/pgvector:pg16
|
||||
environment:
|
||||
POSTGRES_DB: mcphub
|
||||
POSTGRES_USER: mcphub
|
||||
POSTGRES_PASSWORD: mcphub_password
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "5432:5432"
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
```
|
||||
|
||||
Run with:
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
</Tab>
|
||||
|
||||
<Tab title="npm Package">
|
||||
### npm Package Installation
|
||||
|
||||
Install MCPHub as a global npm package:
|
||||
|
||||
#### 1. Global Installation
|
||||
|
||||
```bash
|
||||
# Install globally
|
||||
npm install -g @samanhappy/mcphub
|
||||
|
||||
# Or with yarn
|
||||
yarn global add @samanhappy/mcphub
|
||||
|
||||
# Or with pnpm
|
||||
pnpm add -g @samanhappy/mcphub
|
||||
```
|
||||
|
||||
#### 2. Running MCPHub
|
||||
|
||||
```bash
|
||||
# Run with default settings
|
||||
mcphub
|
||||
|
||||
# Run with custom port
|
||||
PORT=8080 mcphub
|
||||
|
||||
# Run with custom config path
|
||||
MCP_SETTINGS_PATH=/path/to/mcp_settings.json mcphub
|
||||
```
|
||||
|
||||
#### 3. Local Installation
|
||||
|
||||
You can also install MCPHub locally in a project:
|
||||
|
||||
```bash
|
||||
# Create a new directory
|
||||
mkdir my-mcphub
|
||||
cd my-mcphub
|
||||
|
||||
# Initialize package.json
|
||||
npm init -y
|
||||
|
||||
# Install MCPHub locally
|
||||
npm install @samanhappy/mcphub
|
||||
|
||||
# Create a start script
|
||||
echo '#!/bin/bash\nnpx mcphub' > start.sh
|
||||
chmod +x start.sh
|
||||
|
||||
# Run MCPHub
|
||||
./start.sh
|
||||
```
|
||||
|
||||
</Tab>
|
||||
|
||||
<Tab title="Local Development">
|
||||
### Local Development Setup
|
||||
|
||||
For development, customization, or contribution:
|
||||
|
||||
#### 1. Clone Repository
|
||||
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://github.com/samanhappy/mcphub.git
|
||||
cd mcphub
|
||||
```
|
||||
|
||||
#### 2. Install Dependencies
|
||||
|
||||
```bash
|
||||
# Install dependencies with pnpm (recommended)
|
||||
pnpm install
|
||||
|
||||
# Or with npm
|
||||
npm install
|
||||
|
||||
# Or with yarn
|
||||
yarn install
|
||||
```
|
||||
|
||||
#### 3. Development Mode
|
||||
|
||||
```bash
|
||||
# Start both backend and frontend in development mode
|
||||
pnpm dev
|
||||
|
||||
# This will start:
|
||||
# - Backend on http://localhost:3001
|
||||
# - Frontend on http://localhost:5173
|
||||
# - Frontend proxies API calls to backend
|
||||
```
|
||||
|
||||
#### 4. Build for Production
|
||||
|
||||
```bash
|
||||
# Build both backend and frontend
|
||||
pnpm build
|
||||
|
||||
# Start production server
|
||||
pnpm start
|
||||
```
|
||||
|
||||
#### 5. Development Scripts
|
||||
|
||||
```bash
|
||||
# Backend only (for API development)
|
||||
pnpm backend:dev
|
||||
|
||||
# Frontend only (when backend is running separately)
|
||||
pnpm frontend:dev
|
||||
|
||||
# Run tests
|
||||
pnpm test
|
||||
|
||||
# Lint code
|
||||
pnpm lint
|
||||
|
||||
# Format code
|
||||
pnpm format
|
||||
```
|
||||
|
||||
<Note>
|
||||
On Windows, you may need to run backend and frontend separately:
|
||||
```bash
|
||||
# Terminal 1: Backend
|
||||
pnpm backend:dev
|
||||
|
||||
# Terminal 2: Frontend
|
||||
pnpm frontend:dev
|
||||
```
|
||||
</Note>
|
||||
|
||||
</Tab>
|
||||
|
||||
<Tab title="Kubernetes">
|
||||
### Kubernetes Deployment
|
||||
|
||||
Deploy MCPHub on Kubernetes with these manifests:
|
||||
|
||||
#### 1. ConfigMap for Settings
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: mcphub-config
|
||||
data:
|
||||
mcp_settings.json: |
|
||||
{
|
||||
"mcpServers": {
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"]
|
||||
},
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 2. Deployment
|
||||
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mcphub
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mcphub
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: mcphub
|
||||
spec:
|
||||
containers:
|
||||
- name: mcphub
|
||||
image: samanhappy/mcphub:latest
|
||||
ports:
|
||||
- containerPort: 3000
|
||||
env:
|
||||
- name: PORT
|
||||
value: "3000"
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: /app/mcp_settings.json
|
||||
subPath: mcp_settings.json
|
||||
volumes:
|
||||
- name: config
|
||||
configMap:
|
||||
name: mcphub-config
|
||||
```
|
||||
|
||||
#### 3. Service
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: mcphub-service
|
||||
spec:
|
||||
selector:
|
||||
app: mcphub
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 3000
|
||||
type: ClusterIP
|
||||
```
|
||||
|
||||
#### 4. Ingress (Optional)
|
||||
|
||||
```yaml
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: mcphub-ingress
|
||||
annotations:
|
||||
nginx.ingress.kubernetes.io/proxy-buffering: "off"
|
||||
spec:
|
||||
rules:
|
||||
- host: mcphub.yourdomain.com
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: mcphub-service
|
||||
port:
|
||||
number: 80
|
||||
```
|
||||
|
||||
Deploy with:
|
||||
```bash
|
||||
kubectl apply -f mcphub-configmap.yaml
|
||||
kubectl apply -f mcphub-deployment.yaml
|
||||
kubectl apply -f mcphub-service.yaml
|
||||
kubectl apply -f mcphub-ingress.yaml
|
||||
```
|
||||
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
## Smart Routing Setup (Optional)
|
||||
|
||||
Smart Routing provides AI-powered tool discovery using vector semantic search.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
1. **PostgreSQL with pgvector**
|
||||
2. **OpenAI API Key** (or compatible embedding service)
|
||||
|
||||
### Database Setup
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Docker PostgreSQL">
|
||||
```bash
|
||||
# Run PostgreSQL with pgvector
|
||||
docker run -d \
|
||||
--name mcphub-postgres \
|
||||
-e POSTGRES_DB=mcphub \
|
||||
-e POSTGRES_USER=mcphub \
|
||||
-e POSTGRES_PASSWORD=your_password \
|
||||
-p 5432:5432 \
|
||||
pgvector/pgvector:pg16
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="Existing PostgreSQL">
|
||||
If you have an existing PostgreSQL instance:
|
||||
|
||||
```sql
|
||||
-- Connect to your PostgreSQL instance
|
||||
-- Create database
|
||||
CREATE DATABASE mcphub;
|
||||
|
||||
-- Connect to the mcphub database
|
||||
\c mcphub;
|
||||
|
||||
-- Enable pgvector extension
|
||||
CREATE EXTENSION IF NOT EXISTS vector;
|
||||
```
|
||||
|
||||
</Tab>
|
||||
|
||||
<Tab title="Cloud PostgreSQL">
|
||||
For cloud providers (AWS RDS, Google Cloud SQL, etc.):
|
||||
|
||||
1. Enable the pgvector extension in your cloud provider's console
|
||||
2. Create a database named `mcphub`
|
||||
3. Note down the connection details
|
||||
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### Environment Configuration
|
||||
|
||||
Set the following environment variables:
|
||||
|
||||
```bash
|
||||
# Database connection
|
||||
DATABASE_URL=postgresql://mcphub:your_password@localhost:5432/mcphub
|
||||
|
||||
# OpenAI API for embeddings
|
||||
OPENAI_API_KEY=your_openai_api_key
|
||||
|
||||
# Optional: Custom embedding model
|
||||
EMBEDDING_MODEL=text-embedding-3-small
|
||||
|
||||
# Optional: Enable smart routing
|
||||
ENABLE_SMART_ROUTING=true
|
||||
```
|
||||
|
||||
## Verification
|
||||
|
||||
After installation, verify MCPHub is working:
|
||||
|
||||
### 1. Health Check
|
||||
|
||||
```bash
|
||||
curl http://localhost:3000/api/health
|
||||
```
|
||||
|
||||
Expected response:
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
"version": "x.x.x",
|
||||
"uptime": 123
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Dashboard Access
|
||||
|
||||
Open your browser and navigate to:
|
||||
|
||||
```
|
||||
http://localhost:3000
|
||||
```
|
||||
|
||||
### 3. API Test
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/mcp \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "tools/list",
|
||||
"params": {}
|
||||
}'
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Docker Issues">
|
||||
**Port already in use:**
|
||||
```bash
|
||||
# Check what's using port 3000
|
||||
lsof -i :3000
|
||||
|
||||
# Use a different port
|
||||
docker run -p 8080:3000 samanhappy/mcphub
|
||||
```
|
||||
|
||||
**Container won't start:**
|
||||
```bash
|
||||
# Check container logs
|
||||
docker logs mcphub
|
||||
|
||||
# Run interactively for debugging
|
||||
docker run -it --rm samanhappy/mcphub /bin/bash
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="npm Installation Issues">
|
||||
**Permission errors:**
|
||||
```bash
|
||||
# Use npx instead of global install
|
||||
npx @samanhappy/mcphub
|
||||
|
||||
# Or fix npm permissions
|
||||
npm config set prefix ~/.npm-global
|
||||
export PATH=~/.npm-global/bin:$PATH
|
||||
```
|
||||
|
||||
**Node version issues:**
|
||||
```bash
|
||||
# Check Node version
|
||||
node --version
|
||||
|
||||
# Install Node 18+ using nvm
|
||||
nvm install 18
|
||||
nvm use 18
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Network Issues">
|
||||
**Can't access dashboard:**
|
||||
- Check if MCPHub is running: `ps aux | grep mcphub`
|
||||
- Verify port binding: `netstat -tlnp | grep 3000`
|
||||
- Check firewall settings
|
||||
- Try accessing via `127.0.0.1:3000` instead of `localhost:3000`
|
||||
|
||||
**AI clients can't connect:**
|
||||
- Ensure the endpoint URL is correct
|
||||
- Check if MCPHub is behind a proxy
|
||||
- Verify network policies in Kubernetes/Docker environments
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Smart Routing Issues">
|
||||
**Database connection failed:**
|
||||
```bash
|
||||
# Test database connection
|
||||
psql $DATABASE_URL -c "SELECT 1;"
|
||||
|
||||
# Check if pgvector is installed
|
||||
psql $DATABASE_URL -c "CREATE EXTENSION IF NOT EXISTS vector;"
|
||||
```
|
||||
|
||||
**Embedding service errors:**
|
||||
- Verify OpenAI API key is valid
|
||||
- Check internet connectivity
|
||||
- Monitor rate limits
|
||||
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## Next Steps
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Configuration" icon="cog" href="/configuration/mcp-settings">
|
||||
Configure your MCP servers and settings
|
||||
</Card>
|
||||
<Card title="Quick Start" icon="rocket" href="/quickstart">
|
||||
Get up and running in 5 minutes
|
||||
</Card>
|
||||
<Card title="Server Management" icon="server" href="/features/server-management">
|
||||
Learn how to manage your MCP servers
|
||||
</Card>
|
||||
<Card title="API Reference" icon="code" href="/api-reference/introduction">
|
||||
Explore the complete API documentation
|
||||
</Card>
|
||||
</CardGroup>
|
||||
21
docs/logo/dark.svg
Normal file
|
After Width: | Height: | Size: 12 KiB |
21
docs/logo/light.svg
Normal file
|
After Width: | Height: | Size: 12 KiB |
228
docs/quickstart.mdx
Normal file
@@ -0,0 +1,228 @@
|
||||
---
|
||||
title: 'Quick Start Guide'
|
||||
description: 'Get MCPHub running in 5 minutes'
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Docker (Recommended)">
|
||||
The fastest way to get started with MCPHub is using Docker:
|
||||
|
||||
```bash
|
||||
# Run with default configuration
|
||||
docker run -p 3000:3000 samanhappy/mcphub
|
||||
```
|
||||
|
||||
Or mount your custom configuration:
|
||||
|
||||
```bash
|
||||
# Run with custom MCP settings
|
||||
docker run -p 3000:3000 \
|
||||
-v $(pwd)/mcp_settings.json:/app/mcp_settings.json \
|
||||
samanhappy/mcphub
|
||||
```
|
||||
|
||||
</Tab>
|
||||
<Tab title="Local Development">
|
||||
For development or customization:
|
||||
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://github.com/samanhappy/mcphub.git
|
||||
cd mcphub
|
||||
|
||||
# Install dependencies
|
||||
pnpm install
|
||||
|
||||
# Start development servers
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
This starts both backend (port 3001) and frontend (port 5173) in development mode.
|
||||
|
||||
</Tab>
|
||||
<Tab title="npm Package">
|
||||
Install MCPHub as a global package:
|
||||
|
||||
```bash
|
||||
# Install globally
|
||||
npm install -g @samanhappy/mcphub
|
||||
|
||||
# Run MCPHub
|
||||
mcphub
|
||||
```
|
||||
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
## Initial Setup
|
||||
|
||||
### 1. Access the Dashboard
|
||||
|
||||
Open your browser and navigate to:
|
||||
|
||||
```
|
||||
http://localhost:3000
|
||||
```
|
||||
|
||||
### 2. Login
|
||||
|
||||
Use the default credentials:
|
||||
|
||||
- **Username**: `admin`
|
||||
- **Password**: `admin123`
|
||||
|
||||
<Warning>Change these default credentials immediately after first login for security.</Warning>
|
||||
|
||||
### 3. Configure Your First MCP Server
|
||||
|
||||
1. Click **"Add Server"** in the dashboard
|
||||
2. Enter server details:
|
||||
- **Name**: A unique identifier (e.g., `fetch`)
|
||||
- **Command**: The executable command (`uvx`)
|
||||
- **Args**: Command arguments (`["mcp-server-fetch"]`)
|
||||
- **Environment**: Any required environment variables
|
||||
|
||||
Example configuration for a fetch server:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "fetch",
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"],
|
||||
"env": {}
|
||||
}
|
||||
```
|
||||
|
||||
## Basic Usage
|
||||
|
||||
### Connecting AI Clients
|
||||
|
||||
Once your servers are configured, connect your AI clients using MCPHub endpoints:
|
||||
|
||||
<Tabs>
|
||||
<Tab title="All Servers">
|
||||
Access all configured MCP servers: ``` http://localhost:3000/mcp ```
|
||||
</Tab>
|
||||
<Tab title="Specific Group">
|
||||
Access servers in a specific group: ``` http://localhost:3000/mcp/{group - name}
|
||||
```
|
||||
</Tab>
|
||||
<Tab title="Individual Server">
|
||||
Access a single server: ``` http://localhost:3000/mcp/{server - name}
|
||||
```
|
||||
</Tab>
|
||||
<Tab title="Smart Routing">
|
||||
Use AI-powered tool discovery: ``` http://localhost:3000/mcp/$smart ```
|
||||
<Info>Smart routing requires PostgreSQL with pgvector and an OpenAI API key.</Info>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### Example: Adding Popular MCP Servers
|
||||
|
||||
Here are some popular MCP servers you can add:
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Web Fetch Server">
|
||||
```json
|
||||
{
|
||||
"name": "fetch",
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"]
|
||||
}
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Playwright Browser Automation">
|
||||
```json
|
||||
{
|
||||
"name": "playwright",
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"]
|
||||
}
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Amap Maps (with API key)">
|
||||
```json
|
||||
{
|
||||
"name": "amap",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@amap/amap-maps-mcp-server"],
|
||||
"env": {
|
||||
"AMAP_MAPS_API_KEY": "your-api-key-here"
|
||||
}
|
||||
}
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Slack Integration">
|
||||
```json
|
||||
{
|
||||
"name": "slack",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-slack"],
|
||||
"env": {
|
||||
"SLACK_BOT_TOKEN": "your-bot-token",
|
||||
"SLACK_TEAM_ID": "your-team-id"
|
||||
}
|
||||
}
|
||||
```
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## Verification
|
||||
|
||||
Test your setup by making a simple request:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/mcp \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "tools/list",
|
||||
"params": {}
|
||||
}'
|
||||
```
|
||||
|
||||
You should receive a list of available tools from your configured MCP servers.
|
||||
|
||||
## Next Steps
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Server Management" icon="server" href="/features/server-management">
|
||||
Learn advanced server configuration and management
|
||||
</Card>
|
||||
<Card title="Group Management" icon="users" href="/features/group-management">
|
||||
Organize servers into logical groups
|
||||
</Card>
|
||||
<Card title="Smart Routing" icon="route" href="/features/smart-routing">
|
||||
Set up AI-powered tool discovery
|
||||
</Card>
|
||||
<Card title="API Reference" icon="code" href="/api-reference/introduction">
|
||||
Explore the complete API documentation
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Server won't start">
|
||||
- Check if the MCP server command is accessible in your PATH - Verify environment variables are
|
||||
correctly set - Check MCPHub logs for detailed error messages
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Can't connect from AI client">
|
||||
- Ensure MCPHub is running on the correct port - Check firewall settings - Verify the endpoint
|
||||
URL format
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Authentication issues">
|
||||
- Verify credentials are correct - Check if JWT token is valid - Try clearing browser cache and
|
||||
cookies
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
Need more help? Join our [Discord community](https://discord.gg/qMKNsn5Q) for support!
|
||||
4
docs/snippets/snippet-intro.mdx
Normal file
@@ -0,0 +1,4 @@
|
||||
One of the core principles of software development is DRY (Don't Repeat
|
||||
Yourself). This is a principle that apply to documentation as
|
||||
well. If you find yourself repeating the same content in multiple places, you
|
||||
should consider creating a custom snippet to keep your content in sync.
|
||||
572
docs/zh/api-reference/endpoint/create.mdx
Normal file
@@ -0,0 +1,572 @@
|
||||
---
|
||||
title: '创建资源'
|
||||
description: '创建新的 MCP 服务器、用户和组'
|
||||
---
|
||||
|
||||
## 创建服务器
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
POST /api/servers
|
||||
```
|
||||
|
||||
### 请求
|
||||
|
||||
#### 请求头
|
||||
|
||||
```http
|
||||
Content-Type: application/json
|
||||
Authorization: Bearer YOUR_JWT_TOKEN
|
||||
```
|
||||
|
||||
#### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "文件系统服务器",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/allowed/path"],
|
||||
"env": {
|
||||
"NODE_ENV": "production",
|
||||
"DEBUG": "mcp:*",
|
||||
"MAX_FILES": "1000"
|
||||
},
|
||||
"cwd": "/app/workspace",
|
||||
"timeout": 30000,
|
||||
"retries": 3,
|
||||
"enabled": true,
|
||||
"description": "提供文件系统访问的 MCP 服务器",
|
||||
"tags": ["filesystem", "production"],
|
||||
"healthCheck": {
|
||||
"enabled": true,
|
||||
"interval": 30000,
|
||||
"timeout": 5000,
|
||||
"retries": 3,
|
||||
"endpoint": "/health"
|
||||
},
|
||||
"resources": {
|
||||
"memory": {
|
||||
"limit": "512MB",
|
||||
"warning": "400MB"
|
||||
},
|
||||
"cpu": {
|
||||
"limit": "50%"
|
||||
}
|
||||
},
|
||||
"logging": {
|
||||
"level": "info",
|
||||
"file": "/var/log/mcphub/server.log",
|
||||
"maxSize": "100MB",
|
||||
"maxFiles": 5
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 必填字段
|
||||
|
||||
- `name` (string): 服务器唯一名称
|
||||
- `command` (string): 执行命令
|
||||
- `args` (array): 命令参数数组
|
||||
|
||||
#### 可选字段
|
||||
|
||||
- `env` (object): 环境变量键值对
|
||||
- `cwd` (string): 工作目录
|
||||
- `timeout` (number): 超时时间(毫秒)
|
||||
- `retries` (number): 重试次数
|
||||
- `enabled` (boolean): 是否启用(默认 true)
|
||||
- `description` (string): 服务器描述
|
||||
- `tags` (array): 标签数组
|
||||
- `healthCheck` (object): 健康检查配置
|
||||
- `resources` (object): 资源限制配置
|
||||
- `logging` (object): 日志配置
|
||||
|
||||
### 响应
|
||||
|
||||
#### 成功响应 (201 Created)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"id": "server-abc123",
|
||||
"name": "文件系统服务器",
|
||||
"status": "stopped",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/allowed/path"],
|
||||
"env": {
|
||||
"NODE_ENV": "production",
|
||||
"DEBUG": "mcp:*",
|
||||
"MAX_FILES": "1000"
|
||||
},
|
||||
"cwd": "/app/workspace",
|
||||
"timeout": 30000,
|
||||
"retries": 3,
|
||||
"enabled": true,
|
||||
"description": "提供文件系统访问的 MCP 服务器",
|
||||
"tags": ["filesystem", "production"],
|
||||
"healthCheck": {
|
||||
"enabled": true,
|
||||
"interval": 30000,
|
||||
"timeout": 5000,
|
||||
"retries": 3,
|
||||
"endpoint": "/health",
|
||||
"status": "unknown"
|
||||
},
|
||||
"resources": {
|
||||
"memory": {
|
||||
"limit": "512MB",
|
||||
"warning": "400MB",
|
||||
"current": "0MB"
|
||||
},
|
||||
"cpu": {
|
||||
"limit": "50%",
|
||||
"current": "0%"
|
||||
}
|
||||
},
|
||||
"logging": {
|
||||
"level": "info",
|
||||
"file": "/var/log/mcphub/server.log",
|
||||
"maxSize": "100MB",
|
||||
"maxFiles": 5,
|
||||
"currentSize": "0MB"
|
||||
},
|
||||
"createdAt": "2024-01-01T12:00:00Z",
|
||||
"updatedAt": "2024-01-01T12:00:00Z",
|
||||
"createdBy": "user123"
|
||||
},
|
||||
"message": "服务器创建成功"
|
||||
}
|
||||
```
|
||||
|
||||
#### 错误响应
|
||||
|
||||
**400 Bad Request - 参数错误**
|
||||
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"error": {
|
||||
"code": "VALIDATION_ERROR",
|
||||
"message": "请求数据验证失败",
|
||||
"details": [
|
||||
{
|
||||
"field": "name",
|
||||
"message": "服务器名称不能为空"
|
||||
},
|
||||
{
|
||||
"field": "command",
|
||||
"message": "执行命令不能为空"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**409 Conflict - 名称冲突**
|
||||
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"error": {
|
||||
"code": "RESOURCE_CONFLICT",
|
||||
"message": "服务器名称已存在",
|
||||
"details": {
|
||||
"field": "name",
|
||||
"value": "文件系统服务器",
|
||||
"conflictingResourceId": "server-xyz789"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 示例
|
||||
|
||||
#### cURL
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/api/servers \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
|
||||
-d '{
|
||||
"name": "文件系统服务器",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/data"],
|
||||
"env": {
|
||||
"NODE_ENV": "production"
|
||||
},
|
||||
"description": "生产环境文件系统服务器"
|
||||
}'
|
||||
```
|
||||
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const response = await fetch('/api/servers', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: '文件系统服务器',
|
||||
command: 'npx',
|
||||
args: ['-y', '@modelcontextprotocol/server-filesystem', '/data'],
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
},
|
||||
description: '生产环境文件系统服务器',
|
||||
}),
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
console.log('服务器创建成功:', result.data);
|
||||
} else {
|
||||
console.error('创建失败:', result.error);
|
||||
}
|
||||
```
|
||||
|
||||
#### Python
|
||||
|
||||
```python
|
||||
import requests
|
||||
|
||||
response = requests.post(
|
||||
'http://localhost:3000/api/servers',
|
||||
headers={
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': f'Bearer {token}'
|
||||
},
|
||||
json={
|
||||
'name': '文件系统服务器',
|
||||
'command': 'npx',
|
||||
'args': ['-y', '@modelcontextprotocol/server-filesystem', '/data'],
|
||||
'env': {
|
||||
'NODE_ENV': 'production'
|
||||
},
|
||||
'description': '生产环境文件系统服务器'
|
||||
}
|
||||
)
|
||||
|
||||
if response.status_code == 201:
|
||||
result = response.json()
|
||||
print('服务器创建成功:', result['data'])
|
||||
else:
|
||||
error = response.json()
|
||||
print('创建失败:', error['error'])
|
||||
```
|
||||
|
||||
## 创建用户
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
POST /api/users
|
||||
```
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"username": "newuser",
|
||||
"email": "user@example.com",
|
||||
"password": "SecurePassword123!",
|
||||
"role": "user",
|
||||
"groups": ["dev-team", "qa-team"],
|
||||
"profile": {
|
||||
"firstName": "张",
|
||||
"lastName": "三",
|
||||
"department": "开发部",
|
||||
"title": "软件工程师",
|
||||
"phone": "+86-138-0013-8000",
|
||||
"location": "北京"
|
||||
},
|
||||
"preferences": {
|
||||
"language": "zh-CN",
|
||||
"timezone": "Asia/Shanghai",
|
||||
"notifications": {
|
||||
"email": true,
|
||||
"slack": false,
|
||||
"browser": true
|
||||
}
|
||||
},
|
||||
"enabled": true
|
||||
}
|
||||
```
|
||||
|
||||
### 响应 (201 Created)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"id": "user-abc123",
|
||||
"username": "newuser",
|
||||
"email": "user@example.com",
|
||||
"role": "user",
|
||||
"groups": [
|
||||
{
|
||||
"id": "dev-team",
|
||||
"name": "开发团队",
|
||||
"role": "member"
|
||||
}
|
||||
],
|
||||
"profile": {
|
||||
"firstName": "张",
|
||||
"lastName": "三",
|
||||
"fullName": "张三",
|
||||
"department": "开发部",
|
||||
"title": "软件工程师",
|
||||
"phone": "+86-138-0013-8000",
|
||||
"location": "北京",
|
||||
"avatar": null
|
||||
},
|
||||
"preferences": {
|
||||
"language": "zh-CN",
|
||||
"timezone": "Asia/Shanghai",
|
||||
"notifications": {
|
||||
"email": true,
|
||||
"slack": false,
|
||||
"browser": true
|
||||
}
|
||||
},
|
||||
"enabled": true,
|
||||
"lastLoginAt": null,
|
||||
"createdAt": "2024-01-01T12:00:00Z",
|
||||
"updatedAt": "2024-01-01T12:00:00Z"
|
||||
},
|
||||
"message": "用户创建成功"
|
||||
}
|
||||
```
|
||||
|
||||
## 创建组
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
POST /api/groups
|
||||
```
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "dev-team",
|
||||
"displayName": "开发团队",
|
||||
"description": "前端和后端开发人员",
|
||||
"parentGroup": null,
|
||||
"permissions": {
|
||||
"servers": {
|
||||
"create": false,
|
||||
"read": true,
|
||||
"update": true,
|
||||
"delete": false,
|
||||
"execute": true
|
||||
},
|
||||
"tools": {
|
||||
"filesystem": {
|
||||
"read": true,
|
||||
"write": true,
|
||||
"paths": ["/app/data", "/tmp"]
|
||||
},
|
||||
"web-search": {
|
||||
"enabled": true,
|
||||
"maxQueries": 100
|
||||
}
|
||||
},
|
||||
"monitoring": {
|
||||
"viewLogs": true,
|
||||
"viewMetrics": true,
|
||||
"exportData": false
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"autoAssign": false,
|
||||
"maxMembers": 50,
|
||||
"requireApproval": true,
|
||||
"sessionTimeout": "8h"
|
||||
},
|
||||
"quotas": {
|
||||
"requests": {
|
||||
"daily": 1000,
|
||||
"monthly": 30000
|
||||
},
|
||||
"storage": {
|
||||
"maxSize": "10GB"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 响应 (201 Created)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"id": "group-abc123",
|
||||
"name": "dev-team",
|
||||
"displayName": "开发团队",
|
||||
"description": "前端和后端开发人员",
|
||||
"parentGroup": null,
|
||||
"permissions": {
|
||||
"servers": {
|
||||
"create": false,
|
||||
"read": true,
|
||||
"update": true,
|
||||
"delete": false,
|
||||
"execute": true
|
||||
},
|
||||
"tools": {
|
||||
"filesystem": {
|
||||
"read": true,
|
||||
"write": true,
|
||||
"paths": ["/app/data", "/tmp"]
|
||||
},
|
||||
"web-search": {
|
||||
"enabled": true,
|
||||
"maxQueries": 100
|
||||
}
|
||||
},
|
||||
"monitoring": {
|
||||
"viewLogs": true,
|
||||
"viewMetrics": true,
|
||||
"exportData": false
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"autoAssign": false,
|
||||
"maxMembers": 50,
|
||||
"requireApproval": true,
|
||||
"sessionTimeout": "8h"
|
||||
},
|
||||
"quotas": {
|
||||
"requests": {
|
||||
"daily": 1000,
|
||||
"monthly": 30000
|
||||
},
|
||||
"storage": {
|
||||
"maxSize": "10GB"
|
||||
}
|
||||
},
|
||||
"memberCount": 0,
|
||||
"serverCount": 0,
|
||||
"createdAt": "2024-01-01T12:00:00Z",
|
||||
"updatedAt": "2024-01-01T12:00:00Z",
|
||||
"createdBy": "admin"
|
||||
},
|
||||
"message": "组创建成功"
|
||||
}
|
||||
```
|
||||
|
||||
## 批量创建
|
||||
|
||||
### 批量创建服务器
|
||||
|
||||
```http
|
||||
POST /api/servers/bulk
|
||||
```
|
||||
|
||||
#### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"servers": [
|
||||
{
|
||||
"name": "dev-server-1",
|
||||
"command": "python",
|
||||
"args": ["-m", "mcp_server"],
|
||||
"env": { "ENV": "development" }
|
||||
},
|
||||
{
|
||||
"name": "dev-server-2",
|
||||
"command": "node",
|
||||
"args": ["server.js"],
|
||||
"env": { "ENV": "development" }
|
||||
}
|
||||
],
|
||||
"options": {
|
||||
"skipExisting": true,
|
||||
"validateAll": true,
|
||||
"startAfterCreate": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 响应 (201 Created)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"created": [
|
||||
{
|
||||
"id": "server-1",
|
||||
"name": "dev-server-1",
|
||||
"status": "created"
|
||||
},
|
||||
{
|
||||
"id": "server-2",
|
||||
"name": "dev-server-2",
|
||||
"status": "created"
|
||||
}
|
||||
],
|
||||
"skipped": [],
|
||||
"failed": [],
|
||||
"summary": {
|
||||
"total": 2,
|
||||
"created": 2,
|
||||
"skipped": 0,
|
||||
"failed": 0
|
||||
}
|
||||
},
|
||||
"message": "批量创建完成,成功创建 2 个服务器"
|
||||
}
|
||||
```
|
||||
|
||||
## 验证
|
||||
|
||||
### 预验证创建请求
|
||||
|
||||
在实际创建资源之前验证请求:
|
||||
|
||||
```http
|
||||
POST /api/servers/validate
|
||||
```
|
||||
|
||||
#### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "test-server",
|
||||
"command": "invalid-command",
|
||||
"args": []
|
||||
}
|
||||
```
|
||||
|
||||
#### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"data": {
|
||||
"valid": false,
|
||||
"errors": [
|
||||
{
|
||||
"field": "command",
|
||||
"message": "命令 'invalid-command' 不存在或无法执行"
|
||||
}
|
||||
],
|
||||
"warnings": [
|
||||
{
|
||||
"field": "args",
|
||||
"message": "参数数组为空,服务器可能无法正常启动"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
有关更多 API 端点信息,请参阅 [获取资源](/zh/api-reference/endpoint/get)、[删除资源](/zh/api-reference/endpoint/delete) 和 [WebHooks](/zh/api-reference/endpoint/webhook) 文档。
|
||||
303
docs/zh/api-reference/endpoint/delete.mdx
Normal file
@@ -0,0 +1,303 @@
|
||||
---
|
||||
title: 删除资源 API
|
||||
description: 删除各种资源的 API 端点,包括服务器、组和配置等
|
||||
---
|
||||
|
||||
# 删除资源 API
|
||||
|
||||
本文档描述了用于删除各种资源的 API 端点。
|
||||
|
||||
## 删除 MCP 服务器
|
||||
|
||||
删除指定的 MCP 服务器配置。
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
DELETE /api/servers/{id}
|
||||
```
|
||||
|
||||
### 参数
|
||||
|
||||
| 参数名 | 类型 | 位置 | 必需 | 描述 |
|
||||
| ------ | ------ | ---- | ---- | ------------------ |
|
||||
| id | string | path | 是 | 服务器的唯一标识符 |
|
||||
|
||||
### 请求示例
|
||||
|
||||
```bash
|
||||
curl -X DELETE \
|
||||
'https://api.mcphub.io/api/servers/mcp-server-123' \
|
||||
-H 'Authorization: Bearer YOUR_API_TOKEN' \
|
||||
-H 'Content-Type: application/json'
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
#### 成功响应 (204 No Content)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "服务器已成功删除",
|
||||
"data": {
|
||||
"id": "mcp-server-123",
|
||||
"deletedAt": "2024-01-15T10:30:00Z"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 错误响应
|
||||
|
||||
**404 Not Found**
|
||||
|
||||
```json
|
||||
{
|
||||
"error": {
|
||||
"code": "SERVER_NOT_FOUND",
|
||||
"message": "指定的服务器不存在",
|
||||
"details": {
|
||||
"serverId": "mcp-server-123"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**409 Conflict**
|
||||
|
||||
```json
|
||||
{
|
||||
"error": {
|
||||
"code": "SERVER_IN_USE",
|
||||
"message": "服务器正在使用中,无法删除",
|
||||
"details": {
|
||||
"activeConnections": 5,
|
||||
"associatedGroups": ["group-1", "group-2"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 删除服务器组
|
||||
|
||||
删除指定的服务器组。
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
DELETE /api/groups/{id}
|
||||
```
|
||||
|
||||
### 参数
|
||||
|
||||
| 参数名 | 类型 | 位置 | 必需 | 描述 |
|
||||
| ------ | ------- | ----- | ---- | ------------------------------ |
|
||||
| id | string | path | 是 | 组的唯一标识符 |
|
||||
| force | boolean | query | 否 | 是否强制删除(包含服务器的组) |
|
||||
|
||||
### 请求示例
|
||||
|
||||
```bash
|
||||
curl -X DELETE \
|
||||
'https://api.mcphub.io/api/groups/production-group?force=true' \
|
||||
-H 'Authorization: Bearer YOUR_API_TOKEN' \
|
||||
-H 'Content-Type: application/json'
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
#### 成功响应 (204 No Content)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "服务器组已成功删除",
|
||||
"data": {
|
||||
"id": "production-group",
|
||||
"deletedServers": ["server-1", "server-2"],
|
||||
"deletedAt": "2024-01-15T10:30:00Z"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 删除配置项
|
||||
|
||||
删除指定的配置项。
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
DELETE /api/config/{key}
|
||||
```
|
||||
|
||||
### 参数
|
||||
|
||||
| 参数名 | 类型 | 位置 | 必需 | 描述 |
|
||||
| ------ | ------ | ---- | ---- | -------- |
|
||||
| key | string | path | 是 | 配置键名 |
|
||||
|
||||
### 请求示例
|
||||
|
||||
```bash
|
||||
curl -X DELETE \
|
||||
'https://api.mcphub.io/api/config/custom-setting' \
|
||||
-H 'Authorization: Bearer YOUR_API_TOKEN'
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
#### 成功响应 (200 OK)
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "配置项已删除",
|
||||
"data": {
|
||||
"key": "custom-setting",
|
||||
"previousValue": "old-value",
|
||||
"deletedAt": "2024-01-15T10:30:00Z"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 批量删除
|
||||
|
||||
### 批量删除服务器
|
||||
|
||||
删除多个 MCP 服务器。
|
||||
|
||||
#### 端点
|
||||
|
||||
```http
|
||||
DELETE /api/servers/batch
|
||||
```
|
||||
|
||||
#### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"serverIds": ["server-1", "server-2", "server-3"],
|
||||
"force": false
|
||||
}
|
||||
```
|
||||
|
||||
#### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "批量删除完成",
|
||||
"data": {
|
||||
"deleted": ["server-1", "server-3"],
|
||||
"failed": [
|
||||
{
|
||||
"id": "server-2",
|
||||
"reason": "服务器正在使用中"
|
||||
}
|
||||
],
|
||||
"summary": {
|
||||
"total": 3,
|
||||
"deleted": 2,
|
||||
"failed": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 软删除 vs 硬删除
|
||||
|
||||
### 软删除
|
||||
|
||||
默认情况下,MCPHub 使用软删除机制:
|
||||
|
||||
- 资源被标记为已删除但保留在数据库中
|
||||
- 可以通过恢复 API 恢复删除的资源
|
||||
- 删除的资源在列表 API 中默认不显示
|
||||
|
||||
### 硬删除
|
||||
|
||||
使用 `permanent=true` 参数执行硬删除:
|
||||
|
||||
```bash
|
||||
curl -X DELETE \
|
||||
'https://api.mcphub.io/api/servers/mcp-server-123?permanent=true' \
|
||||
-H 'Authorization: Bearer YOUR_API_TOKEN'
|
||||
```
|
||||
|
||||
<Warning>硬删除操作不可逆,请谨慎使用。</Warning>
|
||||
|
||||
## 权限要求
|
||||
|
||||
| 操作 | 所需权限 |
|
||||
| ---------- | ------------------------ |
|
||||
| 删除服务器 | `servers:delete` |
|
||||
| 删除组 | `groups:delete` |
|
||||
| 删除配置 | `config:delete` |
|
||||
| 硬删除 | `admin:permanent_delete` |
|
||||
|
||||
## 错误代码
|
||||
|
||||
| 错误代码 | HTTP 状态码 | 描述 |
|
||||
| -------------------------- | ----------- | ---------------- |
|
||||
| `RESOURCE_NOT_FOUND` | 404 | 资源不存在 |
|
||||
| `RESOURCE_IN_USE` | 409 | 资源正在使用中 |
|
||||
| `INSUFFICIENT_PERMISSIONS` | 403 | 权限不足 |
|
||||
| `VALIDATION_ERROR` | 400 | 请求参数验证失败 |
|
||||
| `INTERNAL_ERROR` | 500 | 服务器内部错误 |
|
||||
|
||||
## 最佳实践
|
||||
|
||||
### 1. 删除前检查
|
||||
|
||||
在删除资源前,建议先检查资源的使用情况:
|
||||
|
||||
```bash
|
||||
# 检查服务器使用情况
|
||||
curl -X GET \
|
||||
'https://api.mcphub.io/api/servers/mcp-server-123/usage' \
|
||||
-H 'Authorization: Bearer YOUR_API_TOKEN'
|
||||
```
|
||||
|
||||
### 2. 备份重要数据
|
||||
|
||||
对于重要资源,建议在删除前进行备份:
|
||||
|
||||
```bash
|
||||
# 导出服务器配置
|
||||
curl -X GET \
|
||||
'https://api.mcphub.io/api/servers/mcp-server-123/export' \
|
||||
-H 'Authorization: Bearer YOUR_API_TOKEN' \
|
||||
> server-backup.json
|
||||
```
|
||||
|
||||
### 3. 使用事务删除
|
||||
|
||||
对于复杂的删除操作,使用事务确保数据一致性:
|
||||
|
||||
```json
|
||||
{
|
||||
"transaction": true,
|
||||
"operations": [
|
||||
{
|
||||
"type": "delete",
|
||||
"resource": "server",
|
||||
"id": "server-1"
|
||||
},
|
||||
{
|
||||
"type": "delete",
|
||||
"resource": "group",
|
||||
"id": "group-1"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 恢复删除的资源
|
||||
|
||||
软删除的资源可以通过恢复 API 恢复:
|
||||
|
||||
```bash
|
||||
curl -X POST \
|
||||
'https://api.mcphub.io/api/servers/mcp-server-123/restore' \
|
||||
-H 'Authorization: Bearer YOUR_API_TOKEN'
|
||||
```
|
||||
607
docs/zh/api-reference/endpoint/get.mdx
Normal file
@@ -0,0 +1,607 @@
|
||||
---
|
||||
title: '获取资源'
|
||||
description: '查询和检索 MCP 服务器、用户和组信息'
|
||||
---
|
||||
|
||||
## 获取服务器列表
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
GET /api/servers
|
||||
```
|
||||
|
||||
### 查询参数
|
||||
|
||||
| 参数 | 类型 | 描述 | 示例 |
|
||||
| ---------------- | ------- | ------------------------------- | ---------------------------- |
|
||||
| `page` | integer | 页码(从 1 开始) | `?page=2` |
|
||||
| `limit` | integer | 每页记录数(默认 20,最大 100) | `?limit=50` |
|
||||
| `sort` | string | 排序字段 | `?sort=name` |
|
||||
| `order` | string | 排序顺序(asc/desc) | `?order=desc` |
|
||||
| `status` | string | 过滤服务器状态 | `?status=running` |
|
||||
| `search` | string | 搜索服务器名称或描述 | `?search=python` |
|
||||
| `group` | string | 过滤所属组 | `?group=dev-team` |
|
||||
| `tags` | string | 过滤标签(逗号分隔) | `?tags=python,production` |
|
||||
| `enabled` | boolean | 过滤启用状态 | `?enabled=true` |
|
||||
| `created_after` | string | 创建时间起始 | `?created_after=2024-01-01` |
|
||||
| `created_before` | string | 创建时间结束 | `?created_before=2024-01-31` |
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"items": [
|
||||
{
|
||||
"id": "server-abc123",
|
||||
"name": "文件系统服务器",
|
||||
"status": "running",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/data"],
|
||||
"env": {
|
||||
"NODE_ENV": "production"
|
||||
},
|
||||
"cwd": "/app",
|
||||
"pid": 12345,
|
||||
"uptime": 3600000,
|
||||
"enabled": true,
|
||||
"description": "提供文件系统访问的 MCP 服务器",
|
||||
"tags": ["filesystem", "production"],
|
||||
"health": {
|
||||
"status": "healthy",
|
||||
"lastCheck": "2024-01-01T12:00:00Z",
|
||||
"responseTime": "45ms"
|
||||
},
|
||||
"resources": {
|
||||
"memory": {
|
||||
"used": "128MB",
|
||||
"limit": "512MB",
|
||||
"percentage": 25
|
||||
},
|
||||
"cpu": {
|
||||
"used": "15%",
|
||||
"limit": "50%"
|
||||
}
|
||||
},
|
||||
"stats": {
|
||||
"totalRequests": 1523,
|
||||
"errorCount": 2,
|
||||
"avgResponseTime": "234ms"
|
||||
},
|
||||
"lastRestart": "2024-01-01T08:00:00Z",
|
||||
"createdAt": "2024-01-01T00:00:00Z",
|
||||
"updatedAt": "2024-01-01T12:00:00Z"
|
||||
}
|
||||
],
|
||||
"pagination": {
|
||||
"page": 1,
|
||||
"limit": 20,
|
||||
"total": 45,
|
||||
"pages": 3,
|
||||
"hasNext": true,
|
||||
"hasPrev": false
|
||||
},
|
||||
"filters": {
|
||||
"status": "running",
|
||||
"totalFiltered": 12
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 示例
|
||||
|
||||
```bash
|
||||
# 获取运行中的服务器,按名称排序
|
||||
curl -X GET "http://localhost:3000/api/servers?status=running&sort=name&order=asc" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
|
||||
# 搜索包含 "python" 的服务器
|
||||
curl -X GET "http://localhost:3000/api/servers?search=python&limit=10" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
|
||||
# 获取开发团队的服务器
|
||||
curl -X GET "http://localhost:3000/api/servers?group=dev-team" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
## 获取服务器详情
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
GET /api/servers/{serverId}
|
||||
```
|
||||
|
||||
### 路径参数
|
||||
|
||||
- `serverId` (string): 服务器唯一标识符
|
||||
|
||||
### 查询参数
|
||||
|
||||
| 参数 | 类型 | 描述 |
|
||||
| --------------- | ------ | ----------------------------------------------- |
|
||||
| `include` | string | 包含额外信息(逗号分隔):`logs,metrics,events` |
|
||||
| `metrics_range` | string | 指标时间范围:`1h`, `24h`, `7d` |
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"id": "server-abc123",
|
||||
"name": "文件系统服务器",
|
||||
"status": "running",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/data"],
|
||||
"env": {
|
||||
"NODE_ENV": "production",
|
||||
"DEBUG": "mcp:*"
|
||||
},
|
||||
"cwd": "/app",
|
||||
"pid": 12345,
|
||||
"uptime": 3600000,
|
||||
"enabled": true,
|
||||
"description": "提供文件系统访问的 MCP 服务器",
|
||||
"tags": ["filesystem", "production"],
|
||||
"healthCheck": {
|
||||
"enabled": true,
|
||||
"interval": 30000,
|
||||
"timeout": 5000,
|
||||
"retries": 3,
|
||||
"endpoint": "/health",
|
||||
"status": "healthy",
|
||||
"lastCheck": "2024-01-01T12:00:00Z",
|
||||
"responseTime": "45ms",
|
||||
"consecutiveFailures": 0
|
||||
},
|
||||
"resources": {
|
||||
"memory": {
|
||||
"used": "128MB",
|
||||
"limit": "512MB",
|
||||
"warning": "400MB",
|
||||
"percentage": 25
|
||||
},
|
||||
"cpu": {
|
||||
"used": "15%",
|
||||
"limit": "50%",
|
||||
"cores": 4
|
||||
},
|
||||
"network": {
|
||||
"bytesIn": "1.2GB",
|
||||
"bytesOut": "890MB"
|
||||
}
|
||||
},
|
||||
"stats": {
|
||||
"totalRequests": 1523,
|
||||
"successfulRequests": 1521,
|
||||
"errorCount": 2,
|
||||
"avgResponseTime": "234ms",
|
||||
"p95ResponseTime": "450ms",
|
||||
"requestsPerMinute": 25,
|
||||
"lastError": {
|
||||
"timestamp": "2024-01-01T11:30:00Z",
|
||||
"message": "Temporary connection timeout",
|
||||
"count": 1
|
||||
}
|
||||
},
|
||||
"capabilities": [
|
||||
{
|
||||
"type": "tool",
|
||||
"name": "read_file",
|
||||
"description": "读取文件内容",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": { "type": "string" }
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "tool",
|
||||
"name": "write_file",
|
||||
"description": "写入文件内容",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": { "type": "string" },
|
||||
"content": { "type": "string" }
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"groups": [
|
||||
{
|
||||
"id": "dev-team",
|
||||
"name": "开发团队",
|
||||
"permissions": ["read", "write", "execute"]
|
||||
}
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"id": "event-123",
|
||||
"type": "started",
|
||||
"timestamp": "2024-01-01T08:00:00Z",
|
||||
"message": "服务器启动成功",
|
||||
"metadata": {
|
||||
"pid": 12345,
|
||||
"startupTime": "2.3s"
|
||||
}
|
||||
}
|
||||
],
|
||||
"lastRestart": "2024-01-01T08:00:00Z",
|
||||
"createdAt": "2024-01-01T00:00:00Z",
|
||||
"updatedAt": "2024-01-01T12:00:00Z",
|
||||
"createdBy": "admin"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 示例
|
||||
|
||||
```bash
|
||||
# 获取服务器基本信息
|
||||
curl -X GET "http://localhost:3000/api/servers/server-abc123" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
|
||||
# 获取服务器详情包含日志和指标
|
||||
curl -X GET "http://localhost:3000/api/servers/server-abc123?include=logs,metrics&metrics_range=24h" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
## 获取服务器状态
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
GET /api/servers/{serverId}/status
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"serverId": "server-abc123",
|
||||
"status": "running",
|
||||
"health": "healthy",
|
||||
"pid": 12345,
|
||||
"uptime": 3600000,
|
||||
"startedAt": "2024-01-01T08:00:00Z",
|
||||
"lastHealthCheck": "2024-01-01T12:00:00Z",
|
||||
"resources": {
|
||||
"memory": {
|
||||
"rss": 134217728,
|
||||
"heapTotal": 67108864,
|
||||
"heapUsed": 45088768,
|
||||
"external": 8388608
|
||||
},
|
||||
"cpu": {
|
||||
"user": 1000000,
|
||||
"system": 500000,
|
||||
"percentage": 15.5
|
||||
}
|
||||
},
|
||||
"connections": {
|
||||
"active": 5,
|
||||
"total": 127
|
||||
},
|
||||
"performance": {
|
||||
"requestsPerSecond": 12.5,
|
||||
"avgResponseTime": "234ms",
|
||||
"errorRate": "0.1%"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 获取服务器日志
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
GET /api/servers/{serverId}/logs
|
||||
```
|
||||
|
||||
### 查询参数
|
||||
|
||||
| 参数 | 类型 | 描述 |
|
||||
| -------- | ------- | ---------------------------------------------- |
|
||||
| `level` | string | 日志级别过滤:`error`, `warn`, `info`, `debug` |
|
||||
| `limit` | integer | 返回日志条数(默认 100,最大 1000) |
|
||||
| `since` | string | 开始时间(ISO 8601 格式) |
|
||||
| `until` | string | 结束时间(ISO 8601 格式) |
|
||||
| `follow` | boolean | 实时跟踪日志流 |
|
||||
| `search` | string | 搜索日志内容 |
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"logs": [
|
||||
{
|
||||
"id": "log-123",
|
||||
"timestamp": "2024-01-01T12:00:00Z",
|
||||
"level": "info",
|
||||
"message": "处理请求: read_file",
|
||||
"source": "mcp-server",
|
||||
"metadata": {
|
||||
"requestId": "req-456",
|
||||
"userId": "user-789",
|
||||
"duration": "45ms"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "log-124",
|
||||
"timestamp": "2024-01-01T12:00:05Z",
|
||||
"level": "error",
|
||||
"message": "文件不存在: /nonexistent/file.txt",
|
||||
"source": "filesystem",
|
||||
"metadata": {
|
||||
"requestId": "req-457",
|
||||
"path": "/nonexistent/file.txt",
|
||||
"error": "ENOENT"
|
||||
}
|
||||
}
|
||||
],
|
||||
"pagination": {
|
||||
"limit": 100,
|
||||
"total": 1523,
|
||||
"hasMore": true,
|
||||
"nextCursor": "cursor-abc123"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 实时日志流
|
||||
|
||||
```bash
|
||||
# 实时跟踪日志
|
||||
curl -X GET "http://localhost:3000/api/servers/server-abc123/logs?follow=true" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Accept: text/event-stream"
|
||||
```
|
||||
|
||||
## 获取服务器指标
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
GET /api/servers/{serverId}/metrics
|
||||
```
|
||||
|
||||
### 查询参数
|
||||
|
||||
| 参数 | 类型 | 描述 |
|
||||
| ------------- | ------ | ------------------------------------------- |
|
||||
| `timeRange` | string | 时间范围:`1h`, `24h`, `7d`, `30d` |
|
||||
| `granularity` | string | 数据粒度:`1m`, `5m`, `1h`, `1d` |
|
||||
| `metrics` | string | 指定指标(逗号分隔):`cpu,memory,requests` |
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"timeRange": "1h",
|
||||
"granularity": "5m",
|
||||
"metrics": {
|
||||
"cpu": {
|
||||
"data": [
|
||||
{ "timestamp": "2024-01-01T11:00:00Z", "value": 12.5 },
|
||||
{ "timestamp": "2024-01-01T11:05:00Z", "value": 15.2 }
|
||||
],
|
||||
"summary": {
|
||||
"avg": 13.8,
|
||||
"min": 8.1,
|
||||
"max": 18.5,
|
||||
"current": 15.2
|
||||
}
|
||||
},
|
||||
"memory": {
|
||||
"data": [
|
||||
{ "timestamp": "2024-01-01T11:00:00Z", "value": 125 },
|
||||
{ "timestamp": "2024-01-01T11:05:00Z", "value": 128 }
|
||||
],
|
||||
"summary": {
|
||||
"avg": 126.5,
|
||||
"min": 120,
|
||||
"max": 135,
|
||||
"current": 128
|
||||
}
|
||||
},
|
||||
"requests": {
|
||||
"data": [
|
||||
{ "timestamp": "2024-01-01T11:00:00Z", "value": 45 },
|
||||
{ "timestamp": "2024-01-01T11:05:00Z", "value": 52 }
|
||||
],
|
||||
"summary": {
|
||||
"total": 2847,
|
||||
"avg": 48.5,
|
||||
"peak": 67
|
||||
}
|
||||
},
|
||||
"responseTime": {
|
||||
"data": [
|
||||
{ "timestamp": "2024-01-01T11:00:00Z", "avg": 230, "p95": 450 },
|
||||
{ "timestamp": "2024-01-01T11:05:00Z", "avg": 245, "p95": 480 }
|
||||
],
|
||||
"summary": {
|
||||
"avgResponseTime": "237ms",
|
||||
"p95ResponseTime": "465ms"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 获取用户列表
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
GET /api/users
|
||||
```
|
||||
|
||||
### 查询参数
|
||||
|
||||
| 参数 | 类型 | 描述 |
|
||||
| ------------------ | ------- | ---------------- |
|
||||
| `role` | string | 过滤用户角色 |
|
||||
| `group` | string | 过滤所属组 |
|
||||
| `enabled` | boolean | 过滤启用状态 |
|
||||
| `search` | string | 搜索用户名或邮箱 |
|
||||
| `last_login_after` | string | 最后登录时间起始 |
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"items": [
|
||||
{
|
||||
"id": "user-abc123",
|
||||
"username": "zhangsan",
|
||||
"email": "zhangsan@example.com",
|
||||
"role": "user",
|
||||
"enabled": true,
|
||||
"profile": {
|
||||
"firstName": "张",
|
||||
"lastName": "三",
|
||||
"fullName": "张三",
|
||||
"department": "开发部",
|
||||
"title": "软件工程师"
|
||||
},
|
||||
"groups": [
|
||||
{
|
||||
"id": "dev-team",
|
||||
"name": "开发团队",
|
||||
"role": "member"
|
||||
}
|
||||
],
|
||||
"stats": {
|
||||
"totalSessions": 45,
|
||||
"totalRequests": 1234,
|
||||
"lastRequestAt": "2024-01-01T11:30:00Z"
|
||||
},
|
||||
"lastLoginAt": "2024-01-01T08:00:00Z",
|
||||
"createdAt": "2023-12-01T00:00:00Z"
|
||||
}
|
||||
],
|
||||
"pagination": {
|
||||
"page": 1,
|
||||
"limit": 20,
|
||||
"total": 89,
|
||||
"pages": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 获取组列表
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
GET /api/groups
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"items": [
|
||||
{
|
||||
"id": "group-abc123",
|
||||
"name": "dev-team",
|
||||
"displayName": "开发团队",
|
||||
"description": "前端和后端开发人员",
|
||||
"memberCount": 12,
|
||||
"serverCount": 8,
|
||||
"parentGroup": null,
|
||||
"children": [],
|
||||
"permissions": {
|
||||
"servers": ["read", "write", "execute"],
|
||||
"tools": ["read", "execute"]
|
||||
},
|
||||
"quotas": {
|
||||
"requests": {
|
||||
"used": 750,
|
||||
"limit": 1000
|
||||
}
|
||||
},
|
||||
"createdAt": "2023-12-01T00:00:00Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 搜索
|
||||
|
||||
### 全局搜索
|
||||
|
||||
```http
|
||||
GET /api/search
|
||||
```
|
||||
|
||||
### 查询参数
|
||||
|
||||
| 参数 | 类型 | 描述 |
|
||||
| ------- | ------- | ---------------------------------------------- |
|
||||
| `q` | string | 搜索关键词 |
|
||||
| `type` | string | 资源类型:`servers`, `users`, `groups`, `logs` |
|
||||
| `limit` | integer | 每种类型的最大结果数 |
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"query": "python",
|
||||
"results": {
|
||||
"servers": [
|
||||
{
|
||||
"id": "server-1",
|
||||
"name": "Python MCP Server",
|
||||
"type": "server",
|
||||
"relevance": 0.95
|
||||
}
|
||||
],
|
||||
"users": [],
|
||||
"groups": [
|
||||
{
|
||||
"id": "python-devs",
|
||||
"name": "Python 开发者",
|
||||
"type": "group",
|
||||
"relevance": 0.8
|
||||
}
|
||||
],
|
||||
"logs": [
|
||||
{
|
||||
"id": "log-123",
|
||||
"message": "Starting Python server...",
|
||||
"type": "log",
|
||||
"relevance": 0.7
|
||||
}
|
||||
]
|
||||
},
|
||||
"total": 3
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
有关更多信息,请参阅 [创建资源](/zh/api-reference/endpoint/create)、[删除资源](/zh/api-reference/endpoint/delete) 和 [WebHooks](/zh/api-reference/endpoint/webhook) 文档。
|
||||
615
docs/zh/api-reference/endpoint/webhook.mdx
Normal file
@@ -0,0 +1,615 @@
|
||||
---
|
||||
title: WebHooks API
|
||||
description: 配置和管理 WebHook 事件通知的完整指南
|
||||
---
|
||||
|
||||
# WebHooks API
|
||||
|
||||
WebHooks 允许 MCPHub 在特定事件发生时向您的应用程序发送实时通知。
|
||||
|
||||
## 概述
|
||||
|
||||
MCPHub WebHooks 系统支持以下功能:
|
||||
|
||||
- 实时事件通知
|
||||
- 自定义过滤器
|
||||
- 重试机制
|
||||
- 签名验证
|
||||
- 批量事件处理
|
||||
|
||||
## 支持的事件类型
|
||||
|
||||
| 事件类型 | 描述 |
|
||||
| ----------------------- | -------------- |
|
||||
| `server.created` | MCP 服务器创建 |
|
||||
| `server.updated` | MCP 服务器更新 |
|
||||
| `server.deleted` | MCP 服务器删除 |
|
||||
| `server.status_changed` | 服务器状态变更 |
|
||||
| `group.created` | 服务器组创建 |
|
||||
| `group.updated` | 服务器组更新 |
|
||||
| `group.deleted` | 服务器组删除 |
|
||||
| `user.login` | 用户登录 |
|
||||
| `user.logout` | 用户登出 |
|
||||
| `config.changed` | 配置变更 |
|
||||
| `system.error` | 系统错误 |
|
||||
|
||||
## 创建 WebHook
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
POST /api/webhooks
|
||||
```
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"url": "https://your-app.com/webhook",
|
||||
"events": ["server.created", "server.status_changed"],
|
||||
"secret": "your-webhook-secret",
|
||||
"active": true,
|
||||
"config": {
|
||||
"contentType": "application/json",
|
||||
"insecureSsl": false,
|
||||
"retryCount": 3,
|
||||
"timeout": 30
|
||||
},
|
||||
"filters": {
|
||||
"serverGroups": ["production", "staging"],
|
||||
"serverTypes": ["ai-assistant", "data-processor"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"id": "webhook-123",
|
||||
"url": "https://your-app.com/webhook",
|
||||
"events": ["server.created", "server.status_changed"],
|
||||
"active": true,
|
||||
"secret": "your-webhook-secret",
|
||||
"config": {
|
||||
"contentType": "application/json",
|
||||
"insecureSsl": false,
|
||||
"retryCount": 3,
|
||||
"timeout": 30
|
||||
},
|
||||
"filters": {
|
||||
"serverGroups": ["production", "staging"],
|
||||
"serverTypes": ["ai-assistant", "data-processor"]
|
||||
},
|
||||
"createdAt": "2024-01-15T10:30:00Z",
|
||||
"updatedAt": "2024-01-15T10:30:00Z"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 获取 WebHook 列表
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
GET /api/webhooks
|
||||
```
|
||||
|
||||
### 查询参数
|
||||
|
||||
| 参数名 | 类型 | 描述 |
|
||||
| ------ | ------- | -------------------- |
|
||||
| page | integer | 页码(默认:1) |
|
||||
| limit | integer | 每页数量(默认:20) |
|
||||
| active | boolean | 过滤活跃状态 |
|
||||
| event | string | 过滤事件类型 |
|
||||
|
||||
### 请求示例
|
||||
|
||||
```bash
|
||||
curl -X GET \
|
||||
'https://api.mcphub.io/api/webhooks?active=true&limit=10' \
|
||||
-H 'Authorization: Bearer YOUR_API_TOKEN'
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"webhooks": [
|
||||
{
|
||||
"id": "webhook-123",
|
||||
"url": "https://your-app.com/webhook",
|
||||
"events": ["server.created", "server.status_changed"],
|
||||
"active": true,
|
||||
"lastDelivery": "2024-01-15T09:30:00Z",
|
||||
"deliveryCount": 145,
|
||||
"failureCount": 2,
|
||||
"createdAt": "2024-01-10T10:30:00Z"
|
||||
}
|
||||
],
|
||||
"pagination": {
|
||||
"page": 1,
|
||||
"limit": 10,
|
||||
"total": 25,
|
||||
"pages": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 获取单个 WebHook
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
GET /api/webhooks/{id}
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"id": "webhook-123",
|
||||
"url": "https://your-app.com/webhook",
|
||||
"events": ["server.created", "server.status_changed"],
|
||||
"active": true,
|
||||
"secret": "your-webhook-secret",
|
||||
"config": {
|
||||
"contentType": "application/json",
|
||||
"insecureSsl": false,
|
||||
"retryCount": 3,
|
||||
"timeout": 30
|
||||
},
|
||||
"filters": {
|
||||
"serverGroups": ["production", "staging"],
|
||||
"serverTypes": ["ai-assistant", "data-processor"]
|
||||
},
|
||||
"stats": {
|
||||
"totalDeliveries": 145,
|
||||
"successfulDeliveries": 143,
|
||||
"failedDeliveries": 2,
|
||||
"lastDelivery": "2024-01-15T09:30:00Z",
|
||||
"lastSuccess": "2024-01-15T09:30:00Z",
|
||||
"lastFailure": "2024-01-14T15:20:00Z"
|
||||
},
|
||||
"createdAt": "2024-01-10T10:30:00Z",
|
||||
"updatedAt": "2024-01-15T10:30:00Z"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 更新 WebHook
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
PUT /api/webhooks/{id}
|
||||
```
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"url": "https://your-app.com/new-webhook",
|
||||
"events": ["server.created", "server.updated", "server.deleted"],
|
||||
"active": true,
|
||||
"config": {
|
||||
"retryCount": 5,
|
||||
"timeout": 45
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 删除 WebHook
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
DELETE /api/webhooks/{id}
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "WebHook 已成功删除"
|
||||
}
|
||||
```
|
||||
|
||||
## WebHook 事件格式
|
||||
|
||||
### 基本结构
|
||||
|
||||
所有 WebHook 事件都遵循以下基本结构:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "event-123",
|
||||
"type": "server.created",
|
||||
"timestamp": "2024-01-15T10:30:00Z",
|
||||
"version": "1.0",
|
||||
"data": {
|
||||
// 事件特定数据
|
||||
},
|
||||
"metadata": {
|
||||
"source": "mcphub",
|
||||
"environment": "production",
|
||||
"triggeredBy": "user-456"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 服务器事件示例
|
||||
|
||||
#### server.created
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "event-123",
|
||||
"type": "server.created",
|
||||
"timestamp": "2024-01-15T10:30:00Z",
|
||||
"version": "1.0",
|
||||
"data": {
|
||||
"server": {
|
||||
"id": "mcp-server-123",
|
||||
"name": "AI Assistant Server",
|
||||
"type": "ai-assistant",
|
||||
"endpoint": "https://ai-assistant.example.com",
|
||||
"group": "production",
|
||||
"status": "active",
|
||||
"capabilities": ["chat", "completion"],
|
||||
"createdAt": "2024-01-15T10:30:00Z"
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"source": "mcphub",
|
||||
"environment": "production",
|
||||
"triggeredBy": "user-456"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### server.status_changed
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "event-124",
|
||||
"type": "server.status_changed",
|
||||
"timestamp": "2024-01-15T11:30:00Z",
|
||||
"version": "1.0",
|
||||
"data": {
|
||||
"server": {
|
||||
"id": "mcp-server-123",
|
||||
"name": "AI Assistant Server",
|
||||
"previousStatus": "active",
|
||||
"currentStatus": "inactive",
|
||||
"reason": "Health check failed",
|
||||
"lastHealthCheck": "2024-01-15T11:25:00Z"
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"source": "mcphub",
|
||||
"environment": "production",
|
||||
"triggeredBy": "system"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 签名验证
|
||||
|
||||
MCPHub 使用 HMAC-SHA256 签名来验证 WebHook 的真实性。
|
||||
|
||||
### 签名生成
|
||||
|
||||
签名在 `X-MCPHub-Signature-256` 头中发送:
|
||||
|
||||
```
|
||||
X-MCPHub-Signature-256: sha256=5757107ea39eca8e35d1e8...
|
||||
```
|
||||
|
||||
### 验证示例
|
||||
|
||||
#### Node.js
|
||||
|
||||
```javascript
|
||||
const crypto = require('crypto');
|
||||
|
||||
function verifySignature(payload, signature, secret) {
|
||||
const expectedSignature = crypto
|
||||
.createHmac('sha256', secret)
|
||||
.update(payload, 'utf8')
|
||||
.digest('hex');
|
||||
|
||||
const actualSignature = signature.replace('sha256=', '');
|
||||
|
||||
return crypto.timingSafeEqual(
|
||||
Buffer.from(expectedSignature, 'hex'),
|
||||
Buffer.from(actualSignature, 'hex'),
|
||||
);
|
||||
}
|
||||
|
||||
// Express.js 中间件示例
|
||||
app.use('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
|
||||
const signature = req.headers['x-mcphub-signature-256'];
|
||||
const payload = req.body;
|
||||
|
||||
if (!verifySignature(payload, signature, process.env.WEBHOOK_SECRET)) {
|
||||
return res.status(401).send('Unauthorized');
|
||||
}
|
||||
|
||||
// 处理 WebHook 事件
|
||||
const event = JSON.parse(payload);
|
||||
console.log('收到事件:', event.type);
|
||||
|
||||
res.status(200).send('OK');
|
||||
});
|
||||
```
|
||||
|
||||
#### Python
|
||||
|
||||
```python
|
||||
import hmac
|
||||
import hashlib
|
||||
|
||||
def verify_signature(payload, signature, secret):
|
||||
expected_signature = hmac.new(
|
||||
secret.encode('utf-8'),
|
||||
payload,
|
||||
hashlib.sha256
|
||||
).hexdigest()
|
||||
|
||||
actual_signature = signature.replace('sha256=', '')
|
||||
|
||||
return hmac.compare_digest(expected_signature, actual_signature)
|
||||
|
||||
# Flask 示例
|
||||
from flask import Flask, request, jsonify
|
||||
import json
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/webhook', methods=['POST'])
|
||||
def webhook():
|
||||
signature = request.headers.get('X-MCPHub-Signature-256')
|
||||
payload = request.get_data()
|
||||
|
||||
if not verify_signature(payload, signature, 'your-webhook-secret'):
|
||||
return jsonify({'error': 'Unauthorized'}), 401
|
||||
|
||||
event = json.loads(payload)
|
||||
print(f'收到事件: {event["type"]}')
|
||||
|
||||
return jsonify({'status': 'success'}), 200
|
||||
```
|
||||
|
||||
## 重试机制
|
||||
|
||||
MCPHub 对失败的 WebHook 交付实施指数退避重试:
|
||||
|
||||
- **重试次数**: 可配置(默认 3 次)
|
||||
- **重试间隔**: 2^n 秒(n 为重试次数)
|
||||
- **最大间隔**: 300 秒(5 分钟)
|
||||
- **超时设置**: 可配置(默认 30 秒)
|
||||
|
||||
### 重试时间表
|
||||
|
||||
| 尝试次数 | 延迟时间 |
|
||||
| -------- | -------- |
|
||||
| 1 | 立即 |
|
||||
| 2 | 2 秒 |
|
||||
| 3 | 4 秒 |
|
||||
| 4 | 8 秒 |
|
||||
| 5 | 16 秒 |
|
||||
|
||||
## 获取交付历史
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
GET /api/webhooks/{id}/deliveries
|
||||
```
|
||||
|
||||
### 查询参数
|
||||
|
||||
| 参数名 | 类型 | 描述 |
|
||||
| ---------- | ------- | ------------------------------------ |
|
||||
| page | integer | 页码 |
|
||||
| limit | integer | 每页数量 |
|
||||
| status | string | 过滤状态(success, failed, pending) |
|
||||
| event_type | string | 过滤事件类型 |
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"deliveries": [
|
||||
{
|
||||
"id": "delivery-123",
|
||||
"eventId": "event-123",
|
||||
"eventType": "server.created",
|
||||
"url": "https://your-app.com/webhook",
|
||||
"status": "success",
|
||||
"responseCode": 200,
|
||||
"responseTime": 145,
|
||||
"attempts": 1,
|
||||
"deliveredAt": "2024-01-15T10:30:15Z",
|
||||
"nextRetry": null
|
||||
},
|
||||
{
|
||||
"id": "delivery-124",
|
||||
"eventId": "event-124",
|
||||
"eventType": "server.status_changed",
|
||||
"url": "https://your-app.com/webhook",
|
||||
"status": "failed",
|
||||
"responseCode": 500,
|
||||
"responseTime": 30000,
|
||||
"attempts": 3,
|
||||
"error": "Connection timeout",
|
||||
"deliveredAt": null,
|
||||
"nextRetry": "2024-01-15T11:45:00Z"
|
||||
}
|
||||
],
|
||||
"pagination": {
|
||||
"page": 1,
|
||||
"limit": 20,
|
||||
"total": 145,
|
||||
"pages": 8
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 测试 WebHook
|
||||
|
||||
### 端点
|
||||
|
||||
```http
|
||||
POST /api/webhooks/{id}/test
|
||||
```
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"eventType": "server.created",
|
||||
"customData": {
|
||||
"test": true,
|
||||
"message": "这是一个测试事件"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"deliveryId": "delivery-test-123",
|
||||
"status": "delivered",
|
||||
"responseCode": 200,
|
||||
"responseTime": 124,
|
||||
"sentAt": "2024-01-15T10:30:00Z"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 最佳实践
|
||||
|
||||
### 1. 幂等性处理
|
||||
|
||||
确保您的 WebHook 端点能够处理重复事件:
|
||||
|
||||
```javascript
|
||||
const processedEvents = new Set();
|
||||
|
||||
app.post('/webhook', (req, res) => {
|
||||
const event = req.body;
|
||||
|
||||
// 检查事件是否已处理
|
||||
if (processedEvents.has(event.id)) {
|
||||
return res.status(200).send('Already processed');
|
||||
}
|
||||
|
||||
// 处理事件
|
||||
processEvent(event);
|
||||
|
||||
// 记录已处理的事件
|
||||
processedEvents.add(event.id);
|
||||
|
||||
res.status(200).send('OK');
|
||||
});
|
||||
```
|
||||
|
||||
### 2. 异步处理
|
||||
|
||||
对于复杂的处理逻辑,使用异步处理避免阻塞:
|
||||
|
||||
```javascript
|
||||
app.post('/webhook', async (req, res) => {
|
||||
const event = req.body;
|
||||
|
||||
// 立即响应
|
||||
res.status(200).send('OK');
|
||||
|
||||
// 异步处理事件
|
||||
setImmediate(() => {
|
||||
processEventAsync(event);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### 3. 错误处理
|
||||
|
||||
实施适当的错误处理和日志记录:
|
||||
|
||||
```javascript
|
||||
app.post('/webhook', (req, res) => {
|
||||
try {
|
||||
const event = req.body;
|
||||
processEvent(event);
|
||||
res.status(200).send('OK');
|
||||
} catch (error) {
|
||||
console.error('WebHook 处理错误:', error);
|
||||
res.status(500).send('Internal Server Error');
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### 4. 监控和告警
|
||||
|
||||
监控 WebHook 的交付状态:
|
||||
|
||||
```bash
|
||||
# 检查失败的交付
|
||||
curl -X GET \
|
||||
'https://api.mcphub.io/api/webhooks/webhook-123/deliveries?status=failed' \
|
||||
-H 'Authorization: Bearer YOUR_API_TOKEN'
|
||||
```
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
1. **签名验证失败**
|
||||
|
||||
- 检查密钥是否正确
|
||||
- 确保使用原始请求体进行验证
|
||||
- 验证 HMAC 计算实现
|
||||
|
||||
2. **超时错误**
|
||||
|
||||
- 增加 WebHook 超时设置
|
||||
- 优化端点响应时间
|
||||
- 使用异步处理
|
||||
|
||||
3. **重复事件**
|
||||
- 实施幂等性检查
|
||||
- 使用事件 ID 去重
|
||||
- 记录处理状态
|
||||
|
||||
### 调试工具
|
||||
|
||||
使用 MCPHub 提供的调试工具:
|
||||
|
||||
```bash
|
||||
# 查看最近的交付日志
|
||||
curl -X GET \
|
||||
'https://api.mcphub.io/api/webhooks/webhook-123/deliveries?limit=5' \
|
||||
-H 'Authorization: Bearer YOUR_API_TOKEN'
|
||||
|
||||
# 重新发送失败的事件
|
||||
curl -X POST \
|
||||
'https://api.mcphub.io/api/webhooks/delivery-124/redeliver' \
|
||||
-H 'Authorization: Bearer YOUR_API_TOKEN'
|
||||
```
|
||||
717
docs/zh/api-reference/introduction.mdx
Normal file
@@ -0,0 +1,717 @@
|
||||
---
|
||||
title: 'API 参考'
|
||||
description: 'MCPHub REST API 完整参考文档'
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
MCPHub 提供全面的 REST API,用于管理 MCP 服务器、用户、组和监控。所有 API 端点都需要身份验证,并支持 JSON 格式的请求和响应。
|
||||
|
||||
## 基础信息
|
||||
|
||||
### 基础 URL
|
||||
|
||||
```
|
||||
https://your-mcphub-instance.com/api
|
||||
```
|
||||
|
||||
### 身份验证
|
||||
|
||||
所有 API 请求都需要身份验证。支持以下方法:
|
||||
|
||||
#### JWT 令牌认证
|
||||
|
||||
```bash
|
||||
curl -X GET https://api.mcphub.com/servers \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
```
|
||||
|
||||
#### API 密钥认证
|
||||
|
||||
```bash
|
||||
curl -X GET https://api.mcphub.com/servers \
|
||||
-H "X-API-Key: YOUR_API_KEY"
|
||||
```
|
||||
|
||||
### 请求格式
|
||||
|
||||
- **Content-Type**: `application/json`
|
||||
- **Accept**: `application/json`
|
||||
- **User-Agent**: 建议包含您的应用程序名称和版本
|
||||
|
||||
### 响应格式
|
||||
|
||||
所有响应都采用 JSON 格式:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
// 响应数据
|
||||
},
|
||||
"message": "操作成功",
|
||||
"timestamp": "2024-01-01T12:00:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
错误响应格式:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"error": {
|
||||
"code": "VALIDATION_ERROR",
|
||||
"message": "请求数据无效",
|
||||
"details": {
|
||||
"field": "name",
|
||||
"reason": "名称不能为空"
|
||||
}
|
||||
},
|
||||
"timestamp": "2024-01-01T12:00:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
## 状态码
|
||||
|
||||
| 状态码 | 说明 |
|
||||
| ------ | -------------------- |
|
||||
| 200 | 请求成功 |
|
||||
| 201 | 资源创建成功 |
|
||||
| 204 | 请求成功,无返回内容 |
|
||||
| 400 | 请求参数错误 |
|
||||
| 401 | 未授权访问 |
|
||||
| 403 | 权限不足 |
|
||||
| 404 | 资源不存在 |
|
||||
| 409 | 资源冲突 |
|
||||
| 422 | 请求数据验证失败 |
|
||||
| 429 | 请求频率超限 |
|
||||
| 500 | 服务器内部错误 |
|
||||
|
||||
## 分页
|
||||
|
||||
支持分页的端点使用以下参数:
|
||||
|
||||
- `page`: 页码(从 1 开始)
|
||||
- `limit`: 每页记录数(默认 20,最大 100)
|
||||
- `sort`: 排序字段
|
||||
- `order`: 排序顺序(`asc` 或 `desc`)
|
||||
|
||||
```bash
|
||||
curl -X GET "https://api.mcphub.com/servers?page=2&limit=50&sort=name&order=asc" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
分页响应格式:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"items": [...],
|
||||
"pagination": {
|
||||
"page": 2,
|
||||
"limit": 50,
|
||||
"total": 234,
|
||||
"pages": 5,
|
||||
"hasNext": true,
|
||||
"hasPrev": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 过滤和搜索
|
||||
|
||||
支持过滤的端点可以使用以下参数:
|
||||
|
||||
- `search`: 全文搜索
|
||||
- `filter[field]`: 字段过滤
|
||||
- `status`: 状态过滤
|
||||
- `created_after`: 创建时间筛选
|
||||
- `created_before`: 创建时间筛选
|
||||
|
||||
```bash
|
||||
curl -X GET "https://api.mcphub.com/servers?search=python&filter[status]=running&created_after=2024-01-01" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
## API 端点
|
||||
|
||||
### 服务器管理
|
||||
|
||||
#### 获取服务器列表
|
||||
|
||||
```http
|
||||
GET /api/servers
|
||||
```
|
||||
|
||||
参数:
|
||||
|
||||
- `status` (可选): 过滤服务器状态 (`running`, `stopped`, `error`)
|
||||
- `group` (可选): 过滤所属组
|
||||
- `search` (可选): 搜索服务器名称或描述
|
||||
|
||||
示例响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"items": [
|
||||
{
|
||||
"id": "server-1",
|
||||
"name": "文件系统服务器",
|
||||
"status": "running",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/data"],
|
||||
"env": {
|
||||
"NODE_ENV": "production"
|
||||
},
|
||||
"cwd": "/app",
|
||||
"pid": 12345,
|
||||
"uptime": 3600000,
|
||||
"lastRestart": "2024-01-01T12:00:00Z",
|
||||
"createdAt": "2024-01-01T10:00:00Z",
|
||||
"updatedAt": "2024-01-01T12:00:00Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 创建服务器
|
||||
|
||||
```http
|
||||
POST /api/servers
|
||||
```
|
||||
|
||||
请求体:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "新服务器",
|
||||
"command": "python",
|
||||
"args": ["-m", "mcp_server"],
|
||||
"env": {
|
||||
"API_KEY": "your-api-key",
|
||||
"LOG_LEVEL": "INFO"
|
||||
},
|
||||
"cwd": "/app/python-server",
|
||||
"enabled": true,
|
||||
"description": "Python MCP 服务器",
|
||||
"tags": ["python", "production"]
|
||||
}
|
||||
```
|
||||
|
||||
#### 获取服务器详情
|
||||
|
||||
```http
|
||||
GET /api/servers/{serverId}
|
||||
```
|
||||
|
||||
#### 更新服务器
|
||||
|
||||
```http
|
||||
PUT /api/servers/{serverId}
|
||||
```
|
||||
|
||||
#### 删除服务器
|
||||
|
||||
```http
|
||||
DELETE /api/servers/{serverId}
|
||||
```
|
||||
|
||||
#### 启动服务器
|
||||
|
||||
```http
|
||||
POST /api/servers/{serverId}/start
|
||||
```
|
||||
|
||||
#### 停止服务器
|
||||
|
||||
```http
|
||||
POST /api/servers/{serverId}/stop
|
||||
```
|
||||
|
||||
请求体(可选):
|
||||
|
||||
```json
|
||||
{
|
||||
"graceful": true,
|
||||
"timeout": 30000
|
||||
}
|
||||
```
|
||||
|
||||
#### 重启服务器
|
||||
|
||||
```http
|
||||
POST /api/servers/{serverId}/restart
|
||||
```
|
||||
|
||||
#### 获取服务器日志
|
||||
|
||||
```http
|
||||
GET /api/servers/{serverId}/logs
|
||||
```
|
||||
|
||||
参数:
|
||||
|
||||
- `level` (可选): 日志级别过滤
|
||||
- `limit` (可选): 返回日志条数
|
||||
- `since` (可选): 开始时间
|
||||
- `follow` (可选): 实时跟踪日志
|
||||
|
||||
### 用户管理
|
||||
|
||||
#### 获取用户列表
|
||||
|
||||
```http
|
||||
GET /api/users
|
||||
```
|
||||
|
||||
#### 创建用户
|
||||
|
||||
```http
|
||||
POST /api/users
|
||||
```
|
||||
|
||||
请求体:
|
||||
|
||||
```json
|
||||
{
|
||||
"username": "newuser",
|
||||
"email": "user@example.com",
|
||||
"password": "securepassword",
|
||||
"role": "user",
|
||||
"groups": ["dev-team"],
|
||||
"profile": {
|
||||
"firstName": "张",
|
||||
"lastName": "三",
|
||||
"department": "开发部"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 获取用户详情
|
||||
|
||||
```http
|
||||
GET /api/users/{userId}
|
||||
```
|
||||
|
||||
#### 更新用户
|
||||
|
||||
```http
|
||||
PUT /api/users/{userId}
|
||||
```
|
||||
|
||||
#### 删除用户
|
||||
|
||||
```http
|
||||
DELETE /api/users/{userId}
|
||||
```
|
||||
|
||||
### 组管理
|
||||
|
||||
#### 获取组列表
|
||||
|
||||
```http
|
||||
GET /api/groups
|
||||
```
|
||||
|
||||
#### 创建组
|
||||
|
||||
```http
|
||||
POST /api/groups
|
||||
```
|
||||
|
||||
请求体:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "dev-team",
|
||||
"displayName": "开发团队",
|
||||
"description": "前端和后端开发人员",
|
||||
"parentGroup": null,
|
||||
"permissions": {
|
||||
"servers": ["read", "write", "execute"],
|
||||
"tools": ["read", "execute"]
|
||||
},
|
||||
"settings": {
|
||||
"autoAssign": false,
|
||||
"maxMembers": 50,
|
||||
"requireApproval": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 添加用户到组
|
||||
|
||||
```http
|
||||
POST /api/groups/{groupId}/members
|
||||
```
|
||||
|
||||
请求体:
|
||||
|
||||
```json
|
||||
{
|
||||
"userId": "user123",
|
||||
"role": "member"
|
||||
}
|
||||
```
|
||||
|
||||
#### 从组中移除用户
|
||||
|
||||
```http
|
||||
DELETE /api/groups/{groupId}/members/{userId}
|
||||
```
|
||||
|
||||
#### 分配服务器到组
|
||||
|
||||
```http
|
||||
POST /api/groups/{groupId}/servers
|
||||
```
|
||||
|
||||
请求体:
|
||||
|
||||
```json
|
||||
{
|
||||
"serverId": "server-1",
|
||||
"permissions": ["read", "write", "execute"]
|
||||
}
|
||||
```
|
||||
|
||||
### 身份验证
|
||||
|
||||
#### 登录
|
||||
|
||||
```http
|
||||
POST /api/auth/login
|
||||
```
|
||||
|
||||
请求体:
|
||||
|
||||
```json
|
||||
{
|
||||
"username": "admin",
|
||||
"password": "password",
|
||||
"mfaCode": "123456"
|
||||
}
|
||||
```
|
||||
|
||||
响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||
"refreshToken": "refresh_token_here",
|
||||
"expiresIn": 86400,
|
||||
"user": {
|
||||
"id": "user123",
|
||||
"username": "admin",
|
||||
"role": "admin",
|
||||
"permissions": ["*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 刷新令牌
|
||||
|
||||
```http
|
||||
POST /api/auth/refresh
|
||||
```
|
||||
|
||||
#### 注销
|
||||
|
||||
```http
|
||||
POST /api/auth/logout
|
||||
```
|
||||
|
||||
#### 验证令牌
|
||||
|
||||
```http
|
||||
GET /api/auth/verify
|
||||
```
|
||||
|
||||
### 监控
|
||||
|
||||
#### 获取系统状态
|
||||
|
||||
```http
|
||||
GET /api/monitoring/status
|
||||
```
|
||||
|
||||
响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"system": {
|
||||
"uptime": 86400,
|
||||
"version": "2.1.0",
|
||||
"nodeVersion": "18.17.0"
|
||||
},
|
||||
"servers": {
|
||||
"total": 12,
|
||||
"running": 10,
|
||||
"stopped": 1,
|
||||
"error": 1
|
||||
},
|
||||
"performance": {
|
||||
"requestsPerMinute": 85,
|
||||
"avgResponseTime": "245ms",
|
||||
"errorRate": "0.3%"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 获取性能指标
|
||||
|
||||
```http
|
||||
GET /api/monitoring/metrics
|
||||
```
|
||||
|
||||
参数:
|
||||
|
||||
- `timeRange`: 时间范围 (`1h`, `24h`, `7d`, `30d`)
|
||||
- `granularity`: 数据粒度 (`1m`, `5m`, `1h`, `1d`)
|
||||
- `metrics`: 指定指标名称(逗号分隔)
|
||||
|
||||
#### 获取日志
|
||||
|
||||
```http
|
||||
GET /api/monitoring/logs
|
||||
```
|
||||
|
||||
参数:
|
||||
|
||||
- `level`: 日志级别
|
||||
- `source`: 日志源
|
||||
- `limit`: 返回条数
|
||||
- `since`: 开始时间
|
||||
- `until`: 结束时间
|
||||
|
||||
### 配置管理
|
||||
|
||||
#### 获取系统配置
|
||||
|
||||
```http
|
||||
GET /api/config
|
||||
```
|
||||
|
||||
#### 更新系统配置
|
||||
|
||||
```http
|
||||
PUT /api/config
|
||||
```
|
||||
|
||||
请求体:
|
||||
|
||||
```json
|
||||
{
|
||||
"smtp": {
|
||||
"host": "smtp.example.com",
|
||||
"port": 587,
|
||||
"secure": false,
|
||||
"auth": {
|
||||
"user": "noreply@example.com",
|
||||
"pass": "password"
|
||||
}
|
||||
},
|
||||
"notifications": {
|
||||
"email": true,
|
||||
"slack": true,
|
||||
"webhook": "https://hooks.example.com/notifications"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## WebSocket API
|
||||
|
||||
MCPHub 支持 WebSocket 连接以获取实时更新。
|
||||
|
||||
### 连接
|
||||
|
||||
```javascript
|
||||
const ws = new WebSocket('wss://api.mcphub.com/ws');
|
||||
ws.onopen = function () {
|
||||
// 发送认证消息
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
type: 'auth',
|
||||
token: 'YOUR_JWT_TOKEN',
|
||||
}),
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
### 订阅事件
|
||||
|
||||
```javascript
|
||||
// 订阅服务器状态更新
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
type: 'subscribe',
|
||||
channel: 'server-status',
|
||||
filters: {
|
||||
serverId: 'server-1',
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
// 订阅系统监控
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
type: 'subscribe',
|
||||
channel: 'monitoring',
|
||||
metrics: ['cpu', 'memory', 'requests'],
|
||||
}),
|
||||
);
|
||||
```
|
||||
|
||||
### 事件类型
|
||||
|
||||
- `server-status`: 服务器状态变化
|
||||
- `server-logs`: 实时日志流
|
||||
- `monitoring`: 系统监控指标
|
||||
- `alerts`: 系统警报
|
||||
- `user-activity`: 用户活动事件
|
||||
|
||||
## 错误处理
|
||||
|
||||
### 错误代码
|
||||
|
||||
| 错误代码 | 描述 |
|
||||
| ----------------------- | -------------- |
|
||||
| `INVALID_REQUEST` | 请求格式无效 |
|
||||
| `AUTHENTICATION_FAILED` | 身份验证失败 |
|
||||
| `AUTHORIZATION_FAILED` | 权限不足 |
|
||||
| `RESOURCE_NOT_FOUND` | 资源不存在 |
|
||||
| `RESOURCE_CONFLICT` | 资源冲突 |
|
||||
| `VALIDATION_ERROR` | 数据验证失败 |
|
||||
| `RATE_LIMIT_EXCEEDED` | 请求频率超限 |
|
||||
| `SERVER_ERROR` | 服务器内部错误 |
|
||||
|
||||
### 错误处理示例
|
||||
|
||||
```javascript
|
||||
async function handleApiRequest() {
|
||||
try {
|
||||
const response = await fetch('/api/servers', {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!data.success) {
|
||||
switch (data.error.code) {
|
||||
case 'AUTHENTICATION_FAILED':
|
||||
// 重新登录
|
||||
redirectToLogin();
|
||||
break;
|
||||
case 'RATE_LIMIT_EXCEEDED':
|
||||
// 延迟重试
|
||||
setTimeout(() => handleApiRequest(), 5000);
|
||||
break;
|
||||
default:
|
||||
// 显示错误消息
|
||||
showError(data.error.message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理成功响应
|
||||
handleSuccessResponse(data.data);
|
||||
} catch (error) {
|
||||
// 处理网络错误
|
||||
console.error('网络请求失败:', error);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 速率限制
|
||||
|
||||
API 实施速率限制以防止滥用:
|
||||
|
||||
- **默认限制**: 每分钟 100 请求
|
||||
- **认证用户**: 每分钟 1000 请求
|
||||
- **管理员**: 每分钟 5000 请求
|
||||
|
||||
响应头包含速率限制信息:
|
||||
|
||||
```
|
||||
X-RateLimit-Limit: 1000
|
||||
X-RateLimit-Remaining: 999
|
||||
X-RateLimit-Reset: 1609459200
|
||||
```
|
||||
|
||||
## SDK 和客户端库
|
||||
|
||||
### JavaScript/Node.js
|
||||
|
||||
```bash
|
||||
npm install @mcphub/sdk
|
||||
```
|
||||
|
||||
```javascript
|
||||
import { MCPHubClient } from '@mcphub/sdk';
|
||||
|
||||
const client = new MCPHubClient({
|
||||
baseURL: 'https://api.mcphub.com',
|
||||
token: 'YOUR_JWT_TOKEN',
|
||||
});
|
||||
|
||||
// 获取服务器列表
|
||||
const servers = await client.servers.list();
|
||||
|
||||
// 创建服务器
|
||||
const newServer = await client.servers.create({
|
||||
name: '新服务器',
|
||||
command: 'python',
|
||||
args: ['-m', 'mcp_server'],
|
||||
});
|
||||
```
|
||||
|
||||
### Python
|
||||
|
||||
```bash
|
||||
pip install mcphub-sdk
|
||||
```
|
||||
|
||||
```python
|
||||
from mcphub_sdk import MCPHubClient
|
||||
|
||||
client = MCPHubClient(
|
||||
base_url='https://api.mcphub.com',
|
||||
token='YOUR_JWT_TOKEN'
|
||||
)
|
||||
|
||||
# 获取服务器列表
|
||||
servers = client.servers.list()
|
||||
|
||||
# 创建服务器
|
||||
new_server = client.servers.create(
|
||||
name='新服务器',
|
||||
command='python',
|
||||
args=['-m', 'mcp_server']
|
||||
)
|
||||
```
|
||||
|
||||
## 最佳实践
|
||||
|
||||
1. **使用 HTTPS**: 始终通过 HTTPS 访问 API
|
||||
2. **安全存储令牌**: 不要在客户端代码中硬编码令牌
|
||||
3. **处理错误**: 实施适当的错误处理和重试逻辑
|
||||
4. **遵守速率限制**: 监控速率限制并实施退避策略
|
||||
5. **使用分页**: 对于大数据集使用分页参数
|
||||
6. **缓存响应**: 适当缓存 API 响应以减少请求
|
||||
7. **版本控制**: 使用 API 版本号以确保兼容性
|
||||
|
||||
有关更多信息,请参阅我们的 [SDK 文档](https://docs.mcphub.com/sdk) 和 [示例代码](https://github.com/mcphub/examples)。
|
||||
539
docs/zh/configuration/docker-setup.mdx
Normal file
@@ -0,0 +1,539 @@
|
||||
---
|
||||
title: 'Docker 部署'
|
||||
description: '使用 Docker 和 Docker Compose 部署 MCPHub'
|
||||
---
|
||||
|
||||
# Docker 部署
|
||||
|
||||
本指南介绍使用 Docker 部署 MCPHub,包括开发和生产配置。
|
||||
|
||||
## Docker 快速开始
|
||||
|
||||
### 使用预构建镜像
|
||||
|
||||
```bash
|
||||
# 拉取最新镜像
|
||||
docker pull mcphub/mcphub:latest
|
||||
|
||||
# 使用默认配置运行
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
-p 3000:3000 \
|
||||
-v $(pwd)/mcp_settings.json:/app/mcp_settings.json \
|
||||
mcphub/mcphub:latest
|
||||
```
|
||||
|
||||
### 从源码构建
|
||||
|
||||
```bash
|
||||
# 克隆仓库
|
||||
git clone https://github.com/your-username/mcphub.git
|
||||
cd mcphub
|
||||
|
||||
# 构建 Docker 镜像
|
||||
docker build -t mcphub:local .
|
||||
|
||||
# 运行容器
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
-p 3000:3000 \
|
||||
-v $(pwd)/mcp_settings.json:/app/mcp_settings.json \
|
||||
mcphub:local
|
||||
```
|
||||
|
||||
## Docker Compose 设置
|
||||
|
||||
### 基本配置
|
||||
|
||||
创建 `docker-compose.yml` 文件:
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
mcphub:
|
||||
image: mcphub/mcphub:latest
|
||||
# 本地开发时使用:
|
||||
# build: .
|
||||
container_name: mcphub
|
||||
ports:
|
||||
- '3000:3000'
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- PORT=3000
|
||||
- JWT_SECRET=${JWT_SECRET:-your-jwt-secret}
|
||||
- DATABASE_URL=postgresql://mcphub:password@postgres:5432/mcphub
|
||||
volumes:
|
||||
- ./mcp_settings.json:/app/mcp_settings.json:ro
|
||||
- ./servers.json:/app/servers.json:ro
|
||||
- mcphub_data:/app/data
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mcphub-network
|
||||
|
||||
postgres:
|
||||
image: postgres:15-alpine
|
||||
container_name: mcphub-postgres
|
||||
environment:
|
||||
- POSTGRES_DB=mcphub
|
||||
- POSTGRES_USER=mcphub
|
||||
- POSTGRES_PASSWORD=password
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- ./scripts/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql:ro
|
||||
ports:
|
||||
- '5432:5432'
|
||||
healthcheck:
|
||||
test: ['CMD-SHELL', 'pg_isready -U mcphub -d mcphub']
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mcphub-network
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
mcphub_data:
|
||||
|
||||
networks:
|
||||
mcphub-network:
|
||||
driver: bridge
|
||||
```
|
||||
|
||||
### 生产配置(包含 Nginx)
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
container_name: mcphub-nginx
|
||||
ports:
|
||||
- '80:80'
|
||||
- '443:443'
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
- ./ssl:/etc/nginx/ssl:ro
|
||||
- nginx_logs:/var/log/nginx
|
||||
depends_on:
|
||||
- mcphub
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mcphub-network
|
||||
|
||||
mcphub:
|
||||
image: mcphub/mcphub:latest
|
||||
container_name: mcphub-app
|
||||
expose:
|
||||
- '3000'
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- PORT=3000
|
||||
- JWT_SECRET=${JWT_SECRET}
|
||||
- JWT_EXPIRES_IN=${JWT_EXPIRES_IN:-24h}
|
||||
- DATABASE_URL=postgresql://mcphub:${POSTGRES_PASSWORD}@postgres:5432/mcphub
|
||||
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
||||
- REDIS_URL=redis://redis:6379
|
||||
volumes:
|
||||
- ./mcp_settings.json:/app/mcp_settings.json:ro
|
||||
- ./servers.json:/app/servers.json:ro
|
||||
- mcphub_data:/app/data
|
||||
- mcphub_logs:/app/logs
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mcphub-network
|
||||
healthcheck:
|
||||
test: ['CMD', 'wget', '--quiet', '--tries=1', '--spider', 'http://localhost:3000/health']
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
postgres:
|
||||
image: postgres:15-alpine
|
||||
container_name: mcphub-postgres
|
||||
environment:
|
||||
- POSTGRES_DB=mcphub
|
||||
- POSTGRES_USER=mcphub
|
||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- ./backups:/backups
|
||||
healthcheck:
|
||||
test: ['CMD-SHELL', 'pg_isready -U mcphub -d mcphub']
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mcphub-network
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: mcphub-redis
|
||||
command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD}
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ['CMD', 'redis-cli', 'ping']
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mcphub-network
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
redis_data:
|
||||
mcphub_data:
|
||||
mcphub_logs:
|
||||
nginx_logs:
|
||||
|
||||
networks:
|
||||
mcphub-network:
|
||||
driver: bridge
|
||||
```
|
||||
|
||||
### 环境变量
|
||||
|
||||
为 Docker Compose 创建 `.env` 文件:
|
||||
|
||||
```env
|
||||
# 应用程序
|
||||
NODE_ENV=production
|
||||
JWT_SECRET=your-super-secret-jwt-key-change-this
|
||||
JWT_EXPIRES_IN=24h
|
||||
|
||||
# 数据库
|
||||
POSTGRES_PASSWORD=your-secure-database-password
|
||||
|
||||
# Redis
|
||||
REDIS_PASSWORD=your-secure-redis-password
|
||||
|
||||
# 外部 API
|
||||
OPENAI_API_KEY=your-openai-api-key
|
||||
|
||||
# 可选:自定义端口
|
||||
# PORT=3000
|
||||
```
|
||||
|
||||
## 开发设置
|
||||
|
||||
### 开发 Docker Compose
|
||||
|
||||
创建 `docker-compose.dev.yml`:
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
mcphub-dev:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.dev
|
||||
container_name: mcphub-dev
|
||||
ports:
|
||||
- '3000:3000'
|
||||
- '5173:5173' # 前端开发服务器
|
||||
- '9229:9229' # 调试端口
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
- PORT=3000
|
||||
- DATABASE_URL=postgresql://mcphub:password@postgres:5432/mcphub
|
||||
volumes:
|
||||
- .:/app
|
||||
- /app/node_modules
|
||||
- /app/frontend/node_modules
|
||||
depends_on:
|
||||
- postgres
|
||||
command: pnpm dev
|
||||
networks:
|
||||
- mcphub-dev
|
||||
|
||||
postgres:
|
||||
image: postgres:15-alpine
|
||||
container_name: mcphub-postgres-dev
|
||||
environment:
|
||||
- POSTGRES_DB=mcphub
|
||||
- POSTGRES_USER=mcphub
|
||||
- POSTGRES_PASSWORD=password
|
||||
ports:
|
||||
- '5432:5432'
|
||||
volumes:
|
||||
- postgres_dev_data:/var/lib/postgresql/data
|
||||
networks:
|
||||
- mcphub-dev
|
||||
|
||||
volumes:
|
||||
postgres_dev_data:
|
||||
|
||||
networks:
|
||||
mcphub-dev:
|
||||
driver: bridge
|
||||
```
|
||||
|
||||
### 开发 Dockerfile
|
||||
|
||||
创建 `Dockerfile.dev`:
|
||||
|
||||
```dockerfile
|
||||
FROM node:20-alpine
|
||||
|
||||
# 安装 pnpm
|
||||
RUN npm install -g pnpm
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制包文件
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
COPY frontend/package.json ./frontend/
|
||||
|
||||
# 安装依赖
|
||||
RUN pnpm install
|
||||
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 3000 5173 9229
|
||||
|
||||
# 启动开发服务器
|
||||
CMD ["pnpm", "dev"]
|
||||
```
|
||||
|
||||
## 运行应用程序
|
||||
|
||||
### 开发模式
|
||||
|
||||
```bash
|
||||
# 启动开发环境
|
||||
docker-compose -f docker-compose.dev.yml up -d
|
||||
|
||||
# 查看日志
|
||||
docker-compose -f docker-compose.dev.yml logs -f mcphub-dev
|
||||
|
||||
# 停止开发环境
|
||||
docker-compose -f docker-compose.dev.yml down
|
||||
```
|
||||
|
||||
### 生产模式
|
||||
|
||||
```bash
|
||||
# 启动生产环境
|
||||
docker-compose up -d
|
||||
|
||||
# 查看日志
|
||||
docker-compose logs -f mcphub
|
||||
|
||||
# 停止生产环境
|
||||
docker-compose down
|
||||
```
|
||||
|
||||
## 配置管理
|
||||
|
||||
### MCP 设置卷挂载
|
||||
|
||||
创建您的 `mcp_settings.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"]
|
||||
},
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"]
|
||||
},
|
||||
"amap": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@amap/amap-maps-mcp-server"],
|
||||
"env": {
|
||||
"AMAP_MAPS_API_KEY": "your-api-key"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 密钥管理
|
||||
|
||||
对于生产环境,使用 Docker 密钥:
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
mcphub:
|
||||
image: mcphub/mcphub:latest
|
||||
environment:
|
||||
- JWT_SECRET_FILE=/run/secrets/jwt_secret
|
||||
- DATABASE_PASSWORD_FILE=/run/secrets/db_password
|
||||
secrets:
|
||||
- jwt_secret
|
||||
- db_password
|
||||
|
||||
secrets:
|
||||
jwt_secret:
|
||||
file: ./secrets/jwt_secret.txt
|
||||
db_password:
|
||||
file: ./secrets/db_password.txt
|
||||
```
|
||||
|
||||
## 数据持久化
|
||||
|
||||
### 数据库备份
|
||||
|
||||
在 `docker-compose.yml` 中添加备份服务:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
backup:
|
||||
image: postgres:15-alpine
|
||||
container_name: mcphub-backup
|
||||
environment:
|
||||
- PGPASSWORD=${POSTGRES_PASSWORD}
|
||||
volumes:
|
||||
- ./backups:/backups
|
||||
- ./scripts/backup.sh:/backup.sh:ro
|
||||
command: /bin/sh -c "chmod +x /backup.sh && /backup.sh"
|
||||
depends_on:
|
||||
- postgres
|
||||
profiles:
|
||||
- backup
|
||||
networks:
|
||||
- mcphub-network
|
||||
```
|
||||
|
||||
创建 `scripts/backup.sh`:
|
||||
|
||||
```bash
|
||||
#!/bin/sh
|
||||
BACKUP_FILE="/backups/mcphub_$(date +%Y%m%d_%H%M%S).sql"
|
||||
pg_dump -h postgres -U mcphub -d mcphub > "$BACKUP_FILE"
|
||||
echo "备份已创建:$BACKUP_FILE"
|
||||
|
||||
# 只保留最近 7 天的备份
|
||||
find /backups -name "mcphub_*.sql" -mtime +7 -delete
|
||||
```
|
||||
|
||||
运行备份:
|
||||
|
||||
```bash
|
||||
docker-compose --profile backup run --rm backup
|
||||
```
|
||||
|
||||
## 监控和健康检查
|
||||
|
||||
### 健康检查端点
|
||||
|
||||
在您的应用程序中添加:
|
||||
|
||||
```javascript
|
||||
// 在您的 Express 应用中
|
||||
app.get('/health', (req, res) => {
|
||||
res.json({
|
||||
status: 'healthy',
|
||||
timestamp: new Date().toISOString(),
|
||||
uptime: process.uptime(),
|
||||
memory: process.memoryUsage(),
|
||||
version: process.env.npm_package_version,
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### Docker 健康检查
|
||||
|
||||
```yaml
|
||||
services:
|
||||
mcphub:
|
||||
# ... 其他配置
|
||||
healthcheck:
|
||||
test: ['CMD', 'wget', '--quiet', '--tries=1', '--spider', 'http://localhost:3000/health']
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 60s
|
||||
```
|
||||
|
||||
### 使用 Watchtower 监控
|
||||
|
||||
添加自动更新:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
watchtower:
|
||||
image: containrrr/watchtower
|
||||
container_name: mcphub-watchtower
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
environment:
|
||||
- WATCHTOWER_CLEANUP=true
|
||||
- WATCHTOWER_POLL_INTERVAL=3600
|
||||
- WATCHTOWER_INCLUDE_STOPPED=true
|
||||
restart: unless-stopped
|
||||
```
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
**容器启动失败**:使用 `docker-compose logs mcphub` 检查日志
|
||||
|
||||
**数据库连接错误**:确保 PostgreSQL 健康且可访问
|
||||
|
||||
**端口冲突**:检查端口 3000/5432 是否已被占用
|
||||
|
||||
**卷挂载问题**:验证文件路径和权限
|
||||
|
||||
### 调试命令
|
||||
|
||||
```bash
|
||||
# 检查容器状态
|
||||
docker-compose ps
|
||||
|
||||
# 查看日志
|
||||
docker-compose logs -f [service_name]
|
||||
|
||||
# 在容器中执行命令
|
||||
docker-compose exec mcphub sh
|
||||
|
||||
# 检查数据库连接
|
||||
docker-compose exec postgres psql -U mcphub -d mcphub
|
||||
|
||||
# 重启特定服务
|
||||
docker-compose restart mcphub
|
||||
|
||||
# 重新构建并重启
|
||||
docker-compose up --build -d
|
||||
```
|
||||
|
||||
### 性能优化
|
||||
|
||||
```yaml
|
||||
services:
|
||||
mcphub:
|
||||
# ... 其他配置
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 512M
|
||||
cpus: '0.5'
|
||||
reservations:
|
||||
memory: 256M
|
||||
cpus: '0.25'
|
||||
```
|
||||
|
||||
此 Docker 设置为 MCPHub 提供了完整的容器化环境,包含开发和生产配置。
|
||||
389
docs/zh/configuration/environment-variables.mdx
Normal file
@@ -0,0 +1,389 @@
|
||||
---
|
||||
title: '环境变量配置'
|
||||
description: '使用环境变量配置 MCPHub'
|
||||
---
|
||||
|
||||
# 环境变量配置
|
||||
|
||||
MCPHub 使用环境变量进行配置。本指南涵盖所有可用变量及其用法。
|
||||
|
||||
## 核心应用设置
|
||||
|
||||
### 服务器配置
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| ----------- | ------------- | ----------------------------------------------- |
|
||||
| `PORT` | `3000` | HTTP 服务器端口号 |
|
||||
| `HOST` | `0.0.0.0` | 服务器绑定的主机地址 |
|
||||
| `NODE_ENV` | `development` | 应用环境(`development`、`production`、`test`) |
|
||||
| `LOG_LEVEL` | `info` | 日志级别(`error`、`warn`、`info`、`debug`) |
|
||||
|
||||
```env
|
||||
PORT=3000
|
||||
HOST=0.0.0.0
|
||||
NODE_ENV=production
|
||||
LOG_LEVEL=info
|
||||
```
|
||||
|
||||
### 数据库配置
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| -------------- | ----------- | --------------------- |
|
||||
| `DATABASE_URL` | - | PostgreSQL 连接字符串 |
|
||||
| `DB_HOST` | `localhost` | 数据库主机 |
|
||||
| `DB_PORT` | `5432` | 数据库端口 |
|
||||
| `DB_NAME` | `mcphub` | 数据库名称 |
|
||||
| `DB_USER` | `mcphub` | 数据库用户名 |
|
||||
| `DB_PASSWORD` | - | 数据库密码 |
|
||||
| `DB_SSL` | `false` | 启用数据库 SSL 连接 |
|
||||
| `DB_POOL_MIN` | `2` | 最小数据库连接池大小 |
|
||||
| `DB_POOL_MAX` | `10` | 最大数据库连接池大小 |
|
||||
|
||||
```env
|
||||
# 选项 1:完整连接字符串
|
||||
DATABASE_URL=postgresql://username:password@localhost:5432/mcphub
|
||||
|
||||
# 选项 2:单独组件
|
||||
DB_HOST=localhost
|
||||
DB_PORT=5432
|
||||
DB_NAME=mcphub
|
||||
DB_USER=mcphub
|
||||
DB_PASSWORD=your-password
|
||||
DB_SSL=false
|
||||
```
|
||||
|
||||
## 认证与安全
|
||||
|
||||
### JWT 配置
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| ------------------------ | ------- | ------------------------ |
|
||||
| `JWT_SECRET` | - | JWT 令牌签名密钥(必需) |
|
||||
| `JWT_EXPIRES_IN` | `24h` | JWT 令牌过期时间 |
|
||||
| `JWT_REFRESH_EXPIRES_IN` | `7d` | 刷新令牌过期时间 |
|
||||
| `JWT_ALGORITHM` | `HS256` | JWT 签名算法 |
|
||||
|
||||
```env
|
||||
JWT_SECRET=your-super-secret-key-change-this-in-production
|
||||
JWT_EXPIRES_IN=24h
|
||||
JWT_REFRESH_EXPIRES_IN=7d
|
||||
```
|
||||
|
||||
### 会话与安全
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| ------------------- | ------ | -------------------- |
|
||||
| `SESSION_SECRET` | - | 会话加密密钥 |
|
||||
| `BCRYPT_ROUNDS` | `12` | bcrypt 哈希轮数 |
|
||||
| `RATE_LIMIT_WINDOW` | `15` | 速率限制窗口(分钟) |
|
||||
| `RATE_LIMIT_MAX` | `100` | 每个窗口最大请求数 |
|
||||
| `CORS_ORIGIN` | `*` | 允许的 CORS 来源 |
|
||||
|
||||
```env
|
||||
SESSION_SECRET=your-session-secret
|
||||
BCRYPT_ROUNDS=12
|
||||
RATE_LIMIT_WINDOW=15
|
||||
RATE_LIMIT_MAX=100
|
||||
CORS_ORIGIN=https://your-domain.com,https://admin.your-domain.com
|
||||
```
|
||||
|
||||
## 外部服务
|
||||
|
||||
### OpenAI 配置
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| ------------------------ | ------------------------ | ------------------------------- |
|
||||
| `OPENAI_API_KEY` | - | OpenAI API 密钥(用于智能路由) |
|
||||
| `OPENAI_MODEL` | `gpt-3.5-turbo` | OpenAI 嵌入模型 |
|
||||
| `OPENAI_EMBEDDING_MODEL` | `text-embedding-ada-002` | 向量嵌入模型 |
|
||||
| `OPENAI_MAX_TOKENS` | `1000` | 每个请求最大令牌数 |
|
||||
| `OPENAI_TEMPERATURE` | `0.1` | AI 响应温度 |
|
||||
|
||||
```env
|
||||
OPENAI_API_KEY=sk-your-openai-api-key
|
||||
OPENAI_MODEL=gpt-3.5-turbo
|
||||
OPENAI_EMBEDDING_MODEL=text-embedding-ada-002
|
||||
OPENAI_MAX_TOKENS=1000
|
||||
OPENAI_TEMPERATURE=0.1
|
||||
```
|
||||
|
||||
### Redis 配置(可选)
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| ---------------- | ----------- | ---------------- |
|
||||
| `REDIS_URL` | - | Redis 连接字符串 |
|
||||
| `REDIS_HOST` | `localhost` | Redis 主机 |
|
||||
| `REDIS_PORT` | `6379` | Redis 端口 |
|
||||
| `REDIS_PASSWORD` | - | Redis 密码 |
|
||||
| `REDIS_DB` | `0` | Redis 数据库编号 |
|
||||
| `REDIS_PREFIX` | `mcphub:` | Redis 键前缀 |
|
||||
|
||||
```env
|
||||
# 选项 1:完整连接字符串
|
||||
REDIS_URL=redis://username:password@localhost:6379/0
|
||||
|
||||
# 选项 2:单独组件
|
||||
REDIS_HOST=localhost
|
||||
REDIS_PORT=6379
|
||||
REDIS_PASSWORD=your-redis-password
|
||||
REDIS_DB=0
|
||||
REDIS_PREFIX=mcphub:
|
||||
```
|
||||
|
||||
## MCP 服务器配置
|
||||
|
||||
### 默认设置
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| ------------------- | ------------------- | ---------------------------- |
|
||||
| `MCP_SETTINGS_FILE` | `mcp_settings.json` | MCP 设置文件路径 |
|
||||
| `MCP_SERVERS_FILE` | `servers.json` | 服务器配置文件路径 |
|
||||
| `MCP_TIMEOUT` | `30000` | MCP 操作默认超时(毫秒) |
|
||||
| `MCP_MAX_RETRIES` | `3` | 失败操作最大重试次数 |
|
||||
| `MCP_RESTART_DELAY` | `5000` | 重启失败服务器的延迟(毫秒) |
|
||||
|
||||
```env
|
||||
MCP_SETTINGS_FILE=./config/mcp_settings.json
|
||||
MCP_SERVERS_FILE=./config/servers.json
|
||||
MCP_TIMEOUT=30000
|
||||
MCP_MAX_RETRIES=3
|
||||
MCP_RESTART_DELAY=5000
|
||||
```
|
||||
|
||||
### 智能路由
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| --------------------------- | ------ | ---------------------- |
|
||||
| `SMART_ROUTING_ENABLED` | `true` | 启用 AI 驱动的智能路由 |
|
||||
| `SMART_ROUTING_THRESHOLD` | `0.7` | 路由相似度阈值 |
|
||||
| `SMART_ROUTING_MAX_RESULTS` | `5` | 返回的最大工具数 |
|
||||
| `VECTOR_CACHE_TTL` | `3600` | 向量缓存 TTL(秒) |
|
||||
|
||||
```env
|
||||
SMART_ROUTING_ENABLED=true
|
||||
SMART_ROUTING_THRESHOLD=0.7
|
||||
SMART_ROUTING_MAX_RESULTS=5
|
||||
VECTOR_CACHE_TTL=3600
|
||||
```
|
||||
|
||||
## 文件存储与上传
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| -------------------- | ---------------- | -------------------------------- |
|
||||
| `UPLOAD_DIR` | `./uploads` | 文件上传目录 |
|
||||
| `MAX_FILE_SIZE` | `10485760` | 最大文件大小(字节,10MB) |
|
||||
| `ALLOWED_FILE_TYPES` | `image/*,text/*` | 允许的 MIME 类型 |
|
||||
| `STORAGE_TYPE` | `local` | 存储类型(`local`、`s3`、`gcs`) |
|
||||
|
||||
```env
|
||||
UPLOAD_DIR=./data/uploads
|
||||
MAX_FILE_SIZE=10485760
|
||||
ALLOWED_FILE_TYPES=image/*,text/*,application/json
|
||||
STORAGE_TYPE=local
|
||||
```
|
||||
|
||||
### S3 存储(可选)
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| ---------------------- | ----------- | -------------- |
|
||||
| `S3_BUCKET` | - | S3 存储桶名称 |
|
||||
| `S3_REGION` | `us-east-1` | S3 区域 |
|
||||
| `S3_ACCESS_KEY_ID` | - | S3 访问密钥 |
|
||||
| `S3_SECRET_ACCESS_KEY` | - | S3 密钥 |
|
||||
| `S3_ENDPOINT` | - | 自定义 S3 端点 |
|
||||
|
||||
```env
|
||||
S3_BUCKET=mcphub-uploads
|
||||
S3_REGION=us-east-1
|
||||
S3_ACCESS_KEY_ID=your-access-key
|
||||
S3_SECRET_ACCESS_KEY=your-secret-key
|
||||
```
|
||||
|
||||
## 监控与日志
|
||||
|
||||
### 应用监控
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| ------------------------ | ------- | -------------------- |
|
||||
| `METRICS_ENABLED` | `true` | 启用指标收集 |
|
||||
| `METRICS_PORT` | `9090` | 指标端点端口 |
|
||||
| `HEALTH_CHECK_INTERVAL` | `30000` | 健康检查间隔(毫秒) |
|
||||
| `PERFORMANCE_MONITORING` | `false` | 启用性能监控 |
|
||||
|
||||
```env
|
||||
METRICS_ENABLED=true
|
||||
METRICS_PORT=9090
|
||||
HEALTH_CHECK_INTERVAL=30000
|
||||
PERFORMANCE_MONITORING=true
|
||||
```
|
||||
|
||||
### 日志配置
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| ------------------ | ------------ | -------------------------------- |
|
||||
| `LOG_FORMAT` | `json` | 日志格式(`json`、`text`) |
|
||||
| `LOG_FILE` | - | 日志文件路径(如果启用文件日志) |
|
||||
| `LOG_MAX_SIZE` | `10m` | 最大日志文件大小 |
|
||||
| `LOG_MAX_FILES` | `5` | 最大日志文件数 |
|
||||
| `LOG_DATE_PATTERN` | `YYYY-MM-DD` | 日志轮换日期模式 |
|
||||
|
||||
```env
|
||||
LOG_FORMAT=json
|
||||
LOG_FILE=./logs/mcphub.log
|
||||
LOG_MAX_SIZE=10m
|
||||
LOG_MAX_FILES=5
|
||||
LOG_DATE_PATTERN=YYYY-MM-DD
|
||||
```
|
||||
|
||||
## 开发与调试
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| ------------------------ | ------- | ------------------------------- |
|
||||
| `DEBUG` | - | 调试命名空间(例如 `mcphub:*`) |
|
||||
| `DEV_TOOLS_ENABLED` | `false` | 启用开发工具 |
|
||||
| `HOT_RELOAD` | `true` | 在开发中启用热重载 |
|
||||
| `MOCK_EXTERNAL_SERVICES` | `false` | 模拟外部 API 调用 |
|
||||
|
||||
```env
|
||||
DEBUG=mcphub:*
|
||||
DEV_TOOLS_ENABLED=true
|
||||
HOT_RELOAD=true
|
||||
MOCK_EXTERNAL_SERVICES=false
|
||||
```
|
||||
|
||||
## 生产优化
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| ------------------ | ------- | ---------------------- |
|
||||
| `CLUSTER_MODE` | `false` | 启用集群模式 |
|
||||
| `WORKER_PROCESSES` | `0` | 工作进程数(0 = 自动) |
|
||||
| `MEMORY_LIMIT` | - | 每个进程内存限制 |
|
||||
| `CPU_LIMIT` | - | 每个进程 CPU 限制 |
|
||||
| `GC_OPTIMIZE` | `false` | 启用垃圾回收优化 |
|
||||
|
||||
```env
|
||||
CLUSTER_MODE=true
|
||||
WORKER_PROCESSES=4
|
||||
MEMORY_LIMIT=512M
|
||||
GC_OPTIMIZE=true
|
||||
```
|
||||
|
||||
## 配置示例
|
||||
|
||||
### 开发环境
|
||||
|
||||
```env
|
||||
# .env.development
|
||||
NODE_ENV=development
|
||||
PORT=3000
|
||||
LOG_LEVEL=debug
|
||||
|
||||
# 数据库
|
||||
DATABASE_URL=postgresql://mcphub:password@localhost:5432/mcphub_dev
|
||||
|
||||
# 认证
|
||||
JWT_SECRET=dev-secret-key
|
||||
JWT_EXPIRES_IN=24h
|
||||
|
||||
# OpenAI(开发时可选)
|
||||
# OPENAI_API_KEY=your-dev-key
|
||||
|
||||
# 调试
|
||||
DEBUG=mcphub:*
|
||||
DEV_TOOLS_ENABLED=true
|
||||
HOT_RELOAD=true
|
||||
```
|
||||
|
||||
### 生产环境
|
||||
|
||||
```env
|
||||
# .env.production
|
||||
NODE_ENV=production
|
||||
PORT=3000
|
||||
LOG_LEVEL=info
|
||||
LOG_FORMAT=json
|
||||
|
||||
# 数据库
|
||||
DATABASE_URL=postgresql://mcphub:secure-password@db.example.com:5432/mcphub
|
||||
DB_SSL=true
|
||||
DB_POOL_MAX=20
|
||||
|
||||
# 安全
|
||||
JWT_SECRET=your-super-secure-production-secret
|
||||
SESSION_SECRET=your-session-secret
|
||||
BCRYPT_ROUNDS=14
|
||||
|
||||
# 外部服务
|
||||
OPENAI_API_KEY=your-production-openai-key
|
||||
REDIS_URL=redis://redis.example.com:6379
|
||||
|
||||
# 监控
|
||||
METRICS_ENABLED=true
|
||||
PERFORMANCE_MONITORING=true
|
||||
|
||||
# 优化
|
||||
CLUSTER_MODE=true
|
||||
GC_OPTIMIZE=true
|
||||
```
|
||||
|
||||
### Docker 环境
|
||||
|
||||
```env
|
||||
# .env.docker
|
||||
NODE_ENV=production
|
||||
HOST=0.0.0.0
|
||||
PORT=3000
|
||||
|
||||
# 使用 Docker 网络的服务名
|
||||
DATABASE_URL=postgresql://mcphub:password@postgres:5432/mcphub
|
||||
REDIS_URL=redis://redis:6379
|
||||
|
||||
# 安全
|
||||
JWT_SECRET_FILE=/run/secrets/jwt_secret
|
||||
DB_PASSWORD_FILE=/run/secrets/db_password
|
||||
|
||||
# 容器中的文件路径
|
||||
MCP_SETTINGS_FILE=/app/mcp_settings.json
|
||||
UPLOAD_DIR=/app/data/uploads
|
||||
LOG_FILE=/app/logs/mcphub.log
|
||||
```
|
||||
|
||||
## 环境变量加载
|
||||
|
||||
MCPHub 按以下顺序加载环境变量:
|
||||
|
||||
1. 系统环境变量
|
||||
2. `.env.local`(被 git 忽略)
|
||||
3. `.env.{NODE_ENV}`(例如 `.env.production`)
|
||||
4. `.env`
|
||||
|
||||
### 使用 dotenv-expand
|
||||
|
||||
MCPHub 支持变量扩展:
|
||||
|
||||
```env
|
||||
BASE_URL=https://api.example.com
|
||||
API_ENDPOINT=${BASE_URL}/v1
|
||||
DATABASE_URL=postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
|
||||
```
|
||||
|
||||
## 安全最佳实践
|
||||
|
||||
1. **永远不要提交密钥**到版本控制
|
||||
2. **为生产使用强唯一密钥**
|
||||
3. **定期轮换密钥**
|
||||
4. **使用特定于环境的文件**
|
||||
5. **在启动时验证所有环境变量**
|
||||
6. **为容器部署使用 Docker 密钥**
|
||||
|
||||
## 验证
|
||||
|
||||
MCPHub 在启动时验证环境变量。无效配置将阻止应用程序启动并提供有用的错误消息。
|
||||
|
||||
生产环境必需变量:
|
||||
|
||||
- `JWT_SECRET`
|
||||
- `DATABASE_URL` 或单独的数据库组件
|
||||
- `OPENAI_API_KEY`(如果启用智能路由)
|
||||
|
||||
这个全面的环境配置确保 MCPHub 可以为任何部署场景正确配置。
|
||||
564
docs/zh/configuration/mcp-settings.mdx
Normal file
@@ -0,0 +1,564 @@
|
||||
---
|
||||
title: 'MCP 设置配置'
|
||||
description: '配置 MCPHub 的 MCP 服务器及其设置'
|
||||
---
|
||||
|
||||
# MCP 设置配置
|
||||
|
||||
本指南说明如何使用 `mcp_settings.json` 文件和相关配置在 MCPHub 中配置 MCP 服务器。
|
||||
|
||||
## 配置文件概述
|
||||
|
||||
MCPHub 使用几个配置文件:
|
||||
|
||||
- **`mcp_settings.json`**:主要的 MCP 服务器配置
|
||||
- **`servers.json`**:服务器元数据和分组
|
||||
- **`.env`**:环境变量和密钥
|
||||
|
||||
## 基本 MCP 设置结构
|
||||
|
||||
### mcp_settings.json
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"server-name": {
|
||||
"command": "command-to-run",
|
||||
"args": ["arg1", "arg2"],
|
||||
"env": {
|
||||
"ENV_VAR": "value"
|
||||
},
|
||||
"cwd": "/working/directory",
|
||||
"timeout": 30000,
|
||||
"restart": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 示例配置
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"],
|
||||
"env": {
|
||||
"USER_AGENT": "MCPHub/1.0"
|
||||
}
|
||||
},
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"],
|
||||
"timeout": 60000
|
||||
},
|
||||
"slack": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-slack"],
|
||||
"env": {
|
||||
"SLACK_BOT_TOKEN": "${SLACK_BOT_TOKEN}",
|
||||
"SLACK_TEAM_ID": "${SLACK_TEAM_ID}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 服务器配置选项
|
||||
|
||||
### 必需字段
|
||||
|
||||
| 字段 | 类型 | 描述 |
|
||||
| --------- | ------ | ---------------- |
|
||||
| `command` | string | 可执行命令或路径 |
|
||||
| `args` | array | 命令行参数 |
|
||||
|
||||
### 可选字段
|
||||
|
||||
| 字段 | 类型 | 默认值 | 描述 |
|
||||
| -------------- | ------- | --------------- | ------------------ |
|
||||
| `env` | object | `{}` | 环境变量 |
|
||||
| `cwd` | string | `process.cwd()` | 工作目录 |
|
||||
| `timeout` | number | `30000` | 启动超时(毫秒) |
|
||||
| `restart` | boolean | `true` | 失败时自动重启 |
|
||||
| `maxRestarts` | number | `5` | 最大重启次数 |
|
||||
| `restartDelay` | number | `5000` | 重启间延迟(毫秒) |
|
||||
| `stdio` | string | `pipe` | stdio 配置 |
|
||||
|
||||
## 常见 MCP 服务器示例
|
||||
|
||||
### Web 和 API 服务器
|
||||
|
||||
#### Fetch 服务器
|
||||
|
||||
```json
|
||||
{
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"],
|
||||
"env": {
|
||||
"USER_AGENT": "MCPHub/1.0",
|
||||
"MAX_REDIRECTS": "10"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 使用 Playwright 进行网页抓取
|
||||
|
||||
```json
|
||||
{
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"],
|
||||
"timeout": 60000,
|
||||
"env": {
|
||||
"PLAYWRIGHT_BROWSERS_PATH": "/tmp/browsers"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 文件和系统服务器
|
||||
|
||||
#### 文件系统服务器
|
||||
|
||||
```json
|
||||
{
|
||||
"filesystem": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/allowed/path"],
|
||||
"env": {
|
||||
"ALLOWED_OPERATIONS": "read,write,list"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### SQLite 服务器
|
||||
|
||||
```json
|
||||
{
|
||||
"sqlite": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-sqlite", "--db-path", "/path/to/database.db"],
|
||||
"env": {
|
||||
"SQLITE_READONLY": "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 通信服务器
|
||||
|
||||
#### Slack 服务器
|
||||
|
||||
```json
|
||||
{
|
||||
"slack": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-slack"],
|
||||
"env": {
|
||||
"SLACK_BOT_TOKEN": "${SLACK_BOT_TOKEN}",
|
||||
"SLACK_TEAM_ID": "${SLACK_TEAM_ID}",
|
||||
"SLACK_APP_TOKEN": "${SLACK_APP_TOKEN}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 邮件服务器
|
||||
|
||||
```json
|
||||
{
|
||||
"email": {
|
||||
"command": "python",
|
||||
"args": ["-m", "mcp_server_email"],
|
||||
"env": {
|
||||
"SMTP_HOST": "smtp.gmail.com",
|
||||
"SMTP_PORT": "587",
|
||||
"EMAIL_USER": "${EMAIL_USER}",
|
||||
"EMAIL_PASSWORD": "${EMAIL_PASSWORD}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 开发和 API 服务器
|
||||
|
||||
#### GitHub 服务器
|
||||
|
||||
```json
|
||||
{
|
||||
"github": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-github"],
|
||||
"env": {
|
||||
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Google Drive 服务器
|
||||
|
||||
```json
|
||||
{
|
||||
"gdrive": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@google/mcp-server-gdrive"],
|
||||
"env": {
|
||||
"GOOGLE_CLIENT_ID": "${GOOGLE_CLIENT_ID}",
|
||||
"GOOGLE_CLIENT_SECRET": "${GOOGLE_CLIENT_SECRET}",
|
||||
"GOOGLE_REFRESH_TOKEN": "${GOOGLE_REFRESH_TOKEN}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 地图和位置服务
|
||||
|
||||
#### 高德地图服务器
|
||||
|
||||
```json
|
||||
{
|
||||
"amap": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@amap/amap-maps-mcp-server"],
|
||||
"env": {
|
||||
"AMAP_MAPS_API_KEY": "${AMAP_API_KEY}",
|
||||
"AMAP_LANGUAGE": "zh-cn"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### OpenStreetMap 服务器
|
||||
|
||||
```json
|
||||
{
|
||||
"osm": {
|
||||
"command": "python",
|
||||
"args": ["-m", "mcp_server_osm"],
|
||||
"env": {
|
||||
"OSM_USER_AGENT": "MCPHub/1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 高级配置
|
||||
|
||||
### 环境变量替换
|
||||
|
||||
MCPHub 支持使用 `${VAR_NAME}` 语法进行环境变量替换:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"api-server": {
|
||||
"command": "python",
|
||||
"args": ["-m", "api_server"],
|
||||
"env": {
|
||||
"API_KEY": "${API_KEY}",
|
||||
"API_URL": "${API_BASE_URL}/v1",
|
||||
"DEBUG": "${NODE_ENV:development}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
可以使用 `${VAR_NAME:default}` 指定默认值:
|
||||
|
||||
```json
|
||||
{
|
||||
"timeout": "${MCP_TIMEOUT:30000}",
|
||||
"maxRestarts": "${MCP_MAX_RESTARTS:5}"
|
||||
}
|
||||
```
|
||||
|
||||
### 条件配置
|
||||
|
||||
根据环境使用不同配置:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"database": {
|
||||
"command": "python",
|
||||
"args": ["-m", "db_server"],
|
||||
"env": {
|
||||
"DB_URL": "${NODE_ENV:development == 'production' ? DATABASE_URL : DEV_DATABASE_URL}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 自定义服务器脚本
|
||||
|
||||
#### 本地 Python 服务器
|
||||
|
||||
```json
|
||||
{
|
||||
"custom-python": {
|
||||
"command": "python",
|
||||
"args": ["./servers/custom_server.py"],
|
||||
"cwd": "/app/custom-servers",
|
||||
"env": {
|
||||
"PYTHONPATH": "/app/custom-servers",
|
||||
"CONFIG_FILE": "./config.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 本地 Node.js 服务器
|
||||
|
||||
```json
|
||||
{
|
||||
"custom-node": {
|
||||
"command": "node",
|
||||
"args": ["./servers/custom-server.js"],
|
||||
"cwd": "/app/custom-servers",
|
||||
"env": {
|
||||
"NODE_ENV": "production"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 服务器元数据配置
|
||||
|
||||
### servers.json
|
||||
|
||||
使用服务器元数据补充 `mcp_settings.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"servers": {
|
||||
"fetch": {
|
||||
"name": "Fetch 服务器",
|
||||
"description": "用于网络请求的 HTTP 客户端",
|
||||
"category": "web",
|
||||
"tags": ["http", "api", "web"],
|
||||
"version": "1.0.0",
|
||||
"author": "MCPHub 团队",
|
||||
"documentation": "https://docs.mcphub.com/servers/fetch",
|
||||
"enabled": true
|
||||
},
|
||||
"playwright": {
|
||||
"name": "Playwright 浏览器",
|
||||
"description": "网页自动化和抓取",
|
||||
"category": "automation",
|
||||
"tags": ["browser", "scraping", "automation"],
|
||||
"version": "2.0.0",
|
||||
"enabled": true
|
||||
}
|
||||
},
|
||||
"groups": {
|
||||
"web-tools": {
|
||||
"name": "网页工具",
|
||||
"description": "用于网页交互的工具",
|
||||
"servers": ["fetch", "playwright"],
|
||||
"access": "public"
|
||||
},
|
||||
"admin-tools": {
|
||||
"name": "管理工具",
|
||||
"description": "管理实用程序",
|
||||
"servers": ["filesystem", "database"],
|
||||
"access": "admin"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 组管理
|
||||
|
||||
### 组配置
|
||||
|
||||
```json
|
||||
{
|
||||
"groups": {
|
||||
"production": {
|
||||
"name": "生产工具",
|
||||
"description": "稳定的生产服务器",
|
||||
"servers": ["fetch", "slack", "github"],
|
||||
"access": "authenticated",
|
||||
"rateLimit": {
|
||||
"requestsPerMinute": 100,
|
||||
"burstLimit": 20
|
||||
}
|
||||
},
|
||||
"experimental": {
|
||||
"name": "实验功能",
|
||||
"description": "测试版和实验性服务器",
|
||||
"servers": ["experimental-ai", "beta-search"],
|
||||
"access": "admin",
|
||||
"enabled": false
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 访问控制
|
||||
|
||||
| 访问级别 | 描述 |
|
||||
| --------------- | ------------------- |
|
||||
| `public` | 无需认证 |
|
||||
| `authenticated` | 需要有效的 JWT 令牌 |
|
||||
| `admin` | 需要管理员角色 |
|
||||
| `custom` | 自定义权限逻辑 |
|
||||
|
||||
## 动态配置
|
||||
|
||||
### 热重载
|
||||
|
||||
MCPHub 支持配置热重载:
|
||||
|
||||
```bash
|
||||
# 不重启重新加载配置
|
||||
curl -X POST http://localhost:3000/api/admin/reload-config \
|
||||
-H "Authorization: Bearer your-admin-token"
|
||||
```
|
||||
|
||||
### 配置验证
|
||||
|
||||
MCPHub 在启动和重新加载时验证配置:
|
||||
|
||||
```json
|
||||
{
|
||||
"validation": {
|
||||
"strict": true,
|
||||
"allowUnknownServers": false,
|
||||
"requireDocumentation": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 最佳实践
|
||||
|
||||
### 安全
|
||||
|
||||
1. **对敏感数据使用环境变量**:
|
||||
|
||||
```json
|
||||
{
|
||||
"env": {
|
||||
"API_KEY": "${API_KEY}",
|
||||
"DATABASE_PASSWORD": "${DB_PASSWORD}"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. **限制服务器权限**:
|
||||
```json
|
||||
{
|
||||
"filesystem": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/restricted/path"],
|
||||
"env": {
|
||||
"READONLY": "true"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 性能
|
||||
|
||||
1. **设置适当的超时**:
|
||||
|
||||
```json
|
||||
{
|
||||
"timeout": 30000,
|
||||
"maxRestarts": 3,
|
||||
"restartDelay": 5000
|
||||
}
|
||||
```
|
||||
|
||||
2. **资源限制**:
|
||||
```json
|
||||
{
|
||||
"env": {
|
||||
"NODE_OPTIONS": "--max-old-space-size=512",
|
||||
"MEMORY_LIMIT": "512MB"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 监控
|
||||
|
||||
1. **启用健康检查**:
|
||||
|
||||
```json
|
||||
{
|
||||
"healthCheck": {
|
||||
"enabled": true,
|
||||
"interval": 30000,
|
||||
"timeout": 5000
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. **日志配置**:
|
||||
```json
|
||||
{
|
||||
"env": {
|
||||
"LOG_LEVEL": "info",
|
||||
"LOG_FORMAT": "json"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
**服务器无法启动**:检查命令和参数
|
||||
|
||||
```bash
|
||||
# 手动测试命令
|
||||
uvx mcp-server-fetch
|
||||
```
|
||||
|
||||
**找不到环境变量**:验证 `.env` 文件
|
||||
|
||||
```bash
|
||||
# 检查环境
|
||||
printenv | grep API_KEY
|
||||
```
|
||||
|
||||
**权限错误**:检查文件权限和路径
|
||||
|
||||
```bash
|
||||
# 验证可执行权限
|
||||
ls -la /path/to/server
|
||||
```
|
||||
|
||||
### 调试配置
|
||||
|
||||
启用调试模式进行详细日志记录:
|
||||
|
||||
```json
|
||||
{
|
||||
"debug": {
|
||||
"enabled": true,
|
||||
"logLevel": "debug",
|
||||
"includeEnv": false,
|
||||
"logStartup": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 验证错误
|
||||
|
||||
常见验证错误和解决方案:
|
||||
|
||||
1. **缺少必需字段**:添加 `command` 和 `args`
|
||||
2. **无效超时**:使用数字,不是字符串
|
||||
3. **找不到环境变量**:检查 `.env` 文件
|
||||
4. **找不到命令**:验证安装和 PATH
|
||||
|
||||
这个全面的指南涵盖了在 MCPHub 中为各种用例和环境配置 MCP 服务器的所有方面。
|
||||
373
docs/zh/configuration/nginx.mdx
Normal file
@@ -0,0 +1,373 @@
|
||||
---
|
||||
title: 'Nginx 配置'
|
||||
description: '配置 Nginx 作为 MCPHub 的反向代理'
|
||||
---
|
||||
|
||||
# Nginx 配置
|
||||
|
||||
本指南说明如何配置 Nginx 作为 MCPHub 的反向代理,包括 SSL 终止、负载均衡和缓存策略。
|
||||
|
||||
## 基本反向代理设置
|
||||
|
||||
### 配置文件
|
||||
|
||||
创建或更新您的 Nginx 配置文件(`/etc/nginx/sites-available/mcphub`):
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name your-domain.com;
|
||||
|
||||
# 将 HTTP 重定向到 HTTPS
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name your-domain.com;
|
||||
|
||||
# SSL 配置
|
||||
ssl_certificate /path/to/your/certificate.crt;
|
||||
ssl_certificate_key /path/to/your/private.key;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384;
|
||||
ssl_prefer_server_ciphers off;
|
||||
|
||||
# 安全头
|
||||
add_header X-Frame-Options DENY;
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
|
||||
# Gzip 压缩
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_types
|
||||
text/plain
|
||||
text/css
|
||||
text/xml
|
||||
text/javascript
|
||||
application/json
|
||||
application/javascript
|
||||
application/xml+rss
|
||||
application/atom+xml
|
||||
image/svg+xml;
|
||||
|
||||
# 主应用程序
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
# API 端点,为 MCP 操作设置更长的超时
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_read_timeout 300;
|
||||
proxy_connect_timeout 60;
|
||||
proxy_send_timeout 60;
|
||||
}
|
||||
|
||||
# 静态资源缓存
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_cache_valid 200 1d;
|
||||
proxy_cache_valid 404 1m;
|
||||
add_header Cache-Control "public, immutable";
|
||||
expires 1y;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 启用配置
|
||||
|
||||
```bash
|
||||
# 创建符号链接启用站点
|
||||
sudo ln -s /etc/nginx/sites-available/mcphub /etc/nginx/sites-enabled/
|
||||
|
||||
# 测试配置
|
||||
sudo nginx -t
|
||||
|
||||
# 重新加载 Nginx
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
## 负载均衡配置
|
||||
|
||||
对于具有多个 MCPHub 实例的高可用性设置:
|
||||
|
||||
```nginx
|
||||
upstream mcphub_backend {
|
||||
least_conn;
|
||||
server 127.0.0.1:3000 weight=1 max_fails=3 fail_timeout=30s;
|
||||
server 127.0.0.1:3001 weight=1 max_fails=3 fail_timeout=30s;
|
||||
server 127.0.0.1:3002 weight=1 max_fails=3 fail_timeout=30s;
|
||||
|
||||
# 健康检查(Nginx Plus 功能)
|
||||
# health_check interval=5s fails=3 passes=2;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name your-domain.com;
|
||||
|
||||
# SSL 和其他配置...
|
||||
|
||||
location / {
|
||||
proxy_pass http://mcphub_backend;
|
||||
# 其他代理设置...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 缓存配置
|
||||
|
||||
### 浏览器缓存
|
||||
|
||||
```nginx
|
||||
# 缓存静态资源
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# 缓存 API 响应(小心动态内容)
|
||||
location /api/public/ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_cache mcphub_cache;
|
||||
proxy_cache_valid 200 5m;
|
||||
proxy_cache_key "$scheme$request_method$host$request_uri";
|
||||
add_header X-Cache-Status $upstream_cache_status;
|
||||
}
|
||||
```
|
||||
|
||||
### Nginx 代理缓存
|
||||
|
||||
在 `nginx.conf` 的 `http` 块中添加:
|
||||
|
||||
```nginx
|
||||
http {
|
||||
# 代理缓存配置
|
||||
proxy_cache_path /var/cache/nginx/mcphub
|
||||
levels=1:2
|
||||
keys_zone=mcphub_cache:10m
|
||||
max_size=1g
|
||||
inactive=60m
|
||||
use_temp_path=off;
|
||||
|
||||
# 其他配置...
|
||||
}
|
||||
```
|
||||
|
||||
## WebSocket 支持
|
||||
|
||||
对于实时功能和 SSE(服务器发送事件):
|
||||
|
||||
```nginx
|
||||
location /api/stream {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# 禁用实时响应的缓冲
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
|
||||
# 长连接超时
|
||||
proxy_read_timeout 24h;
|
||||
proxy_send_timeout 24h;
|
||||
}
|
||||
```
|
||||
|
||||
## 安全配置
|
||||
|
||||
### 速率限制
|
||||
|
||||
```nginx
|
||||
http {
|
||||
# 定义速率限制区域
|
||||
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
|
||||
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
|
||||
|
||||
server {
|
||||
# 对 API 端点应用速率限制
|
||||
location /api/ {
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
# 其他配置...
|
||||
}
|
||||
|
||||
# 登录端点的严格速率限制
|
||||
location /api/auth/login {
|
||||
limit_req zone=login burst=5;
|
||||
# 其他配置...
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### IP 白名单
|
||||
|
||||
```nginx
|
||||
# 为管理端点允许特定 IP
|
||||
location /api/admin/ {
|
||||
allow 192.168.1.0/24;
|
||||
allow 10.0.0.0/8;
|
||||
deny all;
|
||||
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
# 其他代理设置...
|
||||
}
|
||||
```
|
||||
|
||||
## 监控和日志
|
||||
|
||||
### 访问日志
|
||||
|
||||
```nginx
|
||||
http {
|
||||
# 自定义日志格式
|
||||
log_format mcphub_format '$remote_addr - $remote_user [$time_local] '
|
||||
'"$request" $status $body_bytes_sent '
|
||||
'"$http_referer" "$http_user_agent" '
|
||||
'$request_time $upstream_response_time';
|
||||
|
||||
server {
|
||||
# 启用访问日志
|
||||
access_log /var/log/nginx/mcphub_access.log mcphub_format;
|
||||
error_log /var/log/nginx/mcphub_error.log;
|
||||
|
||||
# 其他配置...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 状态页面
|
||||
|
||||
```nginx
|
||||
location /nginx_status {
|
||||
stub_status;
|
||||
allow 127.0.0.1;
|
||||
deny all;
|
||||
}
|
||||
```
|
||||
|
||||
## Docker 集成
|
||||
|
||||
当在 Docker 中运行 MCPHub 时,更新代理配置:
|
||||
|
||||
```nginx
|
||||
upstream mcphub_docker {
|
||||
server mcphub:3000; # Docker 服务名
|
||||
}
|
||||
|
||||
server {
|
||||
location / {
|
||||
proxy_pass http://mcphub_docker;
|
||||
# 其他代理设置...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 完整示例配置
|
||||
|
||||
使用提供的 `nginx.conf.example` 的生产就绪示例:
|
||||
|
||||
```bash
|
||||
# 复制示例配置
|
||||
cp nginx.conf.example /etc/nginx/sites-available/mcphub
|
||||
|
||||
# 使用您的域名和路径更新配置
|
||||
sudo nano /etc/nginx/sites-available/mcphub
|
||||
|
||||
# 启用站点
|
||||
sudo ln -s /etc/nginx/sites-available/mcphub /etc/nginx/sites-enabled/
|
||||
|
||||
# 测试并重新加载
|
||||
sudo nginx -t && sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
**502 Bad Gateway**:检查 MCPHub 是否正在运行且可访问
|
||||
|
||||
**504 Gateway Timeout**:为长时间运行的操作增加 `proxy_read_timeout`
|
||||
|
||||
**WebSocket 连接失败**:确保正确的 `Upgrade` 和 `Connection` 头
|
||||
|
||||
**缓存问题**:清除代理缓存或在开发中禁用
|
||||
|
||||
### 调试命令
|
||||
|
||||
```bash
|
||||
# 测试 Nginx 配置
|
||||
sudo nginx -t
|
||||
|
||||
# 检查 Nginx 状态
|
||||
sudo systemctl status nginx
|
||||
|
||||
# 查看错误日志
|
||||
sudo tail -f /var/log/nginx/error.log
|
||||
|
||||
# 检查 MCPHub 是否响应
|
||||
curl -I http://localhost:3000
|
||||
```
|
||||
|
||||
## 性能优化
|
||||
|
||||
### 工作进程
|
||||
|
||||
```nginx
|
||||
# 在 nginx.conf 中
|
||||
worker_processes auto;
|
||||
worker_connections 1024;
|
||||
```
|
||||
|
||||
### 缓冲区大小
|
||||
|
||||
```nginx
|
||||
proxy_buffering on;
|
||||
proxy_buffer_size 128k;
|
||||
proxy_buffers 4 256k;
|
||||
proxy_busy_buffers_size 256k;
|
||||
```
|
||||
|
||||
### Keep-Alive
|
||||
|
||||
```nginx
|
||||
upstream mcphub_backend {
|
||||
server 127.0.0.1:3000;
|
||||
keepalive 32;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://mcphub_backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
}
|
||||
```
|
||||
|
||||
此配置为在 Nginx 后运行 MCPHub 提供了坚实的基础,具有适当的安全性、性能和可靠性功能。
|
||||
421
docs/zh/development.mdx
Normal file
@@ -0,0 +1,421 @@
|
||||
---
|
||||
title: '开发指南'
|
||||
description: 'MCPHub 本地开发环境搭建和开发工作流指南'
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
本指南将帮助您搭建 MCPHub 的本地开发环境,了解项目结构,并掌握开发工作流。
|
||||
|
||||
<Info>**前提条件**:请确保已安装 Node.js 18+ 和 Git。</Info>
|
||||
|
||||
## 环境准备
|
||||
|
||||
### 系统要求
|
||||
|
||||
在开始开发之前,请确保您的系统满足以下要求:
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="软件依赖" icon="download">
|
||||
- **Node.js**: 18.0+ 版本 - **npm**: 8.0+ 版本 - **Git**: 最新版本 - **Docker**:
|
||||
可选,用于容器化开发
|
||||
</Card>
|
||||
<Card title="推荐工具" icon="toolbox">
|
||||
- **VS Code**: 推荐的代码编辑器 - **Postman**: API 测试工具 - **TablePlus**: 数据库管理工具 -
|
||||
**Docker Desktop**: 容器管理
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
### 验证环境
|
||||
|
||||
```bash
|
||||
# 检查 Node.js 版本
|
||||
node --version # 应该 >= 18.0.0
|
||||
|
||||
# 检查 npm 版本
|
||||
npm --version # 应该 >= 8.0.0
|
||||
|
||||
# 检查 Git 版本
|
||||
git --version
|
||||
|
||||
# 检查 Docker(可选)
|
||||
docker --version
|
||||
```
|
||||
|
||||
## 克隆项目
|
||||
|
||||
### 获取源代码
|
||||
|
||||
```bash
|
||||
# 克隆主仓库
|
||||
git clone https://github.com/mcphub/mcphub.git
|
||||
cd mcphub
|
||||
|
||||
# 或者克隆您的 fork
|
||||
git clone https://github.com/YOUR_USERNAME/mcphub.git
|
||||
cd mcphub
|
||||
```
|
||||
|
||||
### 项目结构
|
||||
|
||||
```
|
||||
mcphub/
|
||||
├── src/ # 源代码目录
|
||||
│ ├── controllers/ # 控制器层
|
||||
│ ├── middleware/ # 中间件
|
||||
│ ├── models/ # 数据模型
|
||||
│ ├── routes/ # 路由定义
|
||||
│ ├── services/ # 业务逻辑层
|
||||
│ ├── utils/ # 工具函数
|
||||
│ └── index.ts # 应用入口
|
||||
├── tests/ # 测试文件
|
||||
├── docs/ # 文档源码
|
||||
├── docker/ # Docker 配置
|
||||
├── scripts/ # 构建脚本
|
||||
├── prisma/ # 数据库模式
|
||||
├── package.json # 项目依赖
|
||||
├── tsconfig.json # TypeScript 配置
|
||||
├── .env.example # 环境变量示例
|
||||
└── README.md # 项目说明
|
||||
```
|
||||
|
||||
## 安装依赖
|
||||
|
||||
### 安装项目依赖
|
||||
|
||||
```bash
|
||||
# 安装生产和开发依赖
|
||||
npm install
|
||||
|
||||
# 仅安装生产依赖
|
||||
npm ci --only=production
|
||||
```
|
||||
|
||||
### 全局工具安装
|
||||
|
||||
```bash
|
||||
# 安装 TypeScript 编译器
|
||||
npm install -g typescript
|
||||
|
||||
# 安装开发工具
|
||||
npm install -g tsx nodemon prisma
|
||||
|
||||
# 安装 MCPHub CLI(可选)
|
||||
npm install -g @mcphub/cli
|
||||
```
|
||||
|
||||
## 配置开发环境
|
||||
|
||||
### 环境变量配置
|
||||
|
||||
```bash
|
||||
# 复制环境变量模板
|
||||
cp .env.example .env
|
||||
|
||||
# 编辑环境变量
|
||||
nano .env
|
||||
```
|
||||
|
||||
开发环境的 `.env` 配置示例:
|
||||
|
||||
```bash title=".env"
|
||||
# 应用配置
|
||||
NODE_ENV=development
|
||||
PORT=3000
|
||||
HOST=localhost
|
||||
|
||||
# 数据库配置
|
||||
DATABASE_URL=sqlite:./data/dev.db
|
||||
|
||||
# JWT 配置
|
||||
JWT_SECRET=dev-jwt-secret-key
|
||||
JWT_EXPIRES_IN=7d
|
||||
|
||||
# 日志配置
|
||||
LOG_LEVEL=debug
|
||||
LOG_FORMAT=dev
|
||||
|
||||
# CORS 配置
|
||||
CORS_ORIGIN=http://localhost:3000,http://localhost:3001
|
||||
|
||||
# 管理员账户
|
||||
ADMIN_EMAIL=dev@mcphub.io
|
||||
ADMIN_PASSWORD=dev123
|
||||
|
||||
# 开发功能开关
|
||||
ENABLE_DEBUG_ROUTES=true
|
||||
ENABLE_SWAGGER=true
|
||||
ENABLE_HOT_RELOAD=true
|
||||
```
|
||||
|
||||
### 数据库初始化
|
||||
|
||||
```bash
|
||||
# 生成 Prisma 客户端
|
||||
npx prisma generate
|
||||
|
||||
# 运行数据库迁移
|
||||
npx prisma migrate dev --name init
|
||||
|
||||
# 填充测试数据
|
||||
npm run db:seed
|
||||
```
|
||||
|
||||
## 启动开发服务器
|
||||
|
||||
### 开发模式启动
|
||||
|
||||
```bash
|
||||
# 启动开发服务器(带热重载)
|
||||
npm run dev
|
||||
|
||||
# 或者使用 tsx 直接运行
|
||||
npx tsx watch src/index.ts
|
||||
```
|
||||
|
||||
### 后台模式启动
|
||||
|
||||
```bash
|
||||
# 使用 PM2 启动(需要先安装 PM2)
|
||||
npm install -g pm2
|
||||
npm run dev:pm2
|
||||
|
||||
# 查看进程状态
|
||||
pm2 status
|
||||
|
||||
# 查看日志
|
||||
pm2 logs mcphub-dev
|
||||
```
|
||||
|
||||
### 验证启动
|
||||
|
||||
访问以下 URL 验证服务是否正常启动:
|
||||
|
||||
- **主页**: http://localhost:3000
|
||||
- **健康检查**: http://localhost:3000/health
|
||||
- **API 文档**: http://localhost:3000/api/docs
|
||||
- **管理界面**: http://localhost:3000/admin
|
||||
|
||||
## 开发工作流
|
||||
|
||||
### 1. 功能开发流程
|
||||
|
||||
```bash
|
||||
# 1. 创建功能分支
|
||||
git checkout -b feature/your-feature-name
|
||||
|
||||
# 2. 进行开发...
|
||||
|
||||
# 3. 运行测试
|
||||
npm test
|
||||
|
||||
# 4. 代码格式化
|
||||
npm run lint:fix
|
||||
|
||||
# 5. 提交代码
|
||||
git add .
|
||||
git commit -m "feat: add your feature description"
|
||||
|
||||
# 6. 推送分支
|
||||
git push origin feature/your-feature-name
|
||||
|
||||
# 7. 创建 Pull Request
|
||||
```
|
||||
|
||||
### 2. 代码规范
|
||||
|
||||
MCPHub 项目使用以下代码规范工具:
|
||||
|
||||
```bash
|
||||
# 代码检查
|
||||
npm run lint
|
||||
|
||||
# 自动修复
|
||||
npm run lint:fix
|
||||
|
||||
# 格式化代码
|
||||
npm run format
|
||||
|
||||
# 类型检查
|
||||
npm run type-check
|
||||
```
|
||||
|
||||
### 3. 测试开发
|
||||
|
||||
```bash
|
||||
# 运行所有测试
|
||||
npm test
|
||||
|
||||
# 运行单元测试
|
||||
npm run test:unit
|
||||
|
||||
# 运行集成测试
|
||||
npm run test:integration
|
||||
|
||||
# 运行测试并生成覆盖率报告
|
||||
npm run test:coverage
|
||||
|
||||
# 监听模式运行测试
|
||||
npm run test:watch
|
||||
```
|
||||
|
||||
## 调试技巧
|
||||
|
||||
### 1. VS Code 调试配置
|
||||
|
||||
创建 `.vscode/launch.json` 文件:
|
||||
|
||||
```json title=".vscode/launch.json"
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug MCPHub",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/src/index.ts",
|
||||
"runtimeArgs": ["-r", "tsx/cjs"],
|
||||
"env": {
|
||||
"NODE_ENV": "development"
|
||||
},
|
||||
"console": "integratedTerminal",
|
||||
"skipFiles": ["<node_internals>/**"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 日志调试
|
||||
|
||||
使用内置的日志系统进行调试:
|
||||
|
||||
```typescript
|
||||
import { logger } from '@/utils/logger';
|
||||
|
||||
// 不同级别的日志
|
||||
logger.debug('调试信息', { data });
|
||||
logger.info('信息日志', { userId });
|
||||
logger.warn('警告信息', { error });
|
||||
logger.error('错误信息', { error, stack });
|
||||
```
|
||||
|
||||
### 3. 数据库调试
|
||||
|
||||
```bash
|
||||
# 查看数据库内容
|
||||
npx prisma studio
|
||||
|
||||
# 重置数据库
|
||||
npx prisma migrate reset
|
||||
|
||||
# 查看迁移状态
|
||||
npx prisma migrate status
|
||||
```
|
||||
|
||||
## 常用开发命令
|
||||
|
||||
### 项目管理
|
||||
|
||||
```bash
|
||||
# 安装新依赖
|
||||
npm install package-name
|
||||
npm install -D package-name # 开发依赖
|
||||
|
||||
# 更新依赖
|
||||
npm update
|
||||
|
||||
# 清理缓存
|
||||
npm cache clean --force
|
||||
|
||||
# 重新安装依赖
|
||||
rm -rf node_modules package-lock.json
|
||||
npm install
|
||||
```
|
||||
|
||||
### 构建和部署
|
||||
|
||||
```bash
|
||||
# 构建项目
|
||||
npm run build
|
||||
|
||||
# 预览构建结果
|
||||
npm run preview
|
||||
|
||||
# 构建 Docker 镜像
|
||||
npm run docker:build
|
||||
|
||||
# 运行 Docker 容器
|
||||
npm run docker:run
|
||||
```
|
||||
|
||||
### 数据库操作
|
||||
|
||||
```bash
|
||||
# 创建新迁移
|
||||
npx prisma migrate dev --name your-migration-name
|
||||
|
||||
# 重置数据库
|
||||
npx prisma migrate reset
|
||||
|
||||
# 推送模式变更
|
||||
npx prisma db push
|
||||
|
||||
# 生成客户端
|
||||
npx prisma generate
|
||||
```
|
||||
|
||||
## 常见问题
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion icon="question" title="端口被占用">
|
||||
**错误信息**: `Error: listen EADDRINUSE :::3000`
|
||||
|
||||
**解决方案**:
|
||||
```bash
|
||||
# 查找占用端口的进程
|
||||
lsof -i :3000
|
||||
|
||||
# 杀死进程
|
||||
kill -9 PID
|
||||
|
||||
# 或者使用不同端口
|
||||
PORT=3001 npm run dev
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
<Accordion icon="question" title="数据库连接失败">
|
||||
**可能原因**: 数据库文件权限或路径问题 **解决方案**: ```bash # 检查数据库文件 ls -la data/ #
|
||||
重新初始化数据库 rm data/dev.db npx prisma migrate dev ```
|
||||
</Accordion>
|
||||
|
||||
<Accordion icon="question" title="TypeScript 编译错误">
|
||||
**解决方案**:
|
||||
```bash
|
||||
# 清理构建缓存
|
||||
npm run clean
|
||||
|
||||
# 重新安装类型定义
|
||||
npm install @types/node @types/express
|
||||
|
||||
# 重新生成 Prisma 客户端
|
||||
npx prisma generate
|
||||
```
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## 进阶主题
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="架构设计" icon="building" href="/zh/development/architecture">
|
||||
了解 MCPHub 的整体架构和设计模式
|
||||
</Card>
|
||||
<Card title="API 开发" icon="code" href="/zh/development/api-development">
|
||||
学习如何开发和设计 RESTful API
|
||||
</Card>
|
||||
<Card title="性能优化" icon="rocket" href="/zh/development/performance">
|
||||
掌握性能分析和优化技巧
|
||||
</Card>
|
||||
<Card title="部署指南" icon="cloud" href="/zh/deployment/production">
|
||||
了解生产环境部署的最佳实践
|
||||
</Card>
|
||||
</CardGroup>
|
||||
244
docs/zh/development/getting-started.mdx
Normal file
@@ -0,0 +1,244 @@
|
||||
---
|
||||
title: '开发环境搭建'
|
||||
description: '学习如何为 MCPHub 搭建开发环境'
|
||||
---
|
||||
|
||||
# 开发环境搭建
|
||||
|
||||
本指南将帮助您搭建 MCPHub 的开发环境,为项目贡献代码。
|
||||
|
||||
## 先决条件
|
||||
|
||||
在开始之前,请确保您已安装以下软件:
|
||||
|
||||
- **Node.js**(版本 18 或更高)
|
||||
- **pnpm**(推荐的包管理器)
|
||||
- **Git**
|
||||
- **Docker**(可选,用于容器化开发)
|
||||
|
||||
## 搭建开发环境
|
||||
|
||||
### 1. 克隆仓库
|
||||
|
||||
```bash
|
||||
git clone https://github.com/your-username/mcphub.git
|
||||
cd mcphub
|
||||
```
|
||||
|
||||
### 2. 安装依赖
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
```
|
||||
|
||||
### 3. 环境配置
|
||||
|
||||
在根目录创建 `.env` 文件:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
配置以下环境变量:
|
||||
|
||||
```env
|
||||
# 服务器配置
|
||||
PORT=3000
|
||||
NODE_ENV=development
|
||||
|
||||
# 数据库配置
|
||||
DATABASE_URL=postgresql://username:password@localhost:5432/mcphub
|
||||
|
||||
# JWT 配置
|
||||
JWT_SECRET=your-secret-key
|
||||
JWT_EXPIRES_IN=24h
|
||||
|
||||
# OpenAI 配置(用于智能路由)
|
||||
OPENAI_API_KEY=your-openai-api-key
|
||||
```
|
||||
|
||||
### 4. 数据库设置
|
||||
|
||||
如果使用 PostgreSQL,创建数据库:
|
||||
|
||||
```bash
|
||||
createdb mcphub
|
||||
```
|
||||
|
||||
### 5. MCP 服务器配置
|
||||
|
||||
创建或修改 `mcp_settings.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"]
|
||||
},
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 开发工作流
|
||||
|
||||
### 运行开发服务器
|
||||
|
||||
同时启动后端和前端开发模式:
|
||||
|
||||
```bash
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
这将启动:
|
||||
|
||||
- 后端服务器:`http://localhost:3000`
|
||||
- 前端开发服务器:`http://localhost:5173`
|
||||
|
||||
### 仅运行后端
|
||||
|
||||
```bash
|
||||
pnpm backend:dev
|
||||
```
|
||||
|
||||
### 仅运行前端
|
||||
|
||||
```bash
|
||||
pnpm frontend:dev
|
||||
```
|
||||
|
||||
### 构建项目
|
||||
|
||||
构建后端和前端:
|
||||
|
||||
```bash
|
||||
pnpm build
|
||||
```
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
mcphub/
|
||||
├── src/ # 后端源代码
|
||||
│ ├── controllers/ # Express 控制器
|
||||
│ ├── routes/ # API 路由
|
||||
│ ├── services/ # 业务逻辑
|
||||
│ ├── models/ # 数据库模型
|
||||
│ └── utils/ # 工具函数
|
||||
├── frontend/ # 前端 React 应用
|
||||
│ ├── src/
|
||||
│ │ ├── components/ # React 组件
|
||||
│ │ ├── pages/ # 页面组件
|
||||
│ │ ├── services/ # API 服务
|
||||
│ │ └── utils/ # 前端工具
|
||||
├── docs/ # 文档
|
||||
├── bin/ # CLI 脚本
|
||||
└── scripts/ # 构建和工具脚本
|
||||
```
|
||||
|
||||
## 开发工具
|
||||
|
||||
### 代码检查和格式化
|
||||
|
||||
```bash
|
||||
# 运行 ESLint
|
||||
pnpm lint
|
||||
|
||||
# 使用 Prettier 格式化代码
|
||||
pnpm format
|
||||
```
|
||||
|
||||
### 测试
|
||||
|
||||
```bash
|
||||
# 运行测试
|
||||
pnpm test
|
||||
|
||||
# 监视模式运行测试
|
||||
pnpm test --watch
|
||||
```
|
||||
|
||||
### 调试
|
||||
|
||||
使用 Node.js 检查器调试后端:
|
||||
|
||||
```bash
|
||||
pnpm backend:debug
|
||||
```
|
||||
|
||||
然后将调试器连接到 `http://localhost:9229`。
|
||||
|
||||
## 进行修改
|
||||
|
||||
### 后端开发
|
||||
|
||||
1. **控制器**:处理 HTTP 请求和响应
|
||||
2. **服务**:实现业务逻辑
|
||||
3. **模型**:定义数据库架构
|
||||
4. **路由**:定义 API 端点
|
||||
|
||||
### 前端开发
|
||||
|
||||
1. **组件**:可重用的 React 组件
|
||||
2. **页面**:特定路由的组件
|
||||
3. **服务**:API 通信
|
||||
4. **钩子**:自定义 React 钩子
|
||||
|
||||
### 添加新的 MCP 服务器
|
||||
|
||||
1. 使用新的服务器配置更新 `mcp_settings.json`
|
||||
2. 测试服务器集成
|
||||
3. 必要时更新文档
|
||||
|
||||
## 常见开发任务
|
||||
|
||||
### 添加新的 API 端点
|
||||
|
||||
1. 在 `src/controllers/` 中创建控制器
|
||||
2. 在 `src/routes/` 中定义路由
|
||||
3. 添加必要的中间件
|
||||
4. 为新端点编写测试
|
||||
|
||||
### 添加新的前端功能
|
||||
|
||||
1. 在 `frontend/src/components/` 中创建组件
|
||||
2. 根据需要添加路由
|
||||
3. 实现 API 集成
|
||||
4. 使用 Tailwind CSS 进行样式设计
|
||||
|
||||
### 数据库迁移
|
||||
|
||||
修改数据库架构时:
|
||||
|
||||
1. 更新 `src/models/` 中的模型
|
||||
2. 如果使用 TypeORM,创建迁移脚本
|
||||
3. 在本地测试迁移
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
**端口冲突**:确保端口 3000 和 5173 可用
|
||||
|
||||
**数据库连接**:验证 PostgreSQL 正在运行且凭据正确
|
||||
|
||||
**MCP 服务器启动**:检查 `mcp_settings.json` 中的服务器配置
|
||||
|
||||
**权限问题**:确保 MCP 服务器具有必要的权限
|
||||
|
||||
### 获取帮助
|
||||
|
||||
- 查看[贡献指南](/zh/development/contributing)
|
||||
- 阅读[架构文档](/zh/development/architecture)
|
||||
- 在 GitHub 上提交问题报告 bug
|
||||
- 加入我们的社区讨论
|
||||
|
||||
## 下一步
|
||||
|
||||
- 阅读[架构概述](/zh/development/architecture)
|
||||
- 了解[贡献指南](/zh/development/contributing)
|
||||
- 探索[配置选项](/zh/configuration/environment-variables)
|
||||
892
docs/zh/essentials/code.mdx
Normal file
@@ -0,0 +1,892 @@
|
||||
---
|
||||
title: '代码块'
|
||||
description: 'MCPHub 文档中代码块的编写和展示指南'
|
||||
---
|
||||
|
||||
## 内联代码
|
||||
|
||||
在 MCPHub 文档中使用内联代码来标记命令、配置键、文件名或短代码片段:
|
||||
|
||||
```md
|
||||
使用 `mcphub start` 命令启动服务器,配置 `MCPHUB_PORT` 环境变量。
|
||||
```
|
||||
|
||||
使用 `mcphub start` 命令启动服务器,配置 `MCPHUB_PORT` 环境变量。
|
||||
|
||||
## 代码块语法
|
||||
|
||||
### 基本代码块
|
||||
|
||||
MCPHub 支持多种编程语言的语法高亮:
|
||||
|
||||
````md
|
||||
```javascript
|
||||
// JavaScript 示例
|
||||
const mcpClient = new MCPClient({
|
||||
endpoint: process.env.MCPHUB_ENDPOINT,
|
||||
apiKey: process.env.MCPHUB_API_KEY,
|
||||
});
|
||||
```
|
||||
````
|
||||
|
||||
```javascript
|
||||
// JavaScript 示例
|
||||
const mcpClient = new MCPClient({
|
||||
endpoint: process.env.MCPHUB_ENDPOINT,
|
||||
apiKey: process.env.MCPHUB_API_KEY,
|
||||
});
|
||||
```
|
||||
|
||||
### TypeScript 代码
|
||||
|
||||
````md
|
||||
```typescript
|
||||
interface MCPServerConfig {
|
||||
id: string;
|
||||
name: string;
|
||||
endpoint: string;
|
||||
capabilities: string[];
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
class MCPServer implements MCPServerConfig {
|
||||
constructor(
|
||||
public id: string,
|
||||
public name: string,
|
||||
public endpoint: string,
|
||||
public capabilities: string[],
|
||||
) {}
|
||||
}
|
||||
```
|
||||
````
|
||||
|
||||
```typescript
|
||||
interface MCPServerConfig {
|
||||
id: string;
|
||||
name: string;
|
||||
endpoint: string;
|
||||
capabilities: string[];
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
class MCPServer implements MCPServerConfig {
|
||||
constructor(
|
||||
public id: string,
|
||||
public name: string,
|
||||
public endpoint: string,
|
||||
public capabilities: string[],
|
||||
) {}
|
||||
}
|
||||
```
|
||||
|
||||
### Python 代码
|
||||
|
||||
````md
|
||||
```python
|
||||
import requests
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
class MCPHubClient:
|
||||
def __init__(self, endpoint: str, api_key: str):
|
||||
self.endpoint = endpoint
|
||||
self.api_key = api_key
|
||||
self.headers = {
|
||||
'Authorization': f'Bearer {api_key}',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
def create_server(self, config: Dict) -> Dict:
|
||||
response = requests.post(
|
||||
f'{self.endpoint}/api/servers',
|
||||
json=config,
|
||||
headers=self.headers
|
||||
)
|
||||
return response.json()
|
||||
```
|
||||
````
|
||||
|
||||
```python
|
||||
import requests
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
class MCPHubClient:
|
||||
def __init__(self, endpoint: str, api_key: str):
|
||||
self.endpoint = endpoint
|
||||
self.api_key = api_key
|
||||
self.headers = {
|
||||
'Authorization': f'Bearer {api_key}',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
def create_server(self, config: Dict) -> Dict:
|
||||
response = requests.post(
|
||||
f'{self.endpoint}/api/servers',
|
||||
json=config,
|
||||
headers=self.headers
|
||||
)
|
||||
return response.json()
|
||||
```
|
||||
|
||||
## 配置文件
|
||||
|
||||
### YAML 配置
|
||||
|
||||
````md
|
||||
```yaml title="mcphub.yml"
|
||||
server:
|
||||
port: 3000
|
||||
host: 0.0.0.0
|
||||
|
||||
database:
|
||||
type: postgresql
|
||||
host: localhost
|
||||
port: 5432
|
||||
database: mcphub
|
||||
username: mcphub_user
|
||||
password: secure_password
|
||||
|
||||
mcp:
|
||||
servers:
|
||||
- id: ai-assistant
|
||||
name: AI Assistant Server
|
||||
endpoint: https://ai.example.com
|
||||
capabilities:
|
||||
- chat
|
||||
- completion
|
||||
- id: data-processor
|
||||
name: Data Processing Server
|
||||
endpoint: https://data.example.com
|
||||
capabilities:
|
||||
- analysis
|
||||
- transformation
|
||||
|
||||
routing:
|
||||
strategy: round_robin
|
||||
health_check:
|
||||
enabled: true
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
|
||||
logging:
|
||||
level: info
|
||||
format: json
|
||||
file: /var/log/mcphub/app.log
|
||||
```
|
||||
````
|
||||
|
||||
```yaml title="mcphub.yml"
|
||||
server:
|
||||
port: 3000
|
||||
host: 0.0.0.0
|
||||
|
||||
database:
|
||||
type: postgresql
|
||||
host: localhost
|
||||
port: 5432
|
||||
database: mcphub
|
||||
username: mcphub_user
|
||||
password: secure_password
|
||||
|
||||
mcp:
|
||||
servers:
|
||||
- id: ai-assistant
|
||||
name: AI Assistant Server
|
||||
endpoint: https://ai.example.com
|
||||
capabilities:
|
||||
- chat
|
||||
- completion
|
||||
- id: data-processor
|
||||
name: Data Processing Server
|
||||
endpoint: https://data.example.com
|
||||
capabilities:
|
||||
- analysis
|
||||
- transformation
|
||||
|
||||
routing:
|
||||
strategy: round_robin
|
||||
health_check:
|
||||
enabled: true
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
|
||||
logging:
|
||||
level: info
|
||||
format: json
|
||||
file: /var/log/mcphub/app.log
|
||||
```
|
||||
|
||||
### JSON 配置
|
||||
|
||||
````md
|
||||
```json title="package.json"
|
||||
{
|
||||
"name": "@mcphub/server",
|
||||
"version": "2.1.0",
|
||||
"description": "Model Context Protocol Hub Server",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"start": "node dist/index.js",
|
||||
"dev": "tsx watch src/index.ts",
|
||||
"build": "tsc",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"migrate": "prisma migrate deploy"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "^5.7.0",
|
||||
"express": "^4.18.2",
|
||||
"helmet": "^7.1.0",
|
||||
"cors": "^2.8.5",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"winston": "^3.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.10.0",
|
||||
"@types/express": "^4.17.21",
|
||||
"typescript": "^5.3.0",
|
||||
"tsx": "^4.6.0",
|
||||
"jest": "^29.7.0",
|
||||
"eslint": "^8.55.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
````
|
||||
|
||||
```json title="package.json"
|
||||
{
|
||||
"name": "@mcphub/server",
|
||||
"version": "2.1.0",
|
||||
"description": "Model Context Protocol Hub Server",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"start": "node dist/index.js",
|
||||
"dev": "tsx watch src/index.ts",
|
||||
"build": "tsc",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"migrate": "prisma migrate deploy"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "^5.7.0",
|
||||
"express": "^4.18.2",
|
||||
"helmet": "^7.1.0",
|
||||
"cors": "^2.8.5",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"winston": "^3.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.10.0",
|
||||
"@types/express": "^4.17.21",
|
||||
"typescript": "^5.3.0",
|
||||
"tsx": "^4.6.0",
|
||||
"jest": "^29.7.0",
|
||||
"eslint": "^8.55.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Docker 配置
|
||||
|
||||
````md
|
||||
```dockerfile title="Dockerfile"
|
||||
FROM node:18-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 复制依赖文件
|
||||
COPY package*.json ./
|
||||
COPY tsconfig.json ./
|
||||
|
||||
# 安装依赖
|
||||
RUN npm ci --only=production
|
||||
|
||||
# 复制源码
|
||||
COPY src/ ./src/
|
||||
|
||||
# 构建应用
|
||||
RUN npm run build
|
||||
|
||||
# 生产环境镜像
|
||||
FROM node:18-alpine AS production
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 创建非 root 用户
|
||||
RUN addgroup -g 1001 -S nodejs
|
||||
RUN adduser -S mcphub -u 1001
|
||||
|
||||
# 复制构建产物
|
||||
COPY --from=builder /app/dist ./dist
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/package*.json ./
|
||||
|
||||
# 设置权限
|
||||
USER mcphub
|
||||
|
||||
# 健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD node dist/health-check.js
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "dist/index.js"]
|
||||
```
|
||||
````
|
||||
|
||||
```dockerfile title="Dockerfile"
|
||||
FROM node:18-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 复制依赖文件
|
||||
COPY package*.json ./
|
||||
COPY tsconfig.json ./
|
||||
|
||||
# 安装依赖
|
||||
RUN npm ci --only=production
|
||||
|
||||
# 复制源码
|
||||
COPY src/ ./src/
|
||||
|
||||
# 构建应用
|
||||
RUN npm run build
|
||||
|
||||
# 生产环境镜像
|
||||
FROM node:18-alpine AS production
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 创建非 root 用户
|
||||
RUN addgroup -g 1001 -S nodejs
|
||||
RUN adduser -S mcphub -u 1001
|
||||
|
||||
# 复制构建产物
|
||||
COPY --from=builder /app/dist ./dist
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/package*.json ./
|
||||
|
||||
# 设置权限
|
||||
USER mcphub
|
||||
|
||||
# 健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD node dist/health-check.js
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "dist/index.js"]
|
||||
```
|
||||
|
||||
## 终端命令
|
||||
|
||||
### Bash/Shell 命令
|
||||
|
||||
````md
|
||||
```bash
|
||||
# 克隆 MCPHub 仓库
|
||||
git clone https://github.com/mcphub/mcphub.git
|
||||
cd mcphub
|
||||
|
||||
# 安装依赖
|
||||
npm install
|
||||
|
||||
# 复制环境变量文件
|
||||
cp .env.example .env
|
||||
|
||||
# 设置数据库
|
||||
npm run db:setup
|
||||
|
||||
# 启动开发服务器
|
||||
npm run dev
|
||||
|
||||
# 构建生产版本
|
||||
npm run build
|
||||
|
||||
# 启动生产服务器
|
||||
npm start
|
||||
```
|
||||
````
|
||||
|
||||
```bash
|
||||
# 克隆 MCPHub 仓库
|
||||
git clone https://github.com/mcphub/mcphub.git
|
||||
cd mcphub
|
||||
|
||||
# 安装依赖
|
||||
npm install
|
||||
|
||||
# 复制环境变量文件
|
||||
cp .env.example .env
|
||||
|
||||
# 设置数据库
|
||||
npm run db:setup
|
||||
|
||||
# 启动开发服务器
|
||||
npm run dev
|
||||
|
||||
# 构建生产版本
|
||||
npm run build
|
||||
|
||||
# 启动生产服务器
|
||||
npm start
|
||||
```
|
||||
|
||||
### PowerShell 命令
|
||||
|
||||
````md
|
||||
```powershell
|
||||
# Windows PowerShell 安装步骤
|
||||
# 克隆仓库
|
||||
git clone https://github.com/mcphub/mcphub.git
|
||||
Set-Location mcphub
|
||||
|
||||
# 安装 Node.js 依赖
|
||||
npm install
|
||||
|
||||
# 复制环境变量文件
|
||||
Copy-Item .env.example .env
|
||||
|
||||
# 启动开发服务器
|
||||
npm run dev
|
||||
```
|
||||
````
|
||||
|
||||
```powershell
|
||||
# Windows PowerShell 安装步骤
|
||||
# 克隆仓库
|
||||
git clone https://github.com/mcphub/mcphub.git
|
||||
Set-Location mcphub
|
||||
|
||||
# 安装 Node.js 依赖
|
||||
npm install
|
||||
|
||||
# 复制环境变量文件
|
||||
Copy-Item .env.example .env
|
||||
|
||||
# 启动开发服务器
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### Docker 命令
|
||||
|
||||
````md
|
||||
```bash
|
||||
# 使用 Docker 运行 MCPHub
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
-p 3000:3000 \
|
||||
-e NODE_ENV=production \
|
||||
-e DATABASE_URL=postgresql://user:pass@host:5432/mcphub \
|
||||
-e JWT_SECRET=your-secret-key \
|
||||
mcphub/server:latest
|
||||
|
||||
# 查看日志
|
||||
docker logs mcphub
|
||||
|
||||
# 进入容器
|
||||
docker exec -it mcphub sh
|
||||
|
||||
# 停止容器
|
||||
docker stop mcphub
|
||||
|
||||
# 使用 Docker Compose
|
||||
docker-compose up -d
|
||||
```
|
||||
````
|
||||
|
||||
```bash
|
||||
# 使用 Docker 运行 MCPHub
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
-p 3000:3000 \
|
||||
-e NODE_ENV=production \
|
||||
-e DATABASE_URL=postgresql://user:pass@host:5432/mcphub \
|
||||
-e JWT_SECRET=your-secret-key \
|
||||
mcphub/server:latest
|
||||
|
||||
# 查看日志
|
||||
docker logs mcphub
|
||||
|
||||
# 进入容器
|
||||
docker exec -it mcphub sh
|
||||
|
||||
# 停止容器
|
||||
docker stop mcphub
|
||||
|
||||
# 使用 Docker Compose
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
## API 请求示例
|
||||
|
||||
### cURL 命令
|
||||
|
||||
````md
|
||||
```bash
|
||||
# 创建新的 MCP 服务器
|
||||
curl -X POST https://api.mcphub.io/api/servers \
|
||||
-H "Authorization: Bearer YOUR_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "AI Assistant Server",
|
||||
"endpoint": "https://ai.example.com",
|
||||
"capabilities": ["chat", "completion"],
|
||||
"groupId": "production"
|
||||
}'
|
||||
|
||||
# 获取服务器列表
|
||||
curl -X GET "https://api.mcphub.io/api/servers?limit=10&active=true" \
|
||||
-H "Authorization: Bearer YOUR_API_TOKEN"
|
||||
|
||||
# 更新服务器配置
|
||||
curl -X PUT https://api.mcphub.io/api/servers/server-123 \
|
||||
-H "Authorization: Bearer YOUR_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "Updated AI Assistant",
|
||||
"active": true
|
||||
}'
|
||||
|
||||
# 删除服务器
|
||||
curl -X DELETE https://api.mcphub.io/api/servers/server-123 \
|
||||
-H "Authorization: Bearer YOUR_API_TOKEN"
|
||||
```
|
||||
````
|
||||
|
||||
```bash
|
||||
# 创建新的 MCP 服务器
|
||||
curl -X POST https://api.mcphub.io/api/servers \
|
||||
-H "Authorization: Bearer YOUR_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "AI Assistant Server",
|
||||
"endpoint": "https://ai.example.com",
|
||||
"capabilities": ["chat", "completion"],
|
||||
"groupId": "production"
|
||||
}'
|
||||
|
||||
# 获取服务器列表
|
||||
curl -X GET "https://api.mcphub.io/api/servers?limit=10&active=true" \
|
||||
-H "Authorization: Bearer YOUR_API_TOKEN"
|
||||
|
||||
# 更新服务器配置
|
||||
curl -X PUT https://api.mcphub.io/api/servers/server-123 \
|
||||
-H "Authorization: Bearer YOUR_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "Updated AI Assistant",
|
||||
"active": true
|
||||
}'
|
||||
|
||||
# 删除服务器
|
||||
curl -X DELETE https://api.mcphub.io/api/servers/server-123 \
|
||||
-H "Authorization: Bearer YOUR_API_TOKEN"
|
||||
```
|
||||
|
||||
### HTTP 请求示例
|
||||
|
||||
````md
|
||||
```http
|
||||
POST /api/servers HTTP/1.1
|
||||
Host: api.mcphub.io
|
||||
Authorization: Bearer YOUR_API_TOKEN
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"name": "AI Assistant Server",
|
||||
"endpoint": "https://ai.example.com",
|
||||
"capabilities": ["chat", "completion"],
|
||||
"groupId": "production"
|
||||
}
|
||||
```
|
||||
````
|
||||
|
||||
```http
|
||||
POST /api/servers HTTP/1.1
|
||||
Host: api.mcphub.io
|
||||
Authorization: Bearer YOUR_API_TOKEN
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"name": "AI Assistant Server",
|
||||
"endpoint": "https://ai.example.com",
|
||||
"capabilities": ["chat", "completion"],
|
||||
"groupId": "production"
|
||||
}
|
||||
```
|
||||
|
||||
## 数据库查询
|
||||
|
||||
### SQL 查询
|
||||
|
||||
````md
|
||||
```sql
|
||||
-- 查询活跃的 MCP 服务器
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
endpoint,
|
||||
status,
|
||||
created_at
|
||||
FROM mcp_servers
|
||||
WHERE status = 'active'
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- 统计每个组的服务器数量
|
||||
SELECT
|
||||
g.name as group_name,
|
||||
COUNT(s.id) as server_count
|
||||
FROM server_groups g
|
||||
LEFT JOIN mcp_servers s ON g.id = s.group_id
|
||||
GROUP BY g.id, g.name
|
||||
ORDER BY server_count DESC;
|
||||
|
||||
-- 查询最近的错误日志
|
||||
SELECT
|
||||
timestamp,
|
||||
level,
|
||||
message,
|
||||
metadata
|
||||
FROM logs
|
||||
WHERE level = 'error'
|
||||
AND timestamp >= NOW() - INTERVAL '1 hour'
|
||||
ORDER BY timestamp DESC
|
||||
LIMIT 50;
|
||||
```
|
||||
````
|
||||
|
||||
```sql
|
||||
-- 查询活跃的 MCP 服务器
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
endpoint,
|
||||
status,
|
||||
created_at
|
||||
FROM mcp_servers
|
||||
WHERE status = 'active'
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- 统计每个组的服务器数量
|
||||
SELECT
|
||||
g.name as group_name,
|
||||
COUNT(s.id) as server_count
|
||||
FROM server_groups g
|
||||
LEFT JOIN mcp_servers s ON g.id = s.group_id
|
||||
GROUP BY g.id, g.name
|
||||
ORDER BY server_count DESC;
|
||||
|
||||
-- 查询最近的错误日志
|
||||
SELECT
|
||||
timestamp,
|
||||
level,
|
||||
message,
|
||||
metadata
|
||||
FROM logs
|
||||
WHERE level = 'error'
|
||||
AND timestamp >= NOW() - INTERVAL '1 hour'
|
||||
ORDER BY timestamp DESC
|
||||
LIMIT 50;
|
||||
```
|
||||
|
||||
## 代码块最佳实践
|
||||
|
||||
### 1. 语言标识
|
||||
|
||||
始终为代码块指定正确的语言:
|
||||
|
||||
````md
|
||||
````javascript // ✅ 正确
|
||||
```js // ✅ 也可以
|
||||
```; // ❌ 避免无语言标识
|
||||
````
|
||||
````
|
||||
|
||||
### 2. 文件名标题
|
||||
|
||||
为配置文件和示例添加文件名:
|
||||
|
||||
````md
|
||||
```yaml title="docker-compose.yml"
|
||||
version: '3.8'
|
||||
services:
|
||||
mcphub:
|
||||
image: mcphub/server:latest
|
||||
```
|
||||
````
|
||||
|
||||
### 3. 突出显示重要行
|
||||
|
||||
使用行号高亮重要代码:
|
||||
|
||||
````md
|
||||
```javascript {3,7-9}
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3000; // 重要:端口配置
|
||||
|
||||
app.get('/health', (req, res) => {
|
||||
res.json({ status: 'ok' });
|
||||
});
|
||||
app.listen(port, () => {
|
||||
// 重要:服务器启动
|
||||
console.log(`Server running on port ${port}`);
|
||||
}); // 重要:结束
|
||||
```
|
||||
````
|
||||
|
||||
### 4. 代码注释
|
||||
|
||||
添加有意义的中文注释:
|
||||
|
||||
```javascript
|
||||
// 初始化 MCPHub 客户端
|
||||
const client = new MCPHubClient({
|
||||
endpoint: 'https://api.mcphub.io',
|
||||
apiKey: process.env.API_KEY,
|
||||
timeout: 30000, // 30 秒超时
|
||||
retries: 3, // 重试 3 次
|
||||
});
|
||||
|
||||
// 配置路由策略
|
||||
client.setRoutingStrategy({
|
||||
type: 'weighted', // 加权轮询
|
||||
healthCheck: true, // 启用健康检查
|
||||
fallback: 'round_robin', // 降级策略
|
||||
});
|
||||
```
|
||||
|
||||
### 5. 错误处理示例
|
||||
|
||||
展示完整的错误处理:
|
||||
|
||||
```javascript
|
||||
try {
|
||||
const server = await mcpClient.createServer({
|
||||
name: 'AI Assistant',
|
||||
endpoint: 'https://ai.example.com',
|
||||
});
|
||||
|
||||
console.log('服务器创建成功:', server.id);
|
||||
} catch (error) {
|
||||
if (error.code === 'DUPLICATE_SERVER') {
|
||||
console.log('服务器已存在,跳过创建');
|
||||
} else if (error.code === 'INVALID_ENDPOINT') {
|
||||
console.error('无效的端点地址:', error.message);
|
||||
} else {
|
||||
console.error('创建失败:', error.message);
|
||||
throw error; // 重新抛出未知错误
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 支持的语言
|
||||
|
||||
MCPHub 文档支持以下编程语言的语法高亮:
|
||||
|
||||
- **JavaScript/TypeScript**: `javascript`, `js`, `typescript`, `ts`
|
||||
- **Python**: `python`, `py`
|
||||
- **Shell/Bash**: `bash`, `shell`, `sh`
|
||||
- **PowerShell**: `powershell`, `ps1`
|
||||
- **SQL**: `sql`, `postgresql`, `mysql`
|
||||
- **YAML**: `yaml`, `yml`
|
||||
- **JSON**: `json`
|
||||
- **XML**: `xml`
|
||||
- **HTML**: `html`
|
||||
- **CSS**: `css`
|
||||
- **Dockerfile**: `dockerfile`
|
||||
- **Go**: `go`
|
||||
- **Rust**: `rust`
|
||||
- **Java**: `java`
|
||||
- **C#**: `csharp`, `cs`
|
||||
- **PHP**: `php`
|
||||
- **Ruby**: `ruby`
|
||||
- **HTTP**: `http`
|
||||
- **Markdown**: `markdown`, `md`
|
||||
|
||||
`````
|
||||
|
||||
### 使用三个反引号
|
||||
|
||||
````md
|
||||
```javascript
|
||||
console.log('Hello World');
|
||||
`````
|
||||
|
||||
`````
|
||||
|
||||
### 语法高亮
|
||||
|
||||
我们使用 [Prism](https://prismjs.com/) 来语法高亮显示。Prism 支持 [各种编程语言](https://prismjs.com/#supported-languages)。
|
||||
|
||||
要添加语法高亮显示,请在代码块的第一行指定语言。
|
||||
|
||||
````md
|
||||
```python
|
||||
def hello():
|
||||
print("Hello World")
|
||||
```
|
||||
`````
|
||||
|
||||
```python
|
||||
def hello():
|
||||
print("Hello World")
|
||||
```
|
||||
|
||||
## 代码组
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash npm
|
||||
npm i mintlify
|
||||
```
|
||||
|
||||
```bash yarn
|
||||
yarn add mintlify
|
||||
```
|
||||
|
||||
```bash pnpm
|
||||
pnpm add mintlify
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
`CodeGroup` 允许您将多个代码块组合在一起,并为它们提供选项卡。
|
||||
|
||||
````md
|
||||
<CodeGroup>
|
||||
|
||||
```bash npm
|
||||
npm i mintlify
|
||||
```
|
||||
|
||||
```bash yarn
|
||||
yarn add mintlify
|
||||
```
|
||||
|
||||
```bash pnpm
|
||||
pnpm add mintlify
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
````
|
||||
|
||||
### 代码标题
|
||||
|
||||
您也可以为代码块设置标题:
|
||||
|
||||
```javascript hello.js
|
||||
const hello = 'world';
|
||||
console.log(hello);
|
||||
```
|
||||
|
||||
````md
|
||||
```javascript hello.js
|
||||
const hello = 'world';
|
||||
console.log(hello);
|
||||
```
|
||||
````
|
||||
134
docs/zh/essentials/images.mdx
Normal file
@@ -0,0 +1,134 @@
|
||||
---
|
||||
title: '图片和视频'
|
||||
description: '在您的文档中添加图片和视频'
|
||||
---
|
||||
|
||||
## 图片
|
||||
|
||||
### 使用 Markdown
|
||||
|
||||
您可以使用标准的 Markdown 语法添加图片:
|
||||
|
||||

|
||||
|
||||
```md
|
||||

|
||||
```
|
||||
|
||||
### 使用 HTML
|
||||
|
||||
您也可以使用原始 HTML 获得更多自定义选项:
|
||||
|
||||
<img height="200" src="/images/hero-light.png" />
|
||||
|
||||
```html
|
||||
<img height="200" src="/images/hero-light.png" />
|
||||
```
|
||||
|
||||
### 图片组件
|
||||
|
||||
使用内置的 `<img>` 组件来显示响应式的明暗主题图片:
|
||||
|
||||
<img className="block dark:hidden" src="/images/hero-light.png" alt="Hero Light" />
|
||||
<img className="hidden dark:block" src="/images/hero-dark.png" alt="Hero Dark" />
|
||||
|
||||
```jsx
|
||||
<img
|
||||
className="block dark:hidden"
|
||||
src="/images/hero-light.png"
|
||||
alt="Hero Light"
|
||||
/>
|
||||
<img
|
||||
className="hidden dark:block"
|
||||
src="/images/hero-dark.png"
|
||||
alt="Hero Dark"
|
||||
/>
|
||||
```
|
||||
|
||||
## 图片缩放
|
||||
|
||||
您可以使图片在点击时可缩放(类似于中等缩放)使用 `zoom` 属性。
|
||||
|
||||
<img src="/images/hero-light.png" alt="可缩放" zoom />
|
||||
|
||||
```jsx
|
||||
<img src="/images/hero-light.png" alt="可缩放" zoom />
|
||||
```
|
||||
|
||||
## 嵌入视频
|
||||
|
||||
### YouTube
|
||||
|
||||
<iframe
|
||||
width="560"
|
||||
height="315"
|
||||
src="https://www.youtube.com/embed/4KzFe50RQkQ"
|
||||
title="YouTube 视频播放器"
|
||||
frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowfullscreen
|
||||
></iframe>
|
||||
|
||||
```html
|
||||
<iframe
|
||||
width="560"
|
||||
height="315"
|
||||
src="https://www.youtube.com/embed/4KzFe50RQkQ"
|
||||
title="YouTube 视频播放器"
|
||||
frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowfullscreen
|
||||
></iframe>
|
||||
```
|
||||
|
||||
### Loom
|
||||
|
||||
<iframe
|
||||
src="https://www.loom.com/embed/9019ef5b27ae417798d65b41749227ac"
|
||||
frameborder="0"
|
||||
webkitallowfullscreen
|
||||
mozallowfullscreen
|
||||
allowfullscreen
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
}}
|
||||
></iframe>
|
||||
|
||||
```html
|
||||
<iframe
|
||||
src="https://www.loom.com/embed/9019ef5b27ae417798d65b41749227ac"
|
||||
frameborder="0"
|
||||
webkitallowfullscreen
|
||||
mozallowfullscreen
|
||||
allowfullscreen
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
}}
|
||||
></iframe>
|
||||
```
|
||||
|
||||
## 图片最佳实践
|
||||
|
||||
### 大小优化
|
||||
|
||||
- 保持图片尺寸在合理范围内(通常不超过 1000px 宽度)
|
||||
- 使用适当的图片格式(PNG 用于图标,JPG 用于照片)
|
||||
- 考虑使用现代格式如 WebP 来减少文件大小
|
||||
|
||||
### 无障碍性
|
||||
|
||||
- 始终包含描述性的 `alt` 文本
|
||||
- 确保图片在各种屏幕尺寸下都能正常显示
|
||||
|
||||
### 组织
|
||||
|
||||
- 将图片存储在 `/images` 或 `/assets` 文件夹中
|
||||
- 使用描述性的文件名
|
||||
412
docs/zh/essentials/markdown.mdx
Normal file
@@ -0,0 +1,412 @@
|
||||
---
|
||||
title: 'Markdown 语法'
|
||||
description: 'MCPHub 文档的 Markdown 编写指南和最佳实践'
|
||||
---
|
||||
|
||||
## 标题
|
||||
|
||||
在 MCPHub 文档中,每个页面应该只使用一个 `#` 标题,它会自动成为页面标题。
|
||||
|
||||
```md
|
||||
# MCP 服务器配置指南
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 安装依赖
|
||||
|
||||
#### 系统要求
|
||||
|
||||
##### Node.js 版本
|
||||
|
||||
###### 推荐版本
|
||||
```
|
||||
|
||||
<ResponseExample>
|
||||
|
||||
# 标题 1
|
||||
|
||||
## 标题 2
|
||||
|
||||
### 标题 3
|
||||
|
||||
#### 标题 4
|
||||
|
||||
##### 标题 5
|
||||
|
||||
###### 标题 6
|
||||
|
||||
</ResponseExample>
|
||||
|
||||
## 文本格式
|
||||
|
||||
### 基本格式
|
||||
|
||||
MCPHub 文档支持标准的 Markdown 文本格式:
|
||||
|
||||
```md
|
||||
**粗体文本** - 用于强调重要概念
|
||||
_斜体文本_ - 用于强调或引用
|
||||
`行内代码` - 用于命令、配置键或代码片段
|
||||
~~删除线~~ - 用于标记过时的内容
|
||||
```
|
||||
|
||||
**粗体文本** - 用于强调重要概念
|
||||
_斜体文本_ - 用于强调或引用
|
||||
`行内代码` - 用于命令、配置键或代码片段
|
||||
~~删除线~~ - 用于标记过时的内容
|
||||
|
||||
### 链接
|
||||
|
||||
#### 内部链接
|
||||
|
||||
链接到其他文档页面:
|
||||
|
||||
```md
|
||||
查看 [服务器配置指南](/zh/configuration/mcp-settings) 获取详细信息。
|
||||
```
|
||||
|
||||
查看 [服务器配置指南](/zh/configuration/mcp-settings) 获取详细信息。
|
||||
|
||||
#### 外部链接
|
||||
|
||||
```md
|
||||
访问 [Model Context Protocol 官网](https://modelcontextprotocol.io) 了解更多。
|
||||
```
|
||||
|
||||
访问 [Model Context Protocol 官网](https://modelcontextprotocol.io) 了解更多。
|
||||
|
||||
## 列表
|
||||
|
||||
### 无序列表
|
||||
|
||||
适用于功能列表、要求等:
|
||||
|
||||
```md
|
||||
MCPHub 主要功能:
|
||||
|
||||
- 智能路由分发
|
||||
- 服务器组管理
|
||||
- 实时监控
|
||||
- 身份认证
|
||||
- JWT 令牌
|
||||
- API 密钥
|
||||
- OAuth 2.0
|
||||
```
|
||||
|
||||
MCPHub 主要功能:
|
||||
|
||||
- 智能路由分发
|
||||
- 服务器组管理
|
||||
- 实时监控
|
||||
- 身份认证
|
||||
- JWT 令牌
|
||||
- API 密钥
|
||||
- OAuth 2.0
|
||||
|
||||
### 有序列表
|
||||
|
||||
适用于步骤说明、安装指南等:
|
||||
|
||||
```md
|
||||
快速部署步骤:
|
||||
|
||||
1. 克隆仓库
|
||||
2. 安装依赖
|
||||
3. 配置环境变量
|
||||
4. 启动服务
|
||||
5. 验证部署
|
||||
```
|
||||
|
||||
快速部署步骤:
|
||||
|
||||
1. 克隆仓库
|
||||
2. 安装依赖
|
||||
3. 配置环境变量
|
||||
4. 启动服务
|
||||
5. 验证部署
|
||||
|
||||
## 代码块
|
||||
|
||||
### 基本代码块
|
||||
|
||||
````md
|
||||
```javascript
|
||||
// MCPHub 客户端初始化
|
||||
const mcpClient = new MCPClient({
|
||||
endpoint: 'https://api.mcphub.io',
|
||||
apiKey: process.env.MCPHUB_API_KEY,
|
||||
});
|
||||
```
|
||||
````
|
||||
|
||||
```javascript
|
||||
// MCPHub 客户端初始化
|
||||
const mcpClient = new MCPClient({
|
||||
endpoint: 'https://api.mcphub.io',
|
||||
apiKey: process.env.MCPHUB_API_KEY,
|
||||
});
|
||||
```
|
||||
|
||||
### 配置文件示例
|
||||
|
||||
````md
|
||||
```yaml title="docker-compose.yml"
|
||||
version: '3.8'
|
||||
services:
|
||||
mcphub:
|
||||
image: mcphub/server:latest
|
||||
ports:
|
||||
- '3000:3000'
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- DATABASE_URL=postgresql://user:pass@db:5432/mcphub
|
||||
```
|
||||
````
|
||||
|
||||
```yaml title="docker-compose.yml"
|
||||
version: '3.8'
|
||||
services:
|
||||
mcphub:
|
||||
image: mcphub/server:latest
|
||||
ports:
|
||||
- '3000:3000'
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- DATABASE_URL=postgresql://user:pass@db:5432/mcphub
|
||||
```
|
||||
|
||||
### 终端命令
|
||||
|
||||
````md
|
||||
```bash
|
||||
# 安装 MCPHub CLI
|
||||
npm install -g @mcphub/cli
|
||||
|
||||
# 初始化项目
|
||||
mcphub init my-project
|
||||
|
||||
# 启动开发服务器
|
||||
mcphub dev
|
||||
```
|
||||
````
|
||||
|
||||
```bash
|
||||
# 安装 MCPHub CLI
|
||||
npm install -g @mcphub/cli
|
||||
|
||||
# 初始化项目
|
||||
mcphub init my-project
|
||||
|
||||
# 启动开发服务器
|
||||
mcphub dev
|
||||
```
|
||||
|
||||
## 表格
|
||||
|
||||
### 基本表格
|
||||
|
||||
```md
|
||||
| 功能 | 开源版 | 企业版 |
|
||||
| ------------ | ------ | ------ |
|
||||
| 基础路由 | ✅ | ✅ |
|
||||
| 智能负载均衡 | ❌ | ✅ |
|
||||
| 高级监控 | ❌ | ✅ |
|
||||
| 24/7 支持 | ❌ | ✅ |
|
||||
```
|
||||
|
||||
| 功能 | 开源版 | 企业版 |
|
||||
| ------------ | ------ | ------ |
|
||||
| 基础路由 | ✅ | ✅ |
|
||||
| 智能负载均衡 | ❌ | ✅ |
|
||||
| 高级监控 | ❌ | ✅ |
|
||||
| 24/7 支持 | ❌ | ✅ |
|
||||
|
||||
### API 参数表格
|
||||
|
||||
```md
|
||||
| 参数名 | 类型 | 必需 | 描述 |
|
||||
| ---------- | ------- | ---- | ---------------------- |
|
||||
| `serverId` | string | 是 | 服务器唯一标识符 |
|
||||
| `groupId` | string | 否 | 服务器组 ID |
|
||||
| `active` | boolean | 否 | 是否激活(默认:true) |
|
||||
```
|
||||
|
||||
| 参数名 | 类型 | 必需 | 描述 |
|
||||
| ---------- | ------- | ---- | ---------------------- |
|
||||
| `serverId` | string | 是 | 服务器唯一标识符 |
|
||||
| `groupId` | string | 否 | 服务器组 ID |
|
||||
| `active` | boolean | 否 | 是否激活(默认:true) |
|
||||
|
||||
## 引用块
|
||||
|
||||
### 信息提示
|
||||
|
||||
```md
|
||||
> 📝 **提示**
|
||||
> 在生产环境中部署前,请确保已正确配置所有环境变量。
|
||||
```
|
||||
|
||||
> 📝 **提示**
|
||||
> 在生产环境中部署前,请确保已正确配置所有环境变量。
|
||||
|
||||
### 警告信息
|
||||
|
||||
```md
|
||||
> ⚠️ **警告**
|
||||
> 修改核心配置可能会影响系统稳定性,请谨慎操作。
|
||||
```
|
||||
|
||||
> ⚠️ **警告**
|
||||
> 修改核心配置可能会影响系统稳定性,请谨慎操作。
|
||||
|
||||
## 任务列表
|
||||
|
||||
```md
|
||||
- [x] 完成服务器配置
|
||||
- [x] 设置数据库连接
|
||||
- [ ] 配置负载均衡
|
||||
- [ ] 设置监控告警
|
||||
- [ ] 编写单元测试
|
||||
```
|
||||
|
||||
- [x] 完成服务器配置
|
||||
- [x] 设置数据库连接
|
||||
- [ ] 配置负载均衡
|
||||
- [ ] 设置监控告警
|
||||
- [ ] 编写单元测试
|
||||
|
||||
## 水平分割线
|
||||
|
||||
用于分隔不同的内容部分:
|
||||
|
||||
```md
|
||||
## 第一部分
|
||||
|
||||
内容...
|
||||
|
||||
---
|
||||
|
||||
## 第二部分
|
||||
|
||||
更多内容...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 转义字符
|
||||
|
||||
当需要显示 Markdown 特殊字符时:
|
||||
|
||||
```md
|
||||
\*这不是斜体\*
|
||||
\`这不是代码\`
|
||||
\[这不是链接\]
|
||||
```
|
||||
|
||||
\*这不是斜体\*
|
||||
\`这不是代码\`
|
||||
\[这不是链接\]
|
||||
|
||||
## MCPHub 文档特定约定
|
||||
|
||||
### 配置项格式
|
||||
|
||||
环境变量和配置项使用特定格式:
|
||||
|
||||
```md
|
||||
设置 `MCPHUB_PORT` 环境变量为 `3000`。
|
||||
```
|
||||
|
||||
设置 `MCPHUB_PORT` 环境变量为 `3000`。
|
||||
|
||||
### API 端点格式
|
||||
|
||||
```md
|
||||
`GET /api/servers/{id}` - 获取服务器详情
|
||||
```
|
||||
|
||||
`GET /api/servers/{id}` - 获取服务器详情
|
||||
|
||||
### 版本标记
|
||||
|
||||
```md
|
||||
该功能在 v2.1.0+ 版本中可用。
|
||||
```
|
||||
|
||||
该功能在 v2.1.0+ 版本中可用。
|
||||
|
||||
## 最佳实践
|
||||
|
||||
1. **标题层级**:保持清晰的标题层级结构
|
||||
2. **代码示例**:为所有代码块指定语言
|
||||
3. **链接检查**:确保所有内部链接有效
|
||||
4. **图片描述**:为图片添加有意义的 alt 文本
|
||||
5. **一致性**:在整个文档中保持术语和格式一致
|
||||
|
||||
### 文档模板示例
|
||||
|
||||
````md
|
||||
---
|
||||
title: '功能名称'
|
||||
description: '简短的功能描述'
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
简要介绍该功能的用途和重要性。
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 前提条件
|
||||
|
||||
- 系统要求
|
||||
- 依赖软件
|
||||
|
||||
### 安装步骤
|
||||
|
||||
1. 第一步
|
||||
2. 第二步
|
||||
3. 第三步
|
||||
|
||||
```bash
|
||||
# 示例命令
|
||||
npm install example
|
||||
```
|
||||
|
||||
## 配置
|
||||
|
||||
### 基本配置
|
||||
|
||||
| 配置项 | 类型 | 描述 |
|
||||
| --------- | ------ | -------- |
|
||||
| `option1` | string | 选项描述 |
|
||||
|
||||
### 高级配置
|
||||
|
||||
详细的配置说明...
|
||||
|
||||
## 示例
|
||||
|
||||
### 基本用法
|
||||
|
||||
```javascript
|
||||
// 代码示例
|
||||
const example = new Example();
|
||||
```
|
||||
|
||||
### 高级用法
|
||||
|
||||
更复杂的使用场景...
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
**问题**:描述问题
|
||||
**解决方案**:解决步骤
|
||||
|
||||
## 参考资料
|
||||
|
||||
- [相关文档链接](/link)
|
||||
- [外部资源](https://example.com)
|
||||
````
|
||||
596
docs/zh/essentials/navigation.mdx
Normal file
@@ -0,0 +1,596 @@
|
||||
---
|
||||
title: '导航配置'
|
||||
description: 'MCPHub 文档的导航结构配置指南'
|
||||
---
|
||||
|
||||
## 基础导航
|
||||
|
||||
MCPHub 文档的导航在 `docs.json` 文件中配置。基本导航结构包含组和页面:
|
||||
|
||||
```json title="docs.json"
|
||||
{
|
||||
"navigation": [
|
||||
{
|
||||
"group": "快速开始",
|
||||
"pages": ["zh/index", "zh/quickstart"]
|
||||
},
|
||||
{
|
||||
"group": "开发指南",
|
||||
"pages": [
|
||||
"zh/development/getting-started",
|
||||
"zh/development/api-integration",
|
||||
"zh/development/testing"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "配置管理",
|
||||
"pages": [
|
||||
"zh/configuration/environment-variables",
|
||||
"zh/configuration/mcp-settings",
|
||||
"zh/configuration/docker-setup",
|
||||
"zh/configuration/nginx"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 标签导航
|
||||
|
||||
当您的文档有多个主要部分时,可以使用标签来组织内容。
|
||||
|
||||
```json docs.json
|
||||
{
|
||||
"navigation": {
|
||||
"tabs": [
|
||||
{
|
||||
"tab": "指南",
|
||||
"groups": [
|
||||
{
|
||||
"group": "基础",
|
||||
"pages": ["basics/introduction"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tab": "API 参考",
|
||||
"groups": [
|
||||
{
|
||||
"group": "端点",
|
||||
"pages": ["api/users", "api/products"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 页面引用
|
||||
|
||||
### 文件路径引用
|
||||
|
||||
最常见的方式是通过文件路径引用页面(不包含 `.mdx` 扩展名):
|
||||
|
||||
```json
|
||||
{
|
||||
"pages": ["quickstart", "advanced/configuration"]
|
||||
}
|
||||
```
|
||||
|
||||
### 外部链接
|
||||
|
||||
您也可以在导航中包含外部链接:
|
||||
|
||||
```json
|
||||
{
|
||||
"pages": [
|
||||
"introduction",
|
||||
{
|
||||
"page": "GitHub",
|
||||
"href": "https://github.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 分组
|
||||
|
||||
### 基本分组
|
||||
|
||||
每个组都有一个名称和页面列表:
|
||||
|
||||
```json
|
||||
{
|
||||
"group": "API 基础",
|
||||
"pages": ["api/authentication", "api/errors", "api/rate-limits"]
|
||||
}
|
||||
```
|
||||
|
||||
### 分组版本控制
|
||||
|
||||
您可以为组指定版本:
|
||||
|
||||
```json
|
||||
{
|
||||
"group": "API v2",
|
||||
"version": "v2.0",
|
||||
"pages": ["api/v2/users"]
|
||||
}
|
||||
```
|
||||
|
||||
## 全局导航元素
|
||||
|
||||
### 锚点
|
||||
|
||||
在所有页面上显示的持久链接:
|
||||
|
||||
```json docs.json
|
||||
{
|
||||
"navigation": {
|
||||
"global": {
|
||||
"anchors": [
|
||||
{
|
||||
"anchor": "API 参考",
|
||||
"href": "/api-reference",
|
||||
"icon": "square-terminal"
|
||||
},
|
||||
{
|
||||
"anchor": "社区",
|
||||
"href": "https://community.example.com",
|
||||
"icon": "discord"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 导航栏
|
||||
|
||||
配置顶部导航栏的链接:
|
||||
|
||||
```json docs.json
|
||||
{
|
||||
"navbar": {
|
||||
"links": [
|
||||
{
|
||||
"label": "支持",
|
||||
"href": "mailto:support@example.com"
|
||||
}
|
||||
],
|
||||
"primary": {
|
||||
"type": "button",
|
||||
"label": "仪表板",
|
||||
"href": "https://dashboard.example.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 分层导航结构
|
||||
|
||||
### 多级导航
|
||||
|
||||
MCPHub 文档支持多级分层导航:
|
||||
|
||||
```json title="docs.json"
|
||||
{
|
||||
"navigation": [
|
||||
{
|
||||
"group": "核心功能",
|
||||
"pages": [
|
||||
{
|
||||
"group": "服务器管理",
|
||||
"pages": [
|
||||
"zh/features/server-management",
|
||||
"zh/features/server-health",
|
||||
"zh/features/server-scaling"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "智能路由",
|
||||
"pages": [
|
||||
"zh/features/smart-routing",
|
||||
"zh/features/load-balancing",
|
||||
"zh/features/failover"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 条件导航
|
||||
|
||||
根据用户权限或版本显示不同的导航项:
|
||||
|
||||
```json title="docs.json"
|
||||
{
|
||||
"navigation": [
|
||||
{
|
||||
"group": "API 参考",
|
||||
"pages": [
|
||||
"zh/api-reference/introduction",
|
||||
"zh/api-reference/authentication",
|
||||
{
|
||||
"group": "端点",
|
||||
"pages": [
|
||||
"zh/api-reference/endpoint/get",
|
||||
"zh/api-reference/endpoint/create",
|
||||
"zh/api-reference/endpoint/delete",
|
||||
"zh/api-reference/endpoint/webhook"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "企业功能",
|
||||
"icon": "crown",
|
||||
"version": "enterprise",
|
||||
"pages": ["zh/enterprise/sso", "zh/enterprise/audit-logs", "zh/enterprise/compliance"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 标签导航
|
||||
|
||||
对于多产品或多语言文档,使用标签组织内容:
|
||||
|
||||
```json title="docs.json"
|
||||
{
|
||||
"tabs": [
|
||||
{
|
||||
"name": "文档",
|
||||
"url": "https://docs.mcphub.io"
|
||||
},
|
||||
{
|
||||
"name": "API",
|
||||
"url": "https://api.mcphub.io"
|
||||
},
|
||||
{
|
||||
"name": "SDK",
|
||||
"url": "https://sdk.mcphub.io"
|
||||
}
|
||||
],
|
||||
"navigation": {
|
||||
"文档": [
|
||||
{
|
||||
"group": "开始使用",
|
||||
"pages": ["zh/index", "zh/quickstart"]
|
||||
}
|
||||
],
|
||||
"API": [
|
||||
{
|
||||
"group": "API 参考",
|
||||
"pages": ["zh/api-reference/introduction", "zh/api-reference/authentication"]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 导航图标
|
||||
|
||||
为导航项添加图标以提高可读性:
|
||||
|
||||
```json title="docs.json"
|
||||
{
|
||||
"navigation": [
|
||||
{
|
||||
"group": "快速开始",
|
||||
"icon": "rocket",
|
||||
"pages": ["zh/index", "zh/quickstart"]
|
||||
},
|
||||
{
|
||||
"group": "配置",
|
||||
"icon": "gear",
|
||||
"pages": ["zh/configuration/environment-variables", "zh/configuration/mcp-settings"]
|
||||
},
|
||||
{
|
||||
"group": "监控",
|
||||
"icon": "chart-line",
|
||||
"pages": ["zh/features/monitoring", "zh/features/analytics"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 支持的图标
|
||||
|
||||
MCPHub 文档支持以下图标库的图标:
|
||||
|
||||
- **Heroicons**: `hero-icon-name`
|
||||
- **Font Awesome**: `fa-icon-name`
|
||||
- **Feather**: `feather-icon-name`
|
||||
- **Lucide**: `lucide-icon-name`
|
||||
|
||||
常用图标示例:
|
||||
|
||||
| 功能 | 图标 | 代码 |
|
||||
| ---- | ---- | ------------- |
|
||||
| 首页 | 🏠 | `"home"` |
|
||||
| 设置 | ⚙️ | `"gear"` |
|
||||
| API | 🔌 | `"plug"` |
|
||||
| 安全 | 🔒 | `"lock"` |
|
||||
| 监控 | 📊 | `"chart-bar"` |
|
||||
| 文档 | 📖 | `"book"` |
|
||||
| 开发 | 💻 | `"code"` |
|
||||
|
||||
## 外部链接
|
||||
|
||||
在导航中包含外部资源链接:
|
||||
|
||||
```json title="docs.json"
|
||||
{
|
||||
"navigation": [
|
||||
{
|
||||
"group": "资源",
|
||||
"pages": [
|
||||
{
|
||||
"name": "GitHub 仓库",
|
||||
"url": "https://github.com/mcphub/mcphub",
|
||||
"icon": "github"
|
||||
},
|
||||
{
|
||||
"name": "Discord 社区",
|
||||
"url": "https://discord.gg/mcphub",
|
||||
"icon": "discord"
|
||||
},
|
||||
{
|
||||
"name": "状态页面",
|
||||
"url": "https://status.mcphub.io",
|
||||
"icon": "status"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 导航排序
|
||||
|
||||
### 自动排序
|
||||
|
||||
默认情况下,导航项按字母顺序排列。可以通过文件名前缀控制排序:
|
||||
|
||||
```
|
||||
zh/
|
||||
├── 01-index.mdx
|
||||
├── 02-quickstart.mdx
|
||||
├── development/
|
||||
│ ├── 01-getting-started.mdx
|
||||
│ ├── 02-api-integration.mdx
|
||||
│ └── 03-testing.mdx
|
||||
└── configuration/
|
||||
├── 01-environment-variables.mdx
|
||||
├── 02-mcp-settings.mdx
|
||||
└── 03-docker-setup.mdx
|
||||
```
|
||||
|
||||
### 手动排序
|
||||
|
||||
在 `docs.json` 中明确指定顺序:
|
||||
|
||||
```json title="docs.json"
|
||||
{
|
||||
"navigation": [
|
||||
{
|
||||
"group": "核心概念",
|
||||
"pages": [
|
||||
"zh/concepts/introduction",
|
||||
"zh/concepts/architecture",
|
||||
"zh/concepts/mcp-protocol",
|
||||
"zh/concepts/routing"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 隐藏导航项
|
||||
|
||||
### 草稿页面
|
||||
|
||||
使用 `draft: true` 隐藏未完成的页面:
|
||||
|
||||
```yaml title="draft-page.mdx"
|
||||
---
|
||||
title: '开发中的功能'
|
||||
description: '此功能正在开发中'
|
||||
draft: true
|
||||
---
|
||||
```
|
||||
|
||||
### 条件显示
|
||||
|
||||
根据用户角色或环境显示导航:
|
||||
|
||||
```json title="docs.json"
|
||||
{
|
||||
"navigation": [
|
||||
{
|
||||
"group": "管理功能",
|
||||
"hidden": "user",
|
||||
"pages": ["zh/admin/user-management", "zh/admin/system-settings"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 导航元数据
|
||||
|
||||
### 页面元数据
|
||||
|
||||
在页面头部添加导航相关的元数据:
|
||||
|
||||
```yaml title="page.mdx"
|
||||
---
|
||||
title: '服务器管理'
|
||||
description: 'MCPHub 服务器管理功能详解'
|
||||
icon: 'server'
|
||||
order: 1
|
||||
hidden: false
|
||||
version: '2.0+'
|
||||
tags: ['管理', '服务器', '配置']
|
||||
---
|
||||
```
|
||||
|
||||
### 组元数据
|
||||
|
||||
为导航组添加描述和图标:
|
||||
|
||||
```json title="docs.json"
|
||||
{
|
||||
"navigation": [
|
||||
{
|
||||
"group": "API 参考",
|
||||
"icon": "api",
|
||||
"description": "完整的 API 接口文档",
|
||||
"version": "v2",
|
||||
"pages": ["zh/api-reference/introduction"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 搜索优化
|
||||
|
||||
### 搜索关键词
|
||||
|
||||
为页面添加搜索关键词:
|
||||
|
||||
```yaml title="page.mdx"
|
||||
---
|
||||
title: 'Docker 部署'
|
||||
description: '使用 Docker 部署 MCPHub'
|
||||
keywords: ['docker', '部署', '容器', '生产环境']
|
||||
searchable: true
|
||||
---
|
||||
```
|
||||
|
||||
### 搜索权重
|
||||
|
||||
控制页面在搜索结果中的权重:
|
||||
|
||||
```yaml title="important-page.mdx"
|
||||
---
|
||||
title: '快速开始'
|
||||
description: '5 分钟快速部署 MCPHub'
|
||||
searchWeight: 10
|
||||
featured: true
|
||||
---
|
||||
```
|
||||
|
||||
## 面包屑导航
|
||||
|
||||
自动生成面包屑导航:
|
||||
|
||||
```json title="docs.json"
|
||||
{
|
||||
"breadcrumbs": {
|
||||
"enabled": true,
|
||||
"separator": "›",
|
||||
"home": "首页"
|
||||
},
|
||||
"navigation": [
|
||||
{
|
||||
"group": "配置管理",
|
||||
"pages": ["zh/configuration/environment-variables"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
显示效果:`首页 › 配置管理 › 环境变量`
|
||||
|
||||
## 导航最佳实践
|
||||
|
||||
### 1. 逻辑分组
|
||||
|
||||
按功能和用户需求逻辑分组:
|
||||
|
||||
```json
|
||||
{
|
||||
"navigation": [
|
||||
{
|
||||
"group": "新手指南",
|
||||
"pages": ["introduction", "quickstart", "first-server"]
|
||||
},
|
||||
{
|
||||
"group": "进阶配置",
|
||||
"pages": ["advanced-routing", "scaling", "monitoring"]
|
||||
},
|
||||
{
|
||||
"group": "参考文档",
|
||||
"pages": ["api-reference", "cli-reference", "troubleshooting"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 渐进式学习路径
|
||||
|
||||
设计符合学习曲线的导航结构:
|
||||
|
||||
1. **入门** → 快速开始、基础概念
|
||||
2. **实践** → 配置、部署、集成
|
||||
3. **进阶** → 优化、监控、故障排除
|
||||
4. **参考** → API 文档、CLI 手册
|
||||
|
||||
### 3. 移动端友好
|
||||
|
||||
确保导航在移动设备上的可用性:
|
||||
|
||||
```json title="docs.json"
|
||||
{
|
||||
"navigation": [
|
||||
{
|
||||
"group": "快速开始",
|
||||
"collapsed": false,
|
||||
"pages": ["zh/index", "zh/quickstart"]
|
||||
},
|
||||
{
|
||||
"group": "详细文档",
|
||||
"collapsed": true,
|
||||
"pages": ["zh/advanced/..."]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 4. 国际化支持
|
||||
|
||||
为多语言文档配置导航:
|
||||
|
||||
```json title="docs.json"
|
||||
{
|
||||
"i18n": {
|
||||
"defaultLocale": "zh",
|
||||
"locales": ["zh", "en"]
|
||||
},
|
||||
"navigation": {
|
||||
"zh": [
|
||||
{
|
||||
"group": "快速开始",
|
||||
"pages": ["zh/index", "zh/quickstart"]
|
||||
}
|
||||
],
|
||||
"en": [
|
||||
{
|
||||
"group": "Getting Started",
|
||||
"pages": ["en/index", "en/quickstart"]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 5. 性能优化
|
||||
|
||||
- 使用懒加载减少初始加载时间
|
||||
- 合理设置导航深度(建议不超过 3 层)
|
||||
- 避免过多的外部链接
|
||||
- 定期清理无效的导航项
|
||||
144
docs/zh/essentials/reusable-snippets.mdx
Normal file
@@ -0,0 +1,144 @@
|
||||
---
|
||||
title: '可重用代码片段'
|
||||
description: '学习如何创建和使用代码片段来保持文档的一致性'
|
||||
---
|
||||
|
||||
## 什么是代码片段?
|
||||
|
||||
代码片段允许您在文档的多个位置重用内容块。这有助于保持一致性并减少重复内容的维护工作。
|
||||
|
||||
## 创建代码片段
|
||||
|
||||
代码片段存储在 `snippets/` 文件夹中,使用 `.mdx` 扩展名。
|
||||
|
||||
### 基本代码片段
|
||||
|
||||
创建 `snippets/api-key-setup.mdx`:
|
||||
|
||||
```md
|
||||
获取您的 API 密钥:
|
||||
|
||||
1. 登录到您的仪表板
|
||||
2. 导航到 **设置** > **API 密钥**
|
||||
3. 点击 **生成新密钥**
|
||||
4. 复制密钥并安全地存储
|
||||
```
|
||||
|
||||
### 带参数的代码片段
|
||||
|
||||
您可以创建接受参数的动态代码片段。创建 `snippets/code-example.mdx`:
|
||||
|
||||
````jsx
|
||||
<CodeGroup>
|
||||
|
||||
```bash {props.packageManager}
|
||||
{props.packageManager} install {props.packageName}
|
||||
````
|
||||
|
||||
</CodeGroup>
|
||||
```
|
||||
|
||||
## 使用代码片段
|
||||
|
||||
### 基本使用
|
||||
|
||||
使用 `<Snippet>` 组件来包含代码片段:
|
||||
|
||||
```jsx
|
||||
<Snippet file="api-key-setup.mdx" />
|
||||
```
|
||||
|
||||
<Snippet file="snippet-intro.mdx" />
|
||||
|
||||
### 带参数使用
|
||||
|
||||
```jsx
|
||||
<Snippet file="code-example.mdx" packageManager="npm" packageName="mintlify" />
|
||||
```
|
||||
|
||||
## 代码片段最佳实践
|
||||
|
||||
### 文件组织
|
||||
|
||||
```
|
||||
snippets/
|
||||
├── setup/
|
||||
│ ├── installation.mdx
|
||||
│ └── configuration.mdx
|
||||
├── examples/
|
||||
│ ├── basic-usage.mdx
|
||||
│ └── advanced-usage.mdx
|
||||
└── common/
|
||||
├── prerequisites.mdx
|
||||
└── troubleshooting.mdx
|
||||
```
|
||||
|
||||
### 命名约定
|
||||
|
||||
- 使用描述性文件名
|
||||
- 使用连字符分隔单词
|
||||
- 按主题分组到子文件夹
|
||||
|
||||
### 内容指导原则
|
||||
|
||||
1. **保持简洁** - 代码片段应该是独立的内容块
|
||||
2. **避免硬编码** - 对可变内容使用参数
|
||||
3. **文档化参数** - 在代码片段中注释必需的参数
|
||||
|
||||
### 参数文档
|
||||
|
||||
在代码片段文件的顶部记录所需参数:
|
||||
|
||||
```md
|
||||
<!--
|
||||
参数:
|
||||
- packageManager: 包管理器名称(npm, yarn, pnpm)
|
||||
- packageName: 要安装的包名称
|
||||
-->
|
||||
|
||||
安装说明...
|
||||
```
|
||||
|
||||
## 高级代码片段
|
||||
|
||||
### 条件内容
|
||||
|
||||
您可以使用条件逻辑来根据参数显示不同的内容:
|
||||
|
||||
```jsx
|
||||
{
|
||||
props.framework === 'react' && <div>React 特定的内容...</div>;
|
||||
}
|
||||
|
||||
{
|
||||
props.framework === 'vue' && <div>Vue 特定的内容...</div>;
|
||||
}
|
||||
```
|
||||
|
||||
### 嵌套代码片段
|
||||
|
||||
代码片段可以包含其他代码片段:
|
||||
|
||||
```jsx
|
||||
<Snippet file="common/prerequisites.mdx" />
|
||||
|
||||
## 安装步骤
|
||||
|
||||
<Snippet file="setup/installation.mdx" framework={props.framework} />
|
||||
```
|
||||
|
||||
## 维护代码片段
|
||||
|
||||
### 版本控制
|
||||
|
||||
当更新代码片段时:
|
||||
|
||||
1. 考虑向后兼容性
|
||||
2. 更新所有使用该代码片段的页面
|
||||
3. 测试更改在所有上下文中的效果
|
||||
|
||||
### 重构检查清单
|
||||
|
||||
- [ ] 确认所有参数仍然有效
|
||||
- [ ] 验证代码片段在所有使用位置正确渲染
|
||||
- [ ] 更新相关文档
|
||||
172
docs/zh/essentials/settings.mdx
Normal file
@@ -0,0 +1,172 @@
|
||||
---
|
||||
title: '设置'
|
||||
description: '了解如何配置您的文档'
|
||||
---
|
||||
|
||||
## 全局配置
|
||||
|
||||
所有的全局配置都在项目根目录的 `docs.json` 文件中设置。
|
||||
|
||||
### 名称
|
||||
|
||||
在配置的顶层设置文档的名称。
|
||||
|
||||
```json docs.json
|
||||
{
|
||||
"name": "Mintlify 文档"
|
||||
}
|
||||
```
|
||||
|
||||
### Logo
|
||||
|
||||
您可以显示浅色和深色模式的 logo。
|
||||
|
||||
```json docs.json
|
||||
{
|
||||
"logo": {
|
||||
"light": "/logo/light.svg",
|
||||
"dark": "/logo/dark.svg"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Favicon
|
||||
|
||||
```json docs.json
|
||||
{
|
||||
"favicon": "/favicon.ico"
|
||||
}
|
||||
```
|
||||
|
||||
### 颜色
|
||||
|
||||
自定义文档的主色调以匹配您的品牌。
|
||||
|
||||
```json docs.json
|
||||
{
|
||||
"colors": {
|
||||
"primary": "#9563FF",
|
||||
"light": "#AE87FF",
|
||||
"dark": "#9563FF"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<Tip>设置一种颜色系统,通过仅更改主色调来协调您文档的配色方案。</Tip>
|
||||
|
||||
### 导航
|
||||
|
||||
您的侧边栏导航在 `navigation` 字段中设置。文档页面必须嵌套在组下,组必须嵌套在导航下。
|
||||
|
||||
```json docs.json
|
||||
{
|
||||
"navigation": [
|
||||
{
|
||||
"group": "开始使用",
|
||||
"pages": ["introduction", "quickstart", "development"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### 标签
|
||||
|
||||
您可以将页面分组为不同的标签。当您想要将概念或 API 参考组织到不同的部分时,这很有用。
|
||||
|
||||
```json docs.json
|
||||
{
|
||||
"navigation": {
|
||||
"tabs": [
|
||||
{
|
||||
"tab": "主要",
|
||||
"groups": [
|
||||
{
|
||||
"group": "开始使用",
|
||||
"pages": ["introduction"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tab": "API 参考",
|
||||
"groups": [
|
||||
{
|
||||
"group": "端点",
|
||||
"pages": ["api-reference/users"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 页脚
|
||||
|
||||
您可以在 `footer` 字段中配置页脚链接。
|
||||
|
||||
```json docs.json
|
||||
{
|
||||
"footer": {
|
||||
"socials": {
|
||||
"website": "https://mintlify.com",
|
||||
"github": "https://github.com/mintlify",
|
||||
"slack": "https://mintlify.com/community"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 搜索
|
||||
|
||||
您可以通过多种方式配置搜索,包括替换默认搜索或添加搜索锚点。
|
||||
|
||||
```json docs.json
|
||||
{
|
||||
"search": {
|
||||
"prompt": "搜索..."
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 页面配置
|
||||
|
||||
页面配置在每个 MDX 文件顶部的 frontmatter 中设置。
|
||||
|
||||
### 标题和描述
|
||||
|
||||
```md
|
||||
---
|
||||
title: '介绍'
|
||||
description: '欢迎来到我们的产品!'
|
||||
---
|
||||
```
|
||||
|
||||
### 侧边栏标题
|
||||
|
||||
```md
|
||||
---
|
||||
sidebarTitle: '主页'
|
||||
---
|
||||
```
|
||||
|
||||
设置不同于页面标题的侧边栏标题。
|
||||
|
||||
### 图标
|
||||
|
||||
```md
|
||||
---
|
||||
icon: 'star'
|
||||
---
|
||||
```
|
||||
|
||||
为侧边栏中的页面设置 [FontAwesome](https://fontawesome.com/search?s=solid&m=free) 图标。
|
||||
|
||||
### 模式
|
||||
|
||||
```md
|
||||
---
|
||||
mode: 'wide'
|
||||
---
|
||||
```
|
||||
|
||||
设置页面的显示模式。选项包括 `"default"` 和 `"wide"`。
|
||||
330
docs/zh/features/authentication.mdx
Normal file
@@ -0,0 +1,330 @@
|
||||
---
|
||||
title: '身份认证与安全'
|
||||
description: '为 MCPHub 配置身份认证和安全设置'
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
MCPHub 提供灵活的身份认证机制来保护您的 MCP 服务器管理平台。系统支持多种身份认证方法和基于角色的访问控制。
|
||||
|
||||
## 身份认证方法
|
||||
|
||||
### 基于环境变量的认证
|
||||
|
||||
使用环境变量配置基础认证:
|
||||
|
||||
```bash
|
||||
# 基础认证凭据
|
||||
AUTH_USERNAME=admin
|
||||
AUTH_PASSWORD=your-secure-password
|
||||
|
||||
# JWT 设置
|
||||
JWT_SECRET=your-jwt-secret-key
|
||||
JWT_EXPIRES_IN=24h
|
||||
```
|
||||
|
||||
### 数据库认证
|
||||
|
||||
对于生产环境部署,启用基于数据库的用户管理:
|
||||
|
||||
```json
|
||||
{
|
||||
"auth": {
|
||||
"provider": "database",
|
||||
"database": {
|
||||
"url": "postgresql://user:pass@localhost:5432/mcphub",
|
||||
"userTable": "users"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 用户管理
|
||||
|
||||
### 创建用户
|
||||
|
||||
通过管理界面或 API 创建用户:
|
||||
|
||||
```bash
|
||||
# 通过 API
|
||||
curl -X POST http://localhost:3000/api/auth/users \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $ADMIN_TOKEN" \
|
||||
-d '{
|
||||
"username": "newuser",
|
||||
"email": "user@example.com",
|
||||
"password": "securepassword",
|
||||
"role": "user"
|
||||
}'
|
||||
```
|
||||
|
||||
### 用户角色
|
||||
|
||||
MCPHub 支持基于角色的访问控制:
|
||||
|
||||
- **管理员**: 完整系统访问权限、用户管理、服务器配置
|
||||
- **管理者**: 服务器管理、组管理、监控
|
||||
- **用户**: 在分配组内的基本服务器访问权限
|
||||
- **查看者**: 对分配资源的只读访问权限
|
||||
|
||||
## 基于组的访问控制
|
||||
|
||||
### 将用户分配到组
|
||||
|
||||
```bash
|
||||
# 添加用户到组
|
||||
curl -X POST http://localhost:3000/api/groups/{groupId}/users \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{"userId": "user123"}'
|
||||
```
|
||||
|
||||
### 组权限
|
||||
|
||||
配置组级别权限:
|
||||
|
||||
```json
|
||||
{
|
||||
"groupId": "dev-team",
|
||||
"permissions": {
|
||||
"servers": ["read", "write", "execute"],
|
||||
"tools": ["read", "execute"],
|
||||
"logs": ["read"],
|
||||
"config": ["read"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## API 认证
|
||||
|
||||
### JWT 令牌认证
|
||||
|
||||
```javascript
|
||||
// 获取认证令牌
|
||||
const response = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: 'your-username',
|
||||
password: 'your-password',
|
||||
}),
|
||||
});
|
||||
|
||||
const { token } = await response.json();
|
||||
|
||||
// 在后续请求中使用令牌
|
||||
const protectedResponse = await fetch('/api/servers', {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
### API 密钥认证
|
||||
|
||||
为系统集成生成 API 密钥:
|
||||
|
||||
```bash
|
||||
# 生成新的 API 密钥
|
||||
curl -X POST http://localhost:3000/api/auth/api-keys \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"name": "Integration Key",
|
||||
"permissions": ["servers:read", "servers:write"],
|
||||
"expiresAt": "2024-12-31T23:59:59.000Z"
|
||||
}'
|
||||
```
|
||||
|
||||
## 安全设置
|
||||
|
||||
### HTTPS 配置
|
||||
|
||||
为生产环境启用 HTTPS:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name mcphub.example.com;
|
||||
|
||||
ssl_certificate /path/to/certificate.crt;
|
||||
ssl_certificate_key /path/to/private.key;
|
||||
|
||||
location / {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 会话安全
|
||||
|
||||
配置安全的会话设置:
|
||||
|
||||
```javascript
|
||||
// 会话配置
|
||||
{
|
||||
"session": {
|
||||
"secret": "your-session-secret",
|
||||
"secure": true, // 生产环境中需要 HTTPS
|
||||
"httpOnly": true,
|
||||
"maxAge": 86400000, // 24 小时
|
||||
"sameSite": "strict"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 速率限制
|
||||
|
||||
实施 API 速率限制:
|
||||
|
||||
```javascript
|
||||
{
|
||||
"rateLimit": {
|
||||
"windowMs": 900000, // 15 分钟
|
||||
"max": 100, // 每个 IP 限制 100 个请求
|
||||
"message": "请求过于频繁,请稍后再试",
|
||||
"standardHeaders": true,
|
||||
"legacyHeaders": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 多因素认证 (MFA)
|
||||
|
||||
### 启用 TOTP
|
||||
|
||||
为管理员帐户启用基于时间的一次性密码:
|
||||
|
||||
```bash
|
||||
# 启用 MFA
|
||||
curl -X POST http://localhost:3000/api/auth/mfa/enable \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"type": "totp",
|
||||
"appName": "MCPHub"
|
||||
}'
|
||||
```
|
||||
|
||||
### 验证 MFA 代码
|
||||
|
||||
```javascript
|
||||
// 登录时验证 MFA
|
||||
const loginResponse = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: 'admin',
|
||||
password: 'password',
|
||||
mfaCode: '123456', // 来自认证器应用的 6 位数字
|
||||
}),
|
||||
});
|
||||
```
|
||||
|
||||
## 审计日志
|
||||
|
||||
### 启用审计日志
|
||||
|
||||
跟踪所有认证和授权事件:
|
||||
|
||||
```json
|
||||
{
|
||||
"audit": {
|
||||
"enabled": true,
|
||||
"logLevel": "info",
|
||||
"events": [
|
||||
"login",
|
||||
"logout",
|
||||
"password_change",
|
||||
"role_change",
|
||||
"permission_change",
|
||||
"server_access",
|
||||
"config_change"
|
||||
],
|
||||
"storage": {
|
||||
"type": "database",
|
||||
"retention": "90d"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 查看审计日志
|
||||
|
||||
```bash
|
||||
# 获取审计日志
|
||||
curl -X GET "http://localhost:3000/api/audit/logs?startDate=2024-01-01&endDate=2024-01-31" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
## 密码策略
|
||||
|
||||
### 配置密码要求
|
||||
|
||||
```json
|
||||
{
|
||||
"passwordPolicy": {
|
||||
"minLength": 12,
|
||||
"requireUppercase": true,
|
||||
"requireLowercase": true,
|
||||
"requireNumbers": true,
|
||||
"requireSpecialChars": true,
|
||||
"preventCommonPasswords": true,
|
||||
"preventReuse": 5, // 防止重复使用最近 5 个密码
|
||||
"maxAge": 7776000 // 90 天后过期
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见认证问题
|
||||
|
||||
1. **JWT 令牌过期**
|
||||
|
||||
```bash
|
||||
# 检查令牌有效期
|
||||
curl -X GET http://localhost:3000/api/auth/verify \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
2. **权限被拒绝**
|
||||
|
||||
```bash
|
||||
# 检查用户权限
|
||||
curl -X GET http://localhost:3000/api/auth/permissions \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
3. **会话问题**
|
||||
- 清除浏览器 cookies
|
||||
- 检查会话配置
|
||||
- 验证服务器时间同步
|
||||
|
||||
### 调试认证流程
|
||||
|
||||
启用调试日志:
|
||||
|
||||
```bash
|
||||
# 设置环境变量
|
||||
export DEBUG=auth:*
|
||||
export LOG_LEVEL=debug
|
||||
|
||||
# 启动服务器
|
||||
npm start
|
||||
```
|
||||
|
||||
## 安全最佳实践
|
||||
|
||||
1. **定期更新凭据**: 定期轮换 JWT 密钥和 API 密钥
|
||||
2. **最小权限原则**: 只授予用户执行其任务所需的最小权限
|
||||
3. **监控异常活动**: 设置警报以检测可疑的登录模式
|
||||
4. **备份配置**: 定期备份认证配置和用户数据
|
||||
5. **安全更新**: 保持 MCPHub 和依赖项的最新状态
|
||||
|
||||
更多安全配置选项,请参阅 [环境变量配置](/zh/configuration/environment-variables) 和 [Docker 设置](/zh/configuration/docker-setup) 文档。
|
||||
567
docs/zh/features/group-management.mdx
Normal file
@@ -0,0 +1,567 @@
|
||||
---
|
||||
title: '组管理'
|
||||
description: '组织用户和服务器为逻辑组,实现高效的访问控制'
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
MCPHub 的组管理系统允许您将用户和服务器组织成逻辑组,从而简化权限管理和访问控制。组提供了一种灵活的方式来管理大规模部署中的资源。
|
||||
|
||||
## 创建组
|
||||
|
||||
### 通过仪表板
|
||||
|
||||
1. **导航到组部分**: 在主仪表板中点击"组"
|
||||
2. **点击"创建组"**: 开始组创建流程
|
||||
3. **填写组详细信息**:
|
||||
- **组名**: 唯一的组标识符
|
||||
- **显示名称**: 用户友好的组名称
|
||||
- **描述**: 组的目的和范围
|
||||
- **父组**: 可选的层次结构
|
||||
|
||||
### 通过 API
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/api/groups \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"name": "development-team",
|
||||
"displayName": "开发团队",
|
||||
"description": "前端和后端开发人员",
|
||||
"parentGroup": null,
|
||||
"settings": {
|
||||
"autoAssign": false,
|
||||
"maxMembers": 50,
|
||||
"requireApproval": true
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
### 通过配置文件
|
||||
|
||||
在 `groups.json` 中定义组:
|
||||
|
||||
```json
|
||||
{
|
||||
"groups": {
|
||||
"dev-team": {
|
||||
"displayName": "开发团队",
|
||||
"description": "应用程序开发人员",
|
||||
"permissions": {
|
||||
"servers": ["read", "write", "execute"],
|
||||
"tools": ["read", "execute"],
|
||||
"logs": ["read"]
|
||||
},
|
||||
"members": ["user1", "user2"],
|
||||
"servers": ["dev-server-1", "dev-server-2"]
|
||||
},
|
||||
"qa-team": {
|
||||
"displayName": "质量保证团队",
|
||||
"description": "测试和质量保证",
|
||||
"permissions": {
|
||||
"servers": ["read", "execute"],
|
||||
"tools": ["read", "execute"],
|
||||
"logs": ["read"]
|
||||
},
|
||||
"members": ["qa1", "qa2"],
|
||||
"servers": ["test-server", "staging-server"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 组层次结构
|
||||
|
||||
### 嵌套组
|
||||
|
||||
创建组层次结构以实现更好的组织:
|
||||
|
||||
```json
|
||||
{
|
||||
"groups": {
|
||||
"engineering": {
|
||||
"displayName": "工程部",
|
||||
"description": "所有工程团队",
|
||||
"children": ["frontend", "backend", "devops"]
|
||||
},
|
||||
"frontend": {
|
||||
"displayName": "前端团队",
|
||||
"parent": "engineering",
|
||||
"servers": ["frontend-dev", "frontend-staging"]
|
||||
},
|
||||
"backend": {
|
||||
"displayName": "后端团队",
|
||||
"parent": "engineering",
|
||||
"servers": ["api-server", "database-server"]
|
||||
},
|
||||
"devops": {
|
||||
"displayName": "运维团队",
|
||||
"parent": "engineering",
|
||||
"servers": ["monitoring", "deployment"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 继承权限
|
||||
|
||||
子组从父组继承权限:
|
||||
|
||||
```bash
|
||||
# 检查继承的权限
|
||||
curl -X GET http://localhost:3000/api/groups/frontend/permissions?inherited=true \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
## 用户管理
|
||||
|
||||
### 添加用户到组
|
||||
|
||||
```bash
|
||||
# 添加单个用户
|
||||
curl -X POST http://localhost:3000/api/groups/dev-team/members \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"userId": "user123",
|
||||
"role": "member"
|
||||
}'
|
||||
|
||||
# 批量添加用户
|
||||
curl -X POST http://localhost:3000/api/groups/dev-team/members/bulk \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"users": [
|
||||
{"userId": "user1", "role": "member"},
|
||||
{"userId": "user2", "role": "admin"},
|
||||
{"userId": "user3", "role": "member"}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
### 用户角色
|
||||
|
||||
每个组内支持不同的用户角色:
|
||||
|
||||
- **组管理员**: 完整的组管理权限
|
||||
- **成员**: 标准组访问权限
|
||||
- **查看者**: 只读访问权限
|
||||
- **访客**: 有限的临时访问权限
|
||||
|
||||
### 移除用户
|
||||
|
||||
```bash
|
||||
# 从组中移除用户
|
||||
curl -X DELETE http://localhost:3000/api/groups/dev-team/members/user123 \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
## 服务器分配
|
||||
|
||||
### 分配服务器到组
|
||||
|
||||
```bash
|
||||
# 分配单个服务器
|
||||
curl -X POST http://localhost:3000/api/groups/dev-team/servers \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"serverId": "my-server",
|
||||
"permissions": ["read", "write", "execute"]
|
||||
}'
|
||||
|
||||
# 批量分配服务器
|
||||
curl -X POST http://localhost:3000/api/groups/dev-team/servers/bulk \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"servers": [
|
||||
{
|
||||
"serverId": "server1",
|
||||
"permissions": ["read", "write"]
|
||||
},
|
||||
{
|
||||
"serverId": "server2",
|
||||
"permissions": ["read", "execute"]
|
||||
}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
### 服务器权限级别
|
||||
|
||||
为每个组-服务器对定义细粒度权限:
|
||||
|
||||
```json
|
||||
{
|
||||
"serverId": "my-server",
|
||||
"permissions": {
|
||||
"execute": {
|
||||
"allowed": true,
|
||||
"tools": ["filesystem", "web-search"],
|
||||
"restrictions": {
|
||||
"maxRequests": 100,
|
||||
"timeWindow": "1h"
|
||||
}
|
||||
},
|
||||
"configure": {
|
||||
"allowed": false
|
||||
},
|
||||
"logs": {
|
||||
"allowed": true,
|
||||
"level": ["info", "warn", "error"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 权限管理
|
||||
|
||||
### 组权限模型
|
||||
|
||||
```json
|
||||
{
|
||||
"groupId": "dev-team",
|
||||
"permissions": {
|
||||
"servers": {
|
||||
"create": false,
|
||||
"read": true,
|
||||
"update": true,
|
||||
"delete": false,
|
||||
"execute": true
|
||||
},
|
||||
"tools": {
|
||||
"filesystem": {
|
||||
"read": true,
|
||||
"write": true,
|
||||
"paths": ["/app/data", "/tmp"]
|
||||
},
|
||||
"web-search": {
|
||||
"enabled": true,
|
||||
"maxQueries": 50
|
||||
}
|
||||
},
|
||||
"monitoring": {
|
||||
"viewLogs": true,
|
||||
"viewMetrics": true,
|
||||
"exportData": false
|
||||
},
|
||||
"administration": {
|
||||
"manageUsers": false,
|
||||
"manageServers": true,
|
||||
"manageGroups": false
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 动态权限
|
||||
|
||||
基于条件的动态权限:
|
||||
|
||||
```json
|
||||
{
|
||||
"permissions": {
|
||||
"servers": {
|
||||
"execute": {
|
||||
"condition": "time.hour >= 9 && time.hour <= 17",
|
||||
"message": "服务器执行仅在工作时间内允许"
|
||||
}
|
||||
},
|
||||
"tools": {
|
||||
"filesystem": {
|
||||
"write": {
|
||||
"condition": "user.role === 'admin' || group.name === 'senior-devs'",
|
||||
"message": "写入权限需要管理员或高级开发者角色"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 配额管理
|
||||
|
||||
### 设置组配额
|
||||
|
||||
```bash
|
||||
curl -X PUT http://localhost:3000/api/groups/dev-team/quotas \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"requests": {
|
||||
"daily": 1000,
|
||||
"monthly": 30000
|
||||
},
|
||||
"storage": {
|
||||
"maxSize": "10GB",
|
||||
"retention": "30d"
|
||||
},
|
||||
"compute": {
|
||||
"maxConcurrentRequests": 10,
|
||||
"maxExecutionTime": "5m"
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
### 监控配额使用
|
||||
|
||||
```bash
|
||||
# 获取当前配额使用情况
|
||||
curl -X GET http://localhost:3000/api/groups/dev-team/quotas/usage \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
响应示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"groupId": "dev-team",
|
||||
"period": "2024-01-01T00:00:00Z",
|
||||
"usage": {
|
||||
"requests": {
|
||||
"used": 750,
|
||||
"limit": 1000,
|
||||
"remaining": 250
|
||||
},
|
||||
"storage": {
|
||||
"used": "7.2GB",
|
||||
"limit": "10GB",
|
||||
"remaining": "2.8GB"
|
||||
},
|
||||
"compute": {
|
||||
"currentConcurrent": 3,
|
||||
"maxConcurrent": 10,
|
||||
"avgExecutionTime": "2m 15s"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 组策略
|
||||
|
||||
### 定义组策略
|
||||
|
||||
```json
|
||||
{
|
||||
"groupId": "dev-team",
|
||||
"policies": {
|
||||
"security": {
|
||||
"requireMFA": false,
|
||||
"sessionTimeout": "8h",
|
||||
"ipWhitelist": ["192.168.1.0/24", "10.0.0.0/8"]
|
||||
},
|
||||
"usage": {
|
||||
"allowWeekendAccess": true,
|
||||
"restrictHolidays": false,
|
||||
"maxSessionDuration": "12h"
|
||||
},
|
||||
"data": {
|
||||
"encryptionRequired": true,
|
||||
"dataRetention": "90d",
|
||||
"exportAllowed": false
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 策略继承
|
||||
|
||||
```bash
|
||||
# 应用策略模板
|
||||
curl -X POST http://localhost:3000/api/groups/dev-team/policies/apply \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"template": "development-team-template",
|
||||
"overrides": {
|
||||
"security.sessionTimeout": "4h"
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
## 自动化组管理
|
||||
|
||||
### 自动用户分配
|
||||
|
||||
基于属性自动分配用户:
|
||||
|
||||
```json
|
||||
{
|
||||
"autoAssignment": {
|
||||
"enabled": true,
|
||||
"rules": [
|
||||
{
|
||||
"condition": "user.department === '开发'",
|
||||
"action": {
|
||||
"addToGroup": "dev-team",
|
||||
"role": "member"
|
||||
}
|
||||
},
|
||||
{
|
||||
"condition": "user.title.includes('高级')",
|
||||
"action": {
|
||||
"addToGroup": "senior-devs",
|
||||
"role": "admin"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 定时任务
|
||||
|
||||
```bash
|
||||
# 创建定时清理任务
|
||||
curl -X POST http://localhost:3000/api/groups/dev-team/jobs \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"name": "cleanup-inactive-users",
|
||||
"schedule": "0 2 * * *",
|
||||
"action": "removeInactiveUsers",
|
||||
"params": {
|
||||
"inactiveDays": 30
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
## 组通知
|
||||
|
||||
### 配置通知
|
||||
|
||||
```json
|
||||
{
|
||||
"groupId": "dev-team",
|
||||
"notifications": {
|
||||
"channels": {
|
||||
"email": {
|
||||
"enabled": true,
|
||||
"recipients": ["team-lead@company.com"]
|
||||
},
|
||||
"slack": {
|
||||
"enabled": true,
|
||||
"webhook": "https://hooks.slack.com/...",
|
||||
"channel": "#dev-team"
|
||||
}
|
||||
},
|
||||
"events": ["userJoined", "userLeft", "serverAdded", "quotaExceeded", "securityAlert"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 发送组通知
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/api/groups/dev-team/notifications \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"type": "announcement",
|
||||
"title": "维护通知",
|
||||
"message": "服务器将在今晚 10 点进行维护",
|
||||
"priority": "high",
|
||||
"channels": ["email", "slack"]
|
||||
}'
|
||||
```
|
||||
|
||||
## 组分析
|
||||
|
||||
### 使用统计
|
||||
|
||||
```bash
|
||||
# 获取组使用统计
|
||||
curl -X GET http://localhost:3000/api/groups/dev-team/analytics \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
响应示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"groupId": "dev-team",
|
||||
"period": "30d",
|
||||
"stats": {
|
||||
"activeUsers": 12,
|
||||
"totalRequests": 15750,
|
||||
"avgResponseTime": "250ms",
|
||||
"errorRate": "0.5%",
|
||||
"mostUsedTools": [
|
||||
{ "name": "filesystem", "usage": 8500 },
|
||||
{ "name": "web-search", "usage": 4200 },
|
||||
{ "name": "database", "usage": 3050 }
|
||||
],
|
||||
"peakUsageHours": [9, 10, 14, 15, 16]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 生成报告
|
||||
|
||||
```bash
|
||||
# 生成月度报告
|
||||
curl -X POST http://localhost:3000/api/groups/dev-team/reports \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"type": "monthly",
|
||||
"format": "pdf",
|
||||
"includeDetails": true,
|
||||
"recipients": ["manager@company.com"]
|
||||
}'
|
||||
```
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
1. **用户无法访问组资源**
|
||||
|
||||
```bash
|
||||
# 检查用户组成员身份
|
||||
curl -X GET http://localhost:3000/api/users/user123/groups \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
2. **权限配置错误**
|
||||
|
||||
```bash
|
||||
# 验证权限设置
|
||||
curl -X GET http://localhost:3000/api/groups/dev-team/permissions/validate \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
3. **配额超限**
|
||||
```bash
|
||||
# 检查配额状态
|
||||
curl -X GET http://localhost:3000/api/groups/dev-team/quotas/status \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
### 调试组权限
|
||||
|
||||
启用权限调试:
|
||||
|
||||
```bash
|
||||
# 调试用户权限
|
||||
curl -X GET http://localhost:3000/api/debug/permissions \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"userId": "user123",
|
||||
"resource": "server:my-server",
|
||||
"action": "execute"
|
||||
}'
|
||||
```
|
||||
|
||||
## 最佳实践
|
||||
|
||||
1. **组织结构**: 使用层次化组结构镜像您的组织架构
|
||||
2. **权限最小化**: 只授予执行任务所需的最小权限
|
||||
3. **定期审核**: 定期审核组成员身份和权限
|
||||
4. **自动化**: 使用自动化规则减少手动管理开销
|
||||
5. **监控**: 设置监控和警报以跟踪组活动
|
||||
|
||||
有关更多信息,请参阅 [身份认证与安全](/zh/features/authentication) 和 [监控](/zh/features/monitoring) 文档。
|
||||
613
docs/zh/features/monitoring.mdx
Normal file
@@ -0,0 +1,613 @@
|
||||
---
|
||||
title: '监控与分析'
|
||||
description: '全面监控 MCP 服务器性能、健康状况和使用情况'
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
MCPHub 提供全面的监控和分析功能,帮助您跟踪 MCP 服务器的性能、健康状况和使用模式。系统提供实时指标、历史分析和智能警报。
|
||||
|
||||
## 实时监控
|
||||
|
||||
### 仪表板概览
|
||||
|
||||
主监控仪表板显示关键指标:
|
||||
|
||||
```bash
|
||||
# 访问监控仪表板
|
||||
curl -X GET http://localhost:3000/api/monitoring/dashboard \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
响应示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"overview": {
|
||||
"totalServers": 12,
|
||||
"activeServers": 10,
|
||||
"totalRequests": 15420,
|
||||
"avgResponseTime": "245ms",
|
||||
"errorRate": "0.3%",
|
||||
"uptime": "99.9%"
|
||||
},
|
||||
"realtime": {
|
||||
"requestsPerMinute": 85,
|
||||
"activeConnections": 156,
|
||||
"memoryUsage": "68%",
|
||||
"cpuUsage": "42%"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 服务器健康状态
|
||||
|
||||
```bash
|
||||
# 获取所有服务器状态
|
||||
curl -X GET http://localhost:3000/api/monitoring/servers/health \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
## 性能指标
|
||||
|
||||
### 响应时间监控
|
||||
|
||||
```json
|
||||
{
|
||||
"responseTime": {
|
||||
"metrics": [
|
||||
{
|
||||
"serverId": "server-1",
|
||||
"average": "180ms",
|
||||
"p50": "150ms",
|
||||
"p95": "300ms",
|
||||
"p99": "500ms"
|
||||
}
|
||||
],
|
||||
"alerts": {
|
||||
"slowResponse": {
|
||||
"threshold": "1s",
|
||||
"current": "180ms",
|
||||
"status": "normal"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 吞吐量分析
|
||||
|
||||
```bash
|
||||
# 获取吞吐量统计
|
||||
curl -X GET http://localhost:3000/api/monitoring/throughput \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-G -d "timeRange=1h" -d "granularity=5m"
|
||||
```
|
||||
|
||||
响应示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"timeRange": "1h",
|
||||
"granularity": "5m",
|
||||
"data": [
|
||||
{
|
||||
"timestamp": "2024-01-01T12:00:00Z",
|
||||
"totalRequests": 450,
|
||||
"successfulRequests": 448,
|
||||
"failedRequests": 2,
|
||||
"avgResponseTime": "230ms"
|
||||
}
|
||||
],
|
||||
"summary": {
|
||||
"peakThroughput": 520,
|
||||
"averageThroughput": 412,
|
||||
"totalRequests": 4944
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 资源使用监控
|
||||
|
||||
```json
|
||||
{
|
||||
"resources": {
|
||||
"cpu": {
|
||||
"usage": "42%",
|
||||
"cores": 8,
|
||||
"processes": [
|
||||
{ "name": "mcp-server-1", "cpu": "15%" },
|
||||
{ "name": "mcp-server-2", "cpu": "12%" }
|
||||
]
|
||||
},
|
||||
"memory": {
|
||||
"total": "32GB",
|
||||
"used": "21.6GB",
|
||||
"available": "10.4GB",
|
||||
"byProcess": [
|
||||
{ "name": "mcp-server-1", "memory": "2.1GB" },
|
||||
{ "name": "mcp-server-2", "memory": "1.8GB" }
|
||||
]
|
||||
},
|
||||
"network": {
|
||||
"bytesIn": "1.2GB",
|
||||
"bytesOut": "890MB",
|
||||
"packetsIn": 1250000,
|
||||
"packetsOut": 980000
|
||||
},
|
||||
"disk": {
|
||||
"total": "1TB",
|
||||
"used": "340GB",
|
||||
"available": "660GB",
|
||||
"iops": 1200
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 日志管理
|
||||
|
||||
### 集中化日志收集
|
||||
|
||||
配置日志聚合:
|
||||
|
||||
```json
|
||||
{
|
||||
"logging": {
|
||||
"centralized": true,
|
||||
"storage": {
|
||||
"type": "elasticsearch",
|
||||
"config": {
|
||||
"hosts": ["localhost:9200"],
|
||||
"index": "mcphub-logs",
|
||||
"retention": "30d"
|
||||
}
|
||||
},
|
||||
"levels": ["error", "warn", "info", "debug"],
|
||||
"sources": ["application", "mcp-servers", "nginx", "system"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 实时日志查看
|
||||
|
||||
```bash
|
||||
# 获取实时日志流
|
||||
curl -X GET http://localhost:3000/api/monitoring/logs/stream \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Accept: text/event-stream"
|
||||
|
||||
# 过滤日志
|
||||
curl -X GET http://localhost:3000/api/monitoring/logs \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-G -d "level=error" -d "server=server-1" -d "limit=100"
|
||||
```
|
||||
|
||||
### 日志分析
|
||||
|
||||
```bash
|
||||
# 错误模式分析
|
||||
curl -X GET http://localhost:3000/api/monitoring/logs/analysis \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-G -d "type=error-patterns" -d "timeRange=24h"
|
||||
```
|
||||
|
||||
响应示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"analysis": {
|
||||
"errorPatterns": [
|
||||
{
|
||||
"pattern": "Connection timeout",
|
||||
"occurrences": 45,
|
||||
"trend": "increasing",
|
||||
"affectedServers": ["server-2", "server-3"]
|
||||
},
|
||||
{
|
||||
"pattern": "Memory allocation failed",
|
||||
"occurrences": 12,
|
||||
"trend": "stable",
|
||||
"affectedServers": ["server-1"]
|
||||
}
|
||||
],
|
||||
"recommendations": ["检查服务器网络连接", "增加内存限制配置"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 警报系统
|
||||
|
||||
### 配置警报规则
|
||||
|
||||
```json
|
||||
{
|
||||
"alerts": [
|
||||
{
|
||||
"name": "high-response-time",
|
||||
"description": "响应时间过高警报",
|
||||
"condition": "avg(response_time) > 1000ms over 5m",
|
||||
"severity": "warning",
|
||||
"notifications": {
|
||||
"email": ["admin@company.com"],
|
||||
"slack": "#alerts",
|
||||
"webhook": "https://hooks.company.com/alerts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "server-down",
|
||||
"description": "服务器宕机警报",
|
||||
"condition": "server_status == 'down'",
|
||||
"severity": "critical",
|
||||
"notifications": {
|
||||
"email": ["oncall@company.com"],
|
||||
"sms": ["+1234567890"],
|
||||
"pagerduty": "service-key"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "high-error-rate",
|
||||
"description": "错误率过高",
|
||||
"condition": "error_rate > 5% over 10m",
|
||||
"severity": "error",
|
||||
"notifications": {
|
||||
"slack": "#dev-team"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 警报通知
|
||||
|
||||
```bash
|
||||
# 测试警报通知
|
||||
curl -X POST http://localhost:3000/api/monitoring/alerts/test \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"alertName": "high-response-time",
|
||||
"channel": "email"
|
||||
}'
|
||||
```
|
||||
|
||||
### 警报历史
|
||||
|
||||
```bash
|
||||
# 获取警报历史
|
||||
curl -X GET http://localhost:3000/api/monitoring/alerts/history \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-G -d "timeRange=7d" -d "severity=critical"
|
||||
```
|
||||
|
||||
## 用户活动监控
|
||||
|
||||
### 用户会话跟踪
|
||||
|
||||
```json
|
||||
{
|
||||
"userActivity": {
|
||||
"activeSessions": 156,
|
||||
"totalUsers": 89,
|
||||
"sessionsByUser": [
|
||||
{
|
||||
"userId": "user123",
|
||||
"sessions": 3,
|
||||
"lastActivity": "2024-01-01T12:30:00Z",
|
||||
"totalRequests": 245
|
||||
}
|
||||
],
|
||||
"topUsers": [
|
||||
{ "userId": "power-user", "requests": 1250 },
|
||||
{ "userId": "regular-user", "requests": 890 }
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 使用模式分析
|
||||
|
||||
```bash
|
||||
# 获取使用模式分析
|
||||
curl -X GET http://localhost:3000/api/monitoring/usage-patterns \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-G -d "timeRange=30d"
|
||||
```
|
||||
|
||||
响应示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"patterns": {
|
||||
"peakHours": [9, 10, 14, 15, 16],
|
||||
"peakDays": ["tuesday", "wednesday", "thursday"],
|
||||
"toolUsage": [
|
||||
{"tool": "filesystem", "usage": 45%},
|
||||
{"tool": "web-search", "usage": 30%},
|
||||
{"tool": "database", "usage": 25%}
|
||||
],
|
||||
"userBehavior": {
|
||||
"avgSessionDuration": "45m",
|
||||
"avgRequestsPerSession": 23,
|
||||
"returnRate": "78%"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 容量规划
|
||||
|
||||
### 资源预测
|
||||
|
||||
```json
|
||||
{
|
||||
"capacityPlanning": {
|
||||
"currentCapacity": {
|
||||
"cpu": "42%",
|
||||
"memory": "68%",
|
||||
"network": "35%",
|
||||
"storage": "34%"
|
||||
},
|
||||
"predictions": {
|
||||
"timeHorizon": "30d",
|
||||
"cpuForecast": [
|
||||
{ "date": "2024-01-07", "usage": "48%" },
|
||||
{ "date": "2024-01-14", "usage": "52%" },
|
||||
{ "date": "2024-01-21", "usage": "56%" },
|
||||
{ "date": "2024-01-28", "usage": "61%" }
|
||||
],
|
||||
"recommendations": [
|
||||
"考虑在第3周增加CPU资源",
|
||||
"内存使用稳定,暂不需要扩容",
|
||||
"建议监控网络带宽趋势"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 自动扩缩容
|
||||
|
||||
```json
|
||||
{
|
||||
"autoScaling": {
|
||||
"enabled": true,
|
||||
"policies": [
|
||||
{
|
||||
"metric": "cpu_usage",
|
||||
"scaleUp": {
|
||||
"threshold": "80%",
|
||||
"duration": "5m",
|
||||
"action": "add_instance"
|
||||
},
|
||||
"scaleDown": {
|
||||
"threshold": "30%",
|
||||
"duration": "15m",
|
||||
"action": "remove_instance"
|
||||
}
|
||||
},
|
||||
{
|
||||
"metric": "request_queue_length",
|
||||
"scaleUp": {
|
||||
"threshold": 100,
|
||||
"duration": "2m",
|
||||
"action": "add_instance"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 性能分析报告
|
||||
|
||||
### 生成性能报告
|
||||
|
||||
```bash
|
||||
# 生成周报
|
||||
curl -X POST http://localhost:3000/api/monitoring/reports \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"type": "performance",
|
||||
"timeRange": "7d",
|
||||
"format": "pdf",
|
||||
"sections": [
|
||||
"overview",
|
||||
"response_times",
|
||||
"error_analysis",
|
||||
"resource_usage",
|
||||
"recommendations"
|
||||
],
|
||||
"recipients": ["manager@company.com"]
|
||||
}'
|
||||
```
|
||||
|
||||
### 自定义报告
|
||||
|
||||
```json
|
||||
{
|
||||
"customReport": {
|
||||
"name": "monthly-summary",
|
||||
"schedule": "0 0 1 * *",
|
||||
"template": "executive-summary",
|
||||
"data": {
|
||||
"kpis": ["uptime", "avg_response_time", "total_requests", "error_rate", "user_satisfaction"],
|
||||
"comparisons": {
|
||||
"previousMonth": true,
|
||||
"yearOverYear": true
|
||||
}
|
||||
},
|
||||
"distribution": {
|
||||
"email": ["executives@company.com"],
|
||||
"dashboard": true,
|
||||
"archive": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 监控 API
|
||||
|
||||
### 指标查询
|
||||
|
||||
```bash
|
||||
# 查询自定义指标
|
||||
curl -X POST http://localhost:3000/api/monitoring/query \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"query": "avg(response_time) by (server_id)",
|
||||
"timeRange": "1h",
|
||||
"step": "5m"
|
||||
}'
|
||||
```
|
||||
|
||||
### 事件跟踪
|
||||
|
||||
```bash
|
||||
# 记录自定义事件
|
||||
curl -X POST http://localhost:3000/api/monitoring/events \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"type": "deployment",
|
||||
"title": "服务器更新",
|
||||
"description": "部署新版本 v2.1.0",
|
||||
"tags": ["deployment", "version-2.1.0"],
|
||||
"metadata": {
|
||||
"version": "2.1.0",
|
||||
"servers": ["server-1", "server-2"]
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
## 第三方集成
|
||||
|
||||
### Prometheus 集成
|
||||
|
||||
```yaml
|
||||
# prometheus.yml
|
||||
global:
|
||||
scrape_interval: 15s
|
||||
|
||||
scrape_configs:
|
||||
- job_name: 'mcphub'
|
||||
static_configs:
|
||||
- targets: ['localhost:3000']
|
||||
metrics_path: '/api/monitoring/prometheus'
|
||||
scrape_interval: 30s
|
||||
```
|
||||
|
||||
### Grafana 仪表板
|
||||
|
||||
```json
|
||||
{
|
||||
"dashboard": {
|
||||
"title": "MCPHub 监控",
|
||||
"panels": [
|
||||
{
|
||||
"title": "请求率",
|
||||
"type": "graph",
|
||||
"targets": [
|
||||
{
|
||||
"expr": "rate(mcphub_requests_total[5m])",
|
||||
"legendFormat": "{{server_id}}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "响应时间",
|
||||
"type": "graph",
|
||||
"targets": [
|
||||
{
|
||||
"expr": "histogram_quantile(0.95, mcphub_response_time_histogram)",
|
||||
"legendFormat": "95th percentile"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### ELK Stack 集成
|
||||
|
||||
```json
|
||||
{
|
||||
"logstash": {
|
||||
"input": {
|
||||
"beats": {
|
||||
"port": 5044
|
||||
}
|
||||
},
|
||||
"filter": {
|
||||
"if": "[fields][service] == 'mcphub'",
|
||||
"json": {
|
||||
"source": "message"
|
||||
},
|
||||
"date": {
|
||||
"match": ["timestamp", "ISO8601"]
|
||||
}
|
||||
},
|
||||
"output": {
|
||||
"elasticsearch": {
|
||||
"hosts": ["localhost:9200"],
|
||||
"index": "mcphub-logs-%{+YYYY.MM.dd}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 监控问题诊断
|
||||
|
||||
```bash
|
||||
# 检查监控服务状态
|
||||
curl -X GET http://localhost:3000/api/monitoring/health \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
|
||||
# 验证指标收集
|
||||
curl -X GET http://localhost:3000/api/monitoring/metrics/validation \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
### 性能问题分析
|
||||
|
||||
```bash
|
||||
# 性能瓶颈分析
|
||||
curl -X GET http://localhost:3000/api/monitoring/performance/bottlenecks \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-G -d "timeRange=1h"
|
||||
```
|
||||
|
||||
### 常见监控问题
|
||||
|
||||
1. **指标丢失**
|
||||
|
||||
- 检查收集器配置
|
||||
- 验证网络连接
|
||||
- 检查存储空间
|
||||
|
||||
2. **警报不触发**
|
||||
|
||||
- 验证警报规则语法
|
||||
- 检查通知配置
|
||||
- 测试通知渠道
|
||||
|
||||
3. **仪表板加载缓慢**
|
||||
- 优化查询时间范围
|
||||
- 增加数据聚合
|
||||
- 检查数据库性能
|
||||
|
||||
## 最佳实践
|
||||
|
||||
1. **监控层次化**: 建立应用、基础设施和业务三层监控
|
||||
2. **合理的警报**: 避免警报疲劳,设置合适的阈值
|
||||
3. **数据保留**: 根据业务需求设置适当的数据保留期
|
||||
4. **安全监控**: 监控安全相关的指标和事件
|
||||
5. **持续优化**: 定期审查和优化监控配置
|
||||
|
||||
有关更多信息,请参阅 [智能路由](/zh/features/smart-routing) 和 [服务器管理](/zh/features/server-management) 文档。
|
||||
496
docs/zh/features/server-management.mdx
Normal file
@@ -0,0 +1,496 @@
|
||||
---
|
||||
title: '服务器管理'
|
||||
description: '通过热插拔配置集中管理多个 MCP 服务器'
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
MCPHub 的服务器管理系统允许您从单个仪表板集中配置、监控和控制多个 MCP(模型上下文协议)服务器。所有更改都会实时应用,无需重启服务器。
|
||||
|
||||
## 添加 MCP 服务器
|
||||
|
||||
### 通过仪表板
|
||||
|
||||
1. **访问仪表板**: 导航到 `http://localhost:3000` 并登录
|
||||
2. **点击"添加服务器"**: 位于服务器部分
|
||||
3. **填写服务器详细信息**:
|
||||
- **名称**: 服务器的唯一标识符
|
||||
- **命令**: 可执行命令(例如 `npx`、`uvx`、`python`)
|
||||
- **参数**: 命令参数数组
|
||||
- **环境变量**: 环境设置的键值对
|
||||
- **工作目录**: 命令的可选工作目录
|
||||
|
||||
### 通过配置文件
|
||||
|
||||
编辑您的 `mcp_settings.json` 文件:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"server-name": {
|
||||
"command": "command-to-run",
|
||||
"args": ["arg1", "arg2"],
|
||||
"env": {
|
||||
"API_KEY": "your-api-key",
|
||||
"CONFIG_VALUE": "some-value"
|
||||
},
|
||||
"cwd": "/optional/working/directory"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 通过 API
|
||||
|
||||
使用 REST API 以编程方式添加服务器:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/api/servers \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
|
||||
-d '{
|
||||
"name": "my-server",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/files"],
|
||||
"env": {
|
||||
"NODE_ENV": "production"
|
||||
},
|
||||
"cwd": "/app"
|
||||
}'
|
||||
```
|
||||
|
||||
## 服务器配置
|
||||
|
||||
### 通用配置选项
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "filesystem-server",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/allowed/path"],
|
||||
"env": {
|
||||
"NODE_ENV": "production",
|
||||
"DEBUG": "mcp:*",
|
||||
"MAX_FILES": "1000"
|
||||
},
|
||||
"cwd": "/app/workspace",
|
||||
"timeout": 30000,
|
||||
"retries": 3,
|
||||
"enabled": true
|
||||
}
|
||||
```
|
||||
|
||||
### Python 服务器示例
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "python-server",
|
||||
"command": "python",
|
||||
"args": ["-m", "mcp_server", "--config", "config.json"],
|
||||
"env": {
|
||||
"PYTHONPATH": "/app/python",
|
||||
"API_KEY": "${API_KEY}",
|
||||
"LOG_LEVEL": "INFO"
|
||||
},
|
||||
"cwd": "/app/python-server"
|
||||
}
|
||||
```
|
||||
|
||||
### Node.js 服务器示例
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "node-server",
|
||||
"command": "node",
|
||||
"args": ["server.js", "--port", "3001"],
|
||||
"env": {
|
||||
"NODE_ENV": "production",
|
||||
"PORT": "3001",
|
||||
"DATABASE_URL": "${DATABASE_URL}"
|
||||
},
|
||||
"cwd": "/app/node-server"
|
||||
}
|
||||
```
|
||||
|
||||
## 服务器生命周期管理
|
||||
|
||||
### 启动服务器
|
||||
|
||||
```bash
|
||||
# 启动特定服务器
|
||||
curl -X POST http://localhost:3000/api/servers/my-server/start \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
|
||||
# 启动所有服务器
|
||||
curl -X POST http://localhost:3000/api/servers/start-all \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
### 停止服务器
|
||||
|
||||
```bash
|
||||
# 停止特定服务器
|
||||
curl -X POST http://localhost:3000/api/servers/my-server/stop \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
|
||||
# 优雅停止(等待当前请求完成)
|
||||
curl -X POST http://localhost:3000/api/servers/my-server/stop \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{"graceful": true, "timeout": 30000}'
|
||||
```
|
||||
|
||||
### 重启服务器
|
||||
|
||||
```bash
|
||||
# 重启服务器
|
||||
curl -X POST http://localhost:3000/api/servers/my-server/restart \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
## 热配置重载
|
||||
|
||||
### 更新服务器配置
|
||||
|
||||
无需重启即可更新配置:
|
||||
|
||||
```bash
|
||||
curl -X PUT http://localhost:3000/api/servers/my-server/config \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"env": {
|
||||
"DEBUG": "mcp:verbose",
|
||||
"NEW_SETTING": "value"
|
||||
},
|
||||
"args": ["--verbose", "--new-flag"]
|
||||
}'
|
||||
```
|
||||
|
||||
### 批量配置更新
|
||||
|
||||
```bash
|
||||
curl -X PUT http://localhost:3000/api/servers/bulk-update \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"servers": ["server1", "server2"],
|
||||
"config": {
|
||||
"env": {
|
||||
"LOG_LEVEL": "DEBUG"
|
||||
}
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
## 服务器状态监控
|
||||
|
||||
### 检查服务器状态
|
||||
|
||||
```bash
|
||||
# 获取所有服务器状态
|
||||
curl -X GET http://localhost:3000/api/servers/status \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
|
||||
# 获取特定服务器状态
|
||||
curl -X GET http://localhost:3000/api/servers/my-server/status \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
响应示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "my-server",
|
||||
"status": "running",
|
||||
"pid": 12345,
|
||||
"uptime": 3600000,
|
||||
"memory": {
|
||||
"rss": 123456789,
|
||||
"heapTotal": 98765432,
|
||||
"heapUsed": 87654321
|
||||
},
|
||||
"cpu": {
|
||||
"user": 1000000,
|
||||
"system": 500000
|
||||
},
|
||||
"lastRestart": "2024-01-01T12:00:00.000Z"
|
||||
}
|
||||
```
|
||||
|
||||
### 健康检查
|
||||
|
||||
配置自动健康检查:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "my-server",
|
||||
"command": "node",
|
||||
"args": ["server.js"],
|
||||
"healthCheck": {
|
||||
"enabled": true,
|
||||
"interval": 30000,
|
||||
"timeout": 5000,
|
||||
"retries": 3,
|
||||
"endpoint": "/health",
|
||||
"expectedStatus": 200
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 负载均衡
|
||||
|
||||
### 配置多实例
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "load-balanced-server",
|
||||
"instances": 3,
|
||||
"command": "node",
|
||||
"args": ["server.js"],
|
||||
"loadBalancer": {
|
||||
"strategy": "round-robin",
|
||||
"healthCheck": true,
|
||||
"stickySession": false
|
||||
},
|
||||
"env": {
|
||||
"PORT": "${PORT}"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 负载均衡策略
|
||||
|
||||
- **round-robin**: 轮询分发请求
|
||||
- **least-connections**: 分发到连接数最少的实例
|
||||
- **weighted**: 基于权重分发
|
||||
- **ip-hash**: 基于客户端 IP 的一致性哈希
|
||||
|
||||
## 资源限制
|
||||
|
||||
### 设置资源限制
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "resource-limited-server",
|
||||
"command": "python",
|
||||
"args": ["server.py"],
|
||||
"resources": {
|
||||
"memory": {
|
||||
"limit": "512MB",
|
||||
"warning": "400MB"
|
||||
},
|
||||
"cpu": {
|
||||
"limit": "50%",
|
||||
"priority": "normal"
|
||||
},
|
||||
"processes": {
|
||||
"max": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 监控资源使用
|
||||
|
||||
```bash
|
||||
# 获取资源使用统计
|
||||
curl -X GET http://localhost:3000/api/servers/my-server/resources \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
## 日志管理
|
||||
|
||||
### 配置日志记录
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "my-server",
|
||||
"command": "node",
|
||||
"args": ["server.js"],
|
||||
"logging": {
|
||||
"level": "info",
|
||||
"file": "/var/log/mcphub/my-server.log",
|
||||
"maxSize": "100MB",
|
||||
"maxFiles": 5,
|
||||
"rotate": true,
|
||||
"format": "json"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 查看日志
|
||||
|
||||
```bash
|
||||
# 获取实时日志
|
||||
curl -X GET http://localhost:3000/api/servers/my-server/logs \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
|
||||
# 获取带过滤器的日志
|
||||
curl -X GET "http://localhost:3000/api/servers/my-server/logs?level=error&limit=100" \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
## 环境变量管理
|
||||
|
||||
### 动态环境变量
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "dynamic-server",
|
||||
"command": "python",
|
||||
"args": ["server.py"],
|
||||
"env": {
|
||||
"API_KEY": "${secrets:api_key}",
|
||||
"DATABASE_URL": "${vault:db_url}",
|
||||
"CURRENT_TIME": "${time:iso}",
|
||||
"SERVER_ID": "${server:id}",
|
||||
"HOSTNAME": "${system:hostname}"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 环境变量模板
|
||||
|
||||
支持的模板变量:
|
||||
|
||||
- `${secrets:key}`: 从密钥存储获取
|
||||
- `${vault:path}`: 从 Vault 获取
|
||||
- `${env:VAR}`: 从系统环境变量获取
|
||||
- `${time:format}`: 当前时间戳
|
||||
- `${server:property}`: 服务器属性
|
||||
- `${system:property}`: 系统属性
|
||||
|
||||
## 服务发现
|
||||
|
||||
### 自动服务发现
|
||||
|
||||
```json
|
||||
{
|
||||
"serviceDiscovery": {
|
||||
"enabled": true,
|
||||
"provider": "consul",
|
||||
"config": {
|
||||
"host": "localhost",
|
||||
"port": 8500,
|
||||
"serviceName": "mcp-server",
|
||||
"tags": ["mcp", "ai", "api"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 注册服务
|
||||
|
||||
```bash
|
||||
# 手动注册服务
|
||||
curl -X POST http://localhost:3000/api/servers/my-server/register \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"service": {
|
||||
"name": "my-mcp-service",
|
||||
"tags": ["mcp", "production"],
|
||||
"port": 3001,
|
||||
"check": {
|
||||
"http": "http://localhost:3001/health",
|
||||
"interval": "30s"
|
||||
}
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
1. **服务器启动失败**
|
||||
|
||||
```bash
|
||||
# 检查服务器日志
|
||||
curl -X GET http://localhost:3000/api/servers/my-server/logs?level=error \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
2. **配置无效**
|
||||
|
||||
```bash
|
||||
# 验证配置
|
||||
curl -X POST http://localhost:3000/api/servers/validate \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d @server-config.json
|
||||
```
|
||||
|
||||
3. **性能问题**
|
||||
```bash
|
||||
# 获取性能指标
|
||||
curl -X GET http://localhost:3000/api/servers/my-server/metrics \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
### 调试模式
|
||||
|
||||
启用详细调试:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "debug-server",
|
||||
"command": "node",
|
||||
"args": ["--inspect=0.0.0.0:9229", "server.js"],
|
||||
"env": {
|
||||
"DEBUG": "*",
|
||||
"LOG_LEVEL": "debug",
|
||||
"NODE_ENV": "development"
|
||||
},
|
||||
"debugging": {
|
||||
"enabled": true,
|
||||
"port": 9229,
|
||||
"breakOnStart": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 高级配置
|
||||
|
||||
### 自定义钩子
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "hooked-server",
|
||||
"command": "node",
|
||||
"args": ["server.js"],
|
||||
"hooks": {
|
||||
"beforeStart": ["./scripts/setup.sh"],
|
||||
"afterStart": ["./scripts/notify.sh"],
|
||||
"beforeStop": ["./scripts/cleanup.sh"],
|
||||
"onError": ["./scripts/alert.sh"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 配置模板
|
||||
|
||||
```json
|
||||
{
|
||||
"templates": {
|
||||
"python-server": {
|
||||
"command": "python",
|
||||
"args": ["-m", "mcp_server"],
|
||||
"env": {
|
||||
"PYTHONPATH": "/app/python",
|
||||
"LOG_LEVEL": "INFO"
|
||||
}
|
||||
}
|
||||
},
|
||||
"servers": {
|
||||
"my-python-server": {
|
||||
"extends": "python-server",
|
||||
"args": ["-m", "mcp_server", "--config", "custom.json"],
|
||||
"env": {
|
||||
"API_KEY": "custom-key"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
有关更多配置选项,请参阅 [MCP 设置配置](/zh/configuration/mcp-settings) 和 [环境变量](/zh/configuration/environment-variables) 文档。
|
||||
691
docs/zh/features/smart-routing.mdx
Normal file
@@ -0,0 +1,691 @@
|
||||
---
|
||||
title: '智能路由'
|
||||
description: '自动负载均衡和请求路由到最佳的 MCP 服务器实例'
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
MCPHub 的智能路由系统自动将传入请求路由到最适合的 MCP 服务器实例。系统考虑服务器负载、响应时间、功能可用性和业务规则来做出路由决策。
|
||||
|
||||
## 路由策略
|
||||
|
||||
### 轮询路由
|
||||
|
||||
最简单的路由策略,按顺序分发请求:
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "round-robin",
|
||||
"targets": [
|
||||
{
|
||||
"serverId": "server-1",
|
||||
"weight": 1,
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"serverId": "server-2",
|
||||
"weight": 1,
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"serverId": "server-3",
|
||||
"weight": 1,
|
||||
"enabled": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 加权轮询
|
||||
|
||||
基于服务器容量分配不同权重:
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "weighted-round-robin",
|
||||
"targets": [
|
||||
{
|
||||
"serverId": "high-performance-server",
|
||||
"weight": 3,
|
||||
"specs": {
|
||||
"cpu": "8 cores",
|
||||
"memory": "32GB"
|
||||
}
|
||||
},
|
||||
{
|
||||
"serverId": "standard-server-1",
|
||||
"weight": 2,
|
||||
"specs": {
|
||||
"cpu": "4 cores",
|
||||
"memory": "16GB"
|
||||
}
|
||||
},
|
||||
{
|
||||
"serverId": "standard-server-2",
|
||||
"weight": 1,
|
||||
"specs": {
|
||||
"cpu": "2 cores",
|
||||
"memory": "8GB"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 最少连接数
|
||||
|
||||
将请求路由到当前连接数最少的服务器:
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "least-connections",
|
||||
"balancingMode": "dynamic",
|
||||
"healthCheck": {
|
||||
"enabled": true,
|
||||
"interval": 10000
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 基于响应时间
|
||||
|
||||
路由到响应时间最短的服务器:
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "fastest-response",
|
||||
"metrics": {
|
||||
"measurementWindow": "5m",
|
||||
"sampleSize": 100,
|
||||
"excludeSlowRequests": true,
|
||||
"slowRequestThreshold": "5s"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 基于功能的路由
|
||||
|
||||
### 工具特定路由
|
||||
|
||||
根据请求的工具类型路由到专门的服务器:
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "capability-based",
|
||||
"rules": [
|
||||
{
|
||||
"condition": {
|
||||
"tool": "filesystem"
|
||||
},
|
||||
"targets": ["filesystem-server-1", "filesystem-server-2"],
|
||||
"strategy": "least-connections"
|
||||
},
|
||||
{
|
||||
"condition": {
|
||||
"tool": "web-search"
|
||||
},
|
||||
"targets": ["search-server-1", "search-server-2"],
|
||||
"strategy": "round-robin"
|
||||
},
|
||||
{
|
||||
"condition": {
|
||||
"tool": "database"
|
||||
},
|
||||
"targets": ["db-server"],
|
||||
"strategy": "single"
|
||||
}
|
||||
],
|
||||
"fallback": {
|
||||
"targets": ["general-server-1", "general-server-2"],
|
||||
"strategy": "round-robin"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 内容感知路由
|
||||
|
||||
基于请求内容进行智能路由:
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "content-aware",
|
||||
"rules": [
|
||||
{
|
||||
"condition": {
|
||||
"content.language": "python"
|
||||
},
|
||||
"targets": ["python-specialized-server"],
|
||||
"reason": "Python代码分析专用服务器"
|
||||
},
|
||||
{
|
||||
"condition": {
|
||||
"content.size": "> 1MB"
|
||||
},
|
||||
"targets": ["high-memory-server"],
|
||||
"reason": "大文件处理专用服务器"
|
||||
},
|
||||
{
|
||||
"condition": {
|
||||
"content.type": "image"
|
||||
},
|
||||
"targets": ["image-processing-server"],
|
||||
"reason": "图像处理专用服务器"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 地理位置路由
|
||||
|
||||
### 基于客户端位置
|
||||
|
||||
根据客户端地理位置路由到最近的服务器:
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "geo-location",
|
||||
"regions": [
|
||||
{
|
||||
"name": "北美",
|
||||
"countries": ["US", "CA", "MX"],
|
||||
"servers": ["us-east-1", "us-west-1", "ca-central-1"],
|
||||
"strategy": "least-latency"
|
||||
},
|
||||
{
|
||||
"name": "欧洲",
|
||||
"countries": ["DE", "FR", "UK", "NL"],
|
||||
"servers": ["eu-west-1", "eu-central-1"],
|
||||
"strategy": "round-robin"
|
||||
},
|
||||
{
|
||||
"name": "亚太",
|
||||
"countries": ["CN", "JP", "KR", "SG"],
|
||||
"servers": ["ap-southeast-1", "ap-northeast-1"],
|
||||
"strategy": "fastest-response"
|
||||
}
|
||||
],
|
||||
"fallback": {
|
||||
"servers": ["global-server-1"],
|
||||
"strategy": "single"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 延迟优化
|
||||
|
||||
```bash
|
||||
# 配置延迟监控
|
||||
curl -X PUT http://localhost:3000/api/routing/latency-config \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"enabled": true,
|
||||
"measurementInterval": 30000,
|
||||
"regions": [
|
||||
{"id": "us-east", "endpoint": "ping.us-east.example.com"},
|
||||
{"id": "eu-west", "endpoint": "ping.eu-west.example.com"},
|
||||
{"id": "ap-southeast", "endpoint": "ping.ap-southeast.example.com"}
|
||||
],
|
||||
"routing": {
|
||||
"preferLowLatency": true,
|
||||
"maxLatencyThreshold": "200ms",
|
||||
"fallbackOnTimeout": true
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
## 负载感知路由
|
||||
|
||||
### 实时负载监控
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "load-aware",
|
||||
"loadMetrics": {
|
||||
"cpu": {
|
||||
"threshold": 80,
|
||||
"weight": 0.4
|
||||
},
|
||||
"memory": {
|
||||
"threshold": 85,
|
||||
"weight": 0.3
|
||||
},
|
||||
"connections": {
|
||||
"threshold": 1000,
|
||||
"weight": 0.2
|
||||
},
|
||||
"responseTime": {
|
||||
"threshold": "2s",
|
||||
"weight": 0.1
|
||||
}
|
||||
},
|
||||
"adaptation": {
|
||||
"enabled": true,
|
||||
"adjustmentInterval": 60000,
|
||||
"emergencyThreshold": 95
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 预测性负载均衡
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "predictive",
|
||||
"prediction": {
|
||||
"algorithm": "linear-regression",
|
||||
"trainingWindow": "7d",
|
||||
"predictionHorizon": "1h",
|
||||
"factors": ["historical_load", "time_of_day", "day_of_week", "seasonal_patterns"]
|
||||
},
|
||||
"adaptation": {
|
||||
"preemptiveScaling": true,
|
||||
"scaleUpThreshold": 70,
|
||||
"scaleDownThreshold": 30
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 故障转移和恢复
|
||||
|
||||
### 自动故障转移
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "high-availability",
|
||||
"failover": {
|
||||
"enabled": true,
|
||||
"detection": {
|
||||
"healthCheckFailures": 3,
|
||||
"timeoutThreshold": "10s",
|
||||
"checkInterval": 5000
|
||||
},
|
||||
"recovery": {
|
||||
"automaticRecovery": true,
|
||||
"recoveryChecks": 5,
|
||||
"recoveryInterval": 30000
|
||||
}
|
||||
},
|
||||
"clusters": [
|
||||
{
|
||||
"name": "primary",
|
||||
"servers": ["server-1", "server-2"],
|
||||
"priority": 1
|
||||
},
|
||||
{
|
||||
"name": "secondary",
|
||||
"servers": ["backup-server-1", "backup-server-2"],
|
||||
"priority": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 断路器模式
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"circuitBreaker": {
|
||||
"enabled": true,
|
||||
"failureThreshold": 10,
|
||||
"timeWindow": 60000,
|
||||
"halfOpenRetries": 3,
|
||||
"fallback": {
|
||||
"type": "cached-response",
|
||||
"ttl": 300000
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 会话亲和性
|
||||
|
||||
### 粘性会话
|
||||
|
||||
保持用户会话与特定服务器的关联:
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "session-affinity",
|
||||
"affinity": {
|
||||
"type": "cookie",
|
||||
"cookieName": "mcphub-server-id",
|
||||
"ttl": 3600000,
|
||||
"fallbackOnUnavailable": true
|
||||
},
|
||||
"sessionStore": {
|
||||
"type": "redis",
|
||||
"config": {
|
||||
"host": "localhost",
|
||||
"port": 6379,
|
||||
"db": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 基于用户 ID 的路由
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "user-based",
|
||||
"userRouting": {
|
||||
"algorithm": "consistent-hashing",
|
||||
"hashFunction": "sha256",
|
||||
"virtualNodes": 100,
|
||||
"replicationFactor": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 动态路由配置
|
||||
|
||||
### 运行时配置更新
|
||||
|
||||
```bash
|
||||
# 更新路由配置
|
||||
curl -X PUT http://localhost:3000/api/routing/config \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"strategy": "weighted-round-robin",
|
||||
"weights": {
|
||||
"server-1": 3,
|
||||
"server-2": 2,
|
||||
"server-3": 1
|
||||
},
|
||||
"applyImmediately": true
|
||||
}'
|
||||
```
|
||||
|
||||
### A/B 测试路由
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "ab-testing",
|
||||
"experiments": [
|
||||
{
|
||||
"name": "new-algorithm-test",
|
||||
"enabled": true,
|
||||
"trafficSplit": {
|
||||
"control": 70,
|
||||
"variant": 30
|
||||
},
|
||||
"rules": {
|
||||
"control": {
|
||||
"strategy": "round-robin",
|
||||
"servers": ["stable-server-1", "stable-server-2"]
|
||||
},
|
||||
"variant": {
|
||||
"strategy": "ai-optimized",
|
||||
"servers": ["experimental-server-1"]
|
||||
}
|
||||
},
|
||||
"metrics": ["response_time", "error_rate", "user_satisfaction"]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 路由分析和监控
|
||||
|
||||
### 实时路由指标
|
||||
|
||||
```bash
|
||||
# 获取路由统计
|
||||
curl -X GET http://localhost:3000/api/routing/metrics \
|
||||
-H "Authorization: Bearer $TOKEN"
|
||||
```
|
||||
|
||||
响应示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"timestamp": "2024-01-01T12:00:00Z",
|
||||
"totalRequests": 15420,
|
||||
"routingDistribution": {
|
||||
"server-1": { "requests": 6168, "percentage": 40 },
|
||||
"server-2": { "requests": 4626, "percentage": 30 },
|
||||
"server-3": { "requests": 3084, "percentage": 20 },
|
||||
"backup-server": { "requests": 1542, "percentage": 10 }
|
||||
},
|
||||
"performance": {
|
||||
"avgResponseTime": "245ms",
|
||||
"p95ResponseTime": "580ms",
|
||||
"errorRate": "0.3%"
|
||||
},
|
||||
"failovers": {
|
||||
"total": 2,
|
||||
"byServer": {
|
||||
"server-2": 1,
|
||||
"server-3": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 路由决策日志
|
||||
|
||||
```bash
|
||||
# 启用路由决策日志
|
||||
curl -X PUT http://localhost:3000/api/routing/logging \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"enabled": true,
|
||||
"level": "info",
|
||||
"includeDecisionFactors": true,
|
||||
"sampleRate": 0.1
|
||||
}'
|
||||
```
|
||||
|
||||
## 自定义路由规则
|
||||
|
||||
### 基于业务逻辑的路由
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "custom-rules",
|
||||
"rules": [
|
||||
{
|
||||
"name": "premium-users",
|
||||
"priority": 1,
|
||||
"condition": "user.tier === 'premium'",
|
||||
"action": {
|
||||
"targetServers": ["premium-server-1", "premium-server-2"],
|
||||
"strategy": "least-connections",
|
||||
"qos": {
|
||||
"maxResponseTime": "1s",
|
||||
"priority": "high"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "high-volume-requests",
|
||||
"priority": 2,
|
||||
"condition": "request.size > 10MB",
|
||||
"action": {
|
||||
"targetServers": ["high-capacity-server"],
|
||||
"strategy": "single",
|
||||
"timeout": "60s"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "batch-processing",
|
||||
"priority": 3,
|
||||
"condition": "request.type === 'batch'",
|
||||
"action": {
|
||||
"targetServers": ["batch-server-1", "batch-server-2"],
|
||||
"strategy": "queue-based",
|
||||
"queueConfig": {
|
||||
"maxSize": 1000,
|
||||
"timeout": "5m"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### JavaScript 路由函数
|
||||
|
||||
```javascript
|
||||
// 自定义路由函数
|
||||
function customRouting(request, servers, metrics) {
|
||||
const { user, content, timestamp } = request;
|
||||
|
||||
// 工作时间优先使用高性能服务器
|
||||
const isBusinessHours =
|
||||
new Date(timestamp).getHours() >= 9 && new Date(timestamp).getHours() <= 17;
|
||||
|
||||
if (isBusinessHours && user.priority === 'high') {
|
||||
return servers.filter((s) => s.tags.includes('high-performance'));
|
||||
}
|
||||
|
||||
// 基于内容类型的特殊路由
|
||||
if (content.type === 'code-analysis') {
|
||||
return servers.filter((s) => s.capabilities.includes('code-analysis'));
|
||||
}
|
||||
|
||||
// 默认负载均衡
|
||||
return servers.sort((a, b) => a.currentLoad - b.currentLoad);
|
||||
}
|
||||
```
|
||||
|
||||
## 路由优化
|
||||
|
||||
### 机器学习优化
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "ml-optimized",
|
||||
"mlConfig": {
|
||||
"algorithm": "reinforcement-learning",
|
||||
"rewardFunction": "response_time_weighted",
|
||||
"trainingData": {
|
||||
"features": [
|
||||
"server_load",
|
||||
"response_time_history",
|
||||
"request_complexity",
|
||||
"user_pattern",
|
||||
"time_of_day"
|
||||
],
|
||||
"targetMetric": "overall_satisfaction"
|
||||
},
|
||||
"updateFrequency": "hourly",
|
||||
"explorationRate": 0.1
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 缓存感知路由
|
||||
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"strategy": "cache-aware",
|
||||
"caching": {
|
||||
"enabled": true,
|
||||
"levels": [
|
||||
{
|
||||
"type": "local",
|
||||
"ttl": 300,
|
||||
"maxSize": "100MB"
|
||||
},
|
||||
{
|
||||
"type": "distributed",
|
||||
"provider": "redis",
|
||||
"ttl": 3600,
|
||||
"maxSize": "1GB"
|
||||
}
|
||||
],
|
||||
"routing": {
|
||||
"preferCachedServers": true,
|
||||
"cacheHitBonus": 0.3,
|
||||
"cacheMissThreshold": 0.8
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 路由调试
|
||||
|
||||
```bash
|
||||
# 调试特定请求的路由决策
|
||||
curl -X POST http://localhost:3000/api/routing/debug \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{
|
||||
"request": {
|
||||
"userId": "user123",
|
||||
"tool": "filesystem",
|
||||
"content": {"type": "read", "path": "/data/file.txt"}
|
||||
},
|
||||
"traceRoute": true
|
||||
}'
|
||||
```
|
||||
|
||||
### 路由性能分析
|
||||
|
||||
```bash
|
||||
# 获取路由性能报告
|
||||
curl -X GET http://localhost:3000/api/routing/performance \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-G -d "timeRange=1h" -d "detailed=true"
|
||||
```
|
||||
|
||||
### 常见问题
|
||||
|
||||
1. **不均匀的负载分布**
|
||||
|
||||
- 检查服务器权重配置
|
||||
- 验证健康检查设置
|
||||
- 分析请求模式
|
||||
|
||||
2. **频繁的故障转移**
|
||||
|
||||
- 调整健康检查阈值
|
||||
- 检查网络连接稳定性
|
||||
- 优化服务器资源
|
||||
|
||||
3. **路由延迟过高**
|
||||
- 简化路由规则
|
||||
- 优化路由算法
|
||||
- 使用缓存加速决策
|
||||
|
||||
有关更多信息,请参阅 [监控](/zh/features/monitoring) 和 [服务器管理](/zh/features/server-management) 文档。
|
||||
97
docs/zh/index.mdx
Normal file
@@ -0,0 +1,97 @@
|
||||
---
|
||||
title: '欢迎使用 MCPHub'
|
||||
description: 'MCPHub 是一个强大的 Model Context Protocol (MCP) 服务器管理平台,提供智能路由、负载均衡和实时监控功能'
|
||||
---
|
||||
|
||||
<img className="block dark:hidden" src="/images/hero-light.png" alt="MCPHub Hero Light" />
|
||||
<img className="hidden dark:block" src="/images/hero-dark.png" alt="MCPHub Hero Dark" />
|
||||
|
||||
## 什么是 MCPHub?
|
||||
|
||||
MCPHub 是一个现代化的 Model Context Protocol (MCP) 服务器管理平台,旨在简化 AI 模型服务的部署、管理和监控。通过智能路由和负载均衡技术,MCPHub 帮助您构建高可用、可扩展的 AI 服务架构。
|
||||
|
||||
### 核心功能
|
||||
|
||||
- **🚀 智能路由** - 基于负载、延迟和健康状态的智能请求分发
|
||||
- **⚖️ 负载均衡** - 多种负载均衡策略,确保最优性能
|
||||
- **📊 实时监控** - 全面的性能指标和健康检查
|
||||
- **🔐 安全认证** - 企业级身份认证和访问控制
|
||||
- **🏗️ 服务器组管理** - 灵活的服务器分组和配置管理
|
||||
- **🔄 故障转移** - 自动故障检测和流量切换
|
||||
|
||||
## 快速开始
|
||||
|
||||
立即开始使用 MCPHub,只需几分钟即可部署您的第一个 MCP 服务器。
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="5 分钟快速部署" icon="rocket" href="/zh/quickstart">
|
||||
跟随我们的快速开始指南,5 分钟内部署 MCPHub 并连接您的第一个 MCP 服务器
|
||||
</Card>
|
||||
<Card title="开发环境搭建" icon="code" href="/zh/development/getting-started">
|
||||
设置本地开发环境,了解 MCPHub 的架构和开发工作流
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## 核心概念
|
||||
|
||||
了解 MCPHub 的核心概念,为深入使用做好准备。
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="MCP 协议介绍" icon="network-wired" href="/zh/concepts/mcp-protocol">
|
||||
深入了解 Model Context Protocol 的工作原理和最佳实践
|
||||
</Card>
|
||||
<Card title="智能路由机制" icon="route" href="/zh/features/smart-routing">
|
||||
学习 MCPHub 的智能路由算法和配置策略
|
||||
</Card>
|
||||
<Card title="服务器管理" icon="server" href="/zh/features/server-management">
|
||||
掌握 MCP 服务器的添加、配置和管理技巧
|
||||
</Card>
|
||||
<Card title="监控与分析" icon="chart-line" href="/zh/features/monitoring">
|
||||
使用内置的监控工具跟踪性能和识别问题
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## 部署选项
|
||||
|
||||
MCPHub 支持多种部署方式,满足不同规模和场景的需求。
|
||||
|
||||
<CardGroup cols={3}>
|
||||
<Card title="Docker 部署" icon="docker" href="/zh/configuration/docker-setup">
|
||||
使用 Docker 容器快速部署,支持单机和集群模式
|
||||
</Card>
|
||||
<Card title="云服务部署" icon="cloud" href="/zh/deployment/cloud">
|
||||
在 AWS、GCP、Azure 等云平台上部署 MCPHub
|
||||
</Card>
|
||||
<Card title="Kubernetes" icon="dharmachakra" href="/zh/deployment/kubernetes">
|
||||
在 Kubernetes 集群中部署高可用的 MCPHub 服务
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## API 和集成
|
||||
|
||||
MCPHub 提供完整的 RESTful API 和多语言 SDK,方便与现有系统集成。
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="API 参考文档" icon="code" href="/zh/api-reference/introduction">
|
||||
完整的 API 接口文档,包含详细的请求示例和响应格式
|
||||
</Card>
|
||||
<Card title="SDK 和工具" icon="toolbox" href="/zh/sdk">
|
||||
官方 SDK 和命令行工具,加速开发集成
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## 社区和支持
|
||||
|
||||
加入 MCPHub 社区,获取帮助和分享经验。
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="GitHub 仓库" icon="github" href="https://github.com/mcphub/mcphub">
|
||||
查看源代码、提交问题和贡献代码
|
||||
</Card>
|
||||
<Card title="Discord 社区" icon="discord" href="https://discord.gg/mcphub">
|
||||
与其他开发者交流,获取实时帮助
|
||||
</Card>
|
||||
<Card title="Sponsor" icon="heart" href="https://ko-fi.com/samanhappy">
|
||||
支持 MCPHub 的开发和维护,帮助我们持续改进
|
||||
</Card>
|
||||
</CardGroup>
|
||||
304
docs/zh/quickstart.mdx
Normal file
@@ -0,0 +1,304 @@
|
||||
---
|
||||
title: '快速开始'
|
||||
description: '5 分钟内部署 MCPHub 并连接您的第一个 MCP 服务器'
|
||||
---
|
||||
|
||||
## 欢迎使用 MCPHub!
|
||||
|
||||
本指南将帮助您在 5 分钟内完成 MCPHub 的部署和配置,并连接您的第一个 MCP 服务器。
|
||||
|
||||
## 前提条件
|
||||
|
||||
在开始之前,请确保您的系统满足以下要求:
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion icon="desktop" title="系统要求">
|
||||
- **操作系统**: Linux、macOS 或 Windows
|
||||
- **内存**: 最少 2GB RAM(推荐 4GB+)
|
||||
- **存储**: 至少 1GB 可用空间
|
||||
- **网络**: 稳定的互联网连接
|
||||
</Accordion>
|
||||
|
||||
<Accordion icon="code" title="软件依赖">
|
||||
- **Node.js**: 18.0+ 版本
|
||||
- **Docker**: 最新版本(可选,用于容器化部署)
|
||||
- **Git**: 用于代码管理
|
||||
|
||||
检查版本:
|
||||
```bash
|
||||
node --version # 应该 >= 18.0.0
|
||||
npm --version # 应该 >= 8.0.0
|
||||
docker --version # 可选
|
||||
```
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## 安装 MCPHub
|
||||
|
||||
### 方式一:使用 npm(推荐)
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion icon="download" title="安装 MCPHub CLI">
|
||||
首先安装 MCPHub 命令行工具:
|
||||
|
||||
```bash
|
||||
npm install -g @mcphub/cli
|
||||
```
|
||||
|
||||
验证安装:
|
||||
```bash
|
||||
mcphub --version
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion icon="folder-plus" title="创建新项目">
|
||||
创建一个新的 MCPHub 项目:
|
||||
|
||||
```bash
|
||||
# 创建项目
|
||||
mcphub init my-mcphub-project
|
||||
cd my-mcphub-project
|
||||
|
||||
# 安装依赖
|
||||
npm install
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion icon="gear" title="配置环境">
|
||||
复制并编辑环境变量文件:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
编辑 `.env` 文件,设置基本配置:
|
||||
```bash
|
||||
# 服务器配置
|
||||
PORT=3000
|
||||
NODE_ENV=development
|
||||
|
||||
# 数据库配置(使用内置 SQLite)
|
||||
DATABASE_URL=sqlite:./data/mcphub.db
|
||||
|
||||
# JWT 密钥(请更改为安全的随机字符串)
|
||||
JWT_SECRET=your-super-secret-jwt-key-change-me
|
||||
|
||||
# 管理员账户
|
||||
ADMIN_EMAIL=admin@example.com
|
||||
ADMIN_PASSWORD=admin123
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
### 方式二:使用 Docker
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion icon="docker" title="Docker 快速部署">
|
||||
使用 Docker Compose 一键部署:
|
||||
|
||||
```bash
|
||||
# 下载配置文件
|
||||
curl -O https://raw.githubusercontent.com/mcphub/mcphub/main/docker-compose.yml
|
||||
|
||||
# 启动服务
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
或者直接运行 Docker 容器:
|
||||
```bash
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
-p 3000:3000 \
|
||||
-e NODE_ENV=production \
|
||||
-e JWT_SECRET=your-secret-key \
|
||||
mcphub/server:latest
|
||||
```
|
||||
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## 启动 MCPHub
|
||||
|
||||
### 开发模式启动
|
||||
|
||||
```bash
|
||||
# 初始化数据库
|
||||
npm run db:setup
|
||||
|
||||
# 启动开发服务器
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### 生产模式启动
|
||||
|
||||
```bash
|
||||
# 构建应用
|
||||
npm run build
|
||||
|
||||
# 启动生产服务器
|
||||
npm start
|
||||
```
|
||||
|
||||
<Note>开发模式下,MCPHub 会在 `http://localhost:3000` 启动,并具有热重载功能。</Note>
|
||||
|
||||
## 首次访问和配置
|
||||
|
||||
### 1. 访问管理界面
|
||||
|
||||
打开浏览器,访问 `http://localhost:3000`,您将看到 MCPHub 的欢迎页面。
|
||||
|
||||
### 2. 登录管理员账户
|
||||
|
||||
使用您在 `.env` 文件中设置的管理员凭据登录:
|
||||
|
||||
- **邮箱**: `admin@example.com`
|
||||
- **密码**: `admin123`
|
||||
|
||||
<Warning>首次登录后,请立即更改默认密码以确保安全!</Warning>
|
||||
|
||||
### 3. 完成初始配置
|
||||
|
||||
登录后,系统会引导您完成初始配置:
|
||||
|
||||
1. **更改管理员密码**
|
||||
2. **设置组织信息**
|
||||
3. **配置基本设置**
|
||||
|
||||
## 添加您的第一个 MCP 服务器
|
||||
|
||||
### 1. 准备 MCP 服务器
|
||||
|
||||
如果您还没有 MCP 服务器,可以使用我们的示例服务器进行测试:
|
||||
|
||||
```bash
|
||||
# 克隆示例服务器
|
||||
git clone https://github.com/mcphub/example-mcp-server.git
|
||||
cd example-mcp-server
|
||||
|
||||
# 安装依赖并启动
|
||||
npm install
|
||||
npm start
|
||||
```
|
||||
|
||||
示例服务器将在 `http://localhost:3001` 启动。
|
||||
|
||||
### 2. 在 MCPHub 中添加服务器
|
||||
|
||||
在 MCPHub 管理界面中:
|
||||
|
||||
1. 点击 **"添加服务器"** 按钮
|
||||
2. 填写服务器信息:
|
||||
```
|
||||
名称: Example MCP Server
|
||||
端点: http://localhost:3001
|
||||
描述: 示例 MCP 服务器用于测试
|
||||
```
|
||||
3. 选择功能类型(如:chat、completion、analysis)
|
||||
4. 点击 **"测试连接"** 验证服务器可达性
|
||||
5. 点击 **"保存"** 完成添加
|
||||
|
||||
### 3. 验证服务器状态
|
||||
|
||||
添加成功后,您应该能在服务器列表中看到新添加的服务器,状态显示为 **"活跃"**(绿色)。
|
||||
|
||||
## 测试路由功能
|
||||
|
||||
### 发送测试请求
|
||||
|
||||
使用 cURL 或其他 HTTP 客户端测试路由功能:
|
||||
|
||||
```bash
|
||||
# 发送聊天请求
|
||||
curl -X POST http://localhost:3000/api/chat \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, this is a test message!"
|
||||
}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
### 查看请求日志
|
||||
|
||||
在 MCPHub 管理界面的 **"监控"** 页面中,您可以实时查看:
|
||||
|
||||
- 请求数量和响应时间
|
||||
- 服务器健康状态
|
||||
- 错误日志和统计
|
||||
|
||||
## 后续步骤
|
||||
|
||||
恭喜!您已经成功部署了 MCPHub 并添加了第一个 MCP 服务器。接下来您可以:
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="配置负载均衡" icon="balance-scale" href="/zh/features/smart-routing">
|
||||
学习如何配置智能路由和负载均衡策略
|
||||
</Card>
|
||||
<Card title="添加更多服务器" icon="plus" href="/zh/features/server-management">
|
||||
了解服务器管理的高级功能
|
||||
</Card>
|
||||
<Card title="设置监控告警" icon="bell" href="/zh/features/monitoring">
|
||||
配置性能监控和告警通知
|
||||
</Card>
|
||||
<Card title="API 集成" icon="code" href="/zh/api-reference/introduction">
|
||||
将 MCPHub 集成到您的应用程序中
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## 常见问题
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion icon="question" title="无法连接到 MCP 服务器">
|
||||
**可能原因**:
|
||||
- 服务器地址错误或服务器未启动
|
||||
- 防火墙阻止连接
|
||||
- 网络配置问题
|
||||
|
||||
**解决方案**:
|
||||
1. 验证服务器是否正在运行:`curl http://localhost:3001/health`
|
||||
2. 检查防火墙设置
|
||||
3. 确认网络连接正常
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion icon="question" title="服务器状态显示为离线">
|
||||
**可能原因**:
|
||||
- 健康检查失败
|
||||
- 服务器响应超时
|
||||
- 服务器崩溃或重启
|
||||
|
||||
**解决方案**:
|
||||
1. 检查服务器日志
|
||||
2. 调整健康检查间隔
|
||||
3. 重启服务器进程
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion icon="question" title="忘记管理员密码">
|
||||
**解决方案**:
|
||||
```bash
|
||||
# 重置管理员密码
|
||||
npm run reset-admin-password
|
||||
```
|
||||
或者删除数据库文件重新初始化:
|
||||
```bash
|
||||
rm data/mcphub.db
|
||||
npm run db:setup
|
||||
```
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## 获取帮助
|
||||
|
||||
如果您在设置过程中遇到问题:
|
||||
|
||||
- 📖 查看 [完整文档](/zh/development/getting-started)
|
||||
- 🐛 在 [GitHub](https://github.com/mcphub/mcphub/issues) 上报告问题
|
||||
- 💬 加入 [Discord 社区](https://discord.gg/mcphub) 获取实时帮助
|
||||
- 📧 发送邮件至 support@mcphub.io
|
||||
@@ -4,7 +4,19 @@ NPM_REGISTRY=${NPM_REGISTRY:-https://registry.npmjs.org/}
|
||||
echo "Setting npm registry to ${NPM_REGISTRY}"
|
||||
npm config set registry "$NPM_REGISTRY"
|
||||
|
||||
# 处理 HTTP_PROXY 和 HTTPS_PROXY 环境变量
|
||||
if [ -n "$HTTP_PROXY" ]; then
|
||||
echo "Setting HTTP proxy to ${HTTP_PROXY}"
|
||||
npm config set proxy "$HTTP_PROXY"
|
||||
export HTTP_PROXY="$HTTP_PROXY"
|
||||
fi
|
||||
|
||||
if [ -n "$HTTPS_PROXY" ]; then
|
||||
echo "Setting HTTPS proxy to ${HTTPS_PROXY}"
|
||||
npm config set https-proxy "$HTTPS_PROXY"
|
||||
export HTTPS_PROXY="$HTTPS_PROXY"
|
||||
fi
|
||||
|
||||
echo "Using REQUEST_TIMEOUT: $REQUEST_TIMEOUT"
|
||||
echo "Using UV_PYTHON_INSTALL_MIRROR: $UV_PYTHON_INSTALL_MIRROR"
|
||||
|
||||
exec "$@"
|
||||
|
||||