MCP API Service
Máy chủ Model Context Protocol (MCP) để tương tác với các API hệ thống nội bộ
Kiến Trúc Hệ Thống
Tổng Quan
MCP API Service là một máy chủ trung gian hoạt động theo giao thức Model Context Protocol (MCP), giúp kết nối Claude AI với các API hệ thống nội bộ. Hệ thống này:
Nhận lệnh từ Claude: Người dùng yêu cầu thực hiện một tác vụ thông qua Claude
Xử lý và chuyển đổi: MCP chuyển đổi các yêu cầu từ người dùng sang định dạng API nội bộ
Gọi API: Thực hiện cuộc gọi đến các API nội bộ
Trả kết quả: Kết quả được định dạng và trả về Claude để hiển thị cho người dùng
Cơ Chế Hoạt Động
Máy chủ MCP hoạt động bằng cách giao tiếp qua stdio (standard input/output):
Standard Input (stdin): Nhận yêu cầu từ Claude (ví dụ: lệnh tìm kiếm nhân viên)
Standard Output (stdout): Trả kết quả về cho Claude (ví dụ: thông tin nhân viên tìm được)
Standard Error (stderr): Ghi log lỗi (ví dụ: lỗi kết nối đến API)
Quy trình khi một yêu cầu được gửi:
Claude gửi yêu cầu dạng JSON qua stdin
MCP Server xử lý yêu cầu và gọi API thích hợp
MCP Server trả kết quả về cho Claude qua stdout
Claude hiển thị kết quả cho người dùng
Tính Năng (Kịch Bản)
Các kịch bản hiện có:
check_connection
- Kiểm tra kết nối tới API serversearch_employee
- Tìm kiếm nhân viên theo tên hoặc mãregister_breakfast
- Đăng ký ăn sáng cho nhân viênupdate_hoa_chat
- Cập nhật thông tin hóa chất theo cachuyen_nhan_vien_thi_cong
- Chuyển nhân viên thi công giao khoán
Thêm Kịch Bản Mới
1. Thêm Endpoint
Định nghĩa endpoint mới trong src/config.ts
:
2. Thêm Interface
Tạo interface trong src/types.ts
cho dữ liệu đầu vào/đầu ra:
3. Tạo Service Mới hoặc Thêm Vào Service Hiện Có
Tạo file mới trong src/services/
hoặc thêm vào service hiện có:
4. Cập Nhật Index
Trong src/index.ts
:
Thêm service mới (nếu có)
Định nghĩa tool mới trong danh sách tools
Thêm case xử lý trong hàm handleToolCall
Phát Triển
Cài đặt thư viện:
Build server:
Chạy chế độ phát triển với tự động build lại:
Gỡ Lỗi
Thách Thức
Việc gỡ lỗi MCP gặp khó khăn vì:
Không thể đặt breakpoint như ứng dụng thông thường
Khó theo dõi luồng dữ liệu vào/ra
Log lỗi có thể bị trộn lẫn với output
Giải Pháp
Sử dụng MCP Inspector để:
Theo dõi yêu cầu gửi đến máy chủ
Xem kết quả trả về của từng yêu cầu
Kiểm tra log lỗi riêng biệt
Giám sát hiệu năng
Khởi động Inspector:
Inspector sẽ cung cấp URL truy cập giao diện web để theo dõi hoạt động của hệ thống.
Best Practices
Nhất Quán
Tuân thủ cấu trúc đặt tên hiện có
Sử dụng mẫu code đã được thiết lập
Xử Lý Lỗi
Luôn implement try/catch
Log đầy đủ thông tin lỗi
Trả về thông báo lỗi rõ ràng
Logging
Log đầy đủ các bước: debug trước khi gọi API, info khi thành công
Bao gồm đầy đủ parameters trong log
Validation
Kiểm tra tham số bắt buộc
Validate kiểu dữ liệu của input
Xem thêm chi tiết trong docs/add-new-scenario.md
.
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Tools
A Model Context Protocol (MCP) server that interacts with system APIs, allowing users to check connections, search employees, register breakfast, and update chemical information by shifts.
Related MCP Servers
- AsecurityFlicenseAqualityA Model Context Protocol (MCP) server that provides programmatic access to the Supabase Management API. This server allows AI models and other clients to manage Supabase projects and organizations through a standardized interface.Last updated -8846
- -securityAlicense-qualityMCP Server simplifies the implementation of the Model Context Protocol by providing a user-friendly API to create custom tools and manage server workflows efficiently.Last updated -14MIT License
- -securityAlicense-qualityMCP Server provides a simpler API to interact with the Model Context Protocol by allowing users to define custom tools and services to streamline workflows and processes.Last updated -03MIT License
- -securityAlicense-qualityA Model Context Protocol (MCP) implementation for connecting to and working with various database systems.Last updated -2618MIT License