瀏覽代碼

first commit

Lukas Goldschmidt 1 月之前
當前提交
332331725e
共有 2 個文件被更改,包括 278 次插入0 次删除
  1. 141 0
      INITIAL_IDEA.md
  2. 137 0
      ORGANIZED_PLAN.md

+ 141 - 0
INITIAL_IDEA.md

@@ -0,0 +1,141 @@
+# Initial Idea: astro-mcp
+
+## Topic
+Building a new MCP server named **astro-mcp** that acts as an MCP client to the existing **ephemeris-mcp** service, consuming its `get_sky_state` tool and exposing calculated astrological data (naked chart calculations) via MCP tools for downstream interpretation by services like astro_service.
+
+## Goal
+- Provide a pure calculation layer that converts astronomical data from ephemeris-mcp into structured astrological data
+- Calculate natal charts (planetary positions, houses, aspects), transit charts, and synastry charts
+- Offer transit previews: given a person and a time range, list significant transit events (exact aspects, ingresses, stations)
+- Maintain a lightweight database of persons with birth datetime, latitude, longitude, and optional nickname
+- Output structured data (JSON-serializable) suitable for downstream astrological interpretation tools
+- Do NOT provide interpretations - only calculations and raw data
+- Follow the established MCP server manifest conventions (FastMCP + FastAPI, SSE transport, logging under ./logs/, health endpoint, etc.)
+- Serve as a reusable data layer for astrological services and coding agents
+- Provide a lightweight dashboard (Jinja2 + vanilla JS) for person management
+- Consider optional SVG chart generation for visual representation (to be implemented in a later phase)
+
+## Constraints & Context
+- **Audience**: Downstream astrological services (like astro_service for horoscopes) and coding agents that need calculated astrological data for interpretation.
+- **Manifest compliance**: Must adhere to `/home/lucky/.openclaw/workspace/MCP_SERVER_MANIFEST.md`:
+  - Use FastMCP behind FastAPI.
+  - Include `run.sh`, `killserver.sh`, `restart.sh`, `tests.sh`.
+  - Mount SSE at `/mcp/sse` with `TransportSecuritySettings(enable_dns_rebinding_protection=False)`.
+  - Provide minimal landing page (`GET /`) and liveness check (`GET /health`).
+  - Keep `/health` lightweight.
+  - Keep app‑specific code isolated from generic server plumbing.
+  - Prefer non‑destructive schema changes (if any persistence is needed).
+  - Store PID and logs under `./logs/`.
+- **Data source**: The server will call `ephemeris-mcp:get_sky_state` (via MCP client) to get planetary positions for any given datetime/location, then perform astrological calculations (zodiac signs, houses, aspects, etc.) based on that data.
+- **Language/runtime**: Python (use existing venv at `.venv`). Dependencies listed in `requirements.txt`.
+- **Extensibility**: Design should allow adding more chart types (progressions, solar returns, etc.) and house systems without breaking changes.
+- **Person database**: Simple SQLite table `persons` with columns: id, name, birth_datetime (UTC), latitude, longitude, elevation (optional), created_at.
+- **Output format**: Structured data (dictionaries/lists) that can be JSON serialized - no interpretive text.
+- **Interpretation boundary**: This server stops at calculation; interpretation happens in downstream services.
+- **Astrological calculation standards** (based on industry practice):
+  - Zodiac signs: 12 signs, 30° each
+  - House systems: Support multiple systems (Placidus default, Koch, Equal House, etc.)
+  - Aspects: Conjunction (0°), Sextile (60°), Square (90°), Trine (120°), Opposition (180°) with configurable orbs
+  - Planets: Sun through Pluto, plus lunar nodes, Chiron (all available from ephemeris-mcp output)
+  - Retrograde calculation: Based on apparent motion (speed_lon) from ephemeris-mcp data
+  - Angles: Ascendant, Midheaven, Descendant, IC calculated from latitude, longitude, and sidereal time (from ephemeris-mcp)
+- **Dashboard**: A simple Jinja2 + vanilla JS dashboard for person management (add, view, list persons) accessible at `/dashboard` or similar.
+- **SVG Charts**: Optional feature to generate SVG visualizations of charts (natal, transit, synastry) for downstream services that wish to display them. This would be an additional tool/resource and is not required for the core calculation layer.
+
+## Energy Preference
+Practical, focused exploration – we want concrete calculation tool definitions and a clear implementation path for pure data provision.
+
+## Ideas Collected
+
+**[Tool #1] get_planetary_positions** (foundational)
+_Concept:_ Wrapper around `ephemeris-mcp:get_sky_state` that returns the `planetary_positions.bodies` array with added zodiac sign and degree information (e.g., {"body": "sun", "sign": "Taurus", "degree": 12.5, ...}). Optionally filtered by a list of bodies. Includes retrograde flag based on speed_lon from ephemeris data.  
+_Novelty:_ Provides astronomical data enhanced with astrological basics (signs, degrees, retrograde) as the base for all chart calculations.  
+_Optional Parameters:_ `bodies` (list of strings) to filter which planets to return; defaults to all bodies.
+
+**[Tool #2] calculate_natal_chart**
+_Concept:_ Takes birth datetime, latitude, longitude, and optional house system (default Placidus) to calculate a complete natal chart structure including:
+  - planets: array of objects with body, sign, degree, house, retrograde flag
+  - houses: array of 12 house cusps (sign and degree)
+  - aspects: array of objects (planet1, planet2, aspect_type, orb, applying/separating)
+  - angles: ascendant, midheaven, descendant, ic (each with sign and degree)
+  - chart_metadata: datetime, latitude, longitude, house_system  
+_Novelty:_ Returns a complete, structured natal chart that downstream services can interpret for personality insights.  
+_Optional Parameters:_ `house_system` (string, default "Placidus"); `orb_limits` (dict of aspect->max orb, defaults to standard orbs: conjunction 8°, sextile 6°, square 8°, trine 8°, opposition 8°).
+
+**[Tool #3] calculate_transit_chart**
+_Concept:_ Takes natal chart data (or birth data) and transit datetime to calculate:
+  - transiting_planets: current planetary positions (same format as natal chart planets)
+  - natal_to_transit_aspects: aspects between transiting planets and natal planets/angles
+  - transit_to_natal_aspects: aspects between natal planets and transiting planets (same data, different perspective)
+  - notable_periods: when slow planets make exact aspects (within 0°01' orb) to natal points
+  - transiting_planets_in_houses: which natal house each transiting planet occupies  
+_Novelty:_ Provides structured transit analysis data for timing events and understanding current influences.  
+_Optional Parameters:_ `house_system` (default Placidus), `orb_limits` (same defaults as natal chart).
+
+**[Tool #4] calculate_synastry_chart**
+_Concept:_ Takes two sets of birth data (or two natal charts) to calculate relationship astrology structure including:
+  - chart1_natal: first person's natal chart structure
+  - chart2_natal: second person's natal chart structure
+  - interaspects: aspects between chart1 planets and chart2 planets
+  - house_overlays: for each person, where the other person's planets fall in their houses
+  - composite_chart: midpoint method chart structure
+  - davison_chart: davison relationship chart structure  
+_Novelty:_ Provides structured relationship astrology data for downstream interpretation of interpersonal dynamics.  
+_Optional Parameters:_ `house_system` (default Placidus for both charts), `orb_limits` (same defaults).
+
+**[Tool #5] get_transit_preview**
+_Concept:_ Given a person identifier (from the database) and a time range (start date, end date, or duration like "next 30 days"), returns a list of significant transit events within that period as structured data:
+  - events: array of objects, each containing:
+    - datetime: ISO timestamp of the event
+    - event_type: "exact_aspect", "ingress", "retrograde_station_start", "retrograde_station_end", "lunar_phase_change"
+    - description: machine-readable string (e.g., "transiting_jupiter_square_natal_mars")
+    - planets_involved: array of body names
+    - orb: exactness of the aspect (for aspect events)
+    - additional_data: any relevant specifics (e.g., new moon phase)
+  - time_range: requested start and end times  
+_Novelty:_ Enables astrological services to quickly answer questions like "What transits are coming up for Lukas in the next month?" with structured data they can interpret.  
+_Optional Parameters:_ `house_system` (default Placidus), `orb_limits` (default orbs), `event_types` (list of event types to include, defaults to all).
+
+**[Tool #6] person_manage**
+_Concept:_ CRUD-lite operations for the persons database:
+  - add_person (name, birth_datetime, latitude, longitude, elevation optional, nickname)
+  - get_person (by id or nickname)
+  - list_persons (optional filter)
+  - update_person / delete_person (if needed)  
+_Novelty:_ Avoids requiring the agent to repeat birth data on every request; enables quick retrieval for transit previews and chart calculations.  
+_Note:_ This tool set is complemented by a lightweight dashboard for manual person management.
+
+**[Resource #1] chart_cache**
+_Concept:_ A read-only MCP resource that provides access to recently calculated charts (with timestamps) to avoid recalculating the same chart multiple times in a session.  
+_Novelty:_ Improves performance for services that need to reference the same chart multiple times.
+
+**[Tool #7] set_default_location**
+_Concept:_ (If we decide to allow mutable state) a tool that updates the server’s default latitude/longitude for subsequent chart calculations, stored in a tiny SQLite table.  
+_Novelty:_ Avoids requiring the agent to repeat location coordinates on every request for charts from the same location.
+
+**[Idea #8] generate_svg_chart** (optional, future feature)
+_Concept:_ Given a chart structure (natal, transit, or synastry), generate an SVG visualization of the chart.
+_Novelty:_ Provides a visual representation that can be embedded in web interfaces or reports.
+_Note:_ This is an optional feature to be considered after the core calculation tools are stable. It would require an additional tool or resource and may depend on an SVG generation library.
+
+## Next Steps (to be fleshed out in a later convergent phase)
+1. Scaffold the project using the MCP Server Manifest (create dir, .gitignore, requirements.txt, README.md, PROJECT.md).
+2. Implement the MCP client call to `ephemeris-mcp:get_sky_state` (likely via MCP SSE client or direct HTTP if exposed).
+3. Create astrological calculation module (zodiac signs, houses, aspects) using the astronomical data from ephemeris-mcp.
+4. Create SQLite schema for persons table and chart cache.
+5. Define core tools: `get_planetary_positions`, `calculate_natal_chart`, `person_manage` (add/get/list).
+6. Implement `get_transit_preview` using the person database and astrological calculation module.
+7. Add `calculate_transit_chart` and `calculate_synastry_chart` as needed.
+8. Add the health endpoint and landing page per manifest.
+9. Add a lightweight dashboard (Jinja2 + vanilla JS) for person management.
+10. Write `run.sh`/`killserver.sh` scripts and verify logging/pid handling.
+11. Iteratively add more chart tools/resources based on priority.
+12. Ensure all code is isolated in `src/astro_mcp/` with server wiring in `src/astro_mcp/server.py`.
+13. Keep the MCP surface small and read‑only where possible (chart calculation tools are read-only; person DB is read/write but limited).
+14. Document usage in README.md with example calls from coding agents/astro_service (e.g., "get transit preview for Lukas next month").
+15. Add a test suite (`tests.sh`) that exercises each tool against mocked ephemeris-mcp data.
+16. Consider house system options (Placidus, Koch, Equal House, etc.) and allow configuration.
+17. (Optional, later phase) Consider implementing `generate_svg_chart` tool/resource for SVG chart visualization.
+
+---
+*End of initial idea capture. Ready to organize, prioritize, and plan actions.*

+ 137 - 0
ORGANIZED_PLAN.md

@@ -0,0 +1,137 @@
+# Astro-MCP: Organized Themes and Action Plan
+
+## Theme 1: Foundation & Infrastructure
+- **Core Requirements**: Follow MCP Server Manifest conventions (FastMCP + FastAPI, SSE transport, logging, health endpoint)
+- **Person Database**: SQLite database for storing birth data (name, birth_datetime, lat/lon, nickname)
+- **Project Structure**: Isolate app-specific code in `src/astro_mcp/` with server wiring in `src/astro_mcp/server.py`
+- **Housekeeping Scripts**: `run.sh`, `killserver.sh`, `restart.sh`, `tests.sh`
+- **Dashboard**: Lightweight Jinja2 + vanilla JS dashboard for person management
+- **SVG Charts (Future)**: Optional SVG chart generation for visual representation
+
+## Theme 2: Astronomical Data Integration
+- **Primary Data Source**: `ephemeris-mcp:get_sky_state` via MCP client
+- **Data Transformation**: Convert astronomical output to astrological basics (zodiac signs, degrees, retrograde)
+- **Calculations**: Zodiac signs (12 signs, 30° each), house systems, aspects, angles (ASC, MC, DSC, IC)
+- **Standards**: Use data directly from ephemeris-mcp (no external ephemeris libraries needed)
+
+## Theme 3: Core Chart Calculation Tools (with Optional Parameters)
+- **Natal Chart Tool**: Complete birth chart with planets in signs/houses, aspects, angles
+  - Optional params: house_system (default Placidus), orb_limits (standard orbs)
+- **Transit Chart Tool**: Current positions + aspects to natal chart
+  - Optional params: house_system (default Placidus), orb_limits (standard orbs)
+- **Synastry Chart Tool**: Relationship analysis (interaspects, house overlays, composite/davison charts)
+  - Optional params: house_system (default Placidus), orb_limits (standard orbs)
+- **Chart Caching**: Optional resource to avoid recalculating same charts
+
+## Theme 4: Transit & Timing Analysis
+- **Transit Preview**: Given person + time range, return significant events (exact aspects, ingresses, stations)
+- **Event Types**: Exact aspects (orb ≤ 0°01'), planet ingresses, retrograde stations, lunar phase changes
+- **Structured Output**: Machine-readable descriptions for downstream interpretation
+- **Optional Parameters**: house_system, orb_limits, event_types (filter which event types to include)
+
+## Theme 5: Person Management
+- **CRUD-lite Operations**: Add, get, list persons (with optional update/delete)
+- **Birth Data Storage**: UTC datetime, latitude, longitude, elevation, nickname
+- **Dashboard**: Lightweight web interface for manual person management
+- **Efficiency**: Avoid repeating birth data on every request
+
+## Theme 6: Configuration & Extensibility
+- **House Systems**: Support multiple systems (Placidus default, Koch, Equal House, etc.)
+- **Aspect Configuration**: Configurable orbs for different aspect types
+- **Chart Types**: Design for adding progressions, solar returns, etc.
+- **Location Defaults**: Optional tool to set default lat/lon for repeated calculations from same location
+
+## Theme 7: Manifest Compliance & Quality
+- **Health Endpoint**: Lightweight `/health` for liveness checks
+- **Landing Page**: Minimal `GET /` endpoint
+- **SSE Transport**: Mount FastMCP at `/mcp` with SSE at `/mcp/sse`
+- **Security**: Use `TransportSecuritySettings(enable_dns_rebinding_protection=False)`
+- **Logging/PID**: Store under `./logs/` directory
+- **Testing**: Comprehensive test suite via `tests.sh`
+
+# Action Plan
+
+## Phase 1: Project Setup & Foundation
+1. [ ] Initialize project structure per MCP Server Manifest
+2. [ ] Create `.gitignore`, `requirements.txt`, `README.md`, `PROJECT.md`
+3. [ ] Set up `src/astro_mcp/` directory with `server.py`
+4. [ ] Implement basic FastAPI app with health and landing endpoints
+5. [ ] Create dashboard template directory and basic Jinja2 template
+6. [ ] Create `run.sh`, `killserver.sh`, `restart.sh` scripts
+7. [ ] Initialize git repository and make initial commit
+
+## Phase 2: Data Layer & Person Management
+1. [ ] Design SQLite schema for persons table
+2. [ ] Implement person_manage tool (add_person, get_person, list_persons)
+3. [ ] Create database initialization/connection handling
+4. [ ] Test person CRUD operations
+5. [ ] Create dashboard routes and templates for person management
+6. [ ] Document API for person management
+
+## Phase 3: Astronomical Data Integration
+1. [ ] Implement MCP client to call `ephemeris-mcp:get_sky_state`
+2. [ ] Create `get_planetary_positions` tool wrapper
+3. [ ] Add zodiac sign calculation (0-360° → sign + degree)
+4. [ ] Add retrograde flag detection from speed_lon
+5. [ ] Test with sample ephemeris-mcp output
+6. [ ] Verify structured output format
+7. [ ] Add optional `bodies` parameter to filter planets
+
+## Phase 4: Core Chart Calculations
+1. [ ] Implement house system calculations (start with Placidus)
+2. [ ] Calculate planetary house placements
+3. [ ] Implement aspect detection (conjunction, sextile, square, trine, opposition)
+4. [ ] Calculate orbs and applying/separating
+5. [ ] Calculate angles (ASC, MC, DSC, IC) from lat/lon and sidereal time
+6. [ ] Assemble complete natal chart structure
+7. [ ] Add optional house_system parameter (default Placidus)
+8. [ ] Add optional orb_limits parameter (standard defaults)
+9. [ ] Test calculate_natal_chart tool with sample data
+
+## Phase 5: Transit & Relationship Charts
+1. [ ] Implement calculate_transit_chart tool
+2. [ ] Implement calculate_synastry_chart tool
+3. [ ] Add optional parameters (house_system, orb_limits) to both
+4. [ ] Verify chart caching mechanism (optional)
+5. [ ] Test all chart tools with various inputs and parameter combinations
+
+## Phase 6: Transit Preview & Events
+1. [ ] Implement transit preview algorithms (ingresses, retrograde stations, lunar phases)
+2. [ ] Implement exact aspect detection within time ranges
+3. [ ] Create get_transit_preview tool
+4. [ ] Add optional parameters: house_system, orb_limits, event_types
+5. [ ] Test with sample person data and date ranges
+
+## Phase 7: Integration & Compliance
+1. [ ] Mount all tools as MCP tools via FastMCP
+2. [ ] Ensure proper SSE transport at `/mcp/sse`
+3. [ ] Verify health endpoint is lightweight
+4. [ ] Test dashboard functionality and routes
+5. [ ] Test housekeeping scripts (run/kill/restart)
+6. [ ] Verify logging and PID file handling
+7. [ ] Run full test suite via `tests.sh`
+
+## Phase 8: Documentation & Examples
+1. [ ] Update README.md with usage examples
+2. [ ] Document API for downstream services (like astro_service)
+3. [ ] Provide example calls for transit previews ("What transits for Lukas next month?")
+4. [ ] Document optional parameters for all tools
+5. [ ] Document dashboard usage for person management
+6. [ ] Document configuration options (house systems, etc.)
+7. [ ] Finalize PROJECT.md with technical specifications
+
+## Phase 9: Optional Enhancements (Post-Core)
+1. [ ] Consider implementing `generate_svg_chart` tool/resource for SVG chart visualization
+2. [ ] Evaluate SVG generation libraries (svgwrite, etc.)
+3. [ ] Implement SVG chart generation for natal, transit, and synastry charts
+4. [ ] Add SVG chart as optional MCP resource or tool
+5. [ ] Test SVG output with various chart types
+
+# Immediate Next Steps
+
+1. Create project structure and initialize git repo
+2. Implement basic server with health endpoint and dashboard routes
+3. Add person management SQLite layer
+4. Integrate with ephemeris-mcp:get_sky_state
+5. Build get_planetary_positions tool with optional bodies parameter
+6. Develop natal chart calculation with optional parameters