Content
# MCP-Server Project Documentation
## Project Overview
MCP-Server is a server and client implementation based on the Model Context Protocol (MCP), allowing large language models (LLM) to invoke external tools through a structured protocol to accomplish complex tasks. The project mainly consists of two parts: the MCP server and the TypeScript implementation of the client.
## System Architecture
```
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│ Frontend App │────▶│ MCP Client │────▶│ MCP Server │
└───────────────┘ └───────────────┘ └───────────────┘
△ │ │
│ ▼ ▼
│ ┌───────────────┐ ┌───────────────┐
└───────────│ Large Language│ │ External API │
│ Model │ │ (Weather, GitHub)│
│ (Deepseek) │ └───────────────┘
└───────────────┘
```
## Core Components
### 1. MCP Server
The server is the provider of tools, responsible for registering and executing various tools.
**Main Functions:**
- Tool Registration: Currently implemented tools include weather forecast queries and GitHub user information queries.
- Tool Execution: Receives client requests, executes the corresponding tools, and returns results.
- Communication: Communicates with the client through standard input/output (stdio).
### 2. MCP Client
The client connects the large language model API and the MCP server, responsible for handling user queries and coordinating model calls and tool calls.
**Main Functions:**
- Connects to the MCP server and retrieves the list of available tools.
- Communicates with the large language model API (default is Deepseek).
- Parses tool invocation requests from the model output.
- Coordinates the tool invocation process and aggregates results.
- Provides a command-line interactive interface.
- Offers an Express-based Web API.
### 3. Web API
The client provides an HTTP interface for frontend applications to call, supporting streaming output and process visualization.
**Main Endpoints:**
- `/sse`: Handles frontend query requests and returns a streaming response containing the thought process and results.
## White-box Process Visualization
The client implements white-box process visualization, allowing users to see:
1. Intent recognition process.
2. Tool selection process.
3. Tool invocation parameters and results.
4. Final answer generation process.
## Technology Stack
- **Backend**: Node.js, TypeScript
- **Framework**: Express
- **Large Language Model**: Deepseek (via OpenAI compatible API)
- **Communication Protocol**: Model Context Protocol
- **SDK**: @modelcontextprotocol/sdk
## Usage Instructions
1. Start the server:
```bash
node dist/src/index.js
```
2. Start the client and connect to the server:
```bash
node dist/mcp-client-typescript/src/index.js /path/to/server/script.js
```
3. Access the Web API:
```
POST http://localhost:3000/sse
Content-Type: application/json
{
"query": "What is the weather like in Beijing today?"
}
```
## Configuration Requirements
You need to set the following environment variables in the `.env` file:
- `LLM_API_KEY`: Deepseek API key
- `GAODE_KEY`: Gaode Map API key (for weather queries)
## Workflow
1. The user sends a query to the client.
2. The client sends the query to the large language model.
3. The large language model analyzes the query and decides whether to invoke a tool.
4. If a tool needs to be invoked, the client sends a request to the server via the MCP protocol.
5. The server executes the tool and returns the result.
6. The client sends the tool result back to the large language model to generate the final answer.
7. The answer is returned to the user.
## Conclusion
The MCP-Server project provides a complete example implementation of tool invocation for large language models, demonstrating how to enable models to access external tools and services through a structured protocol, thereby enhancing the capabilities of the models. Through white-box process visualization, users can better understand the model's thought process and tool invocation logic.
Connection Info
You Might Also Like
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
servers
Model Context Protocol Servers
Time
A Model Context Protocol server for time and timezone conversions.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.
Sequential Thinking
A structured MCP server for dynamic problem-solving and reflective thinking.
git
A Model Context Protocol server for Git automation and interaction.