A backend service providing tools, resources, and prompts for AI models using the Model Context Protocol (MCP).
Model Context Protocol (MCP) là một giao thức mở được phát triển bởi Anthropic để chuẩn hóa cách các AI models tương tác với các nguồn dữ liệu và công cụ bên ngoài. MCP Server là một thành phần quan trọng trong hệ sinh thái này, đóng vai trò là cầu nối giữa AI models và các dịch vụ, cơ sở dữ liệu, API khác nhau.
AI Model ↔ MCP Server ↔ Database (MySQL, PostgreSQL, MongoDB)
AI Model ↔ MCP Server ↔ External APIs (Weather, Stock, Social Media)
AI Model ↔ MCP Server ↔ Local/Cloud Storage
# MCP Server cung cấp tool để query database
tools = [
{
"name": "query_sales_db",
"description": "Query sales database",
"parameters": {"query": "string"}
}
]
tools = [
{
"name": "get_order_status",
"description": "Get customer order status",
"parameters": {"order_id": "string"}
}
]
tools = [
{
"name": "publish_content",
"description": "Publish content to CMS",
"parameters": {"title": "string", "content": "string"}
}
]
tools = [
{
"name": "check_server_health",
"description": "Check server health status",
"parameters": {"server_id": "string"}
}
]
# Python
pip install mcp
# Node.js
npm install @modelcontextprotocol/sdk
# TypeScript
npm install @modelcontextprotocol/sdk typescript
#!/usr/bin/env python3
import asyncio
import json
from mcp.server import Server
from mcp.server.models import InitializationOptions
from mcp.server.stdio import stdio_server
from mcp.types import TextContent, Tool
server = Server("my-mcp-server")
@server.list_tools()
async def handle_list_tools() -> list[Tool]:
"""Danh sách các tools có sẵn"""
return [
Tool(
name="echo",
description="Echo back the input",
inputSchema={
"type": "object",
"properties": {
"message": {"type": "string"}
},
"required": ["message"]
}
)
]
@server.call_tool()
async def handle_call_tool(name: str, arguments: dict) -> list[TextContent]:
"""Xử lý tool calls"""
if name == "echo":
message = arguments.get("message", "")
return [TextContent(type="text", text=f"Echo: {message}")]
else:
raise ValueError(f"Unknown tool: {name}")
async def main():
async with stdio_server() as (read_stream, write_stream):
await server.run(
read_stream,
write_stream,
InitializationOptions(
server_name="my-mcp-server",
server_version="1.0.0",
capabilities=server.get_capabilities()
)
)
if __name__ == "__main__":
asyncio.run(main())
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from '@modelcontextprotocol/sdk/types.js';
class MyMCPServer {
private server: Server;
constructor() {
this.server = new Server(
{
name: 'my-mcp-server',
version: '1.0.0',
},
{
capabilities: {
tools: {},
},
}
);
this.setupHandlers();
}
private setupHandlers() {
this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [
{
name: 'calculator',
description: 'Perform basic math operations',
inputSchema: {
type: 'object',
properties: {
operation: { type: 'string', enum: ['add', 'subtract', 'multiply', 'divide'] },
a: { type: 'number' },
b: { type: 'number' },
},
required: ['operation', 'a', 'b'],
},
},
],
}));
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
if (name === 'calculator') {
const { operation, a, b } = args as any;
let result: number;
switch (operation) {
case 'add':
result = a + b;
break;
case 'subtract':
result = a - b;
break;
case 'multiply':
result = a * b;
break;
case 'divide':
result = a / b;
break;
default:
throw new Error(`Unknown operation: ${operation}`);
}
return {
content: [{ type: 'text', text: `Result: ${result}` }],
};
}
throw new Error(`Unknown tool: ${name}`);
});
}
async run() {
const transport = new StdioServerTransport();
await this.server.connect(transport);
}
}
const server = new MyMCPServer();
server.run().catch(console.error);
{
"mcpServers": {
"my-server": {
"command": "python",
"args": ["path/to/your/mcp_server.py"]
}
}
}
# Test với stdio
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}' | python mcp_server.py
Vị trí: mcp-time-node/
Một MCP Server được viết bằng Node.js cung cấp các chức năng liên quan đến thời gian:
# Chạy với Node.js trực tiếp
cd mcp-time-node
npm install
npm start
# Chạy demo
npm run demo
# Chạy với Docker
docker build -t mcp-time-server .
docker run -i --rm mcp-time-server
get_current_time
timezone
(IANA timezone name)Asia/Ho_Chi_Minh
, America/New_York
, Europe/London
convert_time
time
: Thời gian theo định dạng HH:MMsource_timezone
: Múi giờ nguồntarget_timezone
: Múi giờ đíchProject đã được containerized với Dockerfile optimized cho production:
node:18-alpine
Đã cấu hình sẵn trong .vscode/mcp.json
với 2 options:
// Lấy thời gian hiện tại ở Việt Nam
{
"name": "get_current_time",
"arguments": {
"timezone": "Asia/Ho_Chi_Minh"
}
}
// Chuyển đổi 14:30 từ Việt Nam sang New York
{
"name": "convert_time",
"arguments": {
"time": "14:30",
"source_timezone": "Asia/Ho_Chi_Minh",
"target_timezone": "America/New_York"
}
}
Current: AI ↔ MCP Server ↔ Single Service
Future: AI ↔ MCP Server ↔ Multiple Services (Orchestration)
Timeline | Milestone |
---|---|
2025 Q2 | MCP v2.0 với improved performance |
2025 Q3 | Enterprise security features |
2025 Q4 | Multi-modal support |
2026 Q1 | Service orchestration platform |
2026 Q2 | AI agent collaboration framework |
MCP Server đang trở thành backbone cho việc tích hợp AI vào các hệ thống thực tế. Với khả năng kết nối linh hoạt giữa AI models và external services, MCP mở ra vô số possibilities cho automation và intelligent applications.
Key takeaways:
Bắt đầu với MCP Server ngay hôm nay để tận dụng sức mạnh của AI trong ứng dụng của bạn!
Integrates with the Stability AI API for image generation, editing, and upscaling.
Provides tools for geospatial analysis within Jupyter notebooks.
Enable AI Agents to fix Playwright test failures reported to Currents.
Control CAD software with natural language instructions to perform drawing operations.
Bring the full power of BrowserStack’s Test Platform to your AI tools, making testing faster and easier for every developer and tester on your team.
A comprehensive MCP server for tooling interactions(40+) and resource accessibility(60+) plus many useful prompts to interact with Algorand Blockchain.
MCP server for Autodesk Maya
MCP Server for automated reverse engineering with IDA Pro.
An MCP server for AI coding assistants to control, inspect, and modify Bevy applications using the Bevy Remote Protocol (BRP).
Integration with QA Sphere test management system, enabling LLMs to discover, summarize, and interact with test cases directly from AI-powered IDEs