Compare commits
171 Commits
v0.7.1
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18cacca2d0 | ||
|
|
1f19ac392f | ||
|
|
840b1b34f1 | ||
|
|
b5dff990e5 | ||
|
|
19f11a0927 | ||
|
|
884870c9de | ||
|
|
7b8d9a7e5a | ||
|
|
8770b9ccfe | ||
|
|
063b081297 | ||
|
|
73ae33e777 | ||
|
|
dac0d376e8 | ||
|
|
803e35b14c | ||
|
|
a736398cd5 | ||
|
|
6de3221974 | ||
|
|
ac0b60ed4b | ||
|
|
a57218d076 | ||
|
|
8c985b7de1 | ||
|
|
01bb011736 | ||
|
|
449e6ea4fd | ||
|
|
1869f283ba | ||
|
|
07adeab036 | ||
|
|
5d7d8fdd1a | ||
|
|
fb847797c0 | ||
|
|
8df2b4704a | ||
|
|
602b5cb80e | ||
|
|
e63f045819 | ||
|
|
a4e4791b60 | ||
|
|
01370ea959 | ||
|
|
f5d66c1bb7 | ||
|
|
9e59dd9fb0 | ||
|
|
250487f042 | ||
|
|
da91708420 | ||
|
|
576bba1f9e | ||
|
|
f4b83929a6 | ||
|
|
3825f389cd | ||
|
|
44e0309fd4 | ||
|
|
7e570a900a | ||
|
|
6268a02c0e | ||
|
|
695d663939 | ||
|
|
d595e5d874 | ||
|
|
ff797b4ab9 | ||
|
|
9105507722 | ||
|
|
f79028ed64 | ||
|
|
5ca5e2ad47 | ||
|
|
2f7726b008 | ||
|
|
26b26a5fb1 | ||
|
|
7dbd6c386e | ||
|
|
c1fee91142 | ||
|
|
1130f6833e | ||
|
|
c3f1de8f5b | ||
|
|
86367a4875 | ||
|
|
bd4c546bba | ||
|
|
3e9e5cc3c9 | ||
|
|
16a92096b3 | ||
|
|
4d736c543d | ||
|
|
f53c4a0e3b | ||
|
|
d4bdb099d0 | ||
|
|
435227cbd4 | ||
|
|
6a59becd8d | ||
|
|
91698a50e3 | ||
|
|
a5d5045832 | ||
|
|
198ea85225 | ||
|
|
6b39916909 | ||
|
|
9e8db370ff | ||
|
|
5d8bc44a73 | ||
|
|
021901dbda | ||
|
|
f6934a32dc | ||
|
|
7685b9bca8 | ||
|
|
c2dd91606f | ||
|
|
66b6053f7f | ||
|
|
ba50a78879 | ||
|
|
a856404963 | ||
|
|
9a65532a50 | ||
|
|
c5aa97de50 | ||
|
|
271c9fe2c3 | ||
|
|
d59961c4d4 | ||
|
|
d0ec80303a | ||
|
|
69e92b5aa8 | ||
|
|
5acae64b29 | ||
|
|
a5fc4a429d | ||
|
|
ce15330016 | ||
|
|
621bc36560 | ||
|
|
c398223824 | ||
|
|
5dd3e7978e | ||
|
|
f577351f04 | ||
|
|
62de87b1a4 | ||
|
|
bbd6c891c9 | ||
|
|
f9019545c3 | ||
|
|
d778536388 | ||
|
|
976e90679d | ||
|
|
f6ee9beed3 | ||
|
|
69a800fa7a | ||
|
|
83cbd16821 | ||
|
|
9300814994 | ||
|
|
9952927a13 | ||
|
|
4547ae526a | ||
|
|
80b83bb029 | ||
|
|
fa2de88fea | ||
|
|
6020611f57 | ||
|
|
81c3091a5c | ||
|
|
6a8f246dff | ||
|
|
2bef1fb0bd | ||
|
|
bdb5b37cf5 | ||
|
|
cbb3b15ba2 | ||
|
|
77b423fbcc | ||
|
|
604fe4f71d | ||
|
|
907bca8aac | ||
|
|
8c58200dcc | ||
|
|
0b4dc453a5 | ||
|
|
35012f99fc | ||
|
|
22ad4f83f6 | ||
|
|
26720d9e49 | ||
|
|
a9aa4a9a08 | ||
|
|
48bcf9f5f0 | ||
|
|
f63f06d879 | ||
|
|
63b356b8d7 | ||
|
|
a6cea2ad3f | ||
|
|
5bb2715094 | ||
|
|
9b40f7e101 | ||
|
|
df872823c1 | ||
|
|
9304653c34 | ||
|
|
b5685b7010 | ||
|
|
89c37b2f02 | ||
|
|
c316cb896e | ||
|
|
bc3c8facfa | ||
|
|
69afb865c0 | ||
|
|
ba30d88840 | ||
|
|
6d0d622bd8 | ||
|
|
ab50c7e9eb | ||
|
|
e507bea2e3 | ||
|
|
0f00ad7200 | ||
|
|
b0b0c93337 | ||
|
|
20fd355b87 | ||
|
|
4388084704 | ||
|
|
fe2535461d | ||
|
|
985598e529 | ||
|
|
b2b6d0588b | ||
|
|
64628ee3ed | ||
|
|
66d4142039 | ||
|
|
cf72295f99 | ||
|
|
89f85c73ff | ||
|
|
adabf1d92b | ||
|
|
c3a6dfadb4 | ||
|
|
d119be0f82 | ||
|
|
1e308ec4c5 | ||
|
|
1bd4fd6d9c | ||
|
|
4b3bb26301 | ||
|
|
40af398f68 | ||
|
|
4726f00a22 | ||
|
|
77f64b7b98 | ||
|
|
d9cbc5381a | ||
|
|
56c6447469 | ||
|
|
f8149c4b0b | ||
|
|
e259f30539 | ||
|
|
3a421bc476 | ||
|
|
503b60edb7 | ||
|
|
4039a85ee1 | ||
|
|
3a83b83a9e | ||
|
|
c1621805de | ||
|
|
ecf79eaef3 | ||
|
|
e2cb5fa467 | ||
|
|
7193ca4cdc | ||
|
|
9675cd8533 | ||
|
|
65c95aaa0b | ||
|
|
d2bbadea83 | ||
|
|
394945bbc5 | ||
|
|
bfc184afc6 | ||
|
|
1acacfab88 | ||
|
|
63c55875b5 | ||
|
|
80c6aae116 | ||
|
|
e2c5cc8ed1 |
16
.coveragerc
Normal file
@@ -0,0 +1,16 @@
|
||||
# Test coverage configuration
|
||||
# This file tells Jest what to include/exclude from coverage reports
|
||||
|
||||
# Coverage patterns
|
||||
- "src/**/*.{ts,tsx}"
|
||||
|
||||
# Exclusions
|
||||
- "!src/**/*.d.ts"
|
||||
- "!src/index.ts"
|
||||
- "!src/**/__tests__/**"
|
||||
- "!src/**/*.test.{ts,tsx}"
|
||||
- "!src/**/*.spec.{ts,tsx}"
|
||||
- "!**/node_modules/**"
|
||||
- "!coverage/**"
|
||||
- "!dist/**"
|
||||
- "!build/**"
|
||||
1
.dockerignore
Normal file
@@ -0,0 +1 @@
|
||||
.git
|
||||
@@ -1,2 +1,8 @@
|
||||
PORT=3000
|
||||
NODE_ENV=development
|
||||
|
||||
# Database Configuration (Optional - for database-backed configuration)
|
||||
# Simply set DB_URL to enable database mode (auto-detected)
|
||||
# DB_URL=postgresql://mcphub:password@localhost:5432/mcphub
|
||||
# Or explicitly control with USE_DB (overrides auto-detection)
|
||||
# USE_DB=true
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"no-undef": "off",
|
||||
"no-undef": "off"
|
||||
}
|
||||
}
|
||||
|
||||
124
.github/DOCKER_CLI_TEST.md
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
# Docker Engine Installation Test Procedure
|
||||
|
||||
This document describes how to test the Docker Engine installation feature added with the `INSTALL_EXT=true` build argument.
|
||||
|
||||
## Test 1: Build with INSTALL_EXT=false (default)
|
||||
|
||||
```bash
|
||||
# Build without extended features
|
||||
docker build -t mcphub:base .
|
||||
|
||||
# Run the container
|
||||
docker run --rm mcphub:base docker --version
|
||||
```
|
||||
|
||||
**Expected Result**: `docker: not found` error (Docker is NOT installed)
|
||||
|
||||
## Test 2: Build with INSTALL_EXT=true
|
||||
|
||||
```bash
|
||||
# Build with extended features
|
||||
docker build --build-arg INSTALL_EXT=true -t mcphub:extended .
|
||||
|
||||
# Test Docker CLI is available
|
||||
docker run --rm mcphub:extended docker --version
|
||||
```
|
||||
|
||||
**Expected Result**: Docker version output (e.g., `Docker version 27.x.x, build xxxxx`)
|
||||
|
||||
## Test 3: Docker-in-Docker with Auto-start Daemon
|
||||
|
||||
```bash
|
||||
# Build with extended features
|
||||
docker build --build-arg INSTALL_EXT=true -t mcphub:extended .
|
||||
|
||||
# Run with privileged mode (allows Docker daemon to start)
|
||||
docker run -d \
|
||||
--name mcphub-test \
|
||||
--privileged \
|
||||
-p 3000:3000 \
|
||||
mcphub:extended
|
||||
|
||||
# Wait a few seconds for daemon to start
|
||||
sleep 5
|
||||
|
||||
# Test Docker commands from inside the container
|
||||
docker exec mcphub-test docker ps
|
||||
docker exec mcphub-test docker images
|
||||
docker exec mcphub-test docker info
|
||||
|
||||
# Cleanup
|
||||
docker stop mcphub-test
|
||||
docker rm mcphub-test
|
||||
```
|
||||
|
||||
**Expected Result**:
|
||||
- Docker daemon should auto-start inside the container
|
||||
- Docker commands should work without mounting the host's Docker socket
|
||||
- `docker info` should show the container's own Docker daemon
|
||||
|
||||
## Test 4: Docker-in-Docker with Host Socket (Alternative)
|
||||
|
||||
```bash
|
||||
# Build with extended features
|
||||
docker build --build-arg INSTALL_EXT=true -t mcphub:extended .
|
||||
|
||||
# Run with Docker socket mounted (uses host's daemon)
|
||||
docker run -d \
|
||||
--name mcphub-test \
|
||||
-p 3000:3000 \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
mcphub:extended
|
||||
|
||||
# Test Docker commands from inside the container
|
||||
docker exec mcphub-test docker ps
|
||||
docker exec mcphub-test docker images
|
||||
|
||||
# Cleanup
|
||||
docker stop mcphub-test
|
||||
docker rm mcphub-test
|
||||
```
|
||||
|
||||
**Expected Result**:
|
||||
- Docker daemon should NOT auto-start (socket already exists from host)
|
||||
- Docker commands should work and show the host's containers and images
|
||||
|
||||
## Test 5: Verify Image Size
|
||||
|
||||
```bash
|
||||
# Build both versions
|
||||
docker build -t mcphub:base .
|
||||
docker build --build-arg INSTALL_EXT=true -t mcphub:extended .
|
||||
|
||||
# Compare image sizes
|
||||
docker images mcphub:*
|
||||
```
|
||||
|
||||
**Expected Result**:
|
||||
- The `extended` image should be larger than the `base` image
|
||||
- The size difference should be reasonable (Docker Engine adds ~100-150MB)
|
||||
|
||||
## Test 6: Architecture Support
|
||||
|
||||
```bash
|
||||
# On AMD64/x86_64
|
||||
docker build --build-arg INSTALL_EXT=true --platform linux/amd64 -t mcphub:extended-amd64 .
|
||||
|
||||
# On ARM64
|
||||
docker build --build-arg INSTALL_EXT=true --platform linux/arm64 -t mcphub:extended-arm64 .
|
||||
```
|
||||
|
||||
**Expected Result**:
|
||||
- Both builds should succeed
|
||||
- AMD64 includes Chrome/Playwright + Docker Engine
|
||||
- ARM64 includes Docker Engine only (Chrome installation is skipped)
|
||||
|
||||
## Notes
|
||||
|
||||
- The Docker Engine installation follows the official Docker documentation
|
||||
- Includes full Docker daemon (`dockerd`), CLI (`docker`), and containerd
|
||||
- The daemon auto-starts when running in privileged mode
|
||||
- The installation uses the Debian Bookworm repository
|
||||
- All temporary files are cleaned up to minimize image size
|
||||
- The feature is opt-in via the `INSTALL_EXT` build argument
|
||||
- `iptables` is installed as it's required for Docker networking
|
||||
272
.github/copilot-instructions.md
vendored
Normal file
@@ -0,0 +1,272 @@
|
||||
# MCPHub Coding Instructions
|
||||
|
||||
**ALWAYS follow these instructions first and only fallback to additional search and context gathering if the information here is incomplete or found to be in error.**
|
||||
|
||||
## Project Overview
|
||||
|
||||
MCPHub is a TypeScript/Node.js MCP (Model Context Protocol) server management hub that provides unified access through HTTP endpoints. It serves as a centralized dashboard for managing multiple MCP servers with real-time monitoring, authentication, and flexible routing.
|
||||
|
||||
**Core Components:**
|
||||
|
||||
- **Backend**: Express.js + TypeScript + ESM (`src/server.ts`)
|
||||
- **Frontend**: React/Vite + Tailwind CSS (`frontend/`)
|
||||
- **MCP Integration**: Connects multiple MCP servers (`src/services/mcpService.ts`)
|
||||
- **Authentication**: JWT-based with bcrypt password hashing
|
||||
- **Configuration**: JSON-based MCP server definitions (`mcp_settings.json`)
|
||||
- **Documentation**: API docs and usage instructions(`docs/`)
|
||||
|
||||
## Working Effectively
|
||||
|
||||
### Bootstrap and Setup (CRITICAL - Follow Exact Steps)
|
||||
|
||||
```bash
|
||||
# Install pnpm if not available
|
||||
npm install -g pnpm
|
||||
|
||||
# Install dependencies - takes ~30 seconds
|
||||
pnpm install
|
||||
|
||||
# Setup environment (optional)
|
||||
cp .env.example .env
|
||||
|
||||
# Build and test to verify setup
|
||||
pnpm lint # ~3 seconds - NEVER CANCEL
|
||||
pnpm backend:build # ~5 seconds - NEVER CANCEL
|
||||
pnpm test:ci # ~16 seconds - NEVER CANCEL. Set timeout to 60+ seconds
|
||||
pnpm frontend:build # ~5 seconds - NEVER CANCEL
|
||||
pnpm build # ~10 seconds total - NEVER CANCEL. Set timeout to 60+ seconds
|
||||
```
|
||||
|
||||
**CRITICAL TIMING**: These commands are fast but NEVER CANCEL them. Always wait for completion.
|
||||
|
||||
### Development Environment
|
||||
|
||||
```bash
|
||||
# Start both backend and frontend (recommended for most development)
|
||||
pnpm dev # Backend on :3001, Frontend on :5173
|
||||
|
||||
# OR start separately (required on Windows, optional on Linux/macOS)
|
||||
# Terminal 1: Backend only
|
||||
pnpm backend:dev # Runs on port 3000 (or PORT env var)
|
||||
|
||||
# Terminal 2: Frontend only
|
||||
pnpm frontend:dev # Runs on port 5173, proxies API to backend
|
||||
```
|
||||
|
||||
**NEVER CANCEL**: Development servers may take 10-15 seconds to fully initialize all MCP servers.
|
||||
|
||||
### Build Commands (Production)
|
||||
|
||||
```bash
|
||||
# Full production build - takes ~10 seconds total
|
||||
pnpm build # NEVER CANCEL - Set timeout to 60+ seconds
|
||||
|
||||
# Individual builds
|
||||
pnpm backend:build # TypeScript compilation - ~5 seconds
|
||||
pnpm frontend:build # Vite build - ~5 seconds
|
||||
|
||||
# Start production server
|
||||
pnpm start # Requires dist/ and frontend/dist/ to exist
|
||||
```
|
||||
|
||||
### Testing and Validation
|
||||
|
||||
```bash
|
||||
# Run all tests - takes ~16 seconds with 73 tests
|
||||
pnpm test:ci # NEVER CANCEL - Set timeout to 60+ seconds
|
||||
|
||||
# Development testing
|
||||
pnpm test # Interactive mode
|
||||
pnpm test:watch # Watch mode for development
|
||||
pnpm test:coverage # With coverage report
|
||||
|
||||
# Code quality
|
||||
pnpm lint # ESLint - ~3 seconds
|
||||
pnpm format # Prettier formatting - ~3 seconds
|
||||
```
|
||||
|
||||
**CRITICAL**: All tests MUST pass before committing. Do not modify tests to make them pass unless specifically required for your changes.
|
||||
|
||||
## Manual Validation Requirements
|
||||
|
||||
**ALWAYS perform these validation steps after making changes:**
|
||||
|
||||
### 1. Basic Application Functionality
|
||||
|
||||
```bash
|
||||
# Start the application
|
||||
pnpm dev
|
||||
|
||||
# Verify backend responds (in another terminal)
|
||||
curl http://localhost:3000/api/health
|
||||
# Expected: Should return health status
|
||||
|
||||
# Verify frontend serves
|
||||
curl -I http://localhost:3000/
|
||||
# Expected: HTTP 200 OK with HTML content
|
||||
```
|
||||
|
||||
### 2. MCP Server Integration Test
|
||||
|
||||
```bash
|
||||
# Check MCP servers are loading (look for log messages)
|
||||
# Expected log output should include:
|
||||
# - "Successfully connected client for server: [name]"
|
||||
# - "Successfully listed [N] tools for server: [name]"
|
||||
# - Some servers may fail due to missing API keys (normal in dev)
|
||||
```
|
||||
|
||||
### 3. Build Verification
|
||||
|
||||
```bash
|
||||
# Verify production build works
|
||||
pnpm build
|
||||
node scripts/verify-dist.js
|
||||
# Expected: "✅ Verification passed! Frontend and backend dist files are present."
|
||||
```
|
||||
|
||||
**NEVER skip these validation steps**. If any fail, debug and fix before proceeding.
|
||||
|
||||
## Project Structure and Key Files
|
||||
|
||||
### Critical Backend Files
|
||||
|
||||
- `src/index.ts` - Application entry point
|
||||
- `src/server.ts` - Express server setup and middleware
|
||||
- `src/services/mcpService.ts` - **Core MCP server management logic**
|
||||
- `src/config/index.ts` - Configuration management
|
||||
- `src/routes/` - HTTP route definitions
|
||||
- `src/controllers/` - HTTP request handlers
|
||||
- `src/dao/` - Data access layer (supports JSON file & PostgreSQL)
|
||||
- `src/db/` - TypeORM entities & repositories (for PostgreSQL mode)
|
||||
- `src/types/index.ts` - TypeScript type definitions
|
||||
|
||||
### DAO Layer (Dual Data Source)
|
||||
|
||||
MCPHub supports **JSON file** (default) and **PostgreSQL** storage:
|
||||
|
||||
- Set `USE_DB=true` + `DB_URL=postgresql://...` to use database
|
||||
- When modifying data structures, update: `src/types/`, `src/dao/`, `src/db/entities/`, `src/db/repositories/`, `src/utils/migration.ts`
|
||||
- See `AGENTS.md` for detailed DAO modification checklist
|
||||
|
||||
### Critical Frontend Files
|
||||
|
||||
- `frontend/src/` - React application source
|
||||
- `frontend/src/pages/` - Page components (development entry point)
|
||||
- `frontend/src/components/` - Reusable UI components
|
||||
- `frontend/src/utils/fetchInterceptor.js` - Backend API interaction
|
||||
|
||||
### Configuration Files
|
||||
|
||||
- `mcp_settings.json` - **MCP server definitions and user accounts**
|
||||
- `package.json` - Dependencies and scripts
|
||||
- `tsconfig.json` - TypeScript configuration
|
||||
- `jest.config.cjs` - Test configuration
|
||||
- `.eslintrc.json` - Linting rules
|
||||
|
||||
### Docker and Deployment
|
||||
|
||||
- `Dockerfile` - Multi-stage build with Python base + Node.js
|
||||
- `entrypoint.sh` - Docker startup script
|
||||
- `bin/cli.js` - NPM package CLI entry point
|
||||
|
||||
## Development Process and Conventions
|
||||
|
||||
### Code Style Requirements
|
||||
|
||||
- **ESM modules**: Always use `.js` extensions in imports, not `.ts`
|
||||
- **English only**: All code comments must be written in English
|
||||
- **TypeScript strict**: Follow strict type checking rules
|
||||
- **Import style**: `import { something } from './file.js'` (note .js extension)
|
||||
|
||||
### Key Configuration Notes
|
||||
|
||||
- **MCP servers**: Defined in `mcp_settings.json` with command/args
|
||||
- **Endpoints**: `/mcp/{group|server}` and `/mcp/$smart` for routing
|
||||
- **i18n**: Frontend uses react-i18next with files in `locales/` folder
|
||||
- **Authentication**: JWT tokens with bcrypt password hashing
|
||||
- **Default credentials**: admin/admin123 (configured in mcp_settings.json)
|
||||
|
||||
### Development Entry Points
|
||||
|
||||
- **Add MCP server**: Modify `mcp_settings.json` and restart
|
||||
- **New API endpoint**: Add route in `src/routes/`, controller in `src/controllers/`
|
||||
- **Frontend feature**: Start from `frontend/src/pages/` or `frontend/src/components/`
|
||||
- **Add tests**: Follow patterns in `tests/` directory
|
||||
|
||||
### Common Development Tasks
|
||||
|
||||
#### Adding a new MCP server:
|
||||
|
||||
1. Add server definition to `mcp_settings.json`
|
||||
2. Restart backend to load new server
|
||||
3. Check logs for successful connection
|
||||
4. Test via dashboard or API endpoints
|
||||
|
||||
#### API development:
|
||||
|
||||
1. Define route in `src/routes/`
|
||||
2. Implement controller in `src/controllers/`
|
||||
3. Add types in `src/types/index.ts` if needed
|
||||
4. Write tests in `tests/controllers/`
|
||||
|
||||
#### Frontend development:
|
||||
|
||||
1. Create/modify components in `frontend/src/components/`
|
||||
2. Add pages in `frontend/src/pages/`
|
||||
3. Update routing if needed
|
||||
4. Test in development mode with `pnpm frontend:dev`
|
||||
|
||||
#### Documentation:
|
||||
|
||||
1. Update or add docs in `docs/` folder
|
||||
2. Ensure README.md reflects any major changes
|
||||
|
||||
## Validation and CI Requirements
|
||||
|
||||
### Before Committing - ALWAYS Run:
|
||||
|
||||
```bash
|
||||
pnpm lint # Must pass - ~3 seconds
|
||||
pnpm backend:build # Must compile - ~5 seconds
|
||||
pnpm test:ci # All tests must pass - ~16 seconds
|
||||
pnpm build # Full build must work - ~10 seconds
|
||||
```
|
||||
|
||||
**CRITICAL**: CI will fail if any of these commands fail. Fix issues locally first.
|
||||
|
||||
### CI Pipeline (.github/workflows/ci.yml)
|
||||
|
||||
- Runs on Node.js 20.x
|
||||
- Tests: linting, type checking, unit tests with coverage
|
||||
- **NEVER CANCEL**: CI builds may take 2-3 minutes total
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
- **"uvx command not found"**: Some MCP servers require `uvx` (Python package manager) - this is expected in development
|
||||
- **Port already in use**: Change PORT environment variable or kill existing processes
|
||||
- **Frontend not loading**: Ensure frontend was built with `pnpm frontend:build`
|
||||
- **MCP server connection failed**: Check server command/args in `mcp_settings.json`
|
||||
|
||||
### Build Failures
|
||||
|
||||
- **TypeScript errors**: Run `pnpm backend:build` to see compilation errors
|
||||
- **Test failures**: Run `pnpm test:verbose` for detailed test output
|
||||
- **Lint errors**: Run `pnpm lint` and fix reported issues
|
||||
|
||||
### Development Issues
|
||||
|
||||
- **Backend not starting**: Check for port conflicts, verify `mcp_settings.json` syntax
|
||||
- **Frontend proxy errors**: Ensure backend is running before starting frontend
|
||||
- **Hot reload not working**: Restart development server
|
||||
|
||||
## Performance Notes
|
||||
|
||||
- **Install time**: pnpm install takes ~30 seconds
|
||||
- **Build time**: Full build takes ~10 seconds
|
||||
- **Test time**: Complete test suite takes ~16 seconds
|
||||
- **Startup time**: Backend initialization takes 10-15 seconds (MCP server connections)
|
||||
|
||||
**Remember**: NEVER CANCEL any build or test commands. Always wait for completion even if they seem slow.
|
||||
17
.github/workflows/build.yml
vendored
@@ -8,6 +8,9 @@ on:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
strategy:
|
||||
matrix:
|
||||
variant: ${{ startsWith(github.ref, 'refs/tags/') && fromJSON('["base", "full"]') || fromJSON('["base"]') }}
|
||||
@@ -30,16 +33,27 @@ jobs:
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
if: endsWith(github.repository, 'mcphub')
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
if: endsWith(github.repository, 'mcphubx')
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Docker metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: samanhappy/mcphub
|
||||
images: |
|
||||
${{ endsWith(github.repository, 'mcphub') && github.repository || '' }}
|
||||
${{ endsWith(github.repository, 'mcphubx') && format('ghcr.io/{0}', github.repository) || '' }}
|
||||
tags: |
|
||||
type=raw,value=edge${{ matrix.variant == 'full' && '-full' || '' }},enable=${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
|
||||
type=semver,pattern={{version}}${{ matrix.variant == 'full' && '-full' || '' }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
|
||||
@@ -48,6 +62,7 @@ jobs:
|
||||
latest=false
|
||||
|
||||
- name: Build and Push Docker Image
|
||||
if: endsWith(github.repository, 'mcphub') || endsWith(github.repository, 'mcphubx')
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
|
||||
112
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
name: CI/CD Pipeline
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, develop]
|
||||
pull_request:
|
||||
branches: [main, develop]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [20.x]
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Enable Corepack
|
||||
run: corepack enable
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Run linter
|
||||
run: pnpm lint
|
||||
|
||||
- name: Run type checking
|
||||
run: pnpm backend:build
|
||||
|
||||
- name: Run tests
|
||||
run: pnpm test:ci
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
file: ./coverage/lcov.info
|
||||
flags: unittests
|
||||
name: codecov-umbrella
|
||||
|
||||
# build:
|
||||
# runs-on: ubuntu-latest
|
||||
# needs: test
|
||||
|
||||
# steps:
|
||||
# - name: Checkout code
|
||||
# uses: actions/checkout@v4
|
||||
|
||||
# - name: Setup Node.js
|
||||
# uses: actions/setup-node@v4
|
||||
# with:
|
||||
# node-version: '20.x'
|
||||
|
||||
# - name: Enable Corepack
|
||||
# run: corepack enable
|
||||
|
||||
# - name: Install dependencies
|
||||
# run: pnpm install --frozen-lockfile
|
||||
|
||||
# - name: Build application
|
||||
# run: pnpm build
|
||||
|
||||
# - name: Verify build artifacts
|
||||
# run: node scripts/verify-dist.js
|
||||
|
||||
# integration-test:
|
||||
# runs-on: ubuntu-latest
|
||||
# needs: test
|
||||
|
||||
# services:
|
||||
# postgres:
|
||||
# image: postgres:15
|
||||
# env:
|
||||
# POSTGRES_PASSWORD: postgres
|
||||
# POSTGRES_DB: mcphub_test
|
||||
# options: >-
|
||||
# --health-cmd pg_isready
|
||||
# --health-interval 10s
|
||||
# --health-timeout 5s
|
||||
# --health-retries 5
|
||||
|
||||
# steps:
|
||||
# - name: Checkout code
|
||||
# uses: actions/checkout@v4
|
||||
|
||||
# - name: Setup Node.js
|
||||
# uses: actions/setup-node@v4
|
||||
# with:
|
||||
# node-version: '20.x'
|
||||
|
||||
# - name: Enable Corepack
|
||||
# run: corepack enable
|
||||
|
||||
# - name: Install dependencies
|
||||
# run: pnpm install --frozen-lockfile
|
||||
|
||||
# - name: Build application
|
||||
# run: pnpm build
|
||||
|
||||
# - name: Run integration tests
|
||||
# run: |
|
||||
# export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mcphub_test"
|
||||
# node test-integration.ts
|
||||
# env:
|
||||
# NODE_ENV: test
|
||||
1
.github/workflows/npm-publish.yml
vendored
@@ -7,6 +7,7 @@ on:
|
||||
jobs:
|
||||
publish-npm:
|
||||
runs-on: ubuntu-latest
|
||||
if: endsWith(github.repository, 'mcphub')
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
4
.gitignore
vendored
@@ -2,6 +2,7 @@
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
package-lock.json
|
||||
|
||||
# production
|
||||
dist
|
||||
@@ -24,3 +25,6 @@ yarn-error.log*
|
||||
.vscode/
|
||||
*.log
|
||||
coverage/
|
||||
|
||||
data/
|
||||
temp-test-config/
|
||||
@@ -4,4 +4,4 @@
|
||||
"singleQuote": true,
|
||||
"printWidth": 100,
|
||||
"tabWidth": 2
|
||||
}
|
||||
}
|
||||
78
AGENTS.md
Normal file
@@ -0,0 +1,78 @@
|
||||
# Repository Guidelines
|
||||
|
||||
These notes align current contributors around the code layout, daily commands, and collaboration habits that keep `@samanhappy/mcphub` moving quickly.
|
||||
|
||||
## Project Structure & Module Organization
|
||||
|
||||
- Backend services live in `src`, grouped by responsibility (`controllers/`, `services/`, `dao/`, `routes/`, `utils/`), with `server.ts` orchestrating HTTP bootstrap.
|
||||
- `frontend/src` contains the Vite + React dashboard; `frontend/public` hosts static assets and translations sit in `locales/`.
|
||||
- Jest-aware test code is split between colocated specs (`src/**/*.{test,spec}.ts`) and higher-level suites in `tests/`; use `tests/utils/` helpers when exercising the CLI or SSE flows.
|
||||
- Build artifacts and bundles are generated into `dist/`, `frontend/dist/`, and `coverage/`; never edit these manually.
|
||||
|
||||
## Build, Test, and Development Commands
|
||||
|
||||
- `pnpm dev` runs backend (`tsx watch src/index.ts`) and frontend (`vite`) together for local iteration.
|
||||
- `pnpm backend:dev`, `pnpm frontend:dev`, and `pnpm frontend:preview` target each surface independently; prefer them when debugging one stack.
|
||||
- `pnpm build` executes `pnpm backend:build` (TypeScript to `dist/`) and `pnpm frontend:build`; run before release or publishing.
|
||||
- `pnpm test`, `pnpm test:watch`, and `pnpm test:coverage` drive Jest; `pnpm lint` and `pnpm format` enforce style via ESLint and Prettier.
|
||||
|
||||
## Coding Style & Naming Conventions
|
||||
|
||||
- TypeScript everywhere; default to 2-space indentation and single quotes, letting Prettier settle formatting. ESLint configuration assumes ES modules.
|
||||
- Name services and data access layers with suffixes (`UserService`, `AuthDao`), React components and files in `PascalCase`, and utility modules in `camelCase`.
|
||||
- Keep DTOs and shared types in `src/types` to avoid duplication; re-export through index files only when it clarifies imports.
|
||||
|
||||
## Testing Guidelines
|
||||
|
||||
- Use Jest with the `ts-jest` ESM preset; place shared setup in `tests/setup.ts` and mock helpers under `tests/utils/`.
|
||||
- Mirror production directory names when adding new suites and end filenames with `.test.ts` or `.spec.ts` for automatic discovery.
|
||||
- Aim to maintain or raise coverage when touching critical flows (auth, OAuth, SSE); add integration tests under `tests/integration/` when touching cross-service logic.
|
||||
|
||||
## Commit & Pull Request Guidelines
|
||||
|
||||
- Follow the existing Conventional Commit pattern (`feat:`, `fix:`, `chore:`, etc.) with imperative, present-tense summaries and optional multi-line context.
|
||||
- Each PR should describe the behavior change, list testing performed, and link issues; include before/after screenshots or GIFs for frontend tweaks.
|
||||
- Re-run `pnpm build` and `pnpm test` before requesting review, and ensure generated artifacts stay out of the diff.
|
||||
|
||||
## DAO Layer & Dual Data Source
|
||||
|
||||
MCPHub supports **JSON file** (default) and **PostgreSQL** storage. Set `USE_DB=true` + `DB_URL` to switch.
|
||||
|
||||
### Key Files
|
||||
|
||||
- `src/types/index.ts` - Core interfaces (`IUser`, `IGroup`, `ServerConfig`, etc.)
|
||||
- `src/dao/*Dao.ts` - DAO interface + JSON implementation
|
||||
- `src/dao/*DaoDbImpl.ts` - Database implementation
|
||||
- `src/db/entities/*.ts` - TypeORM entities
|
||||
- `src/db/repositories/*.ts` - TypeORM repository wrappers
|
||||
- `src/utils/migration.ts` - JSON-to-database migration
|
||||
|
||||
### Modifying Data Structures (CRITICAL)
|
||||
|
||||
When adding/changing fields, update **ALL** these files:
|
||||
|
||||
| Step | File | Action |
|
||||
| ---- | -------------------------- | ---------------------------- |
|
||||
| 1 | `src/types/index.ts` | Add field to interface |
|
||||
| 2 | `src/dao/*Dao.ts` | Update JSON impl if needed |
|
||||
| 3 | `src/db/entities/*.ts` | Add TypeORM `@Column` |
|
||||
| 4 | `src/dao/*DaoDbImpl.ts` | Map field in create/update |
|
||||
| 5 | `src/db/repositories/*.ts` | Update if needed |
|
||||
| 6 | `src/utils/migration.ts` | Include in migration |
|
||||
| 7 | `mcp_settings.json` | Update example if applicable |
|
||||
|
||||
### Data Type Mapping
|
||||
|
||||
| Model | DAO | DB Entity | JSON Path |
|
||||
| -------------- | ----------------- | -------------- | ------------------------ |
|
||||
| `IUser` | `UserDao` | `User` | `settings.users[]` |
|
||||
| `ServerConfig` | `ServerDao` | `Server` | `settings.mcpServers{}` |
|
||||
| `IGroup` | `GroupDao` | `Group` | `settings.groups[]` |
|
||||
| `SystemConfig` | `SystemConfigDao` | `SystemConfig` | `settings.systemConfig` |
|
||||
| `UserConfig` | `UserConfigDao` | `UserConfig` | `settings.userConfigs{}` |
|
||||
|
||||
### Common Pitfalls
|
||||
|
||||
- Forgetting migration script → fields won't migrate to DB
|
||||
- Optional fields need `nullable: true` in entity
|
||||
- Complex objects need `simple-json` column type
|
||||
22
Dockerfile
@@ -2,12 +2,6 @@ FROM python:3.13-slim-bookworm AS base
|
||||
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
||||
|
||||
# 添加 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 \
|
||||
@@ -15,12 +9,6 @@ RUN apt-get update && apt-get install -y curl gnupg git \
|
||||
|
||||
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 && \
|
||||
@@ -34,6 +22,16 @@ RUN if [ "$INSTALL_EXT" = "true" ]; then \
|
||||
else \
|
||||
echo "Skipping Chrome installation on non-amd64 architecture: $ARCH"; \
|
||||
fi; \
|
||||
# Install Docker Engine (includes CLI and daemon) \
|
||||
apt-get update && \
|
||||
apt-get install -y ca-certificates curl iptables && \
|
||||
install -m 0755 -d /etc/apt/keyrings && \
|
||||
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && \
|
||||
chmod a+r /etc/apt/keyrings/docker.asc && \
|
||||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian bookworm stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
|
||||
apt-get update && \
|
||||
apt-get install -y docker-ce docker-ce-cli containerd.io && \
|
||||
apt-get clean && rm -rf /var/lib/apt/lists/*; \
|
||||
fi
|
||||
|
||||
RUN uv tool install mcp-server-fetch
|
||||
|
||||
126
QWEN.md
Normal file
@@ -0,0 +1,126 @@
|
||||
# MCPHub Project Overview
|
||||
|
||||
## Project Summary
|
||||
|
||||
MCPHub is a centralized hub server for managing multiple Model Context Protocol (MCP) servers. It allows organizing these servers into flexible Streamable HTTP (SSE) endpoints, supporting access to all servers, individual servers, or logical server groups. It provides a web dashboard for monitoring and managing servers, along with features like authentication, group-based access control, and Smart Routing using vector semantic search.
|
||||
|
||||
## Technology Stack
|
||||
|
||||
### Backend
|
||||
- **Language:** TypeScript (Node.js)
|
||||
- **Framework:** Express
|
||||
- **Key Libraries:**
|
||||
- `@modelcontextprotocol/sdk`: Core library for MCP interactions.
|
||||
- `typeorm`: ORM for database interactions.
|
||||
- `pg` & `pgvector`: PostgreSQL database and vector support.
|
||||
- `jsonwebtoken` & `bcryptjs`: Authentication (JWT) and password hashing.
|
||||
- `openai`: For embedding generation in Smart Routing.
|
||||
- Various utility and validation libraries (e.g., `dotenv`, `express-validator`, `uuid`).
|
||||
|
||||
### Frontend
|
||||
- **Framework:** React (via Vite)
|
||||
- **Language:** TypeScript
|
||||
- **UI Library:** Tailwind CSS
|
||||
- **Routing:** `react-router-dom`
|
||||
- **Internationalization:** `i18next`
|
||||
- **Component Structure:** Modular components and pages within `frontend/src`.
|
||||
|
||||
### Infrastructure
|
||||
- **Build Tool:** `pnpm` (package manager and script runner).
|
||||
- **Containerization:** Docker (`Dockerfile` provided).
|
||||
- **Process Management:** Not explicitly defined in core files, but likely managed by Docker or host system.
|
||||
|
||||
## Key Features
|
||||
|
||||
- **MCP Server Management:** Configure, start, stop, and monitor multiple upstream MCP servers via `stdio`, `SSE`, or `Streamable HTTP` protocols.
|
||||
- **Centralized Dashboard:** Web UI for server status, group management, user administration, and logs.
|
||||
- **Flexible Endpoints:**
|
||||
- Global MCP/SSE endpoint (`/mcp`, `/sse`) for all enabled servers.
|
||||
- Group-based endpoints (`/mcp/{group}`, `/sse/{group}`).
|
||||
- Server-specific endpoints (`/mcp/{server}`, `/sse/{server}`).
|
||||
- Smart Routing endpoint (`/mcp/$smart`, `/sse/$smart`) using vector search.
|
||||
- **Authentication & Authorization:** JWT-based user authentication with role-based access control (admin/user).
|
||||
- **Group Management:** Logical grouping of servers for targeted access and permission control.
|
||||
- **Smart Routing (Experimental):** Uses pgvector and OpenAI embeddings to semantically search and find relevant tools across all connected servers.
|
||||
- **Configuration:** Managed via `mcp_settings.json`.
|
||||
- **Logging:** Server logs are captured and viewable via the dashboard.
|
||||
- **Marketplace Integration:** Access to a marketplace of MCP servers (`servers.json`).
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
C:\code\mcphub\
|
||||
├───src\ # Backend source code (TypeScript)
|
||||
├───frontend\ # Frontend source code (React/TypeScript)
|
||||
│ ├───src\
|
||||
│ ├───components\ # Reusable UI components
|
||||
│ ├───pages\ # Top-level page components
|
||||
│ ├───contexts\ # React contexts (Auth, Theme, Toast)
|
||||
│ ├───layouts\ # Page layouts
|
||||
│ ├───utils\ # Frontend utilities
|
||||
│ └───...
|
||||
├───dist\ # Compiled backend output
|
||||
├───frontend\dist\ # Compiled frontend output
|
||||
├───tests\ # Backend tests
|
||||
├───docs\ # Documentation
|
||||
├───scripts\ # Utility scripts
|
||||
├───bin\ # CLI entry points
|
||||
├───assets\ # Static assets (e.g., images for README)
|
||||
├───.github\ # GitHub workflows
|
||||
├───.vscode\ # VS Code settings
|
||||
├───mcp_settings.json # Main configuration file for MCP servers and users
|
||||
├───servers.json # Marketplace server definitions
|
||||
├───package.json # Node.js project definition, dependencies, and scripts
|
||||
├───pnpm-lock.yaml # Dependency lock file
|
||||
├───tsconfig.json # TypeScript compiler configuration (Backend)
|
||||
├───README.md # Project documentation
|
||||
├───Dockerfile # Docker image definition
|
||||
└───...
|
||||
```
|
||||
|
||||
## Building and Running
|
||||
|
||||
### Prerequisites
|
||||
- Node.js (>=18.0.0 or >=20.0.0)
|
||||
- pnpm
|
||||
- Python 3.13 (for some upstream servers and uvx)
|
||||
- Docker (optional, for containerized deployment)
|
||||
- PostgreSQL with pgvector (optional, for Smart Routing)
|
||||
|
||||
### Local Development
|
||||
1. Clone the repository.
|
||||
2. Install dependencies: `pnpm install`.
|
||||
3. Start development servers: `pnpm dev`.
|
||||
- This runs `pnpm backend:dev` (Node.js with `tsx watch`) and `pnpm frontend:dev` (Vite dev server) concurrently.
|
||||
- Access the dashboard at `http://localhost:5173` (Vite default) or the configured port/path.
|
||||
|
||||
### Production Build
|
||||
1. Install dependencies: `pnpm install`.
|
||||
2. Build the project: `pnpm build`.
|
||||
- This runs `pnpm backend:build` (TypeScript compilation to `dist/`) and `pnpm frontend:build` (Vite build to `frontend/dist/`).
|
||||
3. Start the production server: `pnpm start`.
|
||||
- This runs `node dist/index.js`.
|
||||
|
||||
### Docker Deployment
|
||||
- Pull the image: `docker pull samanhappy/mcphub`.
|
||||
- Run with default settings: `docker run -p 3000:3000 samanhappy/mcphub`.
|
||||
- Run with custom config: `docker run -p 3000:3000 -v ./mcp_settings.json:/app/mcp_settings.json -v ./data:/app/data samanhappy/mcphub`.
|
||||
- Access the dashboard at `http://localhost:3000`.
|
||||
|
||||
## Configuration
|
||||
|
||||
The main configuration file is `mcp_settings.json`. It defines:
|
||||
- `mcpServers`: A map of server configurations (command, args, env, URL, etc.).
|
||||
- `users`: A list of user accounts (username, hashed password, admin status).
|
||||
- `groups`: A map of server groups.
|
||||
- `systemConfig`: System-wide settings (e.g., proxy, registry, installation options).
|
||||
|
||||
## Development Conventions
|
||||
|
||||
- **Language:** TypeScript for both backend and frontend.
|
||||
- **Backend Style:** Modular structure with clear separation of concerns (controllers, services, models, middlewares, routes, config, utils).
|
||||
- **Frontend Style:** Component-based React architecture with contexts for state management.
|
||||
- **Database:** TypeORM with PostgreSQL is used, leveraging decorators for entity definition.
|
||||
- **Testing:** Uses `jest` for backend testing.
|
||||
- **Linting/Formatting:** Uses `eslint` and `prettier`.
|
||||
- **Scripts:** Defined in `package.json` under the `scripts` section for common tasks (dev, build, start, test, lint, format).
|
||||
119
README.fr.md
Normal file
@@ -0,0 +1,119 @@
|
||||
# MCPHub : Le Hub Unifié pour les Serveurs MCP
|
||||
|
||||
[English](README.md) | Français | [中文版](README.zh.md)
|
||||
|
||||
MCPHub facilite la gestion et la mise à l'échelle de plusieurs serveurs MCP (Model Context Protocol) en les organisant en points de terminaison HTTP streamables (SSE) flexibles, prenant en charge l'accès à tous les serveurs, à des serveurs individuels ou à des groupes de serveurs logiques.
|
||||
|
||||

|
||||
|
||||
## 🌐 Démo en direct et Documentation
|
||||
|
||||
- **Documentation** : [docs.mcphubx.com](https://docs.mcphubx.com/)
|
||||
- **Environnement de démo** : [demo.mcphubx.com](https://demo.mcphubx.com/)
|
||||
|
||||
## 🚀 Fonctionnalités
|
||||
|
||||
- **Gestion centralisée** - Surveillez et contrôlez tous les serveurs MCP depuis un tableau de bord unifié
|
||||
- **Routage flexible** - Accédez à tous les serveurs, groupes spécifiques ou serveurs individuels via HTTP/SSE
|
||||
- **Routage intelligent** - Découverte d'outils propulsée par IA utilisant la recherche sémantique vectorielle ([En savoir plus](https://docs.mcphubx.com/features/smart-routing))
|
||||
- **Configuration à chaud** - Ajoutez, supprimez ou mettez à jour les serveurs sans temps d'arrêt
|
||||
- **Support OAuth 2.0** - Modes client et serveur pour une authentification sécurisée ([En savoir plus](https://docs.mcphubx.com/features/oauth))
|
||||
- **Mode Base de données** - Stockez la configuration dans PostgreSQL pour les environnements de production ([En savoir plus](https://docs.mcphubx.com/configuration/database-configuration))
|
||||
- **Prêt pour Docker** - Déployez instantanément avec la configuration conteneurisée
|
||||
|
||||
## 🔧 Démarrage rapide
|
||||
|
||||
### Configuration
|
||||
|
||||
Créez un fichier `mcp_settings.json` :
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"time": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "time-mcp"]
|
||||
},
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
📖 Consultez le [Guide de configuration](https://docs.mcphubx.com/configuration/mcp-settings) pour les options complètes incluant OAuth, les variables d'environnement, et plus.
|
||||
|
||||
### Déploiement avec Docker
|
||||
|
||||
```bash
|
||||
# Exécutez avec une configuration personnalisée (recommandé)
|
||||
docker run -p 3000:3000 -v ./mcp_settings.json:/app/mcp_settings.json -v ./data:/app/data samanhappy/mcphub
|
||||
|
||||
# Ou exécutez avec les paramètres par défaut
|
||||
docker run -p 3000:3000 samanhappy/mcphub
|
||||
```
|
||||
|
||||
### Accéder au tableau de bord
|
||||
|
||||
Ouvrez `http://localhost:3000` et connectez-vous avec les identifiants par défaut : `admin` / `admin123`
|
||||
|
||||
### Connecter les clients IA
|
||||
|
||||
Connectez les clients IA (Claude Desktop, Cursor, etc.) via :
|
||||
|
||||
```
|
||||
http://localhost:3000/mcp # Tous les serveurs
|
||||
http://localhost:3000/mcp/{group} # Groupe spécifique
|
||||
http://localhost:3000/mcp/{server} # Serveur spécifique
|
||||
http://localhost:3000/mcp/$smart # Routage intelligent
|
||||
```
|
||||
|
||||
📖 Consultez la [Référence API](https://docs.mcphubx.com/api-reference) pour la documentation détaillée des points de terminaison.
|
||||
|
||||
## 📚 Documentation
|
||||
|
||||
| Sujet | Description |
|
||||
| ------------------------------------------------------------------------------------- | ------------------------------------------- |
|
||||
| [Démarrage rapide](https://docs.mcphubx.com/quickstart) | Commencez en 5 minutes |
|
||||
| [Configuration](https://docs.mcphubx.com/configuration/mcp-settings) | Options de configuration du serveur MCP |
|
||||
| [Mode Base de données](https://docs.mcphubx.com/configuration/database-configuration) | Configuration PostgreSQL pour la production |
|
||||
| [OAuth](https://docs.mcphubx.com/features/oauth) | Configuration client et serveur OAuth 2.0 |
|
||||
| [Routage intelligent](https://docs.mcphubx.com/features/smart-routing) | Découverte d'outils propulsée par IA |
|
||||
| [Configuration Docker](https://docs.mcphubx.com/configuration/docker-setup) | Guide de déploiement Docker |
|
||||
|
||||
## 🧑💻 Développement local
|
||||
|
||||
```bash
|
||||
git clone https://github.com/samanhappy/mcphub.git
|
||||
cd mcphub
|
||||
pnpm install
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
> Pour les utilisateurs Windows, démarrez le backend et le frontend séparément : `pnpm backend:dev`, `pnpm frontend:dev`
|
||||
|
||||
📖 Consultez le [Guide de développement](https://docs.mcphubx.com/development) pour les instructions de configuration détaillées.
|
||||
|
||||
## 🔍 Stack technique
|
||||
|
||||
- **Backend** : Node.js, Express, TypeScript
|
||||
- **Frontend** : React, Vite, Tailwind CSS
|
||||
- **Authentification** : JWT & bcrypt
|
||||
- **Protocole** : Model Context Protocol SDK
|
||||
|
||||
## 👥 Contribuer
|
||||
|
||||
Les contributions sont les bienvenues ! Rejoignez notre [communauté Discord](https://discord.gg/qMKNsn5Q) pour des discussions et du support.
|
||||
|
||||
## ❤️ Sponsor
|
||||
|
||||
[](https://ko-fi.com/samanhappy)
|
||||
|
||||
## 🌟 Historique des étoiles
|
||||
|
||||
[](https://www.star-history.com/#samanhappy/mcphub&Date)
|
||||
|
||||
## 📄 Licence
|
||||
|
||||
Sous licence [Apache 2.0 License](LICENSE).
|
||||
195
README.md
@@ -1,178 +1,86 @@
|
||||
# MCPHub: The Unified Hub for Model Context Protocol (MCP) Servers
|
||||
|
||||
English | [中文版](README.zh.md)
|
||||
English | [Français](README.fr.md) | [中文版](README.zh.md)
|
||||
|
||||
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.
|
||||
|
||||

|
||||
|
||||
## 🌐 Live Demo & Docs
|
||||
|
||||
- **Documentation**: [docs.mcphubx.com](https://docs.mcphubx.com/)
|
||||
- **Demo Environment**: [demo.mcphubx.com](https://demo.mcphubx.com/)
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- **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.
|
||||
- **Group-Based Access Control**: Organize servers into customizable groups for streamlined permissions management.
|
||||
- **Secure Authentication**: Built-in user management with role-based access powered by JWT and bcrypt.
|
||||
- **Docker-Ready**: Deploy instantly with our containerized setup.
|
||||
- **Centralized Management** - Monitor and control all MCP servers from a unified dashboard
|
||||
- **Flexible Routing** - Access all servers, specific groups, or individual servers via HTTP/SSE
|
||||
- **Smart Routing** - AI-powered tool discovery using vector semantic search ([Learn more](https://docs.mcphubx.com/features/smart-routing))
|
||||
- **Hot-Swappable Config** - Add, remove, or update servers without downtime
|
||||
- **OAuth 2.0 Support** - Both client and server modes for secure authentication ([Learn more](https://docs.mcphubx.com/features/oauth))
|
||||
- **Database Mode** - Store configuration in PostgreSQL for production environments ([Learn more](https://docs.mcphubx.com/configuration/database-configuration))
|
||||
- **Docker-Ready** - Deploy instantly with containerized setup
|
||||
|
||||
## 🔧 Quick Start
|
||||
|
||||
### Configuration
|
||||
|
||||
Create a `mcp_settings.json` file to customize your server settings:
|
||||
Create a `mcp_settings.json` file:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"amap": {
|
||||
"time": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@amap/amap-maps-mcp-server"],
|
||||
"env": {
|
||||
"AMAP_MAPS_API_KEY": "your-api-key"
|
||||
}
|
||||
},
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"]
|
||||
"args": ["-y", "time-mcp"]
|
||||
},
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"]
|
||||
},
|
||||
"slack": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-slack"],
|
||||
"env": {
|
||||
"SLACK_BOT_TOKEN": "your-bot-token",
|
||||
"SLACK_TEAM_ID": "your-team-id"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
📖 See [Configuration Guide](https://docs.mcphubx.com/configuration/mcp-settings) for full options including OAuth, environment variables, and more.
|
||||
|
||||
### Docker Deployment
|
||||
|
||||
**Recommended**: Mount your custom config:
|
||||
|
||||
```bash
|
||||
docker run -p 3000:3000 -v $(pwd)/mcp_settings.json:/app/mcp_settings.json samanhappy/mcphub
|
||||
```
|
||||
# Run with custom config (recommended)
|
||||
docker run -p 3000:3000 -v ./mcp_settings.json:/app/mcp_settings.json -v ./data:/app/data samanhappy/mcphub
|
||||
|
||||
or run with default settings:
|
||||
|
||||
```bash
|
||||
# Or run with default settings
|
||||
docker run -p 3000:3000 samanhappy/mcphub
|
||||
```
|
||||
|
||||
### Access the Dashboard
|
||||
### Access Dashboard
|
||||
|
||||
Open `http://localhost:3000` and log in with your credentials.
|
||||
Open `http://localhost:3000` and log in with default credentials: `admin` / `admin123`
|
||||
|
||||
> **Note**: Default credentials are `admin` / `admin123`.
|
||||
### Connect AI Clients
|
||||
|
||||
**Dashboard Overview**:
|
||||
|
||||
- Live status of all MCP servers
|
||||
- Enable/disable or reconfigure servers
|
||||
- Group management for organizing servers
|
||||
- User administration for access control
|
||||
|
||||
### 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:
|
||||
Connect AI clients (Claude Desktop, Cursor, etc.) via:
|
||||
|
||||
```
|
||||
http://localhost:3000/mcp
|
||||
http://localhost:3000/mcp # All servers
|
||||
http://localhost:3000/mcp/{group} # Specific group
|
||||
http://localhost:3000/mcp/{server} # Specific server
|
||||
http://localhost:3000/mcp/$smart # Smart routing
|
||||
```
|
||||
|
||||
This endpoint provides a unified streamable HTTP interface for all your MCP servers. It allows you to:
|
||||
📖 See [API Reference](https://docs.mcphubx.com/api-reference) for detailed endpoint documentation.
|
||||
|
||||
- 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
|
||||
## 📚 Documentation
|
||||
|
||||
**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:
|
||||
|
||||
```
|
||||
http://localhost:3000/sse
|
||||
```
|
||||
|
||||
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/{group}
|
||||
```
|
||||
|
||||
For direct access to individual servers, use the server-specific SSE endpoint:
|
||||
|
||||
```
|
||||
http://localhost:3000/sse/{server}
|
||||
```
|
||||
| Topic | Description |
|
||||
| ------------------------------------------------------------------------------ | --------------------------------- |
|
||||
| [Quick Start](https://docs.mcphubx.com/quickstart) | Get started in 5 minutes |
|
||||
| [Configuration](https://docs.mcphubx.com/configuration/mcp-settings) | MCP server configuration options |
|
||||
| [Database Mode](https://docs.mcphubx.com/configuration/database-configuration) | PostgreSQL setup for production |
|
||||
| [OAuth](https://docs.mcphubx.com/features/oauth) | OAuth 2.0 client and server setup |
|
||||
| [Smart Routing](https://docs.mcphubx.com/features/smart-routing) | AI-powered tool discovery |
|
||||
| [Docker Setup](https://docs.mcphubx.com/configuration/docker-setup) | Docker deployment guide |
|
||||
|
||||
## 🧑💻 Local Development
|
||||
|
||||
@@ -183,19 +91,9 @@ pnpm install
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
This starts both frontend and backend in development mode with hot-reloading.
|
||||
> For Windows users, start backend and frontend separately: `pnpm backend:dev`, `pnpm frontend:dev`
|
||||
|
||||
> 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
|
||||
```
|
||||
📖 See [Development Guide](https://docs.mcphubx.com/development) for detailed setup instructions.
|
||||
|
||||
## 🔍 Tech Stack
|
||||
|
||||
@@ -206,19 +104,10 @@ proxy_buffering off
|
||||
|
||||
## 👥 Contributing
|
||||
|
||||
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.
|
||||
Contributions welcome! See 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
|
||||
|
||||
191
README.zh.md
@@ -1,178 +1,86 @@
|
||||
# MCPHub:一站式 MCP 服务器聚合平台
|
||||
|
||||
[English Version](README.md) | 中文版
|
||||
[English](README.md) | [Français](README.fr.md) | 中文版
|
||||
|
||||
MCPHub 通过将多个 MCP(Model Context Protocol)服务器组织为灵活的流式 HTTP(SSE)端点,简化了管理与扩展工作。系统支持按需访问全部服务器、单个服务器或按场景分组的服务器集合。
|
||||
|
||||

|
||||
|
||||
## 🌐 在线文档与演示
|
||||
|
||||
- **文档地址**: [docs.mcphubx.com](https://docs.mcphubx.com/)
|
||||
- **演示环境**: [demo.mcphubx.com](https://demo.mcphubx.com/)
|
||||
|
||||
## 🚀 功能亮点
|
||||
|
||||
- **广泛的 MCP 服务器支持**:无缝集成任何 MCP 服务器,配置简单。
|
||||
- **集中式管理控制台**:在一个简洁的 Web UI 中实时监控所有服务器的状态和性能指标。
|
||||
- **灵活的协议兼容**:完全支持 stdio 和 SSE 两种 MCP 协议。
|
||||
- **热插拔式配置**:在运行时动态添加、移除或更新服务器配置,无需停机。
|
||||
- **基于分组的访问控制**:自定义分组并管理服务器访问权限。
|
||||
- **安全认证机制**:内置用户管理,基于 JWT 和 bcrypt,实现角色权限控制。
|
||||
- **Docker 就绪**:提供容器化镜像,快速部署。
|
||||
- **集中式管理** - 在统一控制台中监控和管理所有 MCP 服务器
|
||||
- **灵活路由** - 通过 HTTP/SSE 访问所有服务器、特定分组或单个服务器
|
||||
- **智能路由** - 基于向量语义搜索的 AI 工具发现 ([了解更多](https://docs.mcphubx.com/zh/features/smart-routing))
|
||||
- **热插拔配置** - 无需停机即可添加、移除或更新服务器
|
||||
- **OAuth 2.0 支持** - 客户端和服务端模式,实现安全认证 ([了解更多](https://docs.mcphubx.com/zh/features/oauth))
|
||||
- **数据库模式** - 将配置存储在 PostgreSQL 中,适用于生产环境 ([了解更多](https://docs.mcphubx.com/zh/configuration/database-configuration))
|
||||
- **Docker 就绪** - 容器化部署,开箱即用
|
||||
|
||||
## 🔧 快速开始
|
||||
|
||||
### 配置
|
||||
|
||||
通过创建 `mcp_settings.json` 自定义服务器设置:
|
||||
创建 `mcp_settings.json` 文件:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"amap": {
|
||||
"time": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@amap/amap-maps-mcp-server"],
|
||||
"env": {
|
||||
"AMAP_MAPS_API_KEY": "your-api-key"
|
||||
}
|
||||
},
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["@playwright/mcp@latest", "--headless"]
|
||||
"args": ["-y", "time-mcp"]
|
||||
},
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"]
|
||||
},
|
||||
"slack": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-slack"],
|
||||
"env": {
|
||||
"SLACK_BOT_TOKEN": "your-bot-token",
|
||||
"SLACK_TEAM_ID": "your-team-id"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
📖 查看[配置指南](https://docs.mcphubx.com/zh/configuration/mcp-settings)了解完整选项,包括 OAuth、环境变量等。
|
||||
|
||||
### Docker 部署
|
||||
|
||||
**推荐**:挂载自定义配置:
|
||||
|
||||
```bash
|
||||
docker run -p 3000:3000 -v $(pwd)/mcp_settings.json:/app/mcp_settings.json samanhappy/mcphub
|
||||
```
|
||||
# 挂载自定义配置运行(推荐)
|
||||
docker run -p 3000:3000 -v ./mcp_settings.json:/app/mcp_settings.json -v ./data:/app/data samanhappy/mcphub
|
||||
|
||||
或使用默认配置运行:
|
||||
|
||||
```bash
|
||||
# 或使用默认配置运行
|
||||
docker run -p 3000:3000 samanhappy/mcphub
|
||||
```
|
||||
|
||||
### 访问控制台
|
||||
|
||||
打开 `http://localhost:3000`,使用您的账号登录。
|
||||
打开 `http://localhost:3000`,使用默认账号登录:`admin` / `admin123`
|
||||
|
||||
> **提示**:默认用户名/密码为 `admin` / `admin123`。
|
||||
### 连接 AI 客户端
|
||||
|
||||
**控制台功能**:
|
||||
|
||||
- 实时监控所有 MCP 服务器状态
|
||||
- 启用/禁用或重新配置服务器
|
||||
- 分组管理,组织服务器访问
|
||||
- 用户管理,设定权限
|
||||
|
||||
### 支持流式的 HTTP 端点
|
||||
|
||||
> 截至目前,各家 AI 客户端对流式的 HTTP 端点支持不一,如果遇到问题,可以使用 SSE 端点或者等待更新。
|
||||
|
||||
通过以下地址连接 AI 客户端(如 Claude Desktop、Cursor、DeepChat 等):
|
||||
通过以下地址连接 AI 客户端(Claude Desktop、Cursor 等):
|
||||
|
||||
```
|
||||
http://localhost:3000/mcp
|
||||
http://localhost:3000/mcp # 所有服务器
|
||||
http://localhost:3000/mcp/{group} # 特定分组
|
||||
http://localhost:3000/mcp/{server} # 特定服务器
|
||||
http://localhost:3000/mcp/$smart # 智能路由
|
||||
```
|
||||
|
||||
这个端点为所有 MCP 服务器提供统一的流式 HTTP 接口。它允许您:
|
||||
📖 查看 [API 参考](https://docs.mcphubx.com/zh/api-reference)了解详细的端点文档。
|
||||
|
||||
- 向任何配置的 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 等):
|
||||
|
||||
```
|
||||
http://localhost:3000/sse
|
||||
```
|
||||
|
||||
要启用智能路由,请使用:
|
||||
|
||||
```
|
||||
http://localhost:3000/sse/$smart
|
||||
```
|
||||
|
||||
要针对特定服务器分组进行访问,请使用基于分组的 SSE 端点:
|
||||
|
||||
```
|
||||
http://localhost:3000/sse/{group}
|
||||
```
|
||||
|
||||
要针对特定服务器进行访问,请使用以下格式:
|
||||
|
||||
```
|
||||
http://localhost:3000/sse/{server}
|
||||
```
|
||||
| 主题 | 描述 |
|
||||
| ------------------------------------------------------------------------------ | ---------------------------- |
|
||||
| [快速开始](https://docs.mcphubx.com/zh/quickstart) | 5 分钟快速上手 |
|
||||
| [配置指南](https://docs.mcphubx.com/zh/configuration/mcp-settings) | MCP 服务器配置选项 |
|
||||
| [数据库模式](https://docs.mcphubx.com/zh/configuration/database-configuration) | PostgreSQL 生产环境配置 |
|
||||
| [OAuth](https://docs.mcphubx.com/zh/features/oauth) | OAuth 2.0 客户端和服务端配置 |
|
||||
| [智能路由](https://docs.mcphubx.com/zh/features/smart-routing) | AI 驱动的工具发现 |
|
||||
| [Docker 部署](https://docs.mcphubx.com/zh/configuration/docker-setup) | Docker 部署指南 |
|
||||
|
||||
## 🧑💻 本地开发
|
||||
|
||||
@@ -183,19 +91,9 @@ pnpm install
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
此命令将在开发模式下启动前后端,并启用热重载。
|
||||
> Windows 用户需分别启动后端和前端:`pnpm backend:dev`,`pnpm frontend:dev`
|
||||
|
||||
> 针对 Windows 用户,可能需要分别启动后端服务器和前端:`pnpm backend:dev`,`pnpm frontend:dev`。
|
||||
|
||||
## 🛠️ 常见问题
|
||||
|
||||
### 使用 nginx 反向代理
|
||||
|
||||
如果您在使用 nginx 反向代理 MCPHub,请确保在 nginx 配置中添加以下内容:
|
||||
|
||||
```nginx
|
||||
proxy_buffering off
|
||||
```
|
||||
📖 查看[开发指南](https://docs.mcphubx.com/zh/development)了解详细设置说明。
|
||||
|
||||
## 🔍 技术栈
|
||||
|
||||
@@ -206,13 +104,6 @@ proxy_buffering off
|
||||
|
||||
## 👥 贡献指南
|
||||
|
||||
期待您的贡献!
|
||||
|
||||
- 新功能与优化
|
||||
- 文档完善
|
||||
- Bug 报告与修复
|
||||
- 翻译与建议
|
||||
|
||||
欢迎加入企微交流共建群,由于群人数限制,有兴趣的同学可以扫码添加管理员为好友后拉入群聊。
|
||||
|
||||
<img src="assets/wexin.png" width="350">
|
||||
@@ -223,7 +114,7 @@ proxy_buffering off
|
||||
|
||||
## 致谢
|
||||
|
||||
感谢以下人员的赞赏:小白、琛。你们的支持是我继续前进的动力!
|
||||
感谢以下朋友的赞赏:小白、唐秀川、琛、孔、黄祥取、兰军飞、无名之辈、Kyle,以及其他匿名支持者。
|
||||
|
||||
## 🌟 Star 历史趋势
|
||||
|
||||
|
||||
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 |
@@ -48,11 +48,11 @@ MCPHub 已内置多个常用 MCP 服务,如高德地图、GitHub、Slack、Fet
|
||||
|
||||

|
||||
|
||||
点击保存后,MCP Hub 将自动重启高德地图的 MCP 服务,使新配置生效。
|
||||
点击保存后,MCPHub 将自动重启高德地图的 MCP 服务,使新配置生效。
|
||||
|
||||
### 配置 MCP Hub SSE
|
||||
### 配置 MCPHub SSE
|
||||
|
||||
MCP Hub 提供了单一聚合的 MCP Server SSE 端点:`http://localhost:3000/sse`,可在任意支持 MCP 的客户端中配置使用。这里我们选择开源的 Cherry Studio 进行演示。
|
||||
MCPHub 提供了单一聚合的 MCP Server SSE 端点:`http://localhost:3000/sse`,可在任意支持 MCP 的客户端中配置使用。这里我们选择开源的 Cherry Studio 进行演示。
|
||||
|
||||

|
||||
|
||||
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)。
|
||||
@@ -1,8 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { execSync } from 'child_process';
|
||||
import { fileURLToPath, pathToFileURL } from 'url';
|
||||
import fs from 'fs';
|
||||
|
||||
// Enable debug logging if needed
|
||||
@@ -90,7 +89,10 @@ checkFrontend(projectRoot);
|
||||
|
||||
// Start the server
|
||||
console.log('🚀 Starting MCPHub server...');
|
||||
import(path.join(projectRoot, 'dist', 'index.js')).catch(err => {
|
||||
const entryPath = path.join(projectRoot, 'dist', 'index.js');
|
||||
// Convert to file:// URL for cross-platform ESM compatibility (required on Windows)
|
||||
const entryUrl = pathToFileURL(entryPath).href;
|
||||
import(entryUrl).catch(err => {
|
||||
console.error('Failed to start MCPHub:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -1,271 +0,0 @@
|
||||
# 智能工具发现,精准调用:MCPHub 智能路由重新定义 AI 工具选择
|
||||
|
||||
## 概述
|
||||
|
||||
在现代 AI 应用中,随着 MCP 服务器数量的快速增长和工具种类的日益丰富,如何从数百个可用工具中快速找到最适合当前任务的工具,成为了一个日益突出的挑战。传统方式下,AI 助手要么被迫处理所有可用工具的庞大列表,导致 token 消耗激增和响应延迟,要么依赖开发者手动分组,缺乏灵活性和智能化。MCPHub 的智能路由功能基于向量语义搜索技术,实现了自然语言驱动的工具发现与精准推荐,让 AI 助手能够像人类专家一样,根据任务描述智能地选择最合适的工具组合,大幅提升工作效率和用户体验。
|
||||
|
||||
## 智能路由是什么
|
||||
|
||||
### 技术原理
|
||||
|
||||
智能路由是 MCPHub 的核心创新功能,它基于现代向量语义搜索技术,将每个 MCP 工具的描述、参数和功能特征转换为高维向量表示。当用户提出任务需求时,系统将需求同样转换为向量,通过计算向量间的余弦相似度,快速定位最相关的工具集合。这种方法不依赖精确的关键词匹配,而是理解语义层面的相关性,能够处理自然语言的模糊性和多样性。
|
||||
|
||||
### 核心组件
|
||||
|
||||
**向量嵌入引擎**:支持 OpenAI text-embedding-3-small、BGE-M3 等多种主流嵌入模型,将工具描述转换为 1536 维或 1024 维向量表示,捕获工具功能的语义特征。
|
||||
|
||||
**PostgreSQL + pgvector 数据库**:采用业界领先的向量数据库解决方案,支持高效的向量索引和相似度搜索,能够在毫秒级时间内从大量工具中找到最相关的候选。
|
||||
|
||||
**动态阈值算法**:根据查询复杂度和具体程度自动调整相似度阈值,确保既不遗漏相关工具,也不引入无关噪声。简单查询使用较低阈值(0.2)获得更多样化结果,具体查询使用较高阈值(0.4)确保精确匹配。
|
||||
|
||||
**两步工作流**:`search_tools` 负责工具发现,`call_tool` 负责工具执行,清晰分离发现和执行逻辑,提供更好的可控性和调试体验。
|
||||
|
||||
## 为什么要使用智能路由
|
||||
|
||||
### 1. 解决工具选择的认知负荷
|
||||
|
||||
- **信息过载问题**:当 MCP 服务器数量超过 10 个、工具总数超过 100 个时,AI 助手面临严重的信息过载,难以在合理时间内做出最优选择。
|
||||
- **智能路由优势**:通过语义搜索将候选工具缩减到 5-10 个最相关的选项,让 AI 助手能够专注于理解和使用最合适的工具,而不是被迫处理庞大的工具清单。
|
||||
|
||||
### 2. 大幅降低 Token 消耗
|
||||
|
||||
- **传统方式的成本**:向 AI 模型传递完整的工具列表会消耗大量 token,特别是当工具描述详细时,单次请求可能消耗数千 token。
|
||||
- **智能路由的效益**:只传递最相关的工具信息,通常可以将工具相关的 token 消耗降低 70-90%,显著减少 API 调用成本,特别是在频繁交互的场景中。
|
||||
|
||||
### 3. 提升工具使用的准确性
|
||||
|
||||
- **语义理解能力**:智能路由能够理解"图片处理"、"数据分析"、"文档转换"等抽象概念,将其映射到具体的工具实现,避免了传统关键词匹配的局限性。
|
||||
- **上下文感知**:考虑工具的输入输出模式和使用场景,推荐最适合当前任务流程的工具组合。
|
||||
|
||||

|
||||
|
||||
## 如何使用智能路由
|
||||
|
||||
### 配置智能路由
|
||||
|
||||
#### 1. 数据库配置
|
||||
|
||||
智能路由需要 PostgreSQL 数据库支持 pgvector 扩展:
|
||||
|
||||
```bash
|
||||
# 使用 Docker 快速启动支持 pgvector 的 PostgreSQL
|
||||
docker run --name mcphub-postgres \
|
||||
-e POSTGRES_DB=mcphub \
|
||||
-e POSTGRES_USER=mcphub \
|
||||
-e POSTGRES_PASSWORD=your_password \
|
||||
-p 5432:5432 \
|
||||
-d pgvector/pgvector:pg16
|
||||
```
|
||||
|
||||
#### 2. 在 MCPHub 控制台配置智能路由
|
||||
|
||||
访问 MCPHub 设置页面(http://localhost:3000/settings),在"智能路由配置"部分填写:
|
||||
|
||||
- **数据库 URL**:`postgresql://mcphub:your_password@localhost:5432/mcphub`
|
||||
- **OpenAI API Key**:您的 OpenAI API 密钥
|
||||
- **API Base URL**:可选,默认为 `https://api.openai.com/v1`
|
||||
- **嵌入模型**:推荐使用 `text-embedding-3-small`(1536 维,性价比最佳)
|
||||
|
||||

|
||||
|
||||
#### 3. 启用智能路由
|
||||
|
||||
配置完成后,开启"启用智能路由"开关。系统将自动:
|
||||
|
||||
- 为所有已连接的 MCP 服务器工具生成向量嵌入
|
||||
- 建立向量索引以支持快速搜索
|
||||
- 在后续新增工具时自动更新向量数据库
|
||||
|
||||
### 智能工具发现的使用方式
|
||||
|
||||
启用智能路由后,MCPHub 会自动提供两个核心工具:
|
||||
|
||||
#### search_tools - 智能工具搜索
|
||||
|
||||
```typescript
|
||||
// 使用示例
|
||||
{
|
||||
"name": "search_tools",
|
||||
"arguments": {
|
||||
"query": "help me process images and resize them", // 自然语言查询
|
||||
"limit": 10 // 返回结果数量
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**查询策略建议**:
|
||||
|
||||
- **宽泛查询**:使用较高的 limit(20-30),如"数据处理工具"
|
||||
- **精确查询**:使用较低的 limit(5-10),如"将 PNG 图片转换为 WebP 格式"
|
||||
- **分步查询**:复杂任务可以分解为多个具体查询
|
||||
|
||||
#### call_tool - 精准工具执行
|
||||
|
||||
```typescript
|
||||
// 使用示例
|
||||
{
|
||||
"name": "call_tool",
|
||||
"arguments": {
|
||||
"toolName": "image_resize", // 从 search_tools 结果中获取的工具名
|
||||
"arguments": { // 根据工具的 inputSchema 提供参数
|
||||
"input_path": "/path/to/image.png",
|
||||
"width": 800,
|
||||
"height": 600
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 实际应用场景演示
|
||||
|
||||
#### 场景 1:图像处理工作流
|
||||
|
||||
```markdown
|
||||
用户请求:我需要批量处理一些产品图片,调整大小并转换格式
|
||||
|
||||
AI 工作流:
|
||||
|
||||
1. search_tools("image processing batch resize convert format")
|
||||
→ 返回:image_batch_processor, format_converter, image_optimizer
|
||||
2. call_tool("image_batch_processor", {...})
|
||||
→ 执行批量图像处理
|
||||
```
|
||||
|
||||
#### 场景 2:数据分析任务
|
||||
|
||||
```markdown
|
||||
用户请求:分析这个 CSV 文件的销售数据,生成可视化图表
|
||||
|
||||
AI 工作流:
|
||||
|
||||
1. search_tools("CSV data analysis visualization charts")
|
||||
→ 返回:csv_analyzer, chart_generator, statistics_calculator
|
||||
2. call_tool("csv_analyzer", {"file_path": "sales.csv"})
|
||||
3. call_tool("chart_generator", {"data": analysis_result})
|
||||
```
|
||||
|
||||
#### 场景 3:文档处理流水线
|
||||
|
||||
```markdown
|
||||
用户请求:将 Word 文档转换为 PDF,然后提取其中的文本内容
|
||||
|
||||
AI 工作流:
|
||||
|
||||
1. search_tools("document conversion Word to PDF")
|
||||
→ 返回:doc_converter, pdf_generator
|
||||
2. call_tool("doc_converter", {"input": "document.docx", "output_format": "pdf"})
|
||||
3. search_tools("PDF text extraction")
|
||||
→ 返回:pdf_text_extractor, ocr_processor
|
||||
4. call_tool("pdf_text_extractor", {"pdf_path": "document.pdf"})
|
||||
```
|
||||
|
||||
### 高级配置选项
|
||||
|
||||
#### 多模型支持
|
||||
|
||||
智能路由支持多种嵌入模型,可根据需求选择:
|
||||
|
||||
```json
|
||||
{
|
||||
"embeddingModel": "text-embedding-3-small", // OpenAI,1536维,平衡性能和成本
|
||||
"embeddingModel": "text-embedding-3-large", // OpenAI,3072维,最高精度
|
||||
"embeddingModel": "bge-m3" // 开源模型,1024维,支持多语言
|
||||
}
|
||||
```
|
||||
|
||||
#### 自定义 API 端点
|
||||
|
||||
支持使用自建的嵌入服务或其他 OpenAI 兼容的 API:
|
||||
|
||||
```json
|
||||
{
|
||||
"openaiApiBaseUrl": "https://your-api-endpoint.com/v1",
|
||||
"openaiApiKey": "your-custom-api-key"
|
||||
}
|
||||
```
|
||||
|
||||
## 性能优化与最佳实践
|
||||
|
||||
### 查询优化策略
|
||||
|
||||
**分层查询**:对于复杂任务,使用从宽泛到具体的查询策略:
|
||||
|
||||
```
|
||||
1. 宽泛查询:"文档处理工具" (limit: 20)
|
||||
2. 具体查询:"PDF 转 Word 转换器" (limit: 5)
|
||||
```
|
||||
|
||||
**上下文相关性**:在查询中包含任务上下文信息:
|
||||
|
||||
```
|
||||
好:search_tools("为电商网站批量压缩产品图片")
|
||||
较好:search_tools("图片压缩工具")
|
||||
```
|
||||
|
||||
**动态调整**:根据返回结果质量动态调整查询词和限制数量。
|
||||
|
||||
### 数据库性能调优
|
||||
|
||||
**索引优化**:智能路由自动创建最优的向量索引:
|
||||
|
||||
```sql
|
||||
CREATE INDEX idx_vector_embeddings_embedding
|
||||
ON vector_embeddings USING ivfflat (embedding vector_cosine_ops)
|
||||
WITH (lists = 100);
|
||||
```
|
||||
|
||||
**内存配置**:对于大规模部署,建议增加 PostgreSQL 内存配置:
|
||||
|
||||
```
|
||||
shared_buffers = 256MB
|
||||
effective_cache_size = 1GB
|
||||
work_mem = 64MB
|
||||
```
|
||||
|
||||
### 监控与调试
|
||||
|
||||
**相似度阈值监控**:观察搜索结果的相似度分数,调整阈值以获得最佳效果。
|
||||
|
||||
**查询效果分析**:定期检查常用查询的返回结果,优化工具描述以提高搜索准确性。
|
||||
|
||||
## 智能路由的技术优势
|
||||
|
||||
### 语义理解能力
|
||||
|
||||
与传统的关键词匹配相比,智能路由能够理解:
|
||||
|
||||
- **同义词和近义词**:"图片"和"图像"、"转换"和"变换"
|
||||
- **上下层级概念**:"数据可视化"包含"图表生成"、"统计图绘制"等
|
||||
- **任务意图推理**:"我要做一个数据报告"自动关联数据分析、图表生成、文档创建等工具
|
||||
|
||||
### 多语言支持
|
||||
|
||||
智能路由支持中英文混合查询,能够处理:
|
||||
|
||||
```
|
||||
search_tools("图片 resize 和 format conversion")
|
||||
search_tools("将文档转换为 PDF 格式")
|
||||
search_tools("image processing and 格式转换")
|
||||
```
|
||||
|
||||
### 容错能力
|
||||
|
||||
具备一定的容错能力,能够处理:
|
||||
|
||||
- 拼写错误:自动纠正常见拼写错误
|
||||
- 模糊描述:从不完整的描述中推导完整意图
|
||||
- 领域术语:理解特定领域的专业术语
|
||||
|
||||
## 结语
|
||||
|
||||
MCPHub 的智能路由功能代表着 MCP 生态系统向智能化方向发展的重要一步。通过引入向量语义搜索技术,它不仅解决了工具数量激增带来的选择困难,更为 AI 助手提供了类似人类专家的工具发现和选择能力。
|
||||
|
||||
随着 MCP 服务器生态的不断丰富,智能路由将成为连接用户需求与丰富工具资源的关键桥梁。它让开发者无需担心工具管理的复杂性,让用户享受到更加智能和高效的 AI 助手体验。
|
||||
|
||||
未来,我们还将继续优化智能路由的算法,引入更多先进的 AI 技术,如基于强化学习的工具推荐、多模态工具理解等,为 MCP 生态系统注入更强的智能化动力。
|
||||
|
||||
智能路由不仅仅是一个技术功能,更是 MCPHub 对于"让 AI 工具使用变得简单而智能"这一愿景的具体实现。在这个工具爆炸的时代,智能路由让我们重新定义了 AI 与工具的交互方式。
|
||||
|
||||
项目地址:https://github.com/samanhappy/mcphub
|
||||
|
||||

|
||||
60
docker-compose.db.yml
Normal file
@@ -0,0 +1,60 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
# PostgreSQL database for MCPHub configuration
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
container_name: mcphub-postgres
|
||||
environment:
|
||||
POSTGRES_DB: mcphub
|
||||
POSTGRES_USER: mcphub
|
||||
POSTGRES_PASSWORD: ${DB_PASSWORD:-mcphub_password}
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "${DB_PORT:-5432}:5432"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U mcphub"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
networks:
|
||||
- mcphub-network
|
||||
|
||||
# MCPHub application
|
||||
mcphub:
|
||||
image: samanhappy/mcphub:latest
|
||||
container_name: mcphub
|
||||
environment:
|
||||
# Database connection (setting DB_URL automatically enables database mode)
|
||||
DB_URL: "postgresql://mcphub:${DB_PASSWORD:-mcphub_password}@postgres:5432/mcphub"
|
||||
|
||||
# Optional: Explicitly control database mode (overrides auto-detection)
|
||||
# USE_DB: "true"
|
||||
|
||||
# Application settings
|
||||
PORT: 3000
|
||||
NODE_ENV: production
|
||||
|
||||
# Optional: Custom npm registry
|
||||
# NPM_REGISTRY: https://registry.npmjs.org/
|
||||
|
||||
# Optional: Proxy settings
|
||||
# HTTP_PROXY: http://proxy:8080
|
||||
# HTTPS_PROXY: http://proxy:8080
|
||||
ports:
|
||||
- "${MCPHUB_PORT:-3000}:3000"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mcphub-network
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
driver: local
|
||||
|
||||
networks:
|
||||
mcphub-network:
|
||||
driver: bridge
|
||||
147
docs/api-reference/auth.mdx
Normal file
@@ -0,0 +1,147 @@
|
||||
---
|
||||
title: "Authentication"
|
||||
description: "Manage users and authentication."
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="POST /api/auth/login"
|
||||
href="#login"
|
||||
>
|
||||
Log in to get a JWT token.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/auth/register"
|
||||
href="#register"
|
||||
>
|
||||
Register a new user.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /api/auth/user"
|
||||
href="#get-current-user"
|
||||
>
|
||||
Get the currently authenticated user.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/auth/change-password"
|
||||
href="#change-password"
|
||||
>
|
||||
Change the password for the current user.
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### Login
|
||||
|
||||
Authenticates a user and returns a JWT token along with user details.
|
||||
|
||||
- **Endpoint**: `/api/auth/login`
|
||||
- **Method**: `POST`
|
||||
- **Body**:
|
||||
- `username` (string, required): The user's username.
|
||||
- `password` (string, required): The user's password.
|
||||
- **Request Example**:
|
||||
```json
|
||||
{
|
||||
"username": "admin",
|
||||
"password": "admin123"
|
||||
}
|
||||
```
|
||||
- **Success Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Login successful",
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||
"user": {
|
||||
"username": "admin",
|
||||
"isAdmin": true,
|
||||
"permissions": { ... }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Register
|
||||
|
||||
Registers a new user and returns a JWT token.
|
||||
|
||||
- **Endpoint**: `/api/auth/register`
|
||||
- **Method**: `POST`
|
||||
- **Body**:
|
||||
- `username` (string, required): The desired username.
|
||||
- `password` (string, required): The desired password (must be at least 6 characters).
|
||||
- `isAdmin` (boolean, optional): Whether the user should have admin privileges.
|
||||
- **Request Example**:
|
||||
```json
|
||||
{
|
||||
"username": "newuser",
|
||||
"password": "password123",
|
||||
"isAdmin": false
|
||||
}
|
||||
```
|
||||
- **Success Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||
"user": {
|
||||
"username": "newuser",
|
||||
"isAdmin": false,
|
||||
"permissions": { ... }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Get Current User
|
||||
|
||||
Retrieves the profile of the currently authenticated user.
|
||||
|
||||
- **Endpoint**: `/api/auth/user`
|
||||
- **Method**: `GET`
|
||||
- **Authentication**: Bearer Token required.
|
||||
- **Success Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"user": {
|
||||
"username": "admin",
|
||||
"isAdmin": true,
|
||||
"permissions": { ... }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Change Password
|
||||
|
||||
Allows the authenticated user to change their password.
|
||||
|
||||
- **Endpoint**: `/api/auth/change-password`
|
||||
- **Method**: `POST`
|
||||
- **Authentication**: Bearer Token required.
|
||||
- **Body**:
|
||||
- `currentPassword` (string, required): The user's current password.
|
||||
- `newPassword` (string, required): The desired new password (must be at least 6 characters).
|
||||
- **Request Example**:
|
||||
```json
|
||||
{
|
||||
"currentPassword": "oldpassword",
|
||||
"newPassword": "newpassword123"
|
||||
}
|
||||
```
|
||||
- **Success Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Password updated successfully"
|
||||
}
|
||||
```
|
||||
111
docs/api-reference/config.mdx
Normal file
@@ -0,0 +1,111 @@
|
||||
---
|
||||
title: "Config"
|
||||
description: "Manage and retrieve system-wide configurations."
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card title="PUT /api/system-config" href="#update-system-config">Update the main system configuration.</Card>
|
||||
<Card title="GET /api/settings" href="#get-all-settings">Get all system settings, including servers and groups.</Card>
|
||||
<Card title="GET /config" href="#get-runtime-config">Get public runtime configuration for the frontend.</Card>
|
||||
<Card title="GET /public-config" href="#get-public-config">Get public configuration to check for auth skip.</Card>
|
||||
|
||||
---
|
||||
|
||||
### Update System Config
|
||||
|
||||
Updates various parts of the system configuration. You only need to provide the keys for the sections you want to update.
|
||||
|
||||
- **Endpoint**: `/api/system-config`
|
||||
- **Method**: `PUT`
|
||||
- **Body**: A JSON object containing one or more of the following top-level keys: `routing`, `install`, `smartRouting`, `mcpRouter`.
|
||||
|
||||
#### Routing Configuration (`routing`)
|
||||
|
||||
- `enableGlobalRoute` (boolean): Enable or disable the global `/api/mcp` route.
|
||||
- `enableGroupNameRoute` (boolean): Enable or disable group-based routing (e.g., `/api/mcp/group/:groupName`).
|
||||
- `enableBearerAuth` (boolean): Enable bearer token authentication for MCP routes.
|
||||
- `bearerAuthKey` (string): The secret key to use for bearer authentication.
|
||||
- `skipAuth` (boolean): If true, skips all authentication, making the instance public.
|
||||
|
||||
#### Install Configuration (`install`)
|
||||
|
||||
- `pythonIndexUrl` (string): The base URL of the Python Package Index (PyPI) to use for installations.
|
||||
- `npmRegistry` (string): The URL of the npm registry to use for installations.
|
||||
- `baseUrl` (string): The public base URL of this MCPHub instance.
|
||||
|
||||
#### Smart Routing Configuration (`smartRouting`)
|
||||
|
||||
- `enabled` (boolean): Enable or disable the Smart Routing feature.
|
||||
- `dbUrl` (string): The database connection URL for storing embeddings.
|
||||
- `openaiApiBaseUrl` (string): The base URL for the OpenAI-compatible API for generating embeddings.
|
||||
- `openaiApiKey` (string): The API key for the embeddings service.
|
||||
- `openaiApiEmbeddingModel` (string): The name of the embedding model to use.
|
||||
|
||||
#### MCP Router Configuration (`mcpRouter`)
|
||||
|
||||
- `apiKey` (string): The API key for the MCP Router service.
|
||||
- `referer` (string): The referer header to use for MCP Router requests.
|
||||
- `title` (string): The title to display for this instance on MCP Router.
|
||||
- `baseUrl` (string): The base URL for the MCP Router API.
|
||||
|
||||
- **Request Example**:
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"skipAuth": true
|
||||
},
|
||||
"smartRouting": {
|
||||
"enabled": true,
|
||||
"dbUrl": "postgresql://user:pass@host:port/db"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Get All Settings
|
||||
|
||||
Retrieves the entire settings object for the instance, including all server configurations, groups, and system settings. This is a comprehensive dump of the `mcp_settings.json` file.
|
||||
|
||||
- **Endpoint**: `/api/settings`
|
||||
- **Method**: `GET`
|
||||
|
||||
---
|
||||
|
||||
### Get Runtime Config
|
||||
|
||||
Retrieves the essential runtime configuration required for the frontend application. This endpoint does not require authentication.
|
||||
|
||||
- **Endpoint**: `/config`
|
||||
- **Method**: `GET`
|
||||
- **Success Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"basePath": "",
|
||||
"version": "1.0.0",
|
||||
"name": "MCPHub"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Get Public Config
|
||||
|
||||
Retrieves public configuration, primarily to check if authentication is skipped. This allows the frontend to adjust its behavior accordingly before a user has logged in. This endpoint does not require authentication.
|
||||
|
||||
- **Endpoint**: `/public-config`
|
||||
- **Method**: `GET`
|
||||
- **Success Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"skipAuth": false,
|
||||
"permissions": {}
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -1,4 +0,0 @@
|
||||
---
|
||||
title: 'Create Plant'
|
||||
openapi: 'POST /plants'
|
||||
---
|
||||
@@ -1,4 +0,0 @@
|
||||
---
|
||||
title: 'Delete Plant'
|
||||
openapi: 'DELETE /plants/{id}'
|
||||
---
|
||||
@@ -1,4 +0,0 @@
|
||||
---
|
||||
title: 'Get Plants'
|
||||
openapi: 'GET /plants'
|
||||
---
|
||||
@@ -1,4 +0,0 @@
|
||||
---
|
||||
title: 'New Plant'
|
||||
openapi: 'WEBHOOK /plant/webhook'
|
||||
---
|
||||
212
docs/api-reference/groups.mdx
Normal file
@@ -0,0 +1,212 @@
|
||||
---
|
||||
title: "Groups"
|
||||
description: "Manage server groups to organize and route requests."
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card title="GET /api/groups" href="#get-all-groups">Get a list of all groups.</Card>
|
||||
<Card title="POST /api/groups" href="#create-a-new-group">Create a new group.</Card>
|
||||
<Card title="GET /api/groups/:id" href="#get-a-group">Get details of a specific group.</Card>
|
||||
<Card title="PUT /api/groups/:id" href="#update-a-group">Update an existing group.</Card>
|
||||
<Card title="DELETE /api/groups/:id" href="#delete-a-group">Delete a group.</Card>
|
||||
<Card title="POST /api/groups/:id/servers" href="#add-server-to-group">Add a server to a group.</Card>
|
||||
<Card title="DELETE /api/groups/:id/servers/:serverName" href="#remove-server-from-group">Remove a server from a group.</Card>
|
||||
<Card title="PUT /api/groups/:id/servers/batch" href="#batch-update-group-servers">Batch update servers in a group.</Card>
|
||||
<Card title="GET /api/groups/:id/server-configs" href="#get-group-server-configs">Get detailed server configurations in a group.</Card>
|
||||
<Card title="PUT /api/groups/:id/server-configs/:serverName/tools" href="#update-group-server-tools">Update tool selection for a server in a group.</Card>
|
||||
|
||||
---
|
||||
|
||||
### Get All Groups
|
||||
|
||||
Retrieves a list of all server groups.
|
||||
|
||||
- **Endpoint**: `/api/groups`
|
||||
- **Method**: `GET`
|
||||
- **Success Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"id": "group-1",
|
||||
"name": "My Group",
|
||||
"description": "A collection of servers.",
|
||||
"servers": ["server1", "server2"],
|
||||
"owner": "admin"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Create a New Group
|
||||
|
||||
Creates a new server group.
|
||||
|
||||
- **Endpoint**: `/api/groups`
|
||||
- **Method**: `POST`
|
||||
- **Body**:
|
||||
- `name` (string, required): The name of the group.
|
||||
- `description` (string, optional): A description for the group.
|
||||
- `servers` (array of strings, optional): A list of server names to include in the group.
|
||||
- **Request Example**:
|
||||
```json
|
||||
{
|
||||
"name": "My New Group",
|
||||
"description": "A description for the new group",
|
||||
"servers": ["server1", "server2"]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Get a Group
|
||||
|
||||
Retrieves details for a specific group by its ID or name.
|
||||
|
||||
- **Endpoint**: `/api/groups/:id`
|
||||
- **Method**: `GET`
|
||||
- **Parameters**:
|
||||
- `:id` (string, required): The ID or name of the group.
|
||||
|
||||
---
|
||||
|
||||
### Update a Group
|
||||
|
||||
Updates an existing group's name, description, or server list.
|
||||
|
||||
- **Endpoint**: `/api/groups/:id`
|
||||
- **Method**: `PUT`
|
||||
- **Parameters**:
|
||||
- `:id` (string, required): The ID or name of the group to update.
|
||||
- **Body**:
|
||||
- `name` (string, optional): The new name for the group.
|
||||
- `description` (string, optional): The new description for the group.
|
||||
- `servers` (array, optional): The new list of servers for the group. See [Batch Update Group Servers](#batch-update-group-servers) for format.
|
||||
- **Request Example**:
|
||||
```json
|
||||
{
|
||||
"name": "Updated Group Name",
|
||||
"description": "Updated description"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Delete a Group
|
||||
|
||||
Deletes a group by its ID or name.
|
||||
|
||||
- **Endpoint**: `/api/groups/:id`
|
||||
- **Method**: `DELETE`
|
||||
- **Parameters**:
|
||||
- `:id` (string, required): The ID or name of the group to delete.
|
||||
|
||||
---
|
||||
|
||||
### Add Server to Group
|
||||
|
||||
Adds a single server to a group.
|
||||
|
||||
- **Endpoint**: `/api/groups/:id/servers`
|
||||
- **Method**: `POST`
|
||||
- **Parameters**:
|
||||
- `:id` (string, required): The ID or name of the group.
|
||||
- **Body**:
|
||||
- `serverName` (string, required): The name of the server to add.
|
||||
- **Request Example**:
|
||||
```json
|
||||
{
|
||||
"serverName": "my-server"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Remove Server from Group
|
||||
|
||||
Removes a single server from a group.
|
||||
|
||||
- **Endpoint**: `/api/groups/:id/servers/:serverName`
|
||||
- **Method**: `DELETE`
|
||||
- **Parameters**:
|
||||
- `:id` (string, required): The ID or name of the group.
|
||||
- `:serverName` (string, required): The name of the server to remove.
|
||||
|
||||
---
|
||||
|
||||
### Batch Update Group Servers
|
||||
|
||||
Replaces all servers in a group with a new list. The list can be simple strings or detailed configuration objects.
|
||||
|
||||
- **Endpoint**: `/api/groups/:id/servers/batch`
|
||||
- **Method**: `PUT`
|
||||
- **Parameters**:
|
||||
- `:id` (string, required): The ID or name of the group.
|
||||
- **Body**:
|
||||
- `servers` (array, required): An array of server names (strings) or server configuration objects.
|
||||
- **Request Example (Simple)**:
|
||||
```json
|
||||
{
|
||||
"servers": ["server1", "server2"]
|
||||
}
|
||||
```
|
||||
- **Request Example (Detailed)**:
|
||||
```json
|
||||
{
|
||||
"servers": [
|
||||
{ "name": "server1", "tools": "all" },
|
||||
{ "name": "server2", "tools": ["toolA", "toolB"] }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Get Group Server Configs
|
||||
|
||||
Retrieves the detailed configuration for all servers within a group, including which tools are enabled.
|
||||
|
||||
- **Endpoint**: `/api/groups/:id/server-configs`
|
||||
- **Method**: `GET`
|
||||
- **Parameters**:
|
||||
- `:id` (string, required): The ID or name of the group.
|
||||
- **Success Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"name": "server1",
|
||||
"tools": "all"
|
||||
},
|
||||
{
|
||||
"name": "server2",
|
||||
"tools": ["toolA", "toolB"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Update Group Server Tools
|
||||
|
||||
Updates the tool selection for a specific server within a group.
|
||||
|
||||
- **Endpoint**: `/api/groups/:id/server-configs/:serverName/tools`
|
||||
- **Method**: `PUT`
|
||||
- **Parameters**:
|
||||
- `:id` (string, required): The ID or name of the group.
|
||||
- `:serverName` (string, required): The name of the server to update.
|
||||
- **Body**:
|
||||
- `tools` (string or array of strings, required): Either the string `"all"` to enable all tools, or an array of tool names to enable specifically.
|
||||
- **Request Example**:
|
||||
```json
|
||||
{
|
||||
"tools": ["toolA", "toolC"]
|
||||
}
|
||||
```
|
||||
@@ -1,33 +1,13 @@
|
||||
---
|
||||
title: 'Introduction'
|
||||
description: 'Example section for showcasing API endpoints'
|
||||
title: "Introduction"
|
||||
description: "Welcome to the MCPHub API documentation."
|
||||
---
|
||||
|
||||
<Note>
|
||||
If you're not looking to build API reference documentation, you can delete
|
||||
this section by removing the api-reference folder.
|
||||
</Note>
|
||||
The MCPHub API provides a comprehensive set of endpoints to manage your MCP servers, groups, users, and more. The API is divided into two main categories:
|
||||
|
||||
## Welcome
|
||||
- **MCP Endpoints**: These are the primary endpoints for interacting with your MCP servers. They provide a unified interface for sending requests to your servers and receiving responses in real-time.
|
||||
- **Management API**: These endpoints are used for managing the MCPHub instance itself. This includes managing servers, groups, users, and system settings.
|
||||
|
||||
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.
|
||||
All API endpoints are available under the `/api` path. For example, the endpoint to get all servers is `/api/servers`.
|
||||
|
||||
<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": []
|
||||
}
|
||||
]
|
||||
```
|
||||
Authentication is required for most Management API endpoints. See the [Authentication](/api-reference/auth) section for more details.
|
||||
81
docs/api-reference/logs.mdx
Normal file
@@ -0,0 +1,81 @@
|
||||
---
|
||||
title: "Logs"
|
||||
description: "Access and manage server logs."
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="GET /api/logs"
|
||||
href="#get-all-logs"
|
||||
>
|
||||
Get all logs.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="DELETE /api/logs"
|
||||
href="#clear-logs"
|
||||
>
|
||||
Clear all logs.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /api/logs/stream"
|
||||
href="#stream-logs"
|
||||
>
|
||||
Stream logs in real-time.
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### Get All Logs
|
||||
|
||||
Retrieves all stored logs.
|
||||
|
||||
- **Endpoint**: `/api/logs`
|
||||
- **Method**: `GET`
|
||||
- **Success Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"timestamp": "2023-10-27T10:00:00.000Z",
|
||||
"level": "info",
|
||||
"message": "Server started successfully.",
|
||||
"service": "system"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Clear Logs
|
||||
|
||||
Deletes all stored logs.
|
||||
|
||||
- **Endpoint**: `/api/logs`
|
||||
- **Method**: `DELETE`
|
||||
- **Success Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Logs cleared successfully"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Stream Logs
|
||||
|
||||
Streams logs in real-time using Server-Sent Events (SSE). The connection will remain open, and new log entries will be sent as they occur.
|
||||
|
||||
- **Endpoint**: `/api/logs/stream`
|
||||
- **Method**: `GET`
|
||||
- **Response Format**: The stream sends events with a `data` field containing a JSON object. The first event has `type: 'initial'` and contains all historical logs. Subsequent events have `type: 'log'` and contain a single new log entry.
|
||||
|
||||
- **Example Event**:
|
||||
```
|
||||
data: {"type":"log","log":{"timestamp":"2023-10-27T10:00:05.000Z","level":"debug","message":"Processing request for /api/some-endpoint","service":"mcp-server"}}
|
||||
```
|
||||
33
docs/api-reference/mcp-http.mdx
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
title: "MCP HTTP Endpoints"
|
||||
description: "Connect to your MCP servers using the unified HTTP endpoint."
|
||||
---
|
||||
|
||||
MCPHub provides a unified streamable HTTP interface for all your MCP servers. This allows you to send requests to any configured MCP server and receive responses in real-time.
|
||||
|
||||
### Unified Endpoint
|
||||
|
||||
This endpoint provides access to all enabled MCP servers.
|
||||
|
||||
- **Endpoint**: `http://localhost:3000/mcp`
|
||||
- **Method**: `POST`
|
||||
|
||||
### Group-Specific Endpoint
|
||||
|
||||
For targeted access to specific server groups, use the group-based HTTP endpoint.
|
||||
|
||||
- **Endpoint**: `http://localhost:3000/mcp/{group}`
|
||||
- **Method**: `POST`
|
||||
- **Parameters**:
|
||||
- `{group}`: The ID or name of the group.
|
||||
|
||||
### Server-Specific Endpoint
|
||||
|
||||
For direct access to individual servers, use the server-specific HTTP endpoint.
|
||||
|
||||
- **Endpoint**: `http://localhost:3000/mcp/{server}`
|
||||
- **Method**: `POST`
|
||||
- **Parameters**:
|
||||
- `{server}`: The name of the server.
|
||||
|
||||
> **Note**: If a server name and group name are the same, the group will take precedence.
|
||||
25
docs/api-reference/mcp-sse.mdx
Normal file
@@ -0,0 +1,25 @@
|
||||
---
|
||||
title: "MCP SSE Endpoints (Deprecated)"
|
||||
description: "Connect to your MCP servers using the SSE endpoint."
|
||||
---
|
||||
|
||||
The SSE endpoint is deprecated and will be removed in a future version. Please use the [MCP HTTP Endpoints](/api-reference/mcp-http) instead.
|
||||
|
||||
### Unified Endpoint
|
||||
|
||||
- **Endpoint**: `http://localhost:3000/sse`
|
||||
- **Method**: `GET`
|
||||
|
||||
### Group-Specific Endpoint
|
||||
|
||||
- **Endpoint**: `http://localhost:3000/sse/{group}`
|
||||
- **Method**: `GET`
|
||||
- **Parameters**:
|
||||
- `{group}`: The ID or name of the group.
|
||||
|
||||
### Server-Specific Endpoint
|
||||
|
||||
- **Endpoint**: `http://localhost:3000/sse/{server}`
|
||||
- **Method**: `GET`
|
||||
- **Parameters**:
|
||||
- `{server}`: The name of the server.
|
||||
276
docs/api-reference/openapi.mdx
Normal file
@@ -0,0 +1,276 @@
|
||||
---
|
||||
title: "OpenAPI Integration"
|
||||
description: "Generate OpenAPI specifications from MCP tools for seamless integration with OpenWebUI and other systems"
|
||||
---
|
||||
|
||||
# OpenAPI Generation for OpenWebUI Integration
|
||||
|
||||
MCPHub now supports generating OpenAPI 3.0.3 specifications from MCP tools, enabling seamless integration with OpenWebUI and other OpenAPI-compatible systems without requiring MCPO as an intermediary proxy.
|
||||
|
||||
## Features
|
||||
|
||||
- ✅ **Automatic OpenAPI Generation**: Converts MCP tools to OpenAPI 3.0.3 specification
|
||||
- ✅ **OpenWebUI Compatible**: Direct integration without MCPO proxy
|
||||
- ✅ **Real-time Tool Discovery**: Dynamically includes tools from connected MCP servers
|
||||
- ✅ **Dual Parameter Support**: Supports both GET (query params) and POST (JSON body) for tool execution
|
||||
- ✅ **No Authentication Required**: OpenAPI endpoints are public for easy integration
|
||||
- ✅ **Comprehensive Metadata**: Full OpenAPI specification with proper schemas and documentation
|
||||
|
||||
## API Endpoints
|
||||
|
||||
### OpenAPI Specification
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash GET /api/openapi.json
|
||||
curl "http://localhost:3000/api/openapi.json"
|
||||
```
|
||||
|
||||
```bash With Parameters
|
||||
curl "http://localhost:3000/api/openapi.json?title=My MCP API&version=2.0.0"
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
Generates and returns the complete OpenAPI 3.0.3 specification for all connected MCP tools.
|
||||
|
||||
**Query Parameters:**
|
||||
|
||||
<ParamField query="title" type="string" optional>
|
||||
Custom API title
|
||||
</ParamField>
|
||||
|
||||
<ParamField query="description" type="string" optional>
|
||||
Custom API description
|
||||
</ParamField>
|
||||
|
||||
<ParamField query="version" type="string" optional>
|
||||
Custom API version
|
||||
</ParamField>
|
||||
|
||||
<ParamField query="serverUrl" type="string" optional>
|
||||
Custom server URL
|
||||
</ParamField>
|
||||
|
||||
<ParamField query="includeDisabled" type="boolean" optional default="false">
|
||||
Include disabled tools
|
||||
</ParamField>
|
||||
|
||||
<ParamField query="servers" type="string" optional>
|
||||
Comma-separated list of server names to include
|
||||
</ParamField>
|
||||
|
||||
### Group/Server-Specific OpenAPI Specification
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash GET /api/:name/openapi.json
|
||||
curl "http://localhost:3000/api/mygroup/openapi.json"
|
||||
```
|
||||
|
||||
```bash With Parameters
|
||||
curl "http://localhost:3000/api/myserver/openapi.json?title=My Server API&version=1.0.0"
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
Generates and returns the OpenAPI 3.0.3 specification for a specific group or server. If a group with the given name exists, it returns the specification for all servers in that group. Otherwise, it treats the name as a server name and returns the specification for that server only.
|
||||
|
||||
**Path Parameters:**
|
||||
|
||||
<ParamField path="name" type="string" required>
|
||||
Group ID/name or server name
|
||||
</ParamField>
|
||||
|
||||
**Query Parameters:**
|
||||
|
||||
Same as the main OpenAPI specification endpoint (title, description, version, serverUrl, includeDisabled).
|
||||
|
||||
### Available Servers
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash GET /api/openapi/servers
|
||||
curl "http://localhost:3000/api/openapi/servers"
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
Returns a list of connected MCP server names.
|
||||
|
||||
<ResponseExample>
|
||||
|
||||
```json Example Response
|
||||
{
|
||||
"success": true,
|
||||
"data": ["amap", "playwright", "slack"]
|
||||
}
|
||||
```
|
||||
|
||||
</ResponseExample>
|
||||
|
||||
### Tool Statistics
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash GET /api/openapi/stats
|
||||
curl "http://localhost:3000/api/openapi/stats"
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
Returns statistics about available tools and servers.
|
||||
|
||||
<ResponseExample>
|
||||
|
||||
```json Example Response
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"totalServers": 3,
|
||||
"totalTools": 41,
|
||||
"serverBreakdown": [
|
||||
{"name": "amap", "toolCount": 12, "status": "connected"},
|
||||
{"name": "playwright", "toolCount": 21, "status": "connected"},
|
||||
{"name": "slack", "toolCount": 8, "status": "connected"}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</ResponseExample>
|
||||
|
||||
### Tool Execution
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash GET /api/tools/{serverName}/{toolName}
|
||||
curl "http://localhost:3000/api/tools/amap/amap-maps_weather?city=Beijing"
|
||||
```
|
||||
|
||||
```bash POST /api/tools/{serverName}/{toolName}
|
||||
curl -X POST "http://localhost:3000/api/tools/playwright/playwright-browser_navigate" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"url": "https://example.com"}'
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
Execute MCP tools via OpenAPI-compatible endpoints.
|
||||
|
||||
**Path Parameters:**
|
||||
|
||||
<ParamField path="serverName" type="string" required>
|
||||
The name of the MCP server
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="toolName" type="string" required>
|
||||
The name of the tool to execute
|
||||
</ParamField>
|
||||
|
||||
## OpenWebUI Integration
|
||||
|
||||
To integrate MCPHub with OpenWebUI:
|
||||
|
||||
<Steps>
|
||||
<Step title="Start MCPHub">
|
||||
Ensure MCPHub is running with your MCP servers configured
|
||||
</Step>
|
||||
<Step title="Get OpenAPI Specification">
|
||||
```bash
|
||||
curl http://localhost:3000/api/openapi.json > mcphub-api.json
|
||||
```
|
||||
</Step>
|
||||
<Step title="Add to OpenWebUI">
|
||||
Import the OpenAPI specification file or point to the URL directly in OpenWebUI
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
### Configuration Example
|
||||
|
||||
In OpenWebUI, you can add MCPHub as an OpenAPI tool by using:
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="OpenAPI URL" icon="link">
|
||||
`http://localhost:3000/api/openapi.json`
|
||||
</Card>
|
||||
<Card title="Base URL" icon="server">
|
||||
`http://localhost:3000/api`
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Generated OpenAPI Structure
|
||||
|
||||
The generated OpenAPI specification includes:
|
||||
|
||||
### Tool Conversion Logic
|
||||
|
||||
- **Simple tools** (≤10 primitive parameters) → GET endpoints with query parameters
|
||||
- **Complex tools** (objects, arrays, or >10 parameters) → POST endpoints with JSON request body
|
||||
- **All tools** include comprehensive response schemas and error handling
|
||||
|
||||
### Example Generated Operation
|
||||
|
||||
```yaml
|
||||
/tools/amap/amap-maps_weather:
|
||||
get:
|
||||
summary: "根据城市名称或者标准adcode查询指定城市的天气"
|
||||
operationId: "amap_amap-maps_weather"
|
||||
tags: ["amap"]
|
||||
parameters:
|
||||
- name: city
|
||||
in: query
|
||||
required: true
|
||||
description: "城市名称或者adcode"
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: "Successful tool execution"
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ToolResponse'
|
||||
```
|
||||
|
||||
### Security
|
||||
|
||||
- Bearer authentication is defined but not enforced for tool execution endpoints
|
||||
- Enables flexible integration with various OpenAPI-compatible systems
|
||||
|
||||
## Benefits over MCPO
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Direct Integration" icon="plug">
|
||||
No need for intermediate proxy
|
||||
</Card>
|
||||
<Card title="Real-time Updates" icon="refresh">
|
||||
OpenAPI spec updates automatically as MCP servers connect/disconnect
|
||||
</Card>
|
||||
<Card title="Better Performance" icon="bolt">
|
||||
Direct tool execution without proxy overhead
|
||||
</Card>
|
||||
<Card title="Simplified Architecture" icon="layer-group">
|
||||
One less component to manage
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="OpenAPI spec shows no tools">
|
||||
Ensure MCP servers are connected. Check `/api/openapi/stats` for server status.
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Tool execution fails">
|
||||
Verify the tool name and parameters match the OpenAPI specification. Check server logs for details.
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="OpenWebUI can't connect">
|
||||
Ensure MCPHub is accessible from OpenWebUI and the OpenAPI URL is correct.
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Missing tools in specification">
|
||||
Check if tools are enabled in your MCP server configuration. Use `includeDisabled=true` to see all tools.
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
142
docs/api-reference/prompts.mdx
Normal file
@@ -0,0 +1,142 @@
|
||||
---
|
||||
title: "Prompts"
|
||||
description: "Manage and execute MCP prompts."
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="POST /api/mcp/:serverName/prompts/:promptName"
|
||||
href="#get-a-prompt"
|
||||
>
|
||||
Execute a prompt on an MCP server.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/servers/:serverName/prompts/:promptName/toggle"
|
||||
href="#toggle-a-prompt"
|
||||
>
|
||||
Enable or disable a prompt.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="PUT /api/servers/:serverName/prompts/:promptName/description"
|
||||
href="#update-prompt-description"
|
||||
>
|
||||
Update the description of a prompt.
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### Get a Prompt
|
||||
|
||||
Execute a prompt on an MCP server and get the result.
|
||||
|
||||
- **Endpoint**: `/api/mcp/:serverName/prompts/:promptName`
|
||||
- **Method**: `POST`
|
||||
- **Authentication**: Required
|
||||
- **Parameters**:
|
||||
- `:serverName` (string, required): The name of the MCP server.
|
||||
- `:promptName` (string, required): The name of the prompt.
|
||||
- **Body**:
|
||||
```json
|
||||
{
|
||||
"arguments": {
|
||||
"arg1": "value1",
|
||||
"arg2": "value2"
|
||||
}
|
||||
}
|
||||
```
|
||||
- `arguments` (object, optional): Arguments to pass to the prompt.
|
||||
|
||||
- **Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": {
|
||||
"type": "text",
|
||||
"text": "Prompt content"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Example Request:**
|
||||
|
||||
```bash
|
||||
curl -X POST "http://localhost:3000/api/mcp/myserver/prompts/code-review" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-d '{
|
||||
"arguments": {
|
||||
"language": "typescript",
|
||||
"code": "const x = 1;"
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Toggle a Prompt
|
||||
|
||||
Enable or disable a specific prompt on a server.
|
||||
|
||||
- **Endpoint**: `/api/servers/:serverName/prompts/:promptName/toggle`
|
||||
- **Method**: `POST`
|
||||
- **Authentication**: Required
|
||||
- **Parameters**:
|
||||
- `:serverName` (string, required): The name of the server.
|
||||
- `:promptName` (string, required): The name of the prompt.
|
||||
- **Body**:
|
||||
```json
|
||||
{
|
||||
"enabled": true
|
||||
}
|
||||
```
|
||||
- `enabled` (boolean, required): `true` to enable the prompt, `false` to disable it.
|
||||
|
||||
**Example Request:**
|
||||
|
||||
```bash
|
||||
curl -X POST "http://localhost:3000/api/servers/myserver/prompts/code-review/toggle" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-d '{"enabled": false}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Update Prompt Description
|
||||
|
||||
Update the description of a specific prompt.
|
||||
|
||||
- **Endpoint**: `/api/servers/:serverName/prompts/:promptName/description`
|
||||
- **Method**: `PUT`
|
||||
- **Authentication**: Required
|
||||
- **Parameters**:
|
||||
- `:serverName` (string, required): The name of the server.
|
||||
- `:promptName` (string, required): The name of the prompt.
|
||||
- **Body**:
|
||||
```json
|
||||
{
|
||||
"description": "New prompt description"
|
||||
}
|
||||
```
|
||||
- `description` (string, required): The new description for the prompt.
|
||||
|
||||
**Example Request:**
|
||||
|
||||
```bash
|
||||
curl -X PUT "http://localhost:3000/api/servers/myserver/prompts/code-review/description" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-d '{"description": "Review code for best practices and potential issues"}'
|
||||
```
|
||||
|
||||
**Note**: Prompts are templates that can be used to generate standardized requests to MCP servers. They are defined by the MCP server and can have arguments that are filled in when the prompt is executed.
|
||||
265
docs/api-reference/servers.mdx
Normal file
@@ -0,0 +1,265 @@
|
||||
---
|
||||
title: "Servers"
|
||||
description: "Manage your MCP servers."
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="GET /api/servers"
|
||||
href="#get-all-servers"
|
||||
>
|
||||
Get a list of all MCP servers.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/servers"
|
||||
href="#create-a-new-server"
|
||||
>
|
||||
Create a new MCP server.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="PUT /api/servers/:name"
|
||||
href="#update-a-server"
|
||||
>
|
||||
Update an existing MCP server.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="DELETE /api/servers/:name"
|
||||
href="#delete-a-server"
|
||||
>
|
||||
Delete an MCP server.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/servers/:name/toggle"
|
||||
href="#toggle-a-server"
|
||||
>
|
||||
Toggle the enabled state of a server.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/servers/:serverName/tools/:toolName/toggle"
|
||||
href="#toggle-a-tool"
|
||||
>
|
||||
Toggle the enabled state of a tool.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="PUT /api/servers/:serverName/tools/:toolName/description"
|
||||
href="#update-tool-description"
|
||||
>
|
||||
Update the description of a tool.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="PUT /api/system-config"
|
||||
href="#update-system-config"
|
||||
>
|
||||
Update system configuration settings.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /api/settings"
|
||||
href="#get-settings"
|
||||
>
|
||||
Get all server settings and configurations.
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### Get All Servers
|
||||
|
||||
Retrieves a list of all configured MCP servers, including their status and available tools.
|
||||
|
||||
- **Endpoint**: `/api/servers`
|
||||
- **Method**: `GET`
|
||||
- **Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"name": "example-server",
|
||||
"status": "connected",
|
||||
"tools": [
|
||||
{
|
||||
"name": "tool1",
|
||||
"description": "Description of tool 1"
|
||||
}
|
||||
],
|
||||
"config": {
|
||||
"type": "stdio",
|
||||
"command": "node",
|
||||
"args": ["server.js"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Create a New Server
|
||||
|
||||
Adds a new MCP server to the configuration.
|
||||
|
||||
- **Endpoint**: `/api/servers`
|
||||
- **Method**: `POST`
|
||||
- **Body**:
|
||||
```json
|
||||
{
|
||||
"name": "my-new-server",
|
||||
"config": {
|
||||
"type": "stdio",
|
||||
"command": "python",
|
||||
"args": ["-u", "my_script.py"],
|
||||
"owner": "admin"
|
||||
}
|
||||
}
|
||||
```
|
||||
- `name` (string, required): The unique name for the server.
|
||||
- `config` (object, required): The server configuration object.
|
||||
- `type` (string): `stdio`, `sse`, `streamable-http`, or `openapi`.
|
||||
- `command` (string): Command to execute for `stdio` type.
|
||||
- `args` (array of strings): Arguments for the command.
|
||||
- `url` (string): URL for `sse`, `streamable-http`, or `openapi` types.
|
||||
- `openapi` (object): OpenAPI configuration.
|
||||
- `url` (string): URL to the OpenAPI schema.
|
||||
- `schema` (object): The OpenAPI schema object itself.
|
||||
- `headers` (object): Headers to send with requests for `sse`, `streamable-http`, and `openapi` types.
|
||||
- `keepAliveInterval` (number): Keep-alive interval in milliseconds for `sse` type. Defaults to 60000.
|
||||
- `owner` (string): The owner of the server. Defaults to the current user or 'admin'.
|
||||
|
||||
---
|
||||
|
||||
### Update a Server
|
||||
|
||||
Updates the configuration of an existing MCP server.
|
||||
|
||||
- **Endpoint**: `/api/servers/:name`
|
||||
- **Method**: `PUT`
|
||||
- **Parameters**:
|
||||
- `:name` (string, required): The name of the server to update.
|
||||
- **Body**:
|
||||
```json
|
||||
{
|
||||
"config": {
|
||||
"type": "stdio",
|
||||
"command": "node",
|
||||
"args": ["new_server.js"]
|
||||
}
|
||||
}
|
||||
```
|
||||
- `config` (object, required): The updated server configuration object. See "Create a New Server" for details.
|
||||
|
||||
---
|
||||
|
||||
### Delete a Server
|
||||
|
||||
Removes an MCP server from the configuration.
|
||||
|
||||
- **Endpoint**: `/api/servers/:name`
|
||||
- **Method**: `DELETE`
|
||||
- **Parameters**:
|
||||
- `:name` (string, required): The name of the server to delete.
|
||||
|
||||
---
|
||||
|
||||
### Toggle a Server
|
||||
|
||||
Enables or disables an MCP server.
|
||||
|
||||
- **Endpoint**: `/api/servers/:name/toggle`
|
||||
- **Method**: `POST`
|
||||
- **Parameters**:
|
||||
- `:name` (string, required): The name of the server to toggle.
|
||||
- **Body**:
|
||||
```json
|
||||
{
|
||||
"enabled": true
|
||||
}
|
||||
```
|
||||
- `enabled` (boolean, required): `true` to enable the server, `false` to disable it.
|
||||
|
||||
---
|
||||
|
||||
### Toggle a Tool
|
||||
|
||||
Enables or disables a specific tool on a server.
|
||||
|
||||
- **Endpoint**: `/api/servers/:serverName/tools/:toolName/toggle`
|
||||
- **Method**: `POST`
|
||||
- **Parameters**:
|
||||
- `:serverName` (string, required): The name of the server.
|
||||
- `:toolName` (string, required): The name of the tool.
|
||||
- **Body**:
|
||||
```json
|
||||
{
|
||||
"enabled": true
|
||||
}
|
||||
```
|
||||
- `enabled` (boolean, required): `true` to enable the tool, `false` to disable it.
|
||||
|
||||
---
|
||||
|
||||
### Update Tool Description
|
||||
|
||||
Updates the description of a specific tool.
|
||||
|
||||
- **Endpoint**: `/api/servers/:serverName/tools/:toolName/description`
|
||||
- **Method**: `PUT`
|
||||
- **Parameters**:
|
||||
- `:serverName` (string, required): The name of the server.
|
||||
- `:toolName` (string, required): The name of the tool.
|
||||
- **Body**:
|
||||
```json
|
||||
{
|
||||
"description": "New tool description"
|
||||
}
|
||||
```
|
||||
- `description` (string, required): The new description for the tool.
|
||||
|
||||
---
|
||||
|
||||
### Update System Config
|
||||
|
||||
Updates the system-wide configuration settings.
|
||||
|
||||
- **Endpoint**: `/api/system-config`
|
||||
- **Method**: `PUT`
|
||||
- **Body**:
|
||||
```json
|
||||
{
|
||||
"openaiApiKey": "sk-...",
|
||||
"openaiBaseUrl": "https://api.openai.com/v1",
|
||||
"modelName": "gpt-4",
|
||||
"temperature": 0.7,
|
||||
"maxTokens": 2048
|
||||
}
|
||||
```
|
||||
- All fields are optional. Only provided fields will be updated.
|
||||
|
||||
---
|
||||
|
||||
### Get Settings
|
||||
|
||||
Retrieves all server settings and configurations.
|
||||
|
||||
- **Endpoint**: `/api/settings`
|
||||
- **Method**: `GET`
|
||||
- **Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"servers": [...],
|
||||
"groups": [...],
|
||||
"systemConfig": {...}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Note**: For detailed prompt management, see the [Prompts API](/api-reference/prompts) documentation.
|
||||
29
docs/api-reference/smart-routing.mdx
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
title: "Smart Routing"
|
||||
description: "Intelligent tool discovery using vector semantic search."
|
||||
---
|
||||
|
||||
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 Endpoint
|
||||
|
||||
- **Endpoint**: `http://localhost:3000/mcp/$smart`
|
||||
- **Method**: `POST`
|
||||
|
||||
### SSE Endpoint (Deprecated)
|
||||
|
||||
- **Endpoint**: `http://localhost:3000/sse/$smart`
|
||||
- **Method**: `GET`
|
||||
|
||||
### 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
|
||||
|
||||
- PostgreSQL with pgvector extension
|
||||
- OpenAI API key (or compatible embedding service)
|
||||
- Enable Smart Routing in MCPHub settings
|
||||
113
docs/api-reference/system.mdx
Normal file
@@ -0,0 +1,113 @@
|
||||
---
|
||||
title: "System"
|
||||
description: "System and utility endpoints."
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="GET /health"
|
||||
href="#health-check"
|
||||
>
|
||||
Check the health status of the MCPHub server.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /oauth/callback"
|
||||
href="#oauth-callback"
|
||||
>
|
||||
OAuth callback endpoint for authentication flows.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/dxt/upload"
|
||||
href="#upload-dxt-file"
|
||||
>
|
||||
Upload a DXT configuration file.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /api/mcp-settings/export"
|
||||
href="#export-mcp-settings"
|
||||
>
|
||||
Export MCP settings as JSON.
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### Health Check
|
||||
|
||||
Check the health status of the MCPHub server.
|
||||
|
||||
- **Endpoint**: `/health`
|
||||
- **Method**: `GET`
|
||||
- **Authentication**: Not required
|
||||
- **Response**:
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
"timestamp": "2024-11-12T01:30:00.000Z",
|
||||
"uptime": 12345
|
||||
}
|
||||
```
|
||||
|
||||
**Example Request:**
|
||||
|
||||
```bash
|
||||
curl "http://localhost:3000/health"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### OAuth Callback
|
||||
|
||||
OAuth callback endpoint for handling OAuth authentication flows. This endpoint is automatically called by OAuth providers after user authorization.
|
||||
|
||||
- **Endpoint**: `/oauth/callback`
|
||||
- **Method**: `GET`
|
||||
- **Authentication**: Not required (public callback URL)
|
||||
- **Query Parameters**: Varies by OAuth provider (typically includes `code`, `state`, etc.)
|
||||
|
||||
**Note**: This endpoint is used internally by MCPHub's OAuth integration and should not be called directly by clients.
|
||||
|
||||
---
|
||||
|
||||
### Upload DXT File
|
||||
|
||||
Upload a DXT (Desktop Extension) configuration file to import server configurations.
|
||||
|
||||
- **Endpoint**: `/api/dxt/upload`
|
||||
- **Method**: `POST`
|
||||
- **Authentication**: Required
|
||||
- **Content-Type**: `multipart/form-data`
|
||||
- **Body**:
|
||||
- `file` (file, required): The DXT configuration file to upload.
|
||||
|
||||
**Example Request:**
|
||||
|
||||
```bash
|
||||
curl -X POST "http://localhost:3000/api/dxt/upload" \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-F "file=@config.dxt"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Export MCP Settings
|
||||
|
||||
Export the current MCP settings configuration as a JSON file.
|
||||
|
||||
- **Endpoint**: `/api/mcp-settings/export`
|
||||
- **Method**: `GET`
|
||||
- **Authentication**: Required
|
||||
- **Response**: Returns the `mcp_settings.json` configuration file.
|
||||
|
||||
**Example Request:**
|
||||
|
||||
```bash
|
||||
curl "http://localhost:3000/api/mcp-settings/export" \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-o mcp_settings.json
|
||||
```
|
||||
|
||||
**Note**: This endpoint allows you to download a backup of your MCP settings, which can be used to restore or migrate your configuration.
|
||||
86
docs/api-reference/tools.mdx
Normal file
@@ -0,0 +1,86 @@
|
||||
---
|
||||
title: "Tools"
|
||||
description: "Execute MCP tools programmatically."
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="POST /api/tools/call/:server"
|
||||
href="#call-a-tool"
|
||||
>
|
||||
Call a specific tool on an MCP server.
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### Call a Tool
|
||||
|
||||
Execute a specific tool on an MCP server with given arguments.
|
||||
|
||||
- **Endpoint**: `/api/tools/call/:server`
|
||||
- **Method**: `POST`
|
||||
- **Parameters**:
|
||||
- `:server` (string, required): The name of the MCP server.
|
||||
- **Body**:
|
||||
```json
|
||||
{
|
||||
"toolName": "tool-name",
|
||||
"arguments": {
|
||||
"param1": "value1",
|
||||
"param2": "value2"
|
||||
}
|
||||
}
|
||||
```
|
||||
- `toolName` (string, required): The name of the tool to execute.
|
||||
- `arguments` (object, optional): The arguments to pass to the tool. Defaults to an empty object.
|
||||
|
||||
- **Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "Tool execution result"
|
||||
}
|
||||
],
|
||||
"toolName": "tool-name",
|
||||
"arguments": {
|
||||
"param1": "value1",
|
||||
"param2": "value2"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Example Request:**
|
||||
|
||||
```bash
|
||||
curl -X POST "http://localhost:3000/api/tools/call/amap" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-d '{
|
||||
"toolName": "amap-maps_weather",
|
||||
"arguments": {
|
||||
"city": "Beijing"
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
**Notes:**
|
||||
- The tool arguments are automatically converted to the proper types based on the tool's input schema.
|
||||
- Use the `x-session-id` header to maintain session state across multiple tool calls if needed.
|
||||
- This endpoint requires authentication.
|
||||
|
||||
---
|
||||
|
||||
### Alternative: OpenAPI Tool Execution
|
||||
|
||||
For OpenAPI-compatible tool execution without authentication, see the [OpenAPI Integration](/api-reference/openapi#tool-execution) documentation. The OpenAPI endpoints provide:
|
||||
|
||||
- **GET** `/api/tools/:serverName/:toolName` - For simple tools with query parameters
|
||||
- **POST** `/api/tools/:serverName/:toolName` - For complex tools with JSON body
|
||||
|
||||
These endpoints are designed for integration with OpenWebUI and other OpenAPI-compatible systems.
|
||||
195
docs/api-reference/users.mdx
Normal file
@@ -0,0 +1,195 @@
|
||||
---
|
||||
title: "Users"
|
||||
description: "Manage users in MCPHub."
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="GET /api/users"
|
||||
href="#get-all-users"
|
||||
>
|
||||
Get a list of all users.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /api/users/:username"
|
||||
href="#get-a-user"
|
||||
>
|
||||
Get details of a specific user.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/users"
|
||||
href="#create-a-user"
|
||||
>
|
||||
Create a new user.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="PUT /api/users/:username"
|
||||
href="#update-a-user"
|
||||
>
|
||||
Update an existing user.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="DELETE /api/users/:username"
|
||||
href="#delete-a-user"
|
||||
>
|
||||
Delete a user.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /api/users-stats"
|
||||
href="#get-user-statistics"
|
||||
>
|
||||
Get statistics about users and their server access.
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### Get All Users
|
||||
|
||||
Retrieves a list of all users in the system.
|
||||
|
||||
- **Endpoint**: `/api/users`
|
||||
- **Method**: `GET`
|
||||
- **Authentication**: Required (Admin only)
|
||||
- **Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"username": "admin",
|
||||
"role": "admin",
|
||||
"servers": ["server1", "server2"],
|
||||
"groups": ["group1"]
|
||||
},
|
||||
{
|
||||
"username": "user1",
|
||||
"role": "user",
|
||||
"servers": ["server1"],
|
||||
"groups": []
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Get a User
|
||||
|
||||
Retrieves details of a specific user.
|
||||
|
||||
- **Endpoint**: `/api/users/:username`
|
||||
- **Method**: `GET`
|
||||
- **Authentication**: Required (Admin only)
|
||||
- **Parameters**:
|
||||
- `:username` (string, required): The username of the user.
|
||||
- **Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"username": "user1",
|
||||
"role": "user",
|
||||
"servers": ["server1", "server2"],
|
||||
"groups": ["group1"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Create a User
|
||||
|
||||
Creates a new user in the system.
|
||||
|
||||
- **Endpoint**: `/api/users`
|
||||
- **Method**: `POST`
|
||||
- **Authentication**: Required (Admin only)
|
||||
- **Body**:
|
||||
```json
|
||||
{
|
||||
"username": "newuser",
|
||||
"password": "securepassword",
|
||||
"role": "user",
|
||||
"servers": ["server1"],
|
||||
"groups": ["group1"]
|
||||
}
|
||||
```
|
||||
- `username` (string, required): The username for the new user.
|
||||
- `password` (string, required): The password for the new user. Must be at least 6 characters.
|
||||
- `role` (string, optional): The role of the user. Either `"admin"` or `"user"`. Defaults to `"user"`.
|
||||
- `servers` (array of strings, optional): List of server names the user has access to.
|
||||
- `groups` (array of strings, optional): List of group IDs the user belongs to.
|
||||
|
||||
---
|
||||
|
||||
### Update a User
|
||||
|
||||
Updates an existing user's information.
|
||||
|
||||
- **Endpoint**: `/api/users/:username`
|
||||
- **Method**: `PUT`
|
||||
- **Authentication**: Required (Admin only)
|
||||
- **Parameters**:
|
||||
- `:username` (string, required): The username of the user to update.
|
||||
- **Body**:
|
||||
```json
|
||||
{
|
||||
"password": "newpassword",
|
||||
"role": "admin",
|
||||
"servers": ["server1", "server2", "server3"],
|
||||
"groups": ["group1", "group2"]
|
||||
}
|
||||
```
|
||||
- `password` (string, optional): New password for the user.
|
||||
- `role` (string, optional): New role for the user.
|
||||
- `servers` (array of strings, optional): Updated list of accessible servers.
|
||||
- `groups` (array of strings, optional): Updated list of groups.
|
||||
|
||||
---
|
||||
|
||||
### Delete a User
|
||||
|
||||
Removes a user from the system.
|
||||
|
||||
- **Endpoint**: `/api/users/:username`
|
||||
- **Method**: `DELETE`
|
||||
- **Authentication**: Required (Admin only)
|
||||
- **Parameters**:
|
||||
- `:username` (string, required): The username of the user to delete.
|
||||
|
||||
---
|
||||
|
||||
### Get User Statistics
|
||||
|
||||
Retrieves statistics about users and their access to servers and groups.
|
||||
|
||||
- **Endpoint**: `/api/users-stats`
|
||||
- **Method**: `GET`
|
||||
- **Authentication**: Required (Admin only)
|
||||
- **Response**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"totalUsers": 5,
|
||||
"adminUsers": 1,
|
||||
"regularUsers": 4,
|
||||
"usersPerServer": {
|
||||
"server1": 3,
|
||||
"server2": 2
|
||||
},
|
||||
"usersPerGroup": {
|
||||
"group1": 2,
|
||||
"group2": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Note**: All user management endpoints require admin authentication.
|
||||
304
docs/configuration/database-configuration.mdx
Normal file
@@ -0,0 +1,304 @@
|
||||
---
|
||||
title: 'Database Configuration'
|
||||
description: 'Configuring MCPHub to use a PostgreSQL database as an alternative to the mcp_settings.json file.'
|
||||
---
|
||||
|
||||
# Database Configuration for MCPHub
|
||||
|
||||
## Overview
|
||||
|
||||
MCPHub supports storing configuration data in a PostgreSQL database as an alternative to the `mcp_settings.json` file. Database mode provides enhanced persistence and scalability for production environments and enterprise deployments.
|
||||
|
||||
## Why Use Database Configuration?
|
||||
|
||||
**Core Benefits:**
|
||||
- ✅ **Better Persistence** - Configuration stored in a professional database with transaction support and data integrity
|
||||
- ✅ **High Availability** - Leverage database replication and failover capabilities
|
||||
- ✅ **Enterprise Ready** - Meets enterprise data management and compliance requirements
|
||||
- ✅ **Backup & Recovery** - Use mature database backup tools and strategies
|
||||
|
||||
## Environment Variables
|
||||
|
||||
### Required for Database Mode
|
||||
|
||||
```bash
|
||||
# Database connection URL (PostgreSQL)
|
||||
# Simply setting DB_URL will automatically enable database mode
|
||||
DB_URL=postgresql://user:password@localhost:5432/mcphub
|
||||
|
||||
# Or explicitly control with USE_DB (overrides auto-detection)
|
||||
# USE_DB=true
|
||||
```
|
||||
|
||||
<Note>
|
||||
**Simplified Configuration**: You only need to set `DB_URL` to enable database mode. MCPHub will automatically detect and enable database mode when `DB_URL` is present. Use `USE_DB=false` to explicitly disable database mode even when `DB_URL` is set.
|
||||
</Note>
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
### 1. Using Docker
|
||||
|
||||
#### Option A: Using External Database
|
||||
|
||||
If you already have a PostgreSQL database:
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
-p 3000:3000 \
|
||||
-v ./mcp_settings.json:/app/mcp_settings.json \
|
||||
-e DB_URL="postgresql://user:password@your-db-host:5432/mcphub" \
|
||||
samanhappy/mcphub
|
||||
```
|
||||
|
||||
#### Option B: Using PostgreSQL as a separate service
|
||||
|
||||
Create a `docker-compose.yml`:
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16
|
||||
environment:
|
||||
POSTGRES_DB: mcphub
|
||||
POSTGRES_USER: mcphub
|
||||
POSTGRES_PASSWORD: your_secure_password
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "5432:5432"
|
||||
|
||||
mcphub:
|
||||
image: samanhappy/mcphub:latest
|
||||
environment:
|
||||
USE_DB: "true"
|
||||
DB_URL: "postgresql://mcphub:your_secure_password@postgres:5432/mcphub"
|
||||
PORT: 3000
|
||||
ports:
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
- postgres
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
```
|
||||
|
||||
Run with:
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
### 2. Manual Setup
|
||||
|
||||
#### Step 1: Setup PostgreSQL Database
|
||||
|
||||
```bash
|
||||
# Install PostgreSQL (if not already installed)
|
||||
sudo apt-get install postgresql postgresql-contrib
|
||||
|
||||
# Create database and user
|
||||
sudo -u postgres psql <<EOF
|
||||
CREATE DATABASE mcphub;
|
||||
CREATE USER mcphub WITH ENCRYPTED PASSWORD 'your_password';
|
||||
GRANT ALL PRIVILEGES ON DATABASE mcphub TO mcphub;
|
||||
EOF
|
||||
```
|
||||
|
||||
#### Step 2: Install MCPHub
|
||||
|
||||
```bash
|
||||
npm install -g @samanhappy/mcphub
|
||||
```
|
||||
|
||||
#### Step 3: Set Environment Variables
|
||||
|
||||
Create a `.env` file:
|
||||
|
||||
```bash
|
||||
# Simply set DB_URL to enable database mode (USE_DB is auto-detected)
|
||||
DB_URL=postgresql://mcphub:your_password@localhost:5432/mcphub
|
||||
PORT=3000
|
||||
```
|
||||
|
||||
#### Step 4: Run Migration (Optional)
|
||||
|
||||
If you have an existing `mcp_settings.json` file, migrate it:
|
||||
|
||||
```bash
|
||||
# Run migration script
|
||||
npx tsx src/scripts/migrate-to-database.ts
|
||||
```
|
||||
|
||||
Or let MCPHub auto-migrate on first startup.
|
||||
|
||||
#### Step 5: Start MCPHub
|
||||
|
||||
```bash
|
||||
mcphub
|
||||
```
|
||||
|
||||
## Migration from File-Based to Database
|
||||
|
||||
MCPHub provides automatic migration on first startup when database mode is enabled. However, you can also run the migration manually.
|
||||
|
||||
### Automatic Migration
|
||||
|
||||
When you start MCPHub with `USE_DB=true` for the first time:
|
||||
|
||||
1. MCPHub connects to the database
|
||||
2. Checks if any users exist in the database
|
||||
3. If no users found, automatically migrates from `mcp_settings.json`
|
||||
4. Creates all tables and imports all data
|
||||
|
||||
### Manual Migration
|
||||
|
||||
Run the migration script:
|
||||
|
||||
```bash
|
||||
# Using npx
|
||||
npx tsx src/scripts/migrate-to-database.ts
|
||||
|
||||
# Or using Node
|
||||
node dist/scripts/migrate-to-database.js
|
||||
```
|
||||
|
||||
The migration will:
|
||||
- ✅ Create database tables if they don't exist
|
||||
- ✅ Import all users with hashed passwords
|
||||
- ✅ Import all MCP server configurations
|
||||
- ✅ Import all groups
|
||||
- ✅ Import system configuration
|
||||
- ✅ Import user-specific configurations
|
||||
- ✅ Skip existing records (safe to run multiple times)
|
||||
|
||||
## Configuration After Migration
|
||||
|
||||
Once running in database mode, all configuration changes are stored in the database:
|
||||
|
||||
- User management via `/api/users`
|
||||
- Server management via `/api/servers`
|
||||
- Group management via `/api/groups`
|
||||
- System settings via `/api/system/config`
|
||||
|
||||
The web dashboard works exactly the same way, but now stores changes in the database instead of the file.
|
||||
|
||||
## Database Schema
|
||||
|
||||
MCPHub creates the following tables:
|
||||
|
||||
- **users** - User accounts and authentication
|
||||
- **servers** - MCP server configurations
|
||||
- **groups** - Server groups
|
||||
- **system_config** - System-wide settings
|
||||
- **user_configs** - User-specific settings
|
||||
- **vector_embeddings** - Vector search data (for smart routing)
|
||||
|
||||
## Backup and Restore
|
||||
|
||||
### Backup
|
||||
|
||||
```bash
|
||||
# PostgreSQL backup
|
||||
pg_dump -U mcphub mcphub > mcphub_backup.sql
|
||||
|
||||
# Or using Docker
|
||||
docker exec postgres pg_dump -U mcphub mcphub > mcphub_backup.sql
|
||||
```
|
||||
|
||||
### Restore
|
||||
|
||||
```bash
|
||||
# PostgreSQL restore
|
||||
psql -U mcphub mcphub < mcphub_backup.sql
|
||||
|
||||
# Or using Docker
|
||||
docker exec -i postgres psql -U mcphub mcphub < mcphub_backup.sql
|
||||
```
|
||||
|
||||
## Switching Back to File-Based Config
|
||||
|
||||
If you need to switch back to file-based configuration:
|
||||
|
||||
1. Set `USE_DB=false` or remove `DB_URL` and `USE_DB` environment variables
|
||||
2. Restart MCPHub
|
||||
3. MCPHub will use `mcp_settings.json` again
|
||||
|
||||
Note: Changes made in database mode won't be reflected in the file unless you manually export them.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Connection Refused
|
||||
|
||||
```
|
||||
Error: connect ECONNREFUSED 127.0.0.1:5432
|
||||
```
|
||||
|
||||
**Solution:** Check that PostgreSQL is running and accessible:
|
||||
```bash
|
||||
# Check PostgreSQL status
|
||||
sudo systemctl status postgresql
|
||||
|
||||
# Or for Docker
|
||||
docker ps | grep postgres
|
||||
```
|
||||
|
||||
### Authentication Failed
|
||||
|
||||
```
|
||||
Error: password authentication failed for user "mcphub"
|
||||
```
|
||||
|
||||
**Solution:** Verify database credentials in `DB_URL` environment variable.
|
||||
|
||||
### Migration Failed
|
||||
|
||||
```
|
||||
❌ Migration failed: ...
|
||||
```
|
||||
|
||||
**Solution:**
|
||||
1. Check that `mcp_settings.json` exists and is valid JSON
|
||||
2. Verify database connection
|
||||
3. Check logs for specific error messages
|
||||
4. Ensure database user has CREATE TABLE permissions
|
||||
|
||||
### Tables Already Exist
|
||||
|
||||
Database tables are automatically created if they don't exist. If you get errors about existing tables, check:
|
||||
1. Whether a previous migration partially completed
|
||||
2. Manual table creation conflicts
|
||||
3. Run with `synchronize: false` in database config if needed
|
||||
|
||||
## Environment Variables Reference
|
||||
|
||||
| Variable | Required | Default | Description |
|
||||
|----------|----------|---------|-------------|
|
||||
| `DB_URL` | Yes* | - | Full PostgreSQL connection URL. Setting this automatically enables database mode |
|
||||
| `USE_DB` | No | auto | Explicitly enable/disable database mode. If not set, auto-detected based on `DB_URL` presence |
|
||||
| `MCPHUB_SETTING_PATH` | No | - | Path to mcp_settings.json (for migration) |
|
||||
|
||||
*Required for database mode. Simply setting `DB_URL` enables database mode automatically
|
||||
|
||||
## Security Considerations
|
||||
|
||||
1. **Database Credentials:** Store database credentials securely, use environment variables or secrets management
|
||||
2. **Network Access:** Restrict database access to MCPHub instances only
|
||||
3. **Encryption:** Use SSL/TLS for database connections in production:
|
||||
```bash
|
||||
DB_URL=postgresql://user:password@host:5432/mcphub?sslmode=require
|
||||
```
|
||||
4. **Backup:** Regularly backup your database
|
||||
5. **Access Control:** Use strong database passwords and limit user permissions
|
||||
|
||||
## Performance
|
||||
|
||||
Database mode offers better performance for:
|
||||
- Multiple concurrent users
|
||||
- Frequent configuration changes
|
||||
- Large number of servers/groups
|
||||
|
||||
File mode may be faster for:
|
||||
- Single user setups
|
||||
- Read-heavy workloads with infrequent changes
|
||||
- Development/testing environments
|
||||
583
docs/configuration/docker-setup.mdx
Normal file
@@ -0,0 +1,583 @@
|
||||
---
|
||||
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
|
||||
```
|
||||
|
||||
### Building with Extended Features
|
||||
|
||||
The Docker image supports an `INSTALL_EXT` build argument to include additional tools:
|
||||
|
||||
```bash
|
||||
# Build with extended features (includes Docker Engine, Chrome/Playwright)
|
||||
docker build --build-arg INSTALL_EXT=true -t mcphub:extended .
|
||||
|
||||
# Option 1: Run with automatic Docker-in-Docker (requires privileged mode)
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
--privileged \
|
||||
-p 3000:3000 \
|
||||
-v $(pwd)/mcp_settings.json:/app/mcp_settings.json \
|
||||
mcphub:extended
|
||||
|
||||
# Option 2: Run with Docker socket mounted (use host's Docker daemon)
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
-p 3000:3000 \
|
||||
-v $(pwd)/mcp_settings.json:/app/mcp_settings.json \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
mcphub:extended
|
||||
|
||||
# Verify Docker is available
|
||||
docker exec mcphub docker --version
|
||||
docker exec mcphub docker ps
|
||||
```
|
||||
|
||||
<Note>
|
||||
**What's included with INSTALL_EXT=true:**
|
||||
- **Docker Engine**: Full Docker daemon with CLI for container management. The daemon auto-starts when the container runs in privileged mode.
|
||||
- **Chrome/Playwright** (amd64 only): For browser automation tasks
|
||||
|
||||
The extended image is larger but provides additional capabilities for advanced use cases.
|
||||
</Note>
|
||||
|
||||
<Warning>
|
||||
**Docker-in-Docker Security Considerations:**
|
||||
- **Privileged mode** (`--privileged`): Required for the Docker daemon to start inside the container. This gives the container elevated permissions on the host.
|
||||
- **Docker socket mounting** (`/var/run/docker.sock`): Gives the container access to the host's Docker daemon. Both approaches should only be used in trusted environments.
|
||||
- For production, consider using Docker socket mounting instead of privileged mode for better security.
|
||||
</Warning>
|
||||
|
||||
## 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.
|
||||
104
docs/configuration/environment-variables.mdx
Normal file
@@ -0,0 +1,104 @@
|
||||
---
|
||||
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 |
|
||||
| `INIT_TIMEOUT` | `300000` | Initial timeout for the application |
|
||||
| `BASE_PATH` | `''` | The base path of the application |
|
||||
| `READONLY` | `false` | Set to `true` to enable readonly mode |
|
||||
| `MCPHUB_SETTING_PATH` | | Path to the MCPHub settings |
|
||||
| `NODE_ENV` | `development` | Application environment (`development`, `production`, `test`) |
|
||||
|
||||
```env
|
||||
PORT=3000
|
||||
INIT_TIMEOUT=300000
|
||||
BASE_PATH=/api
|
||||
READONLY=true
|
||||
MCPHUB_SETTING_PATH=/path/to/settings
|
||||
NODE_ENV=production
|
||||
```
|
||||
|
||||
## Authentication & Security
|
||||
|
||||
### JWT Configuration
|
||||
|
||||
| Variable | Default | Description |
|
||||
| --- | --- | --- |
|
||||
| `JWT_SECRET` | - | Secret key for JWT token signing (required) |
|
||||
|
||||
```env
|
||||
JWT_SECRET=your-super-secret-key-change-this-in-production
|
||||
```
|
||||
|
||||
## Configuration Examples
|
||||
|
||||
### Development Environment
|
||||
|
||||
```env
|
||||
# .env.development
|
||||
NODE_ENV=development
|
||||
PORT=3000
|
||||
|
||||
# Auth
|
||||
JWT_SECRET=dev-secret-key
|
||||
```
|
||||
|
||||
### Production Environment
|
||||
|
||||
```env
|
||||
# .env.production
|
||||
NODE_ENV=production
|
||||
PORT=3000
|
||||
|
||||
# Security
|
||||
JWT_SECRET=your-super-secure-production-secret
|
||||
```
|
||||
|
||||
### Docker Environment
|
||||
|
||||
```env
|
||||
# .env.docker
|
||||
NODE_ENV=production
|
||||
PORT=3000
|
||||
|
||||
# Security
|
||||
JWT_SECRET_FILE=/run/secrets/jwt_secret
|
||||
```
|
||||
|
||||
## 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
|
||||
```
|
||||
|
||||
## 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
|
||||
519
docs/configuration/mcp-settings.mdx
Normal file
@@ -0,0 +1,519 @@
|
||||
---
|
||||
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 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"]
|
||||
},
|
||||
"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 |
|
||||
|
||||
## 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
{/* ### 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"]
|
||||
},
|
||||
"experimental": {
|
||||
"name": "Experimental Features",
|
||||
"description": "Beta and experimental servers",
|
||||
"servers": ["experimental-ai", "beta-search"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
{/* ### 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.
|
||||
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/samanhappy/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)
|
||||
158
docs/docs.json
@@ -1,78 +1,151 @@
|
||||
{
|
||||
"$schema": "https://mintlify.com/docs.json",
|
||||
"theme": "mint",
|
||||
"name": "Mint Starter Kit",
|
||||
"name": "MCPHub Documentation",
|
||||
"description": "The Unified Hub for Model Context Protocol (MCP) Servers",
|
||||
"colors": {
|
||||
"primary": "#16A34A",
|
||||
"light": "#07C983",
|
||||
"dark": "#15803D"
|
||||
},
|
||||
"favicon": "/favicon.svg",
|
||||
"favicon": "/favicon.ico",
|
||||
"navigation": {
|
||||
"tabs": [
|
||||
{
|
||||
"tab": "Guides",
|
||||
"tab": "English",
|
||||
"groups": [
|
||||
{
|
||||
"group": "Get Started",
|
||||
"pages": [
|
||||
"index",
|
||||
"quickstart",
|
||||
"development"
|
||||
"installation"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "Essentials",
|
||||
"group": "Core Features",
|
||||
"pages": [
|
||||
"essentials/markdown",
|
||||
"essentials/code",
|
||||
"essentials/images",
|
||||
"essentials/settings",
|
||||
"essentials/navigation",
|
||||
"essentials/reusable-snippets"
|
||||
"features/server-management",
|
||||
"features/group-management",
|
||||
"features/smart-routing",
|
||||
"features/oauth"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "Configuration",
|
||||
"pages": [
|
||||
"configuration/mcp-settings",
|
||||
"configuration/environment-variables",
|
||||
"configuration/docker-setup",
|
||||
"configuration/nginx",
|
||||
"configuration/database-configuration"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tab": "API Reference",
|
||||
"tab": "中文",
|
||||
"groups": [
|
||||
{
|
||||
"group": "API Documentation",
|
||||
"group": "开始使用",
|
||||
"pages": [
|
||||
"api-reference/introduction"
|
||||
"zh/index",
|
||||
"zh/quickstart",
|
||||
"zh/installation"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "Endpoint Examples",
|
||||
"group": "核心功能",
|
||||
"pages": [
|
||||
"api-reference/endpoint/get",
|
||||
"api-reference/endpoint/create",
|
||||
"api-reference/endpoint/delete",
|
||||
"api-reference/endpoint/webhook"
|
||||
"zh/features/server-management",
|
||||
"zh/features/group-management",
|
||||
"zh/features/smart-routing",
|
||||
"zh/features/oauth"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "配置指南",
|
||||
"pages": [
|
||||
"zh/configuration/mcp-settings",
|
||||
"zh/configuration/environment-variables",
|
||||
"zh/configuration/docker-setup",
|
||||
"zh/configuration/nginx",
|
||||
"zh/configuration/database-configuration"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tab": "API",
|
||||
"groups": [
|
||||
{
|
||||
"group": "MCP Endpoints",
|
||||
"pages": [
|
||||
"api-reference/introduction",
|
||||
"api-reference/mcp-http",
|
||||
"api-reference/mcp-sse",
|
||||
"api-reference/smart-routing"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "OpenAPI Endpoints",
|
||||
"pages": [
|
||||
"api-reference/openapi"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "Management Endpoints",
|
||||
"pages": [
|
||||
"api-reference/servers",
|
||||
"api-reference/groups",
|
||||
"api-reference/users",
|
||||
"api-reference/tools",
|
||||
"api-reference/prompts",
|
||||
"api-reference/auth",
|
||||
"api-reference/logs",
|
||||
"api-reference/config",
|
||||
"api-reference/system"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tab": "接口",
|
||||
"groups": [
|
||||
{
|
||||
"group": "MCP 端点",
|
||||
"pages": [
|
||||
"zh/api-reference/introduction",
|
||||
"zh/api-reference/mcp-http",
|
||||
"zh/api-reference/mcp-sse",
|
||||
"zh/api-reference/smart-routing"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "OpenAPI 端点",
|
||||
"pages": [
|
||||
"zh/api-reference/openapi"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "管理端点",
|
||||
"pages": [
|
||||
"zh/api-reference/servers",
|
||||
"zh/api-reference/groups",
|
||||
"zh/api-reference/users",
|
||||
"zh/api-reference/tools",
|
||||
"zh/api-reference/prompts",
|
||||
"zh/api-reference/auth",
|
||||
"zh/api-reference/logs",
|
||||
"zh/api-reference/config",
|
||||
"zh/api-reference/system"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"global": {
|
||||
"anchors": [
|
||||
{
|
||||
"anchor": "Documentation",
|
||||
"href": "https://mintlify.com/docs",
|
||||
"icon": "book-open-cover"
|
||||
},
|
||||
{
|
||||
"anchor": "Community",
|
||||
"href": "https://mintlify.com/community",
|
||||
"icon": "slack"
|
||||
},
|
||||
{
|
||||
"anchor": "Blog",
|
||||
"href": "https://mintlify.com/blog",
|
||||
"icon": "newspaper"
|
||||
}
|
||||
]
|
||||
"anchors": []
|
||||
}
|
||||
},
|
||||
"logo": {
|
||||
@@ -82,21 +155,20 @@
|
||||
"navbar": {
|
||||
"links": [
|
||||
{
|
||||
"label": "Support",
|
||||
"href": "mailto:hi@mintlify.com"
|
||||
"label": "Demo",
|
||||
"href": "https://demo.mcphubx.com"
|
||||
}
|
||||
],
|
||||
"primary": {
|
||||
"type": "button",
|
||||
"label": "Dashboard",
|
||||
"href": "https://dashboard.mintlify.com"
|
||||
"label": "Get Started",
|
||||
"href": "https://docs.mcphubx.com/quickstart"
|
||||
}
|
||||
},
|
||||
"footer": {
|
||||
"socials": {
|
||||
"x": "https://x.com/mintlify",
|
||||
"github": "https://github.com/mintlify",
|
||||
"linkedin": "https://linkedin.com/company/mintlify"
|
||||
"github": "https://github.com/samanhappy/mcphub",
|
||||
"discord": "https://discord.gg/qMKNsn5Q"
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
docs/favicon.ico
Executable file
|
After Width: | Height: | Size: 5.1 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' });
|
||||
}
|
||||
};
|
||||
```
|
||||
578
docs/features/group-management.mdx
Normal file
@@ -0,0 +1,578 @@
|
||||
---
|
||||
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
|
||||
|
||||
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",
|
||||
"servers": ["playwright", "fetch"]
|
||||
}'
|
||||
```
|
||||
|
||||
{/* ### 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": {
|
||||
"name": "web",
|
||||
"servers": ["fetch", "playwright"],
|
||||
},
|
||||
"communication": {
|
||||
"name": "communication",
|
||||
"servers": ["slack"],
|
||||
}
|
||||
}
|
||||
}
|
||||
``` */}
|
||||
|
||||
## 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
|
||||
141
docs/features/oauth.mdx
Normal file
@@ -0,0 +1,141 @@
|
||||
# OAuth Support
|
||||
|
||||
## At a Glance
|
||||
- Covers end-to-end OAuth 2.0 Authorization Code with PKCE for upstream MCP servers.
|
||||
- Supports automatic discovery from `WWW-Authenticate` responses and RFC 8414 metadata.
|
||||
- Implements dynamic client registration (RFC 7591) and resource indicators (RFC 8707).
|
||||
- Persists client credentials and tokens to `mcp_settings.json` for reconnects.
|
||||
|
||||
## When MCPHub Switches to OAuth
|
||||
1. MCPHub calls an MCP server that requires authorization and receives `401 Unauthorized`.
|
||||
2. The response exposes a `WWW-Authenticate` header pointing to protected resource metadata (`authorization_server` or `as_uri`).
|
||||
3. MCPHub discovers the authorization server metadata, registers (if needed), and opens the browser so the user can authorize once.
|
||||
4. After the callback is handled, MCPHub reconnects with fresh tokens and resumes requests transparently.
|
||||
|
||||
> MCPHub logs each stage (discovery, registration, authorization URL, token exchange) in the server detail view and the backend logs.
|
||||
|
||||
## Quick Start by Server Type
|
||||
|
||||
### Servers with Dynamic Registration Support
|
||||
Some servers expose complete OAuth metadata and allow dynamic client registration. For example, Vercel and Linear MCP servers only need their SSE endpoint configured:
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"vercel": {
|
||||
"type": "sse",
|
||||
"url": "https://mcp.vercel.com"
|
||||
},
|
||||
"linear": {
|
||||
"type": "sse",
|
||||
"url": "https://mcp.linear.app/mcp"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- MCPHub discovers the authorization server, registers the client, and handles PKCE automatically.
|
||||
- Tokens are stored in `mcp_settings.json`; no additional dashboard configuration is needed.
|
||||
|
||||
### Servers Requiring Manual Client Provisioning
|
||||
Other providers do not support dynamic registration. GitHub’s MCP endpoint (`https://api.githubcopilot.com/mcp/`) is one example. To connect:
|
||||
|
||||
1. Create an OAuth App in the provider’s console (for GitHub, go to **Settings → Developer settings → OAuth Apps**).
|
||||
2. Set the callback/redirect URL to `http://localhost:3000/oauth/callback` (or your deployed dashboard domain).
|
||||
3. Copy the issued client ID and client secret.
|
||||
4. Supply the credentials through the MCPHub dashboard or by editing `mcp_settings.json` as shown below.
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"github": {
|
||||
"type": "sse",
|
||||
"url": "https://api.githubcopilot.com/mcp/",
|
||||
"oauth": {
|
||||
"clientId": "${GITHUB_OAUTH_APP_ID}",
|
||||
"clientSecret": "${GITHUB_OAUTH_APP_SECRET}",
|
||||
"scopes": ["replace-with-provider-scope"],
|
||||
"resource": "https://api.githubcopilot.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- MCPHub skips dynamic registration and uses the credentials you provide to complete the OAuth exchange.
|
||||
- Update the dashboard or configuration file whenever you rotate secrets.
|
||||
- Replace `scopes` with the exact scope strings required by the provider.
|
||||
|
||||
## Configuration Options
|
||||
You can rely on auto-detection for most servers or declare OAuth settings explicitly in `mcp_settings.json`. Only populate the fields you need.
|
||||
|
||||
### Basic Auto Detection (Minimal Config)
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"secured-sse": {
|
||||
"type": "sse",
|
||||
"url": "https://mcp.example.com/sse",
|
||||
"oauth": {
|
||||
"scopes": ["mcp.tools", "mcp.prompts"],
|
||||
"resource": "https://mcp.example.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
- MCPHub will discover the authorization server from challenge headers and walk the user through authorization automatically.
|
||||
- Tokens (including refresh tokens) are stored on disk and reused on restart.
|
||||
|
||||
### Static Client Credentials (Bring Your Own Client)
|
||||
```json
|
||||
{
|
||||
"oauth": {
|
||||
"clientId": "mcphub-client",
|
||||
"clientSecret": "replace-me-if-required",
|
||||
"authorizationEndpoint": "https://auth.example.com/oauth/authorize",
|
||||
"tokenEndpoint": "https://auth.example.com/oauth/token",
|
||||
"redirectUri": "http://localhost:3000/oauth/callback"
|
||||
}
|
||||
}
|
||||
```
|
||||
- Use this when the authorization server requires manual client provisioning.
|
||||
- `redirectUri` defaults to `http://localhost:3000/oauth/callback`; override it when running behind a custom domain.
|
||||
|
||||
### Dynamic Client Registration (RFC 7591)
|
||||
```json
|
||||
{
|
||||
"oauth": {
|
||||
"dynamicRegistration": {
|
||||
"enabled": true,
|
||||
"issuer": "https://auth.example.com",
|
||||
"metadata": {
|
||||
"client_name": "MCPHub",
|
||||
"redirect_uris": [
|
||||
"http://localhost:3000/oauth/callback",
|
||||
"https://mcphub.example.com/oauth/callback"
|
||||
],
|
||||
"scope": "mcp.tools mcp.prompts",
|
||||
"grant_types": ["authorization_code", "refresh_token"]
|
||||
},
|
||||
"initialAccessToken": "optional-token-if-required"
|
||||
},
|
||||
"scopes": ["mcp.tools", "mcp.prompts"],
|
||||
"resource": "https://mcp.example.com"
|
||||
}
|
||||
}
|
||||
```
|
||||
- MCPHub discovers endpoints via `issuer`, registers itself, and persists the issued `client_id`/`client_secret`.
|
||||
- Provide `initialAccessToken` only when the registration endpoint is protected.
|
||||
|
||||
## Authorization Flow
|
||||
1. **Initialization** – On startup MCPHub processes every server entry, discovers metadata, and registers the client if `dynamicRegistration.enabled` is true.
|
||||
2. **User Authorization** – Initiating a connection launches the system browser to the server’s authorize page with PKCE parameters.
|
||||
3. **Callback Handling** – The built-in route (`/oauth/callback`) verifies the `state`, completes the token exchange, and saves the tokens via the MCP SDK.
|
||||
4. **Token Lifecycle** – Access and refresh tokens are cached in memory, refreshed automatically, and written back to `mcp_settings.json`.
|
||||
|
||||
## Tips & Troubleshooting
|
||||
- Confirm that the redirect URI used during authorization exactly matches one of the `redirect_uris` registered with the authorization server.
|
||||
- When running behind HTTPS, expose the callback URL publicly or configure a reverse proxy at `/oauth/callback`.
|
||||
- If discovery fails, supply `authorizationEndpoint` and `tokenEndpoint` explicitly to bypass metadata lookup.
|
||||
- Remove stale tokens from `mcp_settings.json` if an authorization server revokes access—MCPHub will prompt for a fresh login on the next request.
|
||||
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` */}
|
||||
1. **Dashboard Updates**: Immediately applies changes made through the web interface
|
||||
2. **API Updates**: Real-time updates via REST API calls
|
||||
3. **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>
|
||||
795
docs/features/smart-routing.mdx
Normal file
@@ -0,0 +1,795 @@
|
||||
---
|
||||
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">
|
||||
```
|
||||
# Search across all servers
|
||||
http://localhost:3000/mcp/$smart
|
||||
|
||||
# Search within a specific group
|
||||
http://localhost:3000/mcp/$smart/{group}
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="SSE (Legacy)">
|
||||
```
|
||||
# Search across all servers
|
||||
http://localhost:3000/sse/$smart
|
||||
|
||||
# Search within a specific group
|
||||
http://localhost:3000/sse/$smart/{group}
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### Group-Scoped Smart Routing
|
||||
|
||||
Smart Routing now supports group-scoped searches, allowing you to limit tool discovery to servers within a specific group:
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Using Group-Scoped Smart Routing">
|
||||
Connect your AI client to a group-specific Smart Routing endpoint:
|
||||
|
||||
```
|
||||
http://localhost:3000/mcp/$smart/production
|
||||
```
|
||||
|
||||
This endpoint will only search for tools within servers that belong to the "production" group.
|
||||
|
||||
**Benefits:**
|
||||
- **Focused Results**: Only tools from relevant servers are returned
|
||||
- **Better Performance**: Reduced search space for faster queries
|
||||
- **Environment Isolation**: Keep development, staging, and production tools separate
|
||||
- **Access Control**: Limit tool discovery based on user permissions
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Example: Environment-Based Groups">
|
||||
Create groups for different environments:
|
||||
|
||||
```bash
|
||||
# Development environment
|
||||
http://localhost:3000/mcp/$smart/development
|
||||
|
||||
# Staging environment
|
||||
http://localhost:3000/mcp/$smart/staging
|
||||
|
||||
# Production environment
|
||||
http://localhost:3000/mcp/$smart/production
|
||||
```
|
||||
|
||||
Each endpoint will only return tools from servers in that specific environment group.
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Example: Team-Based Groups">
|
||||
Organize tools by team or department:
|
||||
|
||||
```bash
|
||||
# Backend team tools
|
||||
http://localhost:3000/mcp/$smart/backend-team
|
||||
|
||||
# Frontend team tools
|
||||
http://localhost:3000/mcp/$smart/frontend-team
|
||||
|
||||
# DevOps team tools
|
||||
http://localhost:3000/mcp/$smart/devops-team
|
||||
```
|
||||
|
||||
This enables teams to have focused access to their relevant toolsets.
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="How It Works">
|
||||
When using `$smart/{group}`:
|
||||
|
||||
1. The system identifies the specified group
|
||||
2. Retrieves all servers belonging to that group
|
||||
3. Filters the tool search to only those servers
|
||||
4. Returns results scoped to the group's servers
|
||||
|
||||
If the group doesn't exist or has no servers, the search will return no results.
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
{/* ### 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>
|
||||
128
docs/index.mdx
@@ -1,71 +1,95 @@
|
||||
---
|
||||
title: Introduction
|
||||
description: "Welcome to the home of your new documentation"
|
||||
title: MCPHub
|
||||
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"
|
||||
/>
|
||||
{/* <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" /> */}
|
||||
|
||||
## Setting up
|
||||
# Welcome to MCPHub
|
||||
|
||||
The first step to world-class documentation is setting up your editing environments.
|
||||
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="Edit Your Docs"
|
||||
icon="pen-to-square"
|
||||
href="https://mintlify.com/docs/quickstart"
|
||||
>
|
||||
Get your docs set up locally for easy development
|
||||
<Card title="Unified Management" icon="server" href="/features/server-management">
|
||||
Centrally manage multiple MCP servers with hot-swappable configuration
|
||||
</Card>
|
||||
<Card
|
||||
title="Preview Changes"
|
||||
icon="image"
|
||||
href="https://mintlify.com/docs/development"
|
||||
>
|
||||
Preview your changes before you push to make sure they're perfect
|
||||
<Card title="Group Management" icon="users" href="/features/group-management">
|
||||
Organize servers into logical groups for streamlined access control
|
||||
</Card>
|
||||
<Card title="Smart Routing" icon="route" href="/features/smart-routing">
|
||||
AI-powered tool discovery using vector semantic search
|
||||
</Card>
|
||||
<Card title="Real-time Monitoring" icon="chart-line" href="/features/monitoring">
|
||||
Monitor server status and performance from a unified dashboard
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Make it yours
|
||||
## Quick Start
|
||||
|
||||
Update your docs to your brand and add valuable content for the best user conversion.
|
||||
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="Customize Style"
|
||||
icon="palette"
|
||||
href="https://mintlify.com/docs/settings/global"
|
||||
>
|
||||
Customize your docs to your company's colors and brands
|
||||
<Card title="Quick Start Guide" icon="rocket" href="/quickstart">
|
||||
Get MCPHub running in 5 minutes
|
||||
</Card>
|
||||
<Card
|
||||
title="Reference APIs"
|
||||
icon="code"
|
||||
href="https://mintlify.com/docs/api-playground/openapi"
|
||||
>
|
||||
Automatically generate endpoints from an OpenAPI spec
|
||||
<Card title="Installation Guide" icon="download" href="/installation">
|
||||
Detailed installation instructions for all platforms
|
||||
</Card>
|
||||
<Card
|
||||
title="Add Components"
|
||||
icon="screwdriver-wrench"
|
||||
href="https://mintlify.com/docs/content/components/accordions"
|
||||
>
|
||||
Build interactive features and designs to guide your users
|
||||
<Card title="Configuration" icon="cog" href="/configuration/mcp-settings">
|
||||
Learn how to configure your MCP servers
|
||||
</Card>
|
||||
<Card
|
||||
title="Get Inspiration"
|
||||
icon="stars"
|
||||
href="https://mintlify.com/customers"
|
||||
>
|
||||
Check out our showcase of our favorite documentation
|
||||
<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>
|
||||
|
||||
595
docs/installation.mdx
Normal file
@@ -0,0 +1,595 @@
|
||||
---
|
||||
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="" \
|
||||
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
|
||||
```
|
||||
|
||||
{/* #### 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:
|
||||
initContainers:
|
||||
- name: prepare-config
|
||||
image: busybox:1.28
|
||||
command:
|
||||
[
|
||||
"sh",
|
||||
"-c",
|
||||
"cp /config-ro/mcp_settings.json /etc/mcphub/mcp_settings.json",
|
||||
]
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: /config-ro
|
||||
readOnly: true
|
||||
- name: app-storage
|
||||
mountPath: /etc/mcphub
|
||||
containers:
|
||||
- name: mcphub
|
||||
image: samanhappy/mcphub:latest
|
||||
ports:
|
||||
- containerPort: 3000
|
||||
resources:
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
limits:
|
||||
cpu: 500m
|
||||
memory: 512Mi
|
||||
env:
|
||||
- name: PORT
|
||||
value: "3000"
|
||||
- name: MCPHUB_SETTING_PATH
|
||||
value: /etc/mcphub/mcp_settings.json
|
||||
volumeMounts:
|
||||
- name: app-storage
|
||||
mountPath: /etc/mcphub
|
||||
volumes:
|
||||
- name: config
|
||||
configMap:
|
||||
name: mcphub-config
|
||||
- name: app-storage
|
||||
emptyDir: {}
|
||||
```
|
||||
|
||||
#### 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
|
||||
}
|
||||
``` */}
|
||||
|
||||
### 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>
|
||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 1.1 KiB |
@@ -1,97 +1,226 @@
|
||||
---
|
||||
title: 'Quickstart'
|
||||
description: 'Start building awesome documentation in under 5 minutes'
|
||||
title: 'Quick Start Guide'
|
||||
description: 'Get MCPHub running in 5 minutes'
|
||||
---
|
||||
|
||||
## Setup your development
|
||||
## Installation
|
||||
|
||||
Learn how to update your docs locally and deploy them to the public.
|
||||
<Tabs>
|
||||
<Tab title="Docker (Recommended)">
|
||||
The fastest way to get started with MCPHub is using Docker:
|
||||
|
||||
### Edit and preview
|
||||
```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/{groupName} ```
|
||||
</Tab>
|
||||
<Tab title="Individual Server">
|
||||
Access a single server: ``` http://localhost:3000/mcp/{serverName} ```
|
||||
</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 icon="github" title="Clone your docs locally">
|
||||
During the onboarding process, we created a repository on your Github with
|
||||
your docs content. You can find this repository on our
|
||||
[dashboard](https://dashboard.mintlify.com). To clone the repository
|
||||
locally, follow these
|
||||
[instructions](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository)
|
||||
in your terminal.
|
||||
<Accordion title="Web Fetch Server">
|
||||
```json
|
||||
{
|
||||
"name": "fetch",
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"]
|
||||
}
|
||||
```
|
||||
</Accordion>
|
||||
<Accordion icon="rectangle-terminal" title="Preview changes">
|
||||
Previewing helps you make sure your changes look as intended. We built a
|
||||
command line interface to render these changes locally.
|
||||
1. Install the
|
||||
[Mintlify CLI](https://www.npmjs.com/package/mintlify) to preview the
|
||||
documentation changes locally with this command: ``` npm i -g mintlify ```
|
||||
2. Run the following command at the root of your documentation (where
|
||||
`docs.json` is): ``` mintlify dev ```
|
||||
<Note>
|
||||
If you’re currently using the legacy ```mint.json``` configuration file, please update the Mintlify CLI:
|
||||
|
||||
|
||||
```npm i -g mintlify@latest```
|
||||
And run the new upgrade command in your docs repository:
|
||||
|
||||
```mintlify upgrade```
|
||||
You should now be using the new ```docs.json``` configuration file. Feel free to delete the ```mint.json``` file from your repository.
|
||||
</Note>
|
||||
|
||||
<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>
|
||||
|
||||
### Deploy your changes
|
||||
{/* ## Verification
|
||||
|
||||
<AccordionGroup>
|
||||
Test your setup by making a simple request:
|
||||
|
||||
<Accordion icon="message-bot" title="Install our Github app">
|
||||
Our Github app automatically deploys your changes to your docs site, so you
|
||||
don't need to manage deployments yourself. You can find the link to install on
|
||||
your [dashboard](https://dashboard.mintlify.com). Once the bot has been
|
||||
successfully installed, there should be a check mark next to the commit hash
|
||||
of the repo.
|
||||
</Accordion>
|
||||
<Accordion icon="rocket" title="Push your changes">
|
||||
[Commit and push your changes to
|
||||
Git](https://docs.github.com/en/get-started/using-git/pushing-commits-to-a-remote-repository#about-git-push)
|
||||
for your changes to update in your docs site. If you push and don't see that
|
||||
the Github app successfully deployed your changes, you can also manually
|
||||
update your docs through our [dashboard](https://dashboard.mintlify.com).
|
||||
</Accordion>
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/mcp \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "tools/list",
|
||||
"params": {}
|
||||
}'
|
||||
```
|
||||
|
||||
</AccordionGroup>
|
||||
You should receive a list of available tools from your configured MCP servers. */}
|
||||
|
||||
## Update your docs
|
||||
|
||||
Add content directly in your files with MDX syntax and React components. You can use any of our components, or even build your own.
|
||||
|
||||
<CardGroup>
|
||||
|
||||
<Card title="Add Content With MDX" icon="file" href="/essentials/markdown">
|
||||
Add content to your docs with MDX syntax.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="Add Code Blocks"
|
||||
icon="square-code"
|
||||
href="/essentials/code"
|
||||
>
|
||||
Add code directly to your docs with syntax highlighting.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="Add Images"
|
||||
icon="image"
|
||||
href="/essentials/images"
|
||||
>
|
||||
Add images to your docs to make them more engaging.
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="Add Custom Components"
|
||||
icon="puzzle-piece"
|
||||
href="/essentials/reusable-snippets"
|
||||
>
|
||||
Add templates to your docs to make them more reusable.
|
||||
</Card>
|
||||
## 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!
|
||||
|
||||
147
docs/zh/api-reference/auth.mdx
Normal file
@@ -0,0 +1,147 @@
|
||||
---
|
||||
title: "身份验证"
|
||||
description: "管理用户和身份验证。"
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="POST /api/auth/login"
|
||||
href="#login"
|
||||
>
|
||||
登录以获取 JWT 令牌。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/auth/register"
|
||||
href="#register"
|
||||
>
|
||||
注册一个新用户。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /api/auth/user"
|
||||
href="#get-current-user"
|
||||
>
|
||||
获取当前已验证的用户。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/auth/change-password"
|
||||
href="#change-password"
|
||||
>
|
||||
更改当前用户的密码。
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### 登录
|
||||
|
||||
验证用户身份并返回 JWT 令牌及用户详细信息。
|
||||
|
||||
- **端点**: `/api/auth/login`
|
||||
- **方法**: `POST`
|
||||
- **正文**:
|
||||
- `username` (string, 必填): 用户名。
|
||||
- `password` (string, 必填): 用户密码。
|
||||
- **请求示例**:
|
||||
```json
|
||||
{
|
||||
"username": "admin",
|
||||
"password": "admin123"
|
||||
}
|
||||
```
|
||||
- **成功响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "登录成功",
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||
"user": {
|
||||
"username": "admin",
|
||||
"isAdmin": true,
|
||||
"permissions": { ... }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 注册
|
||||
|
||||
注册一个新用户并返回 JWT 令牌。
|
||||
|
||||
- **端点**: `/api/auth/register`
|
||||
- **方法**: `POST`
|
||||
- **正文**:
|
||||
- `username` (string, 必填): 新的用户名。
|
||||
- `password` (string, 必填): 新的用户密码 (至少6个字符)。
|
||||
- `isAdmin` (boolean, 可选): 用户是否应有管理员权限。
|
||||
- **请求示例**:
|
||||
```json
|
||||
{
|
||||
"username": "newuser",
|
||||
"password": "password123",
|
||||
"isAdmin": false
|
||||
}
|
||||
```
|
||||
- **成功响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||
"user": {
|
||||
"username": "newuser",
|
||||
"isAdmin": false,
|
||||
"permissions": { ... }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 获取当前用户
|
||||
|
||||
检索当前通过身份验证的用户的个人资料。
|
||||
|
||||
- **端点**: `/api/auth/user`
|
||||
- **方法**: `GET`
|
||||
- **身份验证**: 需要承载令牌 (Bearer Token)。
|
||||
- **成功响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"user": {
|
||||
"username": "admin",
|
||||
"isAdmin": true,
|
||||
"permissions": { ... }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 更改密码
|
||||
|
||||
允许通过身份验证的用户更改其密码。
|
||||
|
||||
- **端点**: `/api/auth/change-password`
|
||||
- **方法**: `POST`
|
||||
- **身份验证**: 需要承载令牌 (Bearer Token)。
|
||||
- **正文**:
|
||||
- `currentPassword` (string, 必填): 用户的当前密码。
|
||||
- `newPassword` (string, 必填): 新的密码 (至少6个字符)。
|
||||
- **请求示例**:
|
||||
```json
|
||||
{
|
||||
"currentPassword": "oldpassword",
|
||||
"newPassword": "newpassword123"
|
||||
}
|
||||
```
|
||||
- **成功响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "密码更新成功"
|
||||
}
|
||||
```
|
||||
111
docs/zh/api-reference/config.mdx
Normal file
@@ -0,0 +1,111 @@
|
||||
---
|
||||
title: "配置"
|
||||
description: "管理和检索系统级配置。"
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card title="PUT /api/system-config" href="#update-system-config">更新主系统配置。</Card>
|
||||
<Card title="GET /api/settings" href="#get-all-settings">获取所有系统设置,包括服务器和群组。</Card>
|
||||
<Card title="GET /config" href="#get-runtime-config">获取前端的公共运行时配置。</Card>
|
||||
<Card title="GET /public-config" href="#get-public-config">获取公共配置以检查是否跳过身份验证。</Card>
|
||||
|
||||
---
|
||||
|
||||
### 更新系统配置
|
||||
|
||||
更新系统配置的各个部分。您只需提供要更新部分的键。
|
||||
|
||||
- **端点**: `/api/system-config`
|
||||
- **方法**: `PUT`
|
||||
- **正文**: 一个 JSON 对象,包含以下一个或多个顶级键:`routing`、`install`、`smartRouting`、`mcpRouter`。
|
||||
|
||||
#### 路由配置 (`routing`)
|
||||
|
||||
- `enableGlobalRoute` (boolean): 启用或禁用全局 `/api/mcp` 路由。
|
||||
- `enableGroupNameRoute` (boolean): 启用或禁用基于群组的路由 (例如 `/api/mcp/group/:groupName`)。
|
||||
- `enableBearerAuth` (boolean): 为 MCP 路由启用承载令牌身份验证。
|
||||
- `bearerAuthKey` (string): 用于承载身份验证的密钥。
|
||||
- `skipAuth` (boolean): 如果为 true,则跳过所有身份验证,使实例公开。
|
||||
|
||||
#### 安装配置 (`install`)
|
||||
|
||||
- `pythonIndexUrl` (string): 用于安装的 Python 包索引 (PyPI) 的基础 URL。
|
||||
- `npmRegistry` (string): 用于安装的 npm 注册表 URL。
|
||||
- `baseUrl` (string): 此 MCPHub 实例的公共基础 URL。
|
||||
|
||||
#### 智能路由配置 (`smartRouting`)
|
||||
|
||||
- `enabled` (boolean): 启用或禁用智能路由功能。
|
||||
- `dbUrl` (string): 用于存储嵌入的数据库连接 URL。
|
||||
- `openaiApiBaseUrl` (string): 用于生成嵌入的 OpenAI 兼容 API 的基础 URL。
|
||||
- `openaiApiKey` (string): 嵌入服务的 API 密钥。
|
||||
- `openaiApiEmbeddingModel` (string): 要使用的嵌入模型的名称。
|
||||
|
||||
#### MCP 路由器配置 (`mcpRouter`)
|
||||
|
||||
- `apiKey` (string): MCP 路由器服务的 API 密钥。
|
||||
- `referer` (string): 用于 MCP 路由器请求的 referer 头。
|
||||
- `title` (string): 在 MCP 路由器上显示的此实例的标题。
|
||||
- `baseUrl` (string): MCP 路由器 API 的基础 URL。
|
||||
|
||||
- **请求示例**:
|
||||
```json
|
||||
{
|
||||
"routing": {
|
||||
"skipAuth": true
|
||||
},
|
||||
"smartRouting": {
|
||||
"enabled": true,
|
||||
"dbUrl": "postgresql://user:pass@host:port/db"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 获取所有设置
|
||||
|
||||
检索实例的整个设置对象,包括所有服务器配置、群组和系统设置。这是 `mcp_settings.json` 文件的完整转储。
|
||||
|
||||
- **端点**: `/api/settings`
|
||||
- **方法**: `GET`
|
||||
|
||||
---
|
||||
|
||||
### 获取运行时配置
|
||||
|
||||
检索前端应用程序所需的基本运行时配置。此端点不需要身份验证。
|
||||
|
||||
- **端点**: `/config`
|
||||
- **方法**: `GET`
|
||||
- **成功响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"basePath": "",
|
||||
"version": "1.0.0",
|
||||
"name": "MCPHub"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 获取公共配置
|
||||
|
||||
检索公共配置,主要用于检查是否跳过身份验证。这允许前端在用户登录前相应地调整其行为。此端点不需要身份验证。
|
||||
|
||||
- **端点**: `/public-config`
|
||||
- **方法**: `GET`
|
||||
- **成功响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"skipAuth": false,
|
||||
"permissions": {}
|
||||
}
|
||||
}
|
||||
```
|
||||
212
docs/zh/api-reference/groups.mdx
Normal file
@@ -0,0 +1,212 @@
|
||||
---
|
||||
title: "群组"
|
||||
description: "管理服务器群组以组织和路由请求。"
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card title="GET /api/groups" href="#get-all-groups">获取所有群组的列表。</Card>
|
||||
<Card title="POST /api/groups" href="#create-a-new-group">创建一个新群组。</Card>
|
||||
<Card title="GET /api/groups/:id" href="#get-a-group">获取特定群组的详细信息。</Card>
|
||||
<Card title="PUT /api/groups/:id" href="#update-a-group">更新现有群组。</Card>
|
||||
<Card title="DELETE /api/groups/:id" href="#delete-a-group">删除一个群组。</Card>
|
||||
<Card title="POST /api/groups/:id/servers" href="#add-server-to-group">将服务器添加到群组。</Card>
|
||||
<Card title="DELETE /api/groups/:id/servers/:serverName" href="#remove-server-from-group">从群组中删除服务器。</Card>
|
||||
<Card title="PUT /api/groups/:id/servers/batch" href="#batch-update-group-servers">批量更新群组中的服务器。</Card>
|
||||
<Card title="GET /api/groups/:id/server-configs" href="#get-group-server-configs">获取群组中详细的服务器配置。</Card>
|
||||
<Card title="PUT /api/groups/:id/server-configs/:serverName/tools" href="#update-group-server-tools">更新群组中服务器的工具选择。</Card>
|
||||
|
||||
---
|
||||
|
||||
### 获取所有群组
|
||||
|
||||
检索所有服务器群组的列表。
|
||||
|
||||
- **端点**: `/api/groups`
|
||||
- **方法**: `GET`
|
||||
- **成功响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"id": "group-1",
|
||||
"name": "我的群组",
|
||||
"description": "服务器的集合。",
|
||||
"servers": ["server1", "server2"],
|
||||
"owner": "admin"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 创建一个新群组
|
||||
|
||||
创建一个新的服务器群组。
|
||||
|
||||
- **端点**: `/api/groups`
|
||||
- **方法**: `POST`
|
||||
- **正文**:
|
||||
- `name` (string, 必填): 群组的名称。
|
||||
- `description` (string, 可选): 群组的描述。
|
||||
- `servers` (array of strings, 可选): 要包含在群组中的服务器名称列表。
|
||||
- **请求示例**:
|
||||
```json
|
||||
{
|
||||
"name": "我的新群组",
|
||||
"description": "新群组的描述",
|
||||
"servers": ["server1", "server2"]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 获取一个群组
|
||||
|
||||
通过 ID 或名称检索特定群组的详细信息。
|
||||
|
||||
- **端点**: `/api/groups/:id`
|
||||
- **方法**: `GET`
|
||||
- **参数**:
|
||||
- `:id` (string, 必填): 群组的 ID 或名称。
|
||||
|
||||
---
|
||||
|
||||
### 更新一个群组
|
||||
|
||||
更新现有群组的名称、描述或服务器列表。
|
||||
|
||||
- **端点**: `/api/groups/:id`
|
||||
- **方法**: `PUT`
|
||||
- **参数**:
|
||||
- `:id` (string, 必填): 要更新的群组的 ID 或名称。
|
||||
- **正文**:
|
||||
- `name` (string, 可选): 群组的新名称。
|
||||
- `description` (string, 可选): 群组的新描述。
|
||||
- `servers` (array, 可选): 群组的新服务器列表。格式请参阅 [批量更新群组服务器](#batch-update-group-servers)。
|
||||
- **请求示例**:
|
||||
```json
|
||||
{
|
||||
"name": "更新后的群组名称",
|
||||
"description": "更新后的描述"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 删除一个群组
|
||||
|
||||
通过 ID 或名称删除一个群组。
|
||||
|
||||
- **端点**: `/api/groups/:id`
|
||||
- **方法**: `DELETE`
|
||||
- **参数**:
|
||||
- `:id` (string, 必填): 要删除的群组的 ID 或名称。
|
||||
|
||||
---
|
||||
|
||||
### 将服务器添加到群组
|
||||
|
||||
将单个服务器添加到群组。
|
||||
|
||||
- **端点**: `/api/groups/:id/servers`
|
||||
- **方法**: `POST`
|
||||
- **参数**:
|
||||
- `:id` (string, 必填): 群组的 ID 或名称。
|
||||
- **正文**:
|
||||
- `serverName` (string, 必填): 要添加的服务器的名称。
|
||||
- **请求示例**:
|
||||
```json
|
||||
{
|
||||
"serverName": "my-server"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 从群组中删除服务器
|
||||
|
||||
从群组中删除单个服务器。
|
||||
|
||||
- **端点**: `/api/groups/:id/servers/:serverName`
|
||||
- **方法**: `DELETE`
|
||||
- **参数**:
|
||||
- `:id` (string, 必填): 群组的 ID 或名称。
|
||||
- `:serverName` (string, 必填): 要删除的服务器的名称。
|
||||
|
||||
---
|
||||
|
||||
### 批量更新群组服务器
|
||||
|
||||
用新的列表替换群组中的所有服务器。该列表可以是简单的字符串或详细的配置对象。
|
||||
|
||||
- **端点**: `/api/groups/:id/servers/batch`
|
||||
- **方法**: `PUT`
|
||||
- **参数**:
|
||||
- `:id` (string, 必填): 群组的 ID 或名称。
|
||||
- **正文**:
|
||||
- `servers` (array, 必填): 服务器名称(字符串)或服务器配置对象的数组。
|
||||
- **请求示例 (简单)**:
|
||||
```json
|
||||
{
|
||||
"servers": ["server1", "server2"]
|
||||
}
|
||||
```
|
||||
- **请求示例 (详细)**:
|
||||
```json
|
||||
{
|
||||
"servers": [
|
||||
{ "name": "server1", "tools": "all" },
|
||||
{ "name": "server2", "tools": ["toolA", "toolB"] }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 获取群组服务器配置
|
||||
|
||||
检索群组内所有服务器的详细配置,包括启用了哪些工具。
|
||||
|
||||
- **端点**: `/api/groups/:id/server-configs`
|
||||
- **方法**: `GET`
|
||||
- **参数**:
|
||||
- `:id` (string, 必填): 群组的 ID 或名称。
|
||||
- **成功响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"name": "server1",
|
||||
"tools": "all"
|
||||
},
|
||||
{
|
||||
"name": "server2",
|
||||
"tools": ["toolA", "toolB"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 更新群组服务器工具
|
||||
|
||||
更新群组内特定服务器的工具选择。
|
||||
|
||||
- **端点**: `/api/groups/:id/server-configs/:serverName/tools`
|
||||
- **方法**: `PUT`
|
||||
- **参数**:
|
||||
- `:id` (string, 必填): 群组的 ID 或名称。
|
||||
- `:serverName` (string, 必填): 要更新的服务器的名称。
|
||||
- **正文**:
|
||||
- `tools` (string or array of strings, 必填): 字符串 `"all"` 表示启用所有工具,或一个工具名称数组以指定启用哪些工具。
|
||||
- **请求示例**:
|
||||
```json
|
||||
{
|
||||
"tools": ["toolA", "toolC"]
|
||||
}
|
||||
```
|
||||
13
docs/zh/api-reference/introduction.mdx
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
title: "介绍"
|
||||
description: "欢迎来到 MCPHub API 文档。"
|
||||
---
|
||||
|
||||
MCPHub API 提供了一整套端点来管理您的 MCP 服务器、群组、用户等。该 API 分为两个主要类别:
|
||||
|
||||
- **MCP 端点**: 这些是与您的 MCP 服务器交互的主要端点。它们提供了一个统一的界面,用于向您的服务器发送请求并实时接收响应。
|
||||
- **管理 API**: 这些端点用于管理 MCPHub 实例本身。这包括管理服务器、群组、用户和系统设置。
|
||||
|
||||
所有 API 端点都在 `/api` 路径下可用。例如,获取所有服务器的端点是 `/api/servers`。
|
||||
|
||||
大多数管理 API 端点都需要身份验证。有关更多详细信息,请参阅[身份验证](/api-reference/auth)部分。
|
||||
81
docs/zh/api-reference/logs.mdx
Normal file
@@ -0,0 +1,81 @@
|
||||
---
|
||||
title: "日志"
|
||||
description: "访问和管理服务器日志。"
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="GET /api/logs"
|
||||
href="#get-all-logs"
|
||||
>
|
||||
获取所有日志。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="DELETE /api/logs"
|
||||
href="#clear-logs"
|
||||
>
|
||||
清除所有日志。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /api/logs/stream"
|
||||
href="#stream-logs"
|
||||
>
|
||||
实时流式传输日志。
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### 获取所有日志
|
||||
|
||||
检索所有存储的日志。
|
||||
|
||||
- **端点**: `/api/logs`
|
||||
- **方法**: `GET`
|
||||
- **成功响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"timestamp": "2023-10-27T10:00:00.000Z",
|
||||
"level": "info",
|
||||
"message": "服务器成功启动。",
|
||||
"service": "system"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 清除日志
|
||||
|
||||
删除所有存储的日志。
|
||||
|
||||
- **端点**: `/api/logs`
|
||||
- **方法**: `DELETE`
|
||||
- **成功响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "日志清除成功"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 流式传输日志
|
||||
|
||||
使用服务器发送事件 (SSE) 实时流式传输日志。连接将保持打开状态,新的日志条目将在发生时发送。
|
||||
|
||||
- **端点**: `/api/logs/stream`
|
||||
- **方法**: `GET`
|
||||
- **响应格式**: 该流发送带有包含 JSON 对象的 `data` 字段的事件。第一个事件的 `type` 为 `initial`,包含所有历史日志。后续事件的 `type` 为 `log`,包含单个新日志条目。
|
||||
|
||||
- **事件示例**:
|
||||
```
|
||||
data: {"type":"log","log":{"timestamp":"2023-10-27T10:00:05.000Z","level":"debug","message":"正在处理 /api/some-endpoint 的请求","service":"mcp-server"}}
|
||||
```
|
||||
33
docs/zh/api-reference/mcp-http.mdx
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
title: "MCP HTTP 端点"
|
||||
description: "使用统一的 HTTP 端点连接到您的 MCP 服务器。"
|
||||
---
|
||||
|
||||
MCPHub 为您的所有 MCP 服务器提供统一的可流式 HTTP 接口。这使您可以向任何配置的 MCP 服务器发送请求并实时接收响应。
|
||||
|
||||
### 统一端点
|
||||
|
||||
此端点提供对所有已启用的 MCP 服务器的访问。
|
||||
|
||||
- **端点**: `http://localhost:3000/mcp`
|
||||
- **方法**: `POST`
|
||||
|
||||
### 特定群组的端点
|
||||
|
||||
要定向访问特定的服务器群组,请使用基于群组的 HTTP 端点。
|
||||
|
||||
- **端点**: `http://localhost:3000/mcp/{group}`
|
||||
- **方法**: `POST`
|
||||
- **参数**:
|
||||
- `{group}`: 群组的 ID 或名称。
|
||||
|
||||
### 特定服务器的端点
|
||||
|
||||
要直接访问单个服务器,请使用特定于服务器的 HTTP 端点。
|
||||
|
||||
- **端点**: `http://localhost:3000/mcp/{server}`
|
||||
- **方法**: `POST`
|
||||
- **参数**:
|
||||
- `{server}`: 服务器的名称。
|
||||
|
||||
> **注意**: 如果服务器名称和群组名称相同,则群组将优先。
|
||||
25
docs/zh/api-reference/mcp-sse.mdx
Normal file
@@ -0,0 +1,25 @@
|
||||
---
|
||||
title: "MCP SSE 端点 (已弃用)"
|
||||
description: "使用 SSE 端点连接到您的 MCP 服务器。"
|
||||
---
|
||||
|
||||
SSE 端点已弃用,并将在未来版本中删除。请改用 [MCP HTTP 端点](/api-reference/mcp-http)。
|
||||
|
||||
### 统一端点
|
||||
|
||||
- **端点**: `http://localhost:3000/sse`
|
||||
- **方法**: `GET`
|
||||
|
||||
### 特定群组的端点
|
||||
|
||||
- **端点**: `http://localhost:3000/sse/{group}`
|
||||
- **方法**: `GET`
|
||||
- **参数**:
|
||||
- `{group}`: 群组的 ID 或名称。
|
||||
|
||||
### 特定服务器的端点
|
||||
|
||||
- **端点**: `http://localhost:3000/sse/{server}`
|
||||
- **方法**: `GET`
|
||||
- **参数**:
|
||||
- `{server}`: 服务器的名称。
|
||||
276
docs/zh/api-reference/openapi.mdx
Normal file
@@ -0,0 +1,276 @@
|
||||
---
|
||||
title: "OpenAPI 集成"
|
||||
description: "从 MCP 工具生成 OpenAPI 规范,与 OpenWebUI 和其他系统无缝集成"
|
||||
---
|
||||
|
||||
# OpenWebUI 集成的 OpenAPI 生成
|
||||
|
||||
MCPHub 现在支持从 MCP 工具生成 OpenAPI 3.0.3 规范,实现与 OpenWebUI 和其他 OpenAPI 兼容系统的无缝集成,无需 MCPO 作为中间代理。
|
||||
|
||||
## 功能特性
|
||||
|
||||
- ✅ **自动 OpenAPI 生成**:将 MCP 工具转换为 OpenAPI 3.0.3 规范
|
||||
- ✅ **OpenWebUI 兼容**:无需 MCPO 代理的直接集成
|
||||
- ✅ **实时工具发现**:动态包含已连接 MCP 服务器的工具
|
||||
- ✅ **双参数支持**:支持 GET(查询参数)和 POST(JSON 正文)进行工具执行
|
||||
- ✅ **无需身份验证**:OpenAPI 端点公开,便于集成
|
||||
- ✅ **完整元数据**:具有适当模式和文档的完整 OpenAPI 规范
|
||||
|
||||
## API 端点
|
||||
|
||||
### OpenAPI 规范
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash GET /api/openapi.json
|
||||
curl "http://localhost:3000/api/openapi.json"
|
||||
```
|
||||
|
||||
```bash 带参数
|
||||
curl "http://localhost:3000/api/openapi.json?title=我的 MCP API&version=2.0.0"
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
生成并返回所有已连接 MCP 工具的完整 OpenAPI 3.0.3 规范。
|
||||
|
||||
**查询参数:**
|
||||
|
||||
<ParamField query="title" type="string" optional>
|
||||
自定义 API 标题
|
||||
</ParamField>
|
||||
|
||||
<ParamField query="description" type="string" optional>
|
||||
自定义 API 描述
|
||||
</ParamField>
|
||||
|
||||
<ParamField query="version" type="string" optional>
|
||||
自定义 API 版本
|
||||
</ParamField>
|
||||
|
||||
<ParamField query="serverUrl" type="string" optional>
|
||||
自定义服务器 URL
|
||||
</ParamField>
|
||||
|
||||
<ParamField query="includeDisabled" type="boolean" optional default="false">
|
||||
包含禁用的工具
|
||||
</ParamField>
|
||||
|
||||
<ParamField query="servers" type="string" optional>
|
||||
要包含的服务器名称列表(逗号分隔)
|
||||
</ParamField>
|
||||
|
||||
### 组/服务器特定的 OpenAPI 规范
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash GET /api/:name/openapi.json
|
||||
curl "http://localhost:3000/api/mygroup/openapi.json"
|
||||
```
|
||||
|
||||
```bash 带参数
|
||||
curl "http://localhost:3000/api/myserver/openapi.json?title=我的服务器 API&version=1.0.0"
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
为特定组或服务器生成并返回 OpenAPI 3.0.3 规范。如果存在具有给定名称的组,则返回该组中所有服务器的规范。否则,将名称视为服务器名称并仅返回该服务器的规范。
|
||||
|
||||
**路径参数:**
|
||||
|
||||
<ParamField path="name" type="string" required>
|
||||
组 ID/名称或服务器名称
|
||||
</ParamField>
|
||||
|
||||
**查询参数:**
|
||||
|
||||
与主 OpenAPI 规范端点相同(title、description、version、serverUrl、includeDisabled)。
|
||||
|
||||
### 可用服务器
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash GET /api/openapi/servers
|
||||
curl "http://localhost:3000/api/openapi/servers"
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
返回已连接的 MCP 服务器名称列表。
|
||||
|
||||
<ResponseExample>
|
||||
|
||||
```json 示例响应
|
||||
{
|
||||
"success": true,
|
||||
"data": ["amap", "playwright", "slack"]
|
||||
}
|
||||
```
|
||||
|
||||
</ResponseExample>
|
||||
|
||||
### 工具统计
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash GET /api/openapi/stats
|
||||
curl "http://localhost:3000/api/openapi/stats"
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
返回有关可用工具和服务器的统计信息。
|
||||
|
||||
<ResponseExample>
|
||||
|
||||
```json 示例响应
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"totalServers": 3,
|
||||
"totalTools": 41,
|
||||
"serverBreakdown": [
|
||||
{"name": "amap", "toolCount": 12, "status": "connected"},
|
||||
{"name": "playwright", "toolCount": 21, "status": "connected"},
|
||||
{"name": "slack", "toolCount": 8, "status": "connected"}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</ResponseExample>
|
||||
|
||||
### 工具执行
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash GET /api/tools/{serverName}/{toolName}
|
||||
curl "http://localhost:3000/api/tools/amap/amap-maps_weather?city=Beijing"
|
||||
```
|
||||
|
||||
```bash POST /api/tools/{serverName}/{toolName}
|
||||
curl -X POST "http://localhost:3000/api/tools/playwright/playwright-browser_navigate" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"url": "https://example.com"}'
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
通过 OpenAPI 兼容端点执行 MCP 工具。
|
||||
|
||||
**路径参数:**
|
||||
|
||||
<ParamField path="serverName" type="string" required>
|
||||
MCP 服务器的名称
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="toolName" type="string" required>
|
||||
要执行的工具名称
|
||||
</ParamField>
|
||||
|
||||
## OpenWebUI 集成
|
||||
|
||||
要将 MCPHub 与 OpenWebUI 集成:
|
||||
|
||||
<Steps>
|
||||
<Step title="启动 MCPHub">
|
||||
确保 MCPHub 正在运行,并且已配置 MCP 服务器
|
||||
</Step>
|
||||
<Step title="获取 OpenAPI 规范">
|
||||
```bash
|
||||
curl http://localhost:3000/api/openapi.json > mcphub-api.json
|
||||
```
|
||||
</Step>
|
||||
<Step title="添加到 OpenWebUI">
|
||||
在 OpenWebUI 中导入 OpenAPI 规范文件或直接指向 URL
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
### 配置示例
|
||||
|
||||
在 OpenWebUI 中,您可以通过以下方式将 MCPHub 添加为 OpenAPI 工具:
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="OpenAPI URL" icon="link">
|
||||
`http://localhost:3000/api/openapi.json`
|
||||
</Card>
|
||||
<Card title="基础 URL" icon="server">
|
||||
`http://localhost:3000/api`
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## 生成的 OpenAPI 结构
|
||||
|
||||
生成的 OpenAPI 规范包括:
|
||||
|
||||
### 工具转换逻辑
|
||||
|
||||
- **简单工具**(≤10 个原始参数)→ 带查询参数的 GET 端点
|
||||
- **复杂工具**(对象、数组或 >10 个参数)→ 带 JSON 请求正文的 POST 端点
|
||||
- **所有工具**都包含完整的响应模式和错误处理
|
||||
|
||||
### 生成操作示例
|
||||
|
||||
```yaml
|
||||
/tools/amap/amap-maps_weather:
|
||||
get:
|
||||
summary: "根据城市名称或者标准adcode查询指定城市的天气"
|
||||
operationId: "amap_amap-maps_weather"
|
||||
tags: ["amap"]
|
||||
parameters:
|
||||
- name: city
|
||||
in: query
|
||||
required: true
|
||||
description: "城市名称或者adcode"
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: "Successful tool execution"
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ToolResponse'
|
||||
```
|
||||
|
||||
### 安全性
|
||||
|
||||
- 定义了 Bearer 身份验证但不对工具执行端点强制执行
|
||||
- 支持与各种 OpenAPI 兼容系统的灵活集成
|
||||
|
||||
## 相比 MCPO 的优势
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="直接集成" icon="plug">
|
||||
无需中间代理
|
||||
</Card>
|
||||
<Card title="实时更新" icon="refresh">
|
||||
OpenAPI 规范随着 MCP 服务器连接/断开自动更新
|
||||
</Card>
|
||||
<Card title="更好的性能" icon="bolt">
|
||||
直接工具执行,无代理开销
|
||||
</Card>
|
||||
<Card title="简化架构" icon="layer-group">
|
||||
减少一个需要管理的组件
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## 故障排除
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="OpenAPI 规范显示没有工具">
|
||||
确保 MCP 服务器已连接。检查 `/api/openapi/stats` 查看服务器状态。
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="工具执行失败">
|
||||
验证工具名称和参数是否与 OpenAPI 规范匹配。检查服务器日志以获取详细信息。
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="OpenWebUI 无法连接">
|
||||
确保 MCPHub 可从 OpenWebUI 访问,并且 OpenAPI URL 正确。
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="规范中缺少工具">
|
||||
检查您的 MCP 服务器配置中是否启用了工具。使用 `includeDisabled=true` 查看所有工具。
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
142
docs/zh/api-reference/prompts.mdx
Normal file
@@ -0,0 +1,142 @@
|
||||
---
|
||||
title: "提示词"
|
||||
description: "管理和执行 MCP 提示词。"
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="POST /api/mcp/:serverName/prompts/:promptName"
|
||||
href="#get-a-prompt"
|
||||
>
|
||||
在 MCP 服务器上执行提示词。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/servers/:serverName/prompts/:promptName/toggle"
|
||||
href="#toggle-a-prompt"
|
||||
>
|
||||
启用或禁用提示词。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="PUT /api/servers/:serverName/prompts/:promptName/description"
|
||||
href="#update-prompt-description"
|
||||
>
|
||||
更新提示词的描述。
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### 获取提示词
|
||||
|
||||
在 MCP 服务器上执行提示词并获取结果。
|
||||
|
||||
- **端点**: `/api/mcp/:serverName/prompts/:promptName`
|
||||
- **方法**: `POST`
|
||||
- **身份验证**: 必需
|
||||
- **参数**:
|
||||
- `:serverName` (字符串, 必需): MCP 服务器的名称。
|
||||
- `:promptName` (字符串, 必需): 提示词的名称。
|
||||
- **请求正文**:
|
||||
```json
|
||||
{
|
||||
"arguments": {
|
||||
"arg1": "value1",
|
||||
"arg2": "value2"
|
||||
}
|
||||
}
|
||||
```
|
||||
- `arguments` (对象, 可选): 传递给提示词的参数。
|
||||
|
||||
- **响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": {
|
||||
"type": "text",
|
||||
"text": "提示词内容"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**请求示例:**
|
||||
|
||||
```bash
|
||||
curl -X POST "http://localhost:3000/api/mcp/myserver/prompts/code-review" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-d '{
|
||||
"arguments": {
|
||||
"language": "typescript",
|
||||
"code": "const x = 1;"
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 切换提示词
|
||||
|
||||
启用或禁用服务器上的特定提示词。
|
||||
|
||||
- **端点**: `/api/servers/:serverName/prompts/:promptName/toggle`
|
||||
- **方法**: `POST`
|
||||
- **身份验证**: 必需
|
||||
- **参数**:
|
||||
- `:serverName` (字符串, 必需): 服务器的名称。
|
||||
- `:promptName` (字符串, 必需): 提示词的名称。
|
||||
- **请求正文**:
|
||||
```json
|
||||
{
|
||||
"enabled": true
|
||||
}
|
||||
```
|
||||
- `enabled` (布尔值, 必需): `true` 启用提示词, `false` 禁用提示词。
|
||||
|
||||
**请求示例:**
|
||||
|
||||
```bash
|
||||
curl -X POST "http://localhost:3000/api/servers/myserver/prompts/code-review/toggle" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-d '{"enabled": false}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 更新提示词描述
|
||||
|
||||
更新特定提示词的描述。
|
||||
|
||||
- **端点**: `/api/servers/:serverName/prompts/:promptName/description`
|
||||
- **方法**: `PUT`
|
||||
- **身份验证**: 必需
|
||||
- **参数**:
|
||||
- `:serverName` (字符串, 必需): 服务器的名称。
|
||||
- `:promptName` (字符串, 必需): 提示词的名称。
|
||||
- **请求正文**:
|
||||
```json
|
||||
{
|
||||
"description": "新的提示词描述"
|
||||
}
|
||||
```
|
||||
- `description` (字符串, 必需): 提示词的新描述。
|
||||
|
||||
**请求示例:**
|
||||
|
||||
```bash
|
||||
curl -X PUT "http://localhost:3000/api/servers/myserver/prompts/code-review/description" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-d '{"description": "审查代码的最佳实践和潜在问题"}'
|
||||
```
|
||||
|
||||
**注意**: 提示词是可用于生成标准化请求到 MCP 服务器的模板。它们由 MCP 服务器定义,并且可以具有在执行提示词时填充的参数。
|
||||
265
docs/zh/api-reference/servers.mdx
Normal file
@@ -0,0 +1,265 @@
|
||||
---
|
||||
title: "服务器"
|
||||
description: "管理您的 MCP 服务器。"
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="GET /api/servers"
|
||||
href="#get-all-servers"
|
||||
>
|
||||
获取所有 MCP 服务器的列表。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/servers"
|
||||
href="#create-a-new-server"
|
||||
>
|
||||
创建一个新的 MCP 服务器。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="PUT /api/servers/:name"
|
||||
href="#update-a-server"
|
||||
>
|
||||
更新现有的 MCP 服务器。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="DELETE /api/servers/:name"
|
||||
href="#delete-a-server"
|
||||
>
|
||||
删除一个 MCP 服务器。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/servers/:name/toggle"
|
||||
href="#toggle-a-server"
|
||||
>
|
||||
切换服务器的启用状态。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/servers/:serverName/tools/:toolName/toggle"
|
||||
href="#toggle-a-tool"
|
||||
>
|
||||
切换工具的启用状态。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="PUT /api/servers/:serverName/tools/:toolName/description"
|
||||
href="#update-tool-description"
|
||||
>
|
||||
更新工具的描述。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="PUT /api/system-config"
|
||||
href="#update-system-config"
|
||||
>
|
||||
更新系统配置设置。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /api/settings"
|
||||
href="#get-settings"
|
||||
>
|
||||
获取所有服务器设置和配置。
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### 获取所有服务器
|
||||
|
||||
检索所有已配置的 MCP 服务器的列表,包括其状态和可用工具。
|
||||
|
||||
- **端点**: `/api/servers`
|
||||
- **方法**: `GET`
|
||||
- **响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"name": "example-server",
|
||||
"status": "connected",
|
||||
"tools": [
|
||||
{
|
||||
"name": "tool1",
|
||||
"description": "工具1的描述"
|
||||
}
|
||||
],
|
||||
"config": {
|
||||
"type": "stdio",
|
||||
"command": "node",
|
||||
"args": ["server.js"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 创建一个新服务器
|
||||
|
||||
将一个新的 MCP 服务器添加到配置中。
|
||||
|
||||
- **端点**: `/api/servers`
|
||||
- **方法**: `POST`
|
||||
- **正文**:
|
||||
```json
|
||||
{
|
||||
"name": "my-new-server",
|
||||
"config": {
|
||||
"type": "stdio",
|
||||
"command": "python",
|
||||
"args": ["-u", "my_script.py"],
|
||||
"owner": "admin"
|
||||
}
|
||||
}
|
||||
```
|
||||
- `name` (string, 必填): 服务器的唯一名称。
|
||||
- `config` (object, 必填): 服务器配置对象。
|
||||
- `type` (string): `stdio`、`sse`、`streamable-http` 或 `openapi`。
|
||||
- `command` (string): `stdio` 类型要执行的命令。
|
||||
- `args` (array of strings): 命令的参数。
|
||||
- `url` (string): `sse`、`streamable-http` 或 `openapi` 类型的 URL。
|
||||
- `openapi` (object): OpenAPI 配置。
|
||||
- `url` (string): OpenAPI 模式的 URL。
|
||||
- `schema` (object): OpenAPI 模式对象本身。
|
||||
- `headers` (object): `sse`、`streamable-http` 和 `openapi` 类型请求要发送的标头。
|
||||
- `keepAliveInterval` (number): `sse` 类型的保持活动间隔(毫秒)。默认为 60000。
|
||||
- `owner` (string): 服务器的所有者。默认为当前用户或“admin”。
|
||||
|
||||
---
|
||||
|
||||
### 更新一个服务器
|
||||
|
||||
更新现有 MCP 服务器的配置。
|
||||
|
||||
- **端点**: `/api/servers/:name`
|
||||
- **方法**: `PUT`
|
||||
- **参数**:
|
||||
- `:name` (string, 必填): 要更新的服务器的名称。
|
||||
- **正文**:
|
||||
```json
|
||||
{
|
||||
"config": {
|
||||
"type": "stdio",
|
||||
"command": "node",
|
||||
"args": ["new_server.js"]
|
||||
}
|
||||
}
|
||||
```
|
||||
- `config` (object, 必填): 更新后的服务器配置对象。详情请参阅“创建一个新服务器”。
|
||||
|
||||
---
|
||||
|
||||
### 删除一个服务器
|
||||
|
||||
从配置中删除一个 MCP 服务器。
|
||||
|
||||
- **端点**: `/api/servers/:name`
|
||||
- **方法**: `DELETE`
|
||||
- **参数**:
|
||||
- `:name` (string, 必填): 要删除的服务器的名称。
|
||||
|
||||
---
|
||||
|
||||
### 切换一个服务器
|
||||
|
||||
启用或禁用一个 MCP 服务器。
|
||||
|
||||
- **端点**: `/api/servers/:name/toggle`
|
||||
- **方法**: `POST`
|
||||
- **参数**:
|
||||
- `:name` (string, 必填): 要切换的服务器的名称。
|
||||
- **正文**:
|
||||
```json
|
||||
{
|
||||
"enabled": true
|
||||
}
|
||||
```
|
||||
- `enabled` (boolean, 必填): `true` 启用服务器,`false` 禁用服务器。
|
||||
|
||||
---
|
||||
|
||||
### 切换一个工具
|
||||
|
||||
启用或禁用服务器上的特定工具。
|
||||
|
||||
- **端点**: `/api/servers/:serverName/tools/:toolName/toggle`
|
||||
- **方法**: `POST`
|
||||
- **参数**:
|
||||
- `:serverName` (string, 必填): 服务器的名称。
|
||||
- `:toolName` (string, 必填): 工具的名称。
|
||||
- **正文**:
|
||||
```json
|
||||
{
|
||||
"enabled": true
|
||||
}
|
||||
```
|
||||
- `enabled` (boolean, 必填): `true` 启用工具,`false` 禁用工具。
|
||||
|
||||
---
|
||||
|
||||
### 更新工具描述
|
||||
|
||||
更新特定工具的描述。
|
||||
|
||||
- **端点**: `/api/servers/:serverName/tools/:toolName/description`
|
||||
- **方法**: `PUT`
|
||||
- **参数**:
|
||||
- `:serverName` (string, 必填): 服务器的名称。
|
||||
- `:toolName` (string, 必填): 工具的名称。
|
||||
- **正文**:
|
||||
```json
|
||||
{
|
||||
"description": "新的工具描述"
|
||||
}
|
||||
```
|
||||
- `description` (string, 必填): 工具的新描述。
|
||||
|
||||
---
|
||||
|
||||
### 更新系统配置
|
||||
|
||||
更新系统范围的配置设置。
|
||||
|
||||
- **端点**: `/api/system-config`
|
||||
- **方法**: `PUT`
|
||||
- **正文**:
|
||||
```json
|
||||
{
|
||||
"openaiApiKey": "sk-...",
|
||||
"openaiBaseUrl": "https://api.openai.com/v1",
|
||||
"modelName": "gpt-4",
|
||||
"temperature": 0.7,
|
||||
"maxTokens": 2048
|
||||
}
|
||||
```
|
||||
- 所有字段都是可选的。只有提供的字段会被更新。
|
||||
|
||||
---
|
||||
|
||||
### 获取设置
|
||||
|
||||
检索所有服务器设置和配置。
|
||||
|
||||
- **端点**: `/api/settings`
|
||||
- **方法**: `GET`
|
||||
- **响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"servers": [...],
|
||||
"groups": [...],
|
||||
"systemConfig": {...}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**注意**: 有关详细的提示词管理,请参阅 [提示词 API](/zh/api-reference/prompts) 文档。
|
||||
29
docs/zh/api-reference/smart-routing.mdx
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
title: "智能路由"
|
||||
description: "使用向量语义搜索进行智能工具发现。"
|
||||
---
|
||||
|
||||
智能路由是 MCPHub 的智能工具发现系统,它使用向量语义搜索来自动为任何给定任务找到最相关的工具。
|
||||
|
||||
### HTTP 端点
|
||||
|
||||
- **端点**: `http://localhost:3000/mcp/$smart`
|
||||
- **方法**: `POST`
|
||||
|
||||
### SSE 端点 (已弃用)
|
||||
|
||||
- **端点**: `http://localhost:3000/sse/$smart`
|
||||
- **方法**: `GET`
|
||||
|
||||
### 工作原理
|
||||
|
||||
1. **工具索引**: 所有 MCP 工具都会自动转换为向量嵌入并存储在带有 pgvector 的 PostgreSQL 中。
|
||||
2. **语义搜索**: 用户查询被转换为向量,并使用余弦相似度与工具嵌入进行匹配。
|
||||
3. **智能过滤**: 动态阈值可确保相关结果而无噪音。
|
||||
4. **精确执行**: 找到的工具可以通过适当的参数验证直接执行。
|
||||
|
||||
### 设置要求
|
||||
|
||||
- 带有 pgvector 扩展的 PostgreSQL
|
||||
- OpenAI API 密钥(或兼容的嵌入服务)
|
||||
- 在 MCPHub 设置中启用智能路由
|
||||
113
docs/zh/api-reference/system.mdx
Normal file
@@ -0,0 +1,113 @@
|
||||
---
|
||||
title: "系统"
|
||||
description: "系统和实用程序端点。"
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="GET /health"
|
||||
href="#health-check"
|
||||
>
|
||||
检查 MCPHub 服务器的健康状态。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /oauth/callback"
|
||||
href="#oauth-callback"
|
||||
>
|
||||
用于身份验证流程的 OAuth 回调端点。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/dxt/upload"
|
||||
href="#upload-dxt-file"
|
||||
>
|
||||
上传 DXT 配置文件。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /api/mcp-settings/export"
|
||||
href="#export-mcp-settings"
|
||||
>
|
||||
将 MCP 设置导出为 JSON。
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### 健康检查
|
||||
|
||||
检查 MCPHub 服务器的健康状态。
|
||||
|
||||
- **端点**: `/health`
|
||||
- **方法**: `GET`
|
||||
- **身份验证**: 不需要
|
||||
- **响应**:
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
"timestamp": "2024-11-12T01:30:00.000Z",
|
||||
"uptime": 12345
|
||||
}
|
||||
```
|
||||
|
||||
**请求示例:**
|
||||
|
||||
```bash
|
||||
curl "http://localhost:3000/health"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### OAuth 回调
|
||||
|
||||
用于处理 OAuth 身份验证流程的 OAuth 回调端点。此端点在用户授权后由 OAuth 提供商自动调用。
|
||||
|
||||
- **端点**: `/oauth/callback`
|
||||
- **方法**: `GET`
|
||||
- **身份验证**: 不需要(公共回调 URL)
|
||||
- **查询参数**: 因 OAuth 提供商而异(通常包括 `code`、`state` 等)
|
||||
|
||||
**注意**: 此端点由 MCPHub 的 OAuth 集成内部使用,客户端不应直接调用。
|
||||
|
||||
---
|
||||
|
||||
### 上传 DXT 文件
|
||||
|
||||
上传 DXT(桌面扩展)配置文件以导入服务器配置。
|
||||
|
||||
- **端点**: `/api/dxt/upload`
|
||||
- **方法**: `POST`
|
||||
- **身份验证**: 必需
|
||||
- **Content-Type**: `multipart/form-data`
|
||||
- **正文**:
|
||||
- `file` (文件, 必需): 要上传的 DXT 配置文件。
|
||||
|
||||
**请求示例:**
|
||||
|
||||
```bash
|
||||
curl -X POST "http://localhost:3000/api/dxt/upload" \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-F "file=@config.dxt"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 导出 MCP 设置
|
||||
|
||||
将当前 MCP 设置配置导出为 JSON 文件。
|
||||
|
||||
- **端点**: `/api/mcp-settings/export`
|
||||
- **方法**: `GET`
|
||||
- **身份验证**: 必需
|
||||
- **响应**: 返回 `mcp_settings.json` 配置文件。
|
||||
|
||||
**请求示例:**
|
||||
|
||||
```bash
|
||||
curl "http://localhost:3000/api/mcp-settings/export" \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-o mcp_settings.json
|
||||
```
|
||||
|
||||
**注意**: 此端点允许您下载 MCP 设置的备份,可用于恢复或迁移您的配置。
|
||||
86
docs/zh/api-reference/tools.mdx
Normal file
@@ -0,0 +1,86 @@
|
||||
---
|
||||
title: "工具"
|
||||
description: "以编程方式执行 MCP 工具。"
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="POST /api/tools/call/:server"
|
||||
href="#call-a-tool"
|
||||
>
|
||||
在 MCP 服务器上调用特定工具。
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### 调用工具
|
||||
|
||||
使用给定参数在 MCP 服务器上执行特定工具。
|
||||
|
||||
- **端点**: `/api/tools/call/:server`
|
||||
- **方法**: `POST`
|
||||
- **参数**:
|
||||
- `:server` (字符串, 必需): MCP 服务器的名称。
|
||||
- **请求正文**:
|
||||
```json
|
||||
{
|
||||
"toolName": "tool-name",
|
||||
"arguments": {
|
||||
"param1": "value1",
|
||||
"param2": "value2"
|
||||
}
|
||||
}
|
||||
```
|
||||
- `toolName` (字符串, 必需): 要执行的工具名称。
|
||||
- `arguments` (对象, 可选): 传递给工具的参数。默认为空对象。
|
||||
|
||||
- **响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "工具执行结果"
|
||||
}
|
||||
],
|
||||
"toolName": "tool-name",
|
||||
"arguments": {
|
||||
"param1": "value1",
|
||||
"param2": "value2"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**请求示例:**
|
||||
|
||||
```bash
|
||||
curl -X POST "http://localhost:3000/api/tools/call/amap" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-d '{
|
||||
"toolName": "amap-maps_weather",
|
||||
"arguments": {
|
||||
"city": "Beijing"
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
**注意事项:**
|
||||
- 工具参数会根据工具的输入模式自动转换为适当的类型。
|
||||
- 如果需要,可以使用 `x-session-id` 请求头在多个工具调用之间维护会话状态。
|
||||
- 此端点需要身份验证。
|
||||
|
||||
---
|
||||
|
||||
### 替代方案:OpenAPI 工具执行
|
||||
|
||||
有关无需身份验证的 OpenAPI 兼容工具执行,请参阅 [OpenAPI 集成](/api-reference/openapi#tool-execution) 文档。OpenAPI 端点提供:
|
||||
|
||||
- **GET** `/api/tools/:serverName/:toolName` - 用于带查询参数的简单工具
|
||||
- **POST** `/api/tools/:serverName/:toolName` - 用于带 JSON 正文的复杂工具
|
||||
|
||||
这些端点专为与 OpenWebUI 和其他 OpenAPI 兼容系统集成而设计。
|
||||
195
docs/zh/api-reference/users.mdx
Normal file
@@ -0,0 +1,195 @@
|
||||
---
|
||||
title: "用户"
|
||||
description: "在 MCPHub 中管理用户。"
|
||||
---
|
||||
|
||||
import { Card, Cards } from 'mintlify';
|
||||
|
||||
<Card
|
||||
title="GET /api/users"
|
||||
href="#get-all-users"
|
||||
>
|
||||
获取所有用户的列表。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /api/users/:username"
|
||||
href="#get-a-user"
|
||||
>
|
||||
获取特定用户的详细信息。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="POST /api/users"
|
||||
href="#create-a-user"
|
||||
>
|
||||
创建新用户。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="PUT /api/users/:username"
|
||||
href="#update-a-user"
|
||||
>
|
||||
更新现有用户。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="DELETE /api/users/:username"
|
||||
href="#delete-a-user"
|
||||
>
|
||||
删除用户。
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="GET /api/users-stats"
|
||||
href="#get-user-statistics"
|
||||
>
|
||||
获取有关用户及其服务器访问权限的统计信息。
|
||||
</Card>
|
||||
|
||||
---
|
||||
|
||||
### 获取所有用户
|
||||
|
||||
检索系统中所有用户的列表。
|
||||
|
||||
- **端点**: `/api/users`
|
||||
- **方法**: `GET`
|
||||
- **身份验证**: 必需(仅管理员)
|
||||
- **响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"username": "admin",
|
||||
"role": "admin",
|
||||
"servers": ["server1", "server2"],
|
||||
"groups": ["group1"]
|
||||
},
|
||||
{
|
||||
"username": "user1",
|
||||
"role": "user",
|
||||
"servers": ["server1"],
|
||||
"groups": []
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 获取用户
|
||||
|
||||
检索特定用户的详细信息。
|
||||
|
||||
- **端点**: `/api/users/:username`
|
||||
- **方法**: `GET`
|
||||
- **身份验证**: 必需(仅管理员)
|
||||
- **参数**:
|
||||
- `:username` (字符串, 必需): 用户的用户名。
|
||||
- **响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"username": "user1",
|
||||
"role": "user",
|
||||
"servers": ["server1", "server2"],
|
||||
"groups": ["group1"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 创建用户
|
||||
|
||||
在系统中创建新用户。
|
||||
|
||||
- **端点**: `/api/users`
|
||||
- **方法**: `POST`
|
||||
- **身份验证**: 必需(仅管理员)
|
||||
- **请求正文**:
|
||||
```json
|
||||
{
|
||||
"username": "newuser",
|
||||
"password": "securepassword",
|
||||
"role": "user",
|
||||
"servers": ["server1"],
|
||||
"groups": ["group1"]
|
||||
}
|
||||
```
|
||||
- `username` (字符串, 必需): 新用户的用户名。
|
||||
- `password` (字符串, 必需): 新用户的密码。至少 6 个字符。
|
||||
- `role` (字符串, 可选): 用户的角色。可以是 `"admin"` 或 `"user"`。默认为 `"user"`。
|
||||
- `servers` (字符串数组, 可选): 用户可以访问的服务器名称列表。
|
||||
- `groups` (字符串数组, 可选): 用户所属的组 ID 列表。
|
||||
|
||||
---
|
||||
|
||||
### 更新用户
|
||||
|
||||
更新现有用户的信息。
|
||||
|
||||
- **端点**: `/api/users/:username`
|
||||
- **方法**: `PUT`
|
||||
- **身份验证**: 必需(仅管理员)
|
||||
- **参数**:
|
||||
- `:username` (字符串, 必需): 要更新的用户的用户名。
|
||||
- **请求正文**:
|
||||
```json
|
||||
{
|
||||
"password": "newpassword",
|
||||
"role": "admin",
|
||||
"servers": ["server1", "server2", "server3"],
|
||||
"groups": ["group1", "group2"]
|
||||
}
|
||||
```
|
||||
- `password` (字符串, 可选): 用户的新密码。
|
||||
- `role` (字符串, 可选): 用户的新角色。
|
||||
- `servers` (字符串数组, 可选): 更新的可访问服务器列表。
|
||||
- `groups` (字符串数组, 可选): 更新的组列表。
|
||||
|
||||
---
|
||||
|
||||
### 删除用户
|
||||
|
||||
从系统中删除用户。
|
||||
|
||||
- **端点**: `/api/users/:username`
|
||||
- **方法**: `DELETE`
|
||||
- **身份验证**: 必需(仅管理员)
|
||||
- **参数**:
|
||||
- `:username` (字符串, 必需): 要删除的用户的用户名。
|
||||
|
||||
---
|
||||
|
||||
### 获取用户统计信息
|
||||
|
||||
检索有关用户及其对服务器和组的访问权限的统计信息。
|
||||
|
||||
- **端点**: `/api/users-stats`
|
||||
- **方法**: `GET`
|
||||
- **身份验证**: 必需(仅管理员)
|
||||
- **响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"totalUsers": 5,
|
||||
"adminUsers": 1,
|
||||
"regularUsers": 4,
|
||||
"usersPerServer": {
|
||||
"server1": 3,
|
||||
"server2": 2
|
||||
},
|
||||
"usersPerGroup": {
|
||||
"group1": 2,
|
||||
"group2": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**注意**: 所有用户管理端点都需要管理员身份验证。
|
||||
304
docs/zh/configuration/database-configuration.mdx
Normal file
@@ -0,0 +1,304 @@
|
||||
---
|
||||
title: '数据库配置'
|
||||
description: '使用 PostgreSQL 数据库配置 MCPHub 作为 mcp_settings.json 文件的替代方案。'
|
||||
---
|
||||
|
||||
# MCPHub 数据库配置
|
||||
|
||||
## 概述
|
||||
|
||||
MCPHub 支持将配置数据存储在 PostgreSQL 数据库中,作为 `mcp_settings.json` 文件配置的替代方案。数据库模式为生产环境和企业级部署提供了更强大的持久化和扩展能力。
|
||||
|
||||
## 为什么使用数据库配置?
|
||||
|
||||
**核心优势:**
|
||||
- ✅ **更好的持久化** - 配置数据存储在专业数据库中,支持事务和数据完整性
|
||||
- ✅ **高可用性** - 利用数据库复制和故障转移能力
|
||||
- ✅ **企业级支持** - 符合企业数据管理和合规要求
|
||||
- ✅ **备份恢复** - 使用成熟的数据库备份工具和策略
|
||||
|
||||
## 环境变量
|
||||
|
||||
### 数据库模式必需变量
|
||||
|
||||
```bash
|
||||
# 数据库连接 URL(PostgreSQL)
|
||||
# 只需设置 DB_URL 即可自动启用数据库模式
|
||||
DB_URL=postgresql://user:password@localhost:5432/mcphub
|
||||
|
||||
# 或显式控制 USE_DB(覆盖自动检测)
|
||||
# USE_DB=true
|
||||
```
|
||||
|
||||
<Note>
|
||||
**简化配置**:您只需设置 `DB_URL` 即可启用数据库模式。MCPHub 会自动检测 `DB_URL` 是否存在并启用数据库模式。如果需要在设置了 `DB_URL` 的情况下禁用数据库模式,可以显式设置 `USE_DB=false`。
|
||||
</Note>
|
||||
|
||||
## 设置说明
|
||||
|
||||
### 1. 使用 Docker
|
||||
|
||||
#### 方案 A:使用外部数据库
|
||||
|
||||
如果您已有 PostgreSQL 数据库:
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
-p 3000:3000 \
|
||||
-v ./mcp_settings.json:/app/mcp_settings.json \
|
||||
-e DB_URL="postgresql://user:password@your-db-host:5432/mcphub" \
|
||||
samanhappy/mcphub
|
||||
```
|
||||
|
||||
#### 方案 B:将 PostgreSQL 作为独立服务
|
||||
|
||||
创建 `docker-compose.yml` 文件:
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16
|
||||
environment:
|
||||
POSTGRES_DB: mcphub
|
||||
POSTGRES_USER: mcphub
|
||||
POSTGRES_PASSWORD: your_secure_password
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "5432:5432"
|
||||
|
||||
mcphub:
|
||||
image: samanhappy/mcphub:latest
|
||||
environment:
|
||||
USE_DB: "true"
|
||||
DB_URL: "postgresql://mcphub:your_secure_password@postgres:5432/mcphub"
|
||||
PORT: 3000
|
||||
ports:
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
- postgres
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
```
|
||||
|
||||
运行:
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
### 2. 手动设置
|
||||
|
||||
#### 步骤 1:设置 PostgreSQL 数据库
|
||||
|
||||
```bash
|
||||
# 安装 PostgreSQL(如果尚未安装)
|
||||
sudo apt-get install postgresql postgresql-contrib
|
||||
|
||||
# 创建数据库和用户
|
||||
sudo -u postgres psql <<EOF
|
||||
CREATE DATABASE mcphub;
|
||||
CREATE USER mcphub WITH ENCRYPTED PASSWORD 'your_password';
|
||||
GRANT ALL PRIVILEGES ON DATABASE mcphub TO mcphub;
|
||||
EOF
|
||||
```
|
||||
|
||||
#### 步骤 2:安装 MCPHub
|
||||
|
||||
```bash
|
||||
npm install -g @samanhappy/mcphub
|
||||
```
|
||||
|
||||
#### 步骤 3:设置环境变量
|
||||
|
||||
创建 `.env` 文件:
|
||||
|
||||
```bash
|
||||
# 只需设置 DB_URL 即可启用数据库模式(USE_DB 会自动检测)
|
||||
DB_URL=postgresql://mcphub:your_password@localhost:5432/mcphub
|
||||
PORT=3000
|
||||
```
|
||||
|
||||
#### 步骤 4:运行迁移(可选)
|
||||
|
||||
如果您有现有的 `mcp_settings.json` 文件,可以进行迁移:
|
||||
|
||||
```bash
|
||||
# 运行迁移脚本
|
||||
npx tsx src/scripts/migrate-to-database.ts
|
||||
```
|
||||
|
||||
或者让 MCPHub 在首次启动时自动迁移。
|
||||
|
||||
#### 步骤 5:启动 MCPHub
|
||||
|
||||
```bash
|
||||
mcphub
|
||||
```
|
||||
|
||||
## 从基于文件迁移到数据库
|
||||
|
||||
MCPHub 在启用数据库模式首次启动时提供自动迁移功能。您也可以手动运行迁移。
|
||||
|
||||
### 自动迁移
|
||||
|
||||
当您首次使用 `USE_DB=true` 启动 MCPHub 时:
|
||||
|
||||
1. MCPHub 连接到数据库
|
||||
2. 检查数据库中是否存在任何用户
|
||||
3. 如果未找到用户,自动从 `mcp_settings.json` 迁移
|
||||
4. 创建所有表并导入所有数据
|
||||
|
||||
### 手动迁移
|
||||
|
||||
运行迁移脚本:
|
||||
|
||||
```bash
|
||||
# 使用 npx
|
||||
npx tsx src/scripts/migrate-to-database.ts
|
||||
|
||||
# 或使用 Node
|
||||
node dist/scripts/migrate-to-database.js
|
||||
```
|
||||
|
||||
迁移将:
|
||||
- ✅ 如果不存在则创建数据库表
|
||||
- ✅ 导入所有用户(包含哈希密码)
|
||||
- ✅ 导入所有 MCP 服务器配置
|
||||
- ✅ 导入所有分组
|
||||
- ✅ 导入系统配置
|
||||
- ✅ 导入用户特定配置
|
||||
- ✅ 跳过已存在的记录(可安全多次运行)
|
||||
|
||||
## 迁移后的配置
|
||||
|
||||
在数据库模式下运行时,所有配置更改都存储在数据库中:
|
||||
|
||||
- 通过 `/api/users` 进行用户管理
|
||||
- 通过 `/api/servers` 进行服务器管理
|
||||
- 通过 `/api/groups` 进行分组管理
|
||||
- 通过 `/api/system/config` 进行系统设置
|
||||
|
||||
Web 仪表板的工作方式完全相同,但现在将更改存储在数据库中而不是文件中。
|
||||
|
||||
## 数据库架构
|
||||
|
||||
MCPHub 创建以下表:
|
||||
|
||||
- **users** - 用户账户和认证
|
||||
- **servers** - MCP 服务器配置
|
||||
- **groups** - 服务器分组
|
||||
- **system_config** - 系统级设置
|
||||
- **user_configs** - 用户特定设置
|
||||
- **vector_embeddings** - 向量搜索数据(用于智能路由)
|
||||
|
||||
## 备份和恢复
|
||||
|
||||
### 备份
|
||||
|
||||
```bash
|
||||
# PostgreSQL 备份
|
||||
pg_dump -U mcphub mcphub > mcphub_backup.sql
|
||||
|
||||
# 或使用 Docker
|
||||
docker exec postgres pg_dump -U mcphub mcphub > mcphub_backup.sql
|
||||
```
|
||||
|
||||
### 恢复
|
||||
|
||||
```bash
|
||||
# PostgreSQL 恢复
|
||||
psql -U mcphub mcphub < mcphub_backup.sql
|
||||
|
||||
# 或使用 Docker
|
||||
docker exec -i postgres psql -U mcphub mcphub < mcphub_backup.sql
|
||||
```
|
||||
|
||||
## 切换回基于文件的配置
|
||||
|
||||
如果您需要切换回基于文件的配置:
|
||||
|
||||
1. 设置 `USE_DB=false` 或删除 `DB_URL` 和 `USE_DB` 环境变量
|
||||
2. 重启 MCPHub
|
||||
3. MCPHub 将再次使用 `mcp_settings.json`
|
||||
|
||||
注意:在数据库模式下所做的更改不会反映到文件中,除非您手动导出。
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 连接被拒绝
|
||||
|
||||
```
|
||||
Error: connect ECONNREFUSED 127.0.0.1:5432
|
||||
```
|
||||
|
||||
**解决方案:** 检查 PostgreSQL 是否正在运行并可访问:
|
||||
```bash
|
||||
# 检查 PostgreSQL 状态
|
||||
sudo systemctl status postgresql
|
||||
|
||||
# 或对于 Docker
|
||||
docker ps | grep postgres
|
||||
```
|
||||
|
||||
### 认证失败
|
||||
|
||||
```
|
||||
Error: password authentication failed for user "mcphub"
|
||||
```
|
||||
|
||||
**解决方案:** 验证 `DB_URL` 环境变量中的数据库凭据。
|
||||
|
||||
### 迁移失败
|
||||
|
||||
```
|
||||
❌ Migration failed: ...
|
||||
```
|
||||
|
||||
**解决方案:**
|
||||
1. 检查 `mcp_settings.json` 是否存在且为有效的 JSON
|
||||
2. 验证数据库连接
|
||||
3. 检查日志获取具体错误信息
|
||||
4. 确保数据库用户具有 CREATE TABLE 权限
|
||||
|
||||
### 表已存在
|
||||
|
||||
如果数据库表不存在,会自动创建。如果遇到关于已存在表的错误,请检查:
|
||||
1. 之前的迁移是否部分完成
|
||||
2. 手动创建表的冲突
|
||||
3. 如果需要,在数据库配置中使用 `synchronize: false` 运行
|
||||
|
||||
## 环境变量参考
|
||||
|
||||
| 变量 | 必需 | 默认值 | 描述 |
|
||||
|------|------|--------|------|
|
||||
| `DB_URL` | 是* | - | 完整的 PostgreSQL 连接 URL。设置此变量会自动启用数据库模式 |
|
||||
| `USE_DB` | 否 | 自动 | 显式启用/禁用数据库模式。如果未设置,根据 `DB_URL` 是否存在自动检测 |
|
||||
| `MCPHUB_SETTING_PATH` | 否 | - | mcp_settings.json 的路径(用于迁移) |
|
||||
|
||||
*数据库模式必需。只需设置 `DB_URL` 即可自动启用数据库模式
|
||||
|
||||
## 安全注意事项
|
||||
|
||||
1. **数据库凭据:** 安全存储数据库凭据,使用环境变量或密钥管理
|
||||
2. **网络访问:** 仅限 MCPHub 实例访问数据库
|
||||
3. **加密:** 在生产环境中使用 SSL/TLS 进行数据库连接:
|
||||
```bash
|
||||
DB_URL=postgresql://user:password@host:5432/mcphub?sslmode=require
|
||||
```
|
||||
4. **备份:** 定期备份您的数据库
|
||||
5. **访问控制:** 使用强密码并限制用户权限
|
||||
|
||||
## 性能
|
||||
|
||||
数据库模式在以下场景提供更好的性能:
|
||||
- 多个并发用户
|
||||
- 频繁的配置更改
|
||||
- 大量服务器/分组
|
||||
|
||||
文件模式可能更快的场景:
|
||||
- 单用户设置
|
||||
- 读取密集型工作负载且更改不频繁
|
||||
- 开发/测试环境
|
||||
583
docs/zh/configuration/docker-setup.mdx
Normal file
@@ -0,0 +1,583 @@
|
||||
---
|
||||
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 镜像支持 `INSTALL_EXT` 构建参数以包含额外工具:
|
||||
|
||||
```bash
|
||||
# 构建扩展功能版本(包含 Docker 引擎、Chrome/Playwright)
|
||||
docker build --build-arg INSTALL_EXT=true -t mcphub:extended .
|
||||
|
||||
# 方式 1: 使用自动 Docker-in-Docker(需要特权模式)
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
--privileged \
|
||||
-p 3000:3000 \
|
||||
-v $(pwd)/mcp_settings.json:/app/mcp_settings.json \
|
||||
mcphub:extended
|
||||
|
||||
# 方式 2: 挂载 Docker socket(使用宿主机的 Docker 守护进程)
|
||||
docker run -d \
|
||||
--name mcphub \
|
||||
-p 3000:3000 \
|
||||
-v $(pwd)/mcp_settings.json:/app/mcp_settings.json \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
mcphub:extended
|
||||
|
||||
# 验证 Docker 可用
|
||||
docker exec mcphub docker --version
|
||||
docker exec mcphub docker ps
|
||||
```
|
||||
|
||||
<Note>
|
||||
**INSTALL_EXT=true 包含的功能:**
|
||||
- **Docker 引擎**:完整的 Docker 守护进程和 CLI,用于容器管理。在特权模式下运行时,守护进程会自动启动。
|
||||
- **Chrome/Playwright**(仅 amd64):用于浏览器自动化任务
|
||||
|
||||
扩展镜像较大,但为高级用例提供了额外功能。
|
||||
</Note>
|
||||
|
||||
<Warning>
|
||||
**Docker-in-Docker 安全注意事项:**
|
||||
- **特权模式**(`--privileged`):容器内启动 Docker 守护进程需要此权限。这会授予容器在宿主机上的提升权限。
|
||||
- **Docker socket 挂载**(`/var/run/docker.sock`):使容器可以访问宿主机的 Docker 守护进程。两种方式都应仅在可信环境中使用。
|
||||
- 生产环境建议使用 Docker socket 挂载而非特权模式,以提高安全性。
|
||||
</Warning>
|
||||
|
||||
## 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 提供了完整的容器化环境,包含开发和生产配置。
|
||||
104
docs/zh/configuration/environment-variables.mdx
Normal file
@@ -0,0 +1,104 @@
|
||||
---
|
||||
title: '环境变量'
|
||||
description: '使用环境变量配置 MCPHub'
|
||||
---
|
||||
|
||||
# 环境变量
|
||||
|
||||
MCPHub 使用环境变量进行配置。本指南涵盖了所有可用的变量及其用法。
|
||||
|
||||
## 核心应用设置
|
||||
|
||||
### 服务器配置
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| `PORT` | `3000` | HTTP 服务器的端口号 |
|
||||
| `INIT_TIMEOUT` | `300000` | 应用程序的初始超时时间 |
|
||||
| `BASE_PATH` | `''` | 应用程序的基本路径 |
|
||||
| `READONLY` | `false` | 设置为 `true` 以启用只读模式 |
|
||||
| `MCPHUB_SETTING_PATH` | | MCPHub 设置文件的路径 |
|
||||
| `NODE_ENV` | `development` | 应用程序环境 (`development`, `production`, `test`) |
|
||||
|
||||
```env
|
||||
PORT=3000
|
||||
INIT_TIMEOUT=300000
|
||||
BASE_PATH=/api
|
||||
READONLY=true
|
||||
MCPHUB_SETTING_PATH=/path/to/settings
|
||||
NODE_ENV=production
|
||||
```
|
||||
|
||||
## 认证与安全
|
||||
|
||||
### JWT 配置
|
||||
|
||||
| 变量 | 默认值 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| `JWT_SECRET` | - | 用于 JWT 令牌签名的密钥 (必需) |
|
||||
|
||||
```env
|
||||
JWT_SECRET=your-super-secret-key-change-this-in-production
|
||||
```
|
||||
|
||||
## 配置示例
|
||||
|
||||
### 开发环境
|
||||
|
||||
```env
|
||||
# .env.development
|
||||
NODE_ENV=development
|
||||
PORT=3000
|
||||
|
||||
# 认证
|
||||
JWT_SECRET=dev-secret-key
|
||||
```
|
||||
|
||||
### 生产环境
|
||||
|
||||
```env
|
||||
# .env.production
|
||||
NODE_ENV=production
|
||||
PORT=3000
|
||||
|
||||
# 安全
|
||||
JWT_SECRET=your-super-secure-production-secret
|
||||
```
|
||||
|
||||
### Docker 环境
|
||||
|
||||
```env
|
||||
# .env.docker
|
||||
NODE_ENV=production
|
||||
PORT=3000
|
||||
|
||||
# 安全
|
||||
JWT_SECRET_FILE=/run/secrets/jwt_secret
|
||||
```
|
||||
|
||||
## 环境变量加载
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
## 安全最佳实践
|
||||
|
||||
1. **永远不要将密钥提交**到版本控制
|
||||
2. **为生产环境使用强大、独特的密钥**
|
||||
3. **定期轮换密钥**
|
||||
4. **使用特定于环境的文件**
|
||||
5. **在启动时验证所有环境变量**
|
||||
6. **为容器部署使用 Docker 密钥**
|
||||
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 提供了坚实的基础,具有适当的安全性、性能和可靠性功能。
|
||||
385
docs/zh/development.mdx
Normal file
@@ -0,0 +1,385 @@
|
||||
---
|
||||
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/samanhappy/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
|
||||
```
|
||||
|
||||
## 启动开发服务器
|
||||
|
||||
### 开发模式启动
|
||||
|
||||
```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/samanhappy/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/samanhappy/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/samanhappy/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/samanhappy/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 http://localhost:3000/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 "http://localhost:3000/api/servers?limit=10&active=true" \
|
||||
-H "Authorization: Bearer YOUR_API_TOKEN"
|
||||
|
||||
# 更新服务器配置
|
||||
curl -X PUT http://localhost:3000/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 http://localhost:3000/api/servers/server-123 \
|
||||
-H "Authorization: Bearer YOUR_API_TOKEN"
|
||||
```
|
||||
````
|
||||
|
||||
```bash
|
||||
# 创建新的 MCP 服务器
|
||||
curl -X POST http://localhost:3000/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 "http://localhost:3000/api/servers?limit=10&active=true" \
|
||||
-H "Authorization: Bearer YOUR_API_TOKEN"
|
||||
|
||||
# 更新服务器配置
|
||||
curl -X PUT http://localhost:3000/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 http://localhost:3000/api/servers/server-123 \
|
||||
-H "Authorization: Bearer YOUR_API_TOKEN"
|
||||
```
|
||||
|
||||
### HTTP 请求示例
|
||||
|
||||
````md
|
||||
```http
|
||||
POST /api/servers HTTP/1.1
|
||||
Host: localhost:3000
|
||||
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: localhost:3000
|
||||
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: 'http://localhost:3000',
|
||||
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: 'http://localhost:3000',
|
||||
apiKey: process.env.MCPHUB_API_KEY,
|
||||
});
|
||||
```
|
||||
````
|
||||
|
||||
```javascript
|
||||
// MCPHub 客户端初始化
|
||||
const mcpClient = new MCPClient({
|
||||
endpoint: 'http://localhost:3000',
|
||||
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)
|
||||
````
|
||||
576
docs/zh/essentials/navigation.mdx
Normal file
@@ -0,0 +1,576 @@
|
||||
---
|
||||
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"
|
||||
{
|
||||
"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/samanhappy/mcphub",
|
||||
"icon": "github"
|
||||
},
|
||||
{
|
||||
"name": "Discord 社区",
|
||||
"url": "https://discord.gg/qMKNsn5Q",
|
||||
"icon": "discord"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 导航排序
|
||||
|
||||
### 自动排序
|
||||
|
||||
默认情况下,导航项按字母顺序排列。可以通过文件名前缀控制排序:
|
||||
|
||||
```
|
||||
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/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) 文档。
|
||||
573
docs/zh/features/group-management.mdx
Normal file
@@ -0,0 +1,573 @@
|
||||
---
|
||||
title: '分组管理'
|
||||
description: '将服务器组织成逻辑组以简化访问控制'
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
MCPHub 的分组管理功能允许您根据功能、用例或访问要求将 MCP 服务器组织成逻辑集合。这使您能够对不同的 AI 客户端和用户可用的工具进行精细控制。
|
||||
|
||||
## 核心概念
|
||||
|
||||
### 什么是分组?
|
||||
|
||||
分组是可通过专用端点访问的 MCP 服务器的命名集合。AI 客户端可以连接到特定分组以仅访问相关工具,而不是一次性连接到所有服务器。
|
||||
|
||||
### 分组的优势
|
||||
|
||||
- **聚焦工具访问**: AI 客户端只看到与其用例相关的工具
|
||||
- **更好的性能**: 减少工具发现开销
|
||||
- **增强安全性**: 限制对敏感工具的访问
|
||||
- **改进组织**: 功能的逻辑分离
|
||||
- **简化管理**: 更容易一起管理相关服务器
|
||||
|
||||
## 创建分组
|
||||
|
||||
### 通过仪表板
|
||||
|
||||
1. **导航到分组部分**: 在主导航中点击"分组"
|
||||
2. **点击"创建分组"**: 开始分组创建流程
|
||||
3. **填写分组详细信息**:
|
||||
|
||||
- **名称**: 分组的唯一标识符
|
||||
|
||||
4. **添加服务器**: 选择要包含在分组中的服务器
|
||||
|
||||
### 通过 API
|
||||
|
||||
以编程方式创建分组:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/api/groups \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
|
||||
-d '{
|
||||
"name": "web-automation",
|
||||
"servers": ["playwright", "fetch"]
|
||||
}'
|
||||
```
|
||||
|
||||
{/* ### 通过配置文件
|
||||
|
||||
在您的 `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": {
|
||||
"name": "web",
|
||||
"servers": ["fetch", "playwright"],
|
||||
},
|
||||
"communication": {
|
||||
"name": "communication",
|
||||
"servers": ["slack"],
|
||||
}
|
||||
}
|
||||
}
|
||||
``` */}
|
||||
|
||||
## 分组类型和用例
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Web 自动化分组">
|
||||
**用途**: 浏览器自动化和网页抓取
|
||||
|
||||
**服务器**:
|
||||
- `playwright`: 浏览器自动化
|
||||
- `fetch`: HTTP 请求和网页抓取
|
||||
- `selenium`: 替代浏览器自动化
|
||||
|
||||
**用例**:
|
||||
- 自动化测试
|
||||
- 数据收集
|
||||
- 网页监控
|
||||
- 内容分析
|
||||
|
||||
**端点**: `http://localhost:3000/mcp/web-automation`
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="数据处理分组">
|
||||
**用途**: 数据操作和分析
|
||||
|
||||
**服务器**:
|
||||
- `sqlite`: 数据库操作
|
||||
- `filesystem`: 文件操作
|
||||
- `spreadsheet`: Excel/CSV 处理
|
||||
|
||||
**用例**:
|
||||
- 数据分析
|
||||
- 报告生成
|
||||
- 文件处理
|
||||
- 数据库查询
|
||||
|
||||
**端点**: `http://localhost:3000/mcp/data-processing`
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="通信分组">
|
||||
**用途**: 消息传递和协作
|
||||
|
||||
**服务器**:
|
||||
- `slack`: Slack 集成
|
||||
- `discord`: Discord 机器人
|
||||
- `email`: 邮件发送
|
||||
- `sms`: 短信通知
|
||||
|
||||
**用例**:
|
||||
- 团队通知
|
||||
- 客户沟通
|
||||
- 警报系统
|
||||
- 社交媒体管理
|
||||
|
||||
**端点**: `http://localhost:3000/mcp/communication`
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="开发分组">
|
||||
**用途**: 软件开发工具
|
||||
|
||||
**服务器**:
|
||||
- `github`: GitHub 操作
|
||||
- `gitlab`: GitLab 集成
|
||||
- `docker`: 容器管理
|
||||
- `kubernetes`: K8s 操作
|
||||
|
||||
**用例**:
|
||||
- 代码部署
|
||||
- 仓库管理
|
||||
- CI/CD 操作
|
||||
- 基础设施管理
|
||||
|
||||
**端点**: `http://localhost:3000/mcp/development`
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="AI/ML 分组">
|
||||
**用途**: 机器学习和 AI 工具
|
||||
|
||||
**服务器**:
|
||||
- `openai`: OpenAI API 集成
|
||||
- `huggingface`: Hugging Face 模型
|
||||
- `vector-db`: 向量数据库操作
|
||||
|
||||
**用例**:
|
||||
- 模型推理
|
||||
- 数据嵌入
|
||||
- 自然语言处理
|
||||
- 计算机视觉
|
||||
|
||||
**端点**: `http://localhost:3000/mcp/ai-ml`
|
||||
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
{/* ## 分组访问控制
|
||||
|
||||
### 访问级别
|
||||
|
||||
<Tabs>
|
||||
<Tab title="公开">
|
||||
**公开分组**:
|
||||
- 所有认证用户都可访问
|
||||
- 无需额外权限
|
||||
- 在分组列表中可见
|
||||
- 默认访问级别
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "public-tools",
|
||||
"accessLevel": "public",
|
||||
"servers": ["fetch", "calculator"]
|
||||
}
|
||||
```
|
||||
|
||||
</Tab>
|
||||
|
||||
<Tab title="私有">
|
||||
**私有分组**:
|
||||
- 仅对分组成员可见
|
||||
- 需要明确的用户分配
|
||||
- 在公开列表中隐藏
|
||||
- 管理员控制成员身份
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "internal-tools",
|
||||
"accessLevel": "private",
|
||||
"members": ["user1", "user2"],
|
||||
"servers": ["internal-api", "database"]
|
||||
}
|
||||
```
|
||||
|
||||
</Tab>
|
||||
|
||||
<Tab title="受限">
|
||||
**受限分组**:
|
||||
- 基于角色的访问控制
|
||||
- 需要特定权限
|
||||
- 启用审计日志
|
||||
- 限时访问
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "admin-tools",
|
||||
"accessLevel": "restricted",
|
||||
"requiredRoles": ["admin", "operator"],
|
||||
"servers": ["system-control", "user-management"]
|
||||
}
|
||||
```
|
||||
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### 用户管理
|
||||
|
||||
将用户分配给分组:
|
||||
|
||||
```bash
|
||||
# 添加用户到分组
|
||||
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"}'
|
||||
|
||||
# 从分组中移除用户
|
||||
curl -X DELETE http://localhost:3000/api/groups/web-tools/members/user123 \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
|
||||
# 列出分组成员
|
||||
curl http://localhost:3000/api/groups/web-tools/members \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
``` */}
|
||||
|
||||
## 分组端点
|
||||
|
||||
### 访问分组
|
||||
|
||||
每个分组都有自己的 MCP 端点:
|
||||
|
||||
<Tabs>
|
||||
<Tab title="HTTP MCP">
|
||||
```
|
||||
http://localhost:3000/mcp/{group-name}
|
||||
```
|
||||
|
||||
示例:
|
||||
- `http://localhost:3000/mcp/web-tools`
|
||||
- `http://localhost:3000/mcp/data-processing`
|
||||
- `http://localhost:3000/mcp/communication`
|
||||
|
||||
</Tab>
|
||||
|
||||
<Tab title="SSE (旧版)">
|
||||
```
|
||||
http://localhost:3000/sse/{group-name}
|
||||
```
|
||||
|
||||
示例:
|
||||
- `http://localhost:3000/sse/web-tools`
|
||||
- `http://localhost:3000/sse/data-processing`
|
||||
- `http://localhost:3000/sse/communication`
|
||||
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### 分组工具发现
|
||||
|
||||
当连接到分组端点时,AI 客户端将只看到该分组内服务器的工具:
|
||||
|
||||
```bash
|
||||
# 列出 web-tools 分组中的工具
|
||||
curl -X POST http://localhost:3000/mcp/web-tools \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "tools/list",
|
||||
"params": {}
|
||||
}'
|
||||
```
|
||||
|
||||
响应将只包含来自 `fetch` 和 `playwright` 服务器的工具。
|
||||
|
||||
## 动态分组管理
|
||||
|
||||
### 向分组添加服务器
|
||||
|
||||
<Tabs>
|
||||
<Tab title="仪表板">
|
||||
1. 在仪表板中导航到分组
|
||||
2. 点击"管理服务器"
|
||||
3. 选择要添加的其他服务器
|
||||
4. 点击"保存更改"
|
||||
</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>
|
||||
|
||||
### 从分组中移除服务器
|
||||
|
||||
<Tabs>
|
||||
<Tab title="仪表板">
|
||||
1. 在仪表板中导航到分组
|
||||
2. 点击"管理服务器"
|
||||
3. 取消选择要移除的服务器
|
||||
4. 点击"保存更改"
|
||||
</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>
|
||||
|
||||
{/* ### 批量服务器更新
|
||||
|
||||
一次更新多个服务器:
|
||||
|
||||
```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"]
|
||||
}'
|
||||
``` */}
|
||||
|
||||
{/* ## 分组监控
|
||||
|
||||
### 分组状态
|
||||
|
||||
监控分组健康状况和活动:
|
||||
|
||||
```bash
|
||||
# 获取分组状态
|
||||
curl http://localhost:3000/api/groups/web-tools/status \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
```
|
||||
|
||||
响应包括:
|
||||
|
||||
- 活跃服务器数量
|
||||
- 工具数量
|
||||
- 活跃连接
|
||||
- 最近活动
|
||||
|
||||
### 分组分析
|
||||
|
||||
跟踪分组使用情况:
|
||||
|
||||
```bash
|
||||
# 获取分组分析
|
||||
curl http://localhost:3000/api/groups/web-tools/analytics \
|
||||
-H "Authorization: Bearer YOUR_JWT_TOKEN"
|
||||
```
|
||||
|
||||
指标包括:
|
||||
|
||||
- 按工具分类的请求计数
|
||||
- 响应时间
|
||||
- 错误率
|
||||
- 用户活动 */}
|
||||
|
||||
{/* ## 高级分组功能
|
||||
|
||||
### 嵌套分组
|
||||
|
||||
创建层次化分组结构:
|
||||
|
||||
```json
|
||||
{
|
||||
"groups": {
|
||||
"development": {
|
||||
"displayName": "开发工具",
|
||||
"subGroups": ["frontend-dev", "backend-dev", "devops"]
|
||||
},
|
||||
"frontend-dev": {
|
||||
"displayName": "前端开发",
|
||||
"servers": ["playwright", "webpack-server"],
|
||||
"parent": "development"
|
||||
},
|
||||
"backend-dev": {
|
||||
"displayName": "后端开发",
|
||||
"servers": ["database", "api-server"],
|
||||
"parent": "development"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 分组模板
|
||||
|
||||
使用模板快速创建分组:
|
||||
|
||||
```json
|
||||
{
|
||||
"groupTemplates": {
|
||||
"web-project": {
|
||||
"description": "标准 Web 项目工具集",
|
||||
"servers": ["fetch", "playwright", "filesystem"],
|
||||
"accessLevel": "public"
|
||||
},
|
||||
"data-science": {
|
||||
"description": "数据科学和 ML 工具",
|
||||
"servers": ["python-tools", "jupyter", "vector-db"],
|
||||
"accessLevel": "private"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
应用模板:
|
||||
|
||||
```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": "我的 Web 项目工具"
|
||||
}'
|
||||
```
|
||||
|
||||
### 分组策略
|
||||
|
||||
定义分组行为策略:
|
||||
|
||||
```json
|
||||
{
|
||||
"groupPolicies": {
|
||||
"web-tools": {
|
||||
"maxConcurrentConnections": 10,
|
||||
"requestTimeout": 30000,
|
||||
"rateLimiting": {
|
||||
"requestsPerMinute": 100,
|
||||
"burstLimit": 20
|
||||
},
|
||||
"allowedOrigins": ["localhost", "myapp.com"]
|
||||
}
|
||||
}
|
||||
}
|
||||
``` */}
|
||||
|
||||
## 最佳实践
|
||||
|
||||
### 分组组织
|
||||
|
||||
<Tip>
|
||||
**按用例组织**: 根据用户想要完成的任务来组织服务器分组,而不仅仅是技术相似性。
|
||||
</Tip>
|
||||
|
||||
<Tip>
|
||||
**保持分组聚焦**: 避免创建包含太多不同工具的分组。更小、更聚焦的分组更有用。
|
||||
</Tip>
|
||||
|
||||
<Tip>
|
||||
**使用描述性名称**: 选择能清楚表明分组目的和内容的名称。
|
||||
</Tip>
|
||||
|
||||
{/* ### 安全考虑
|
||||
|
||||
<Warning>
|
||||
**最小权限原则**: 只给用户访问他们实际需要的分组。
|
||||
</Warning>
|
||||
|
||||
<Warning>
|
||||
**敏感工具隔离**: 将敏感工具保存在具有适当访问控制的受限分组中。
|
||||
</Warning>
|
||||
|
||||
<Warning>
|
||||
**定期访问审查**: 定期审查分组成员身份并移除不必要的访问权限。
|
||||
</Warning> */}
|
||||
|
||||
### 性能优化
|
||||
|
||||
<Info>
|
||||
**平衡分组大小**: 非常大的分组可能导致工具发现较慢。考虑拆分为更小的分组。
|
||||
</Info>
|
||||
|
||||
<Info>
|
||||
**监控使用情况**: 使用分析来识别哪些分组被大量使用并相应优化。
|
||||
</Info>
|
||||
|
||||
## 故障排除
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="分组无法访问">
|
||||
**检查:**
|
||||
- 用户具有适当权限
|
||||
- 分组存在且处于活跃状态
|
||||
- 分组中的服务器正在运行
|
||||
- 网络连接
|
||||
|
||||
**解决方案:**
|
||||
1. 验证用户分组成员身份
|
||||
2. 检查分组配置
|
||||
3. 测试单个服务器连接
|
||||
4. 查看访问日志
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="分组中缺少工具">
|
||||
**可能原因:**
|
||||
- 服务器未正确添加到分组
|
||||
- 服务器未运行
|
||||
- 工具发现失败
|
||||
- 缓存问题
|
||||
|
||||
**调试步骤:**
|
||||
1. 验证服务器在分组配置中
|
||||
2. 检查服务器状态
|
||||
3. 强制刷新工具发现
|
||||
4. 清除分组缓存
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="分组性能问题">
|
||||
**常见问题:**
|
||||
- 分组中服务器过多
|
||||
- 服务器响应慢
|
||||
- 网络延迟
|
||||
- 资源约束
|
||||
|
||||
**优化方案:**
|
||||
1. 拆分大型分组
|
||||
2. 监控服务器性能
|
||||
3. 实施请求缓存
|
||||
4. 使用连接池
|
||||
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## 下一步
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="智能路由" icon="route" href="/zh/features/smart-routing">
|
||||
跨分组的 AI 驱动工具发现
|
||||
</Card>
|
||||
<Card title="身份认证" icon="shield" href="/zh/features/authentication">
|
||||
用户管理和访问控制
|
||||
</Card>
|
||||
<Card title="API 参考" icon="code" href="/zh/api-reference/groups">
|
||||
完整的分组管理 API
|
||||
</Card>
|
||||
<Card title="配置" icon="cog" href="/zh/configuration/mcp-settings">
|
||||
高级分组配置选项
|
||||
</Card>
|
||||
</CardGroup>
|
||||