MCP Server
A robust server implementing the Model Context Protocol with SSE and STDIO transport, enabling real-time communication and extensible tooling for AI models.
README
MCP Server
A robust server implementation of the Model Context Protocol (MCP) that supports multiple transport methods (SSE and STDIO) for real-time communication with AI models.
🚀 Features
- Full MCP Implementation: Complete and standard-compliant implementation of the Model Context Protocol
- Multiple Transports: Seamless communication via SSE (Server-Sent Events) and STDIO
- Robust Architecture: Built on Clean Architecture and SOLID principles for maintainability and extensibility
- Powerful Tooling: Easily extensible tools, resources, and prompts
- Developer-Friendly: Comprehensive logging, error handling, and testing support
🏗️ Architecture
The project follows a clean, layered architecture adhering to SOLID principles:
| Layer | Responsibility | Components |
|---|---|---|
| Domain | Core business logic | Interfaces, Models, Entities |
| Application | Use cases, application flow | Services, Use Cases, DTOs |
| Infrastructure | Technical concerns | Implementations, Adapters, External services |
| Presentation | User interface | API Controllers, HTTP endpoints |
Architectural Diagram
┌─────────────────────┐ ┌─────────────────────┐
│ Presentation │ │ Application │
│ Layer │ │ Layer │
│ - Express API │─────▶│ - Use Cases │
│ - Controllers │ │ - Services │
└─────────────────────┘ └──────────┬──────────┘
│
▼
┌─────────────────────┐ ┌─────────────────────┐
│ Infrastructure │ │ Domain │
│ Layer │◀─────│ Layer │
│ - Implementations │ │ - Interfaces │
│ - Adapters │ │ - Models │
└─────────────────────┘ └─────────────────────┘
💻 Requirements
- Node.js 18 or higher
- Yarn or npm package manager
📦 Installation
# Clone the repository
git clone https://github.com/your-username/mcp-server.git
cd mcp-server
# Install dependencies
yarn install
# Build the project
yarn build
🚀 Running the Server
# Start the server
yarn start
# Build and start in one command (for development)
yarn rebuild
By default, the server runs on port 3001. You can configure this using the PORT environment variable.
🔌 Transport Options
The MCP server supports two transport methods:
| Transport | Description | Use Case |
|---|---|---|
| SSE | Server-Sent Events over HTTP | Web applications, browser clients |
| STDIO | Standard input/output streams | CLI tools, local applications |
🛣️ API Endpoints
- SSE:
/sse- Establish SSE connections for real-time communication - Messages:
/messages- Send JSON-RPC messages to the server
🧪 Testing
Use the official MCP Inspector tool to test your server implementation:
- Build and start your MCP Server
yarn build
yarn rebuild # if using SSE transport (builds & starts)
# OR
yarn start # manual start
- Run the inspector against your server
npx @modelcontextprotocol/inspector node build/index.js
- Access to Inspecto UI http://127.0.0.1:6274 🚀
🧩 Extending Functionality
Adding a New Tool
// tools/custom/my-tool.ts
import { z } from "zod";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { ITool } from "../core/domain/interfaces/tool.interface.js";
import { ILogger } from "../core/domain/interfaces/logger.interface.js";
export class MyTool implements ITool {
private readonly logger: ILogger;
constructor(logger: ILogger) {
this.logger = logger;
}
public register(server: McpServer): void {
server.tool(
"my-tool",
"Description of my tool",
{
param1: z.string().describe("Parameter description"),
},
async ({ param1 }) => {
this.logger.info(`MyTool called with param1: ${param1}`);
return {
content: [
{
type: "text",
text: `Result: ${param1}`,
},
],
};
},
);
this.logger.info("MyTool registered");
}
}
Adding a New Resource
// resources/custom/my-resource.ts
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { IResource } from "../core/domain/interfaces/resource.interface.js";
import { ILogger } from "../core/domain/interfaces/logger.interface.js";
export class MyResource implements IResource {
private readonly logger: ILogger;
constructor(logger: ILogger) {
this.logger = logger;
}
public register(server: McpServer): void {
server.resource('my-resource', 'my-data.json', async () => {
this.logger.info('My resource accessed');
return {
contents: [
{
uri: 'my-data.json',
text: JSON.stringify({ key: "value" }, null, 2),
mimeType: 'application/json',
},
],
};
});
this.logger.info('My resource registered');
}
}
Adding a New Prompt
// prompts/custom/my-prompt.ts
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { IPrompt } from "../core/domain/interfaces/prompt.interface.js";
import { ILogger } from "../core/domain/interfaces/logger.interface.js";
export class MyPrompt implements IPrompt {
private readonly logger: ILogger;
constructor(logger: ILogger) {
this.logger = logger;
}
public register(server: McpServer): void {
server.prompt(
'my-prompt',
'Description of my prompt',
() => {
this.logger.info('My prompt accessed');
return {
messages: [
{
role: 'user',
content: {
type: 'text',
text: 'Initial user message',
},
},
{
role: 'assistant',
content: {
type: 'text',
text: 'Initial assistant response',
},
},
],
};
},
);
this.logger.info('My prompt registered');
}
}
📝 SOLID Principles Applied
| Principle | Implementation |
|---|---|
| Single Responsibility | Each class has one clear responsibility |
| Open/Closed | System can be extended without modifying existing code |
| Liskov Substitution | Derived types can be substituted for their base types |
| Interface Segregation | Specific interfaces for specific clients |
| Dependency Inversion | High-level modules depend on abstractions |
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。