The full upstream README, mirrored here for reference. Install config, tool schemas, adoption signals, and an original overview live on the TuViMCP listing page.
This is a Model Context Protocol (MCP) server developed in Python that calculates and manages Vietnamese "Tử Vi" horoscope charts. It is optimized to output clean, structured JSON data that LLM agents can easily read, interpret, and explain to users.

tuvi_mcp.database) for Python library consumers to save, retrieve, list, and delete horoscope profiles. (MCP tools are stateless and do not require a database.)ansaotuvi calculation logic internally with custom Tuần/Triệt double-cung fixes.Beyond the MCP server, tuvi-mcp-server ships a typed, ergonomic Python API for direct use in scripts, notebooks, or web backends:
The same library is what the MCP tools wrap, so behavior is identical whether you call Horoscope.from_birth(...).chart() or invoke the generate_horoscope tool from an MCP client.
timezone explicitly to the MCP tool (timezone accepts an integer like 8 or an h:30 string like "8:30"). Defaults to 7 when omitted. The astronomical engine uses the supplied timezone only for boundary rounding of the Solar↔Lunar date — the civil hour branch (chi giờ) is always derived from the user-supplied local clock time.[!NOTE] Traditional Calculations Disclaimer: Vietnamese "Tử Vi" is a highly rich astrological methodology with various traditional schools (e.g., Nam Phái vs. Bắc Phái). Calculation parameters, star rankings, element determinations, and interpretations may differ depending on the specific lineage or school. The output generated by this tool is calculated strictly according to standard consensus computational logic and should be treated as a computational reference rather than a definitive astrological interpretation.
You can install tuvi-mcp-server directly from PyPI:
If you want to contribute to the package or run unit tests, set up a local development environment:
Create Virtual Environment:
Install Package in Editable Mode:
Running Tests: Verify your local setup by running the test suite:
To run the server over HTTP (runs on port 1850 by default):
Override host and port:
All tools run locally inside the MCP environment. They require no external authentication or network rate limiting.
generate_horoscopeGenerates a full Tử Vi chart from raw birth details, with optional high-quality chart image rendering.
generate_image is True, renders a PNG file to a temporary location on the local filesystem and returns its path.name (string): Person's name (default: "Khách").day (integer): Day of birth (1-31).month (integer): Month of birth (1-12).year (integer): Year of birth.hour_val (string): Hour of birth (e.g., "14:30", "Ngọ", "Tý", or branch index 1-12). Interpreted as local civil time at the birthplace — do not convert to Vietnam time unless that is the intended civil-tz reference (see timezone below).gender_val (string): Gender ("Nam" or "Nữ", case-insensitive).is_solar (boolean): True for Solar, False for Lunar (default: True).current_year (integer, optional): Year to inspect transit stars/Vận Hạn for (defaults to current year).generate_image (boolean, optional): Whether to generate and return the high-quality chart image along with the chart data (default: True).timezone (integer or string, optional): UTC offset for the civil timezone at the birthplace. Accepts an integer (e.g. 7, -5) or an h:30 string (e.g. "7:30", "-5:30"). Default: 7 (ICT/Vietnam). Other minute values and out-of-range inputs are rejected. Only the boundary rounding of astronomical events (lunar day, tiết-khí, Đông chí) is affected — the civil hour branch (chi giờ) is always derived from hour_val.generate_image is True, returns a list containing [Image, chart_data] (where Image is a FastMCP Image content block pointing to the generated PNG).generate_image is False, returns the raw JSON dictionary chart_data directly. Contains keys: thien_ban (demographics, pillars, element, destiny) and dia_ban (12 houses with stars).{"error": "error_message"} if calculations fail.get_van_hanCalculates yearly transit stars and active houses (major, yearly, monthly, and daily periods) for a target period.
current_year, current_month, and (if provided) current_day represent the Lunar year, month, and day. If inspecting a Solar timeframe (e.g. 'October 2026'), you MUST convert it using convert_calendar first.name, day, month, year, hour_val, gender_val, is_solar (same as birth parameters above).current_year (integer): Target Lunar year to inspect (default: current year).current_month (integer): Target Lunar month to inspect (1-12, default: 1).current_day (integer, optional): Target Lunar day to inspect (1-30, enables Nhật Hạn).timezone (integer or string, optional): same as generate_horoscope.timezone.person_details (Can-Chi), target_period (resolved age and target), transit_stars, dai_han, tieu_han, nguyet_han, and (if current_day given) nhat_han. Returns {"error": "error_message"} if input details are invalid.convert_calendarConverts a date between the Solar (Dương lịch) and Lunar (Âm lịch) calendars.
get_van_han.day (integer): Day of the date to convert.month (integer): Month of the date to convert.year (integer): Year of the date to convert.from_solar (boolean): True to convert Solar -> Lunar (default), False to convert Lunar -> Solar.lunar_leap (boolean): Only used if from_solar is False. True if the input lunar month is a leap month (tháng nhuận).timezone (integer or string): Timezone offset. Accepts an integer hour (e.g. 7, -5, 9) or an h:30 string (e.g. "7:30", "-5:30", "9:30"). Default: 7 for Vietnam/ICT.from_solar is True, returns a dictionary with lunar_day, lunar_month, lunar_year, lunar_leap (boolean), and formatted string date (e.g., "14/5/1995" or "14/5/1995 (nhuận)").from_solar is False, returns a dictionary with solar_day, solar_month, solar_year, and formatted string date (e.g., "28/6/1995").{"error": "error_message"} if date arguments fail validation.get_auspicious_infoEvaluates auspicious days, hours, 12 Trực, 28 Tú, Tiết Khí, and travel directions for a given date.
generate_horoscope for a full birth chart instead.day (integer, optional): Day of month. Defaults to today.month (integer, optional): Month of year. Defaults to current month.year (integer, optional): Year (4 digits). Defaults to current year.is_solar (boolean, optional): True for Solar date (default), False for Lunar date.timezone (integer or string, optional): same as generate_horoscope.timezone. The Solar↔Lunar date mapping honors this; metadata lookups (can chi of day, tiết-khí names, trực, hoàng đạo) are derived from the Solar date via the OO layer which is anchored at UTC+7 for those J2000-epoch tables — exact tiết-khí timestamps in the response may differ slightly for non-7 tz near a tiết-khí boundary.duong_lich, am_lich, can_chi_ngay, ngay_hoang_dao, truc_ngay, nhi_thap_bat_tu, huong_xuat_hanh, gio_hoang_dao, tiet_khi_hien_tai, tiet_khi_tiep_theo.To illustrate the structured responses, here is an example of what the server outputs when calling the core tools.
generate_horoscope)When calling generate_horoscope(name="Nguyễn Văn A", day=10, month=6, year=1995, hour_val="14:30", gender_val="Nam", is_solar=true), the server outputs a structured JSON response containing thien_ban (person information), dia_ban (the list of 12 houses and their stars), and cach_cuc (recognized astrological formations).
Response Snippet:
For the complete output, see examples/sample_horoscope_output.json.
get_van_han)When calling get_van_han(...) for a target year/month, it tracks yearly transit stars (sao lưu) and flags the active houses:
Response Snippet:
For the complete output, see examples/sample_van_han_output.json.
Add the following to your claude_desktop_config.json file:
Go to Settings -> Features -> MCP, click "+ Add New MCP Server":
/path/to/TuViMCP/.venv/bin/tuvi-mcpĐây là máy chủ Model Context Protocol (MCP) được phát triển bằng Python, dùng để lập và quản lý lá số Tử Vi theo hệ Việt Nam. Kết quả được chuẩn hóa dưới dạng JSON sạch, có cấu trúc rõ ràng, giúp các LLM agent dễ dàng đọc, phân tích và diễn giải lại cho người dùng.

Lập lá số Tử Vi: Hỗ trợ chuyển đổi ngày giờ sinh Dương lịch hoặc Âm lịch thành lá số Tử Vi đầy đủ, bao gồm Thiên Bàn, Địa Bàn, 12 cung và hơn 100 sao.
51 Cách Cục Evaluation Engine: Tự động nhận diện toàn bộ 51 cách cục Trung Châu Phái trong quá trình lập lá số, trả về các cách cục khớp kèm Cổ Ca, Bình Chú, và Ưu/Khuyết điểm.
Vẽ lá số chất lượng cao: Xuất ảnh lá số sắc nét tỷ lệ chuẩn phù hợp in ấn, tự động tô màu chữ theo ngũ hành của sao (Mộc: Xanh lá, Hỏa: Đỏ, Thổ: Vàng cam, Kim: Xám, Thủy: Xanh dương), vẽ nhãn bao nổi bật cho cung bị Tuần/Triệt, vẽ các đường nối hình học làm nổi bật tam hợp chiếu mệnh thân.
Xem Vận Hạn: Tính toán các sao lưu động như Lưu Thái Tuế, Lưu Lộc Tồn, v.v., đồng thời xác định các cung hạn đang kích hoạt gồm Đại Hạn 10 năm, Tiểu Hạn theo năm, Nguyệt Hạn theo tháng và Nhật Hạn theo ngày cho bất kỳ năm/tháng/ngày cần xem nào, ví dụ năm 2026.
Xem Ngày Tốt / Giờ Hoàng Đạo: Đánh giá Hoàng Đạo/Hắc Đạo, 12 Trực, 28 Tú, Tiết Khí, hướng xuất hành và giờ tốt cho bất kỳ ngày tháng nào.
Lưu trữ cục bộ (Dành cho Python Library): Cung cấp sẵn module cơ sở dữ liệu SQLite cục bộ (tuvi_mcp.database) hỗ trợ lưu, truy xuất, liệt kê và xóa thông tin lá số khi tích hợp trực tiếp bằng mã Python. (Các MCP tool không dùng cơ sở dữ liệu.)
Tự động quy đổi giờ sinh: Có thể tự động chuyển đổi giờ theo đồng hồ, ví dụ "14:30", hoặc tên giờ truyền thống, ví dụ "Ngọ", "Tý", sang đúng chỉ số Địa Chi tương ứng.
Tích hợp logic tính toán nội bộ: Bao gồm sẵn phần lõi tính toán từ ansaotuvi, đồng thời bổ sung các chỉnh sửa riêng cho trường hợp Tuần/Triệt bao phủ hai cung.
Ngoài việc chạy như một máy chủ MCP, tuvi-mcp-server cung cấp giao diện Python API chuẩn hóa, có gợi ý kiểu dữ liệu (typing) để sử dụng trực tiếp trong mã nguồn, notebook hoặc dịch vụ backend:
Các kết quả đều hỗ trợ truy xuất thuộc tính và phương thức .to_dict() để chuyển đổi sang JSON:
timezone vào công cụ MCP (chấp nhận số nguyên như 8 hoặc chuỗi h:30 như "8:30", mặc định là 7). Công cụ thiên văn sử dụng timezone để quy đổi ranh giới ngày Âm/Dương lịch — chi giờ sinh luôn được xác định theo giờ địa phương thực tế.[!NOTE] Tuyên bố về các trường phái tính toán: Tử Vi Việt Nam là một bộ môn học thuật vô cùng phong phú với nhiều trường phái truyền thống khác nhau (như Nam Phái, Bắc Phái). Các phương pháp an sao, phân định thứ hạng sao, ngũ hành bản mệnh hay luận giải có thể có sự khác biệt nhất định tùy thuộc vào từng truyền thừa hay học phái. Kết quả thu được từ công cụ này được tính toán hoàn toàn dựa trên logic đồng thuận phổ biến và chỉ nên được sử dụng như một tài liệu tham khảo tính toán khách quan, không phải là lời luận giải Tử Vi mang tính chất duy nhất hay định mệnh.
Bạn có thể cài đặt trực tiếp tuvi-mcp-server từ PyPI bằng pip:
Nếu muốn đóng góp cho dự án hoặc chạy kiểm thử tự động, bạn có thể thiết lập môi trường phát triển cục bộ:
Tạo môi trường ảo:
Cài đặt gói ở chế độ editable cùng các thư viện kiểm thử:
Chạy kiểm thử (Unit Tests):
Xác minh cài đặt bằng cách chạy bộ kiểm thử với pytest:
Đây là chế độ mặc định, phù hợp để tích hợp với Claude Desktop và Cursor.
Dùng khi muốn triển khai server qua HTTP, phù hợp cho môi trường remote hoặc cloud. Mặc định server chạy trên cổng 1850.
Có thể tùy chỉnh host và port như sau:
generate_horoscopeTạo lá số Tử Vi đầy đủ từ thông tin ngày giờ sinh, hỗ trợ xuất ảnh lá số chất lượng cao.
name (string): Tên người xem, mặc định là "Khách".day (integer): Ngày sinh, từ 1 đến 31.month (integer): Tháng sinh, từ 1 đến 12.year (integer): Năm sinh.hour_val (string): Giờ sinh, ví dụ "14:30", "Ngọ", "Tý".gender_val (string): Giới tính, nhận giá trị "Nam" hoặc "Nữ".is_solar (boolean): True nếu dùng Dương lịch, False nếu dùng Âm lịch. Mặc định là True.current_year (integer, tùy chọn): Năm cần xem vận hạn để tính sao lưu (mặc định là năm hiện tại).generate_image (boolean, tùy chọn): Có xuất và trả về ảnh lá số chất lượng cao đi kèm hay không (mặc định: True).timezone (integer hoặc string, tùy chọn): Múi giờ nơi sinh. Chấp nhận số nguyên (vd: 7, -5) hoặc chuỗi h:30 (vd: "7:30", "-5:30"). Mặc định: 7 (Việt Nam/ICT).generate_image là True, trả về danh sách [Image, chart_data] (trong đó Image là block chứa dữ liệu ảnh của FastMCP).generate_image là False, trả về trực tiếp đối tượng JSON chart_data.get_van_hanTính toán sao lưu động và xác định các cung hạn đang kích hoạt, bao gồm Đại Hạn, Tiểu Hạn, Nguyệt Hạn và Nhật Hạn cho ngày/tháng/năm cần xem.
name, day, month, year, hour_val, gender_val, is_solar: giống như trong generate_horoscope.current_year (integer): Năm âm lịch cần xem hạn. Mặc định là năm hiện tại.current_month (integer): Tháng âm lịch cần xem hạn, từ 1 đến 12. Mặc định là 1.current_day (integer, tùy chọn): Ngày âm lịch cần xem hạn (1-30). Nếu cung cấp, sẽ tính thêm Nhật Hạn.timezone (integer hoặc string, tùy chọn): giống như generate_horoscope.timezone.convert_calendarChuyển đổi ngày qua lại giữa Dương lịch và Âm lịch.
day (integer): Ngày cần chuyển đổi.month (integer): Tháng cần chuyển đổi.year (integer): Năm cần chuyển đổi.from_solar (boolean): True để chuyển đổi từ Dương lịch sang Âm lịch (mặc định), hoặc False để chuyển từ Âm lịch sang Dương lịch.lunar_leap (boolean): Chỉ dùng khi from_solar là False. True nếu tháng âm lịch đầu vào là tháng nhuận.timezone (integer hoặc string): Múi giờ. Chấp nhận số nguyên giờ (vd. 7, -5, 9) hoặc chuỗi h:30 (vd. "7:30", "-5:30", "9:30"). Mặc định: 7 (Giờ Việt Nam/ICT).from_solar là True, trả về dictionary chứa lunar_day, lunar_month, lunar_year, lunar_leap (boolean), và chuỗi ngày đã định dạng formatted.from_solar là False, trả về dictionary chứa solar_day, solar_month, solar_year, và chuỗi ngày đã định dạng formatted.get_auspicious_infoĐánh giá ngày tốt, giờ Hoàng Đạo, 12 Trực, 28 Tú, Tiết Khí và hướng xuất hành cho một ngày bất kỳ.
day (integer, tùy chọn): Ngày trong tháng. Mặc định là hôm nay.month (integer, tùy chọn): Tháng. Mặc định là tháng hiện tại.year (integer, tùy chọn): Năm (4 chữ số). Mặc định là năm hiện tại.is_solar (boolean, tùy chọn): True nếu dùng Dương lịch (mặc định), False nếu dùng Âm lịch.timezone (integer hoặc string, tùy chọn): giống như generate_horoscope.timezone. Mapping Dương↔Âm theo múi giờ này; các tra cứu metadata (can chi ngày, tên tiết khí, trực, hoàng đạo) lấy từ lớp OO neo tại UTC+7 cho các bảng J2000 — timestamp tiết khí trong response có thể lệch nhẹ với tz ≠ 7.duong_lich, am_lich, can_chi_ngay, ngay_hoang_dao, truc_ngay, nhi_thap_bat_tu, huong_xuat_hanh, gio_hoang_dao, tiet_khi_hien_tai, tiet_khi_tiep_theo.Dưới đây là cấu trúc dữ liệu JSON thực tế do máy chủ MCP trả về để minh họa tính rõ ràng và gọn gàng của định dạng đầu ra.
generate_horoscope)Khi gọi generate_horoscope(name="Nguyễn Văn A", day=10, month=6, year=1995, hour_val="14:30", gender_val="Nam", is_solar=true), đầu ra trả về đối tượng JSON gồm thông tin Thiên Bàn (thien_ban), danh sách 12 cung Địa Bàn (dia_ban), và các cách cục (cach_cuc).
Đoạn trích đầu ra:
Để xem dữ liệu đầy đủ, vui lòng tham khảo file mẫu tại examples/sample_horoscope_output.json.
get_van_han)Khi gọi get_van_han(...) cho một năm/tháng cụ thể, hệ thống tính toán vị trí các sao lưu và đánh dấu các cung hạn đang kích hoạt:
Đoạn trích đầu ra:
Để xem dữ liệu đầy đủ, vui lòng tham khảo file mẫu tại examples/sample_van_han_output.json.
Thêm cấu hình sau vào file claude_desktop_config.json:
Vào Settings -> Features -> MCP, sau đó chọn "+ Add New MCP Server":
/path/to/TuViMCP/.venv/bin/tuvi-mcp