Content
# Knowledge Base MCP Service
A knowledge base retrieval system based on the MCP (Model Context Protocol) protocol, providing integration capabilities with the Dify knowledge base.
## Project Introduction
The Knowledge Base MCP Service is a lightweight service that connects your Dify knowledge base to MCP-supported AI assistants (such as Claude AI) via the MCP protocol. This service supports various transport methods, including STDIO, HTTP, and SSE, making it suitable for different application scenarios.
### Key Features
- Supports the MCP protocol for seamless integration with AI assistants like Claude
- Provides tools for parsing knowledge base IDs and retrieving knowledge base documents
- Supports multiple transport methods: STDIO, HTTP, and SSE
- Caching mechanism improves query efficiency
- Supports simultaneous queries across multiple knowledge bases
- Simple and easy-to-use API interface
## Technical Architecture

The system consists of the following main components:
1. MCP Server: Handles communication with AI assistants
2. Dify Service: Interacts with the Dify API to retrieve knowledge base content
3. Tool Service: Provides MCP tool implementations, including parsing knowledge base IDs and retrieving knowledge base documents
## Installation and Setup
### Environment Requirements
- Node.js 18+
- TypeScript
- A valid Dify API key
### Installation Steps
1. Clone the repository
```bash
git clone https://github.com/yourusername/knowledge-base-mcp.git
cd knowledge-base-mcp
```
2. Install dependencies
```bash
pnpm install
# or use npm
npm install
```
3. Configure environment variables
Copy `.env.example` to `.env` and fill in the necessary configuration information:
```bash
cp .env.example .env
```
Edit the `.env` file to set the Dify API key and other configurations.
4. Configure Docker
```bash
cp Dockerfile.example Dockerfile
```
Edit the `Dockerfile` to set the Dify API key and other configurations.
### Configuration Description
The following parameters can be configured in the `.env` file:
| Variable Name | Description | Default Value |
|---------------|-------------|---------------|
| DIFY_BASE_URL | Dify API Base URL | https://api.dify.ai/v1 |
| DIFY_API_KEY | Dify API Key | - |
| TRANSPORT_TYPE | Transport type (stdio/http/sse) | stdio |
| PORT | HTTP/SSE service port | 3000 |
| CACHE_TTL | Cache time-to-live (milliseconds) | 3600000 (1 hour) |
| CACHE_CLEANUP | Cache cleanup interval (milliseconds) | 300000 (5 minutes) |
| ALLOWED_ORIGINS | Allowed CORS origins (comma-separated) | * |
## Build and Run
### Build the Project
```bash
pnpm run build
```
### Run the Service
You can run the service in the following ways:
#### STDIO Mode (default)
```bash
pnpm start
# or
pnpm run dev
```
#### HTTP Mode
```bash
pnpm run dev:http
# or
node dist/index.js --transport http --port 8008
```
#### SSE Mode
```bash
pnpm run dev:sse
# or
node dist/index.js --transport sse --port 8006
```
### Command Line Parameters
The service supports the following command line parameters:
- `--transport <stdio|http|sse>`: Specify the transport type
- `--port <number>`: Specify the HTTP/SSE service port
- `--dify-api-key <string>`: Specify the Dify API key (overrides environment variable settings)
## License
MIT License
Connection Info
You Might Also Like
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
markitdown
Python tool for converting files and office documents to Markdown.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.
OmniRoute
Never stop coding. The free AI gateway — one endpoint, 160+ providers, zero...
TrendRadar
TrendRadar: Your hotspot assistant for real news in just 30 seconds.
mempalace
The highest-scoring AI memory system ever benchmarked. And it's free.