astro-sdk-services
One small FastAPI HTTP service per astronomy SDK (prototype). Each service exposes a curated whitelist of tools
(552 in total across five SDKs; euclid is separate), with JSON-serialisable inputs/outputs.
| SDK |
port |
tools |
| astropy |
9101 |
281 |
| astroquery |
9102 |
116 (network: SIMBAD/VizieR/Gaia/NED/SDSS/IRSA/HEASARC/MPC/Horizons/MAST/ESASky/…) |
| photutils |
9103 |
61 |
| astroplan |
9104 |
47 |
| sunpy |
9105 |
47 |
| euclid |
(all-in-one /euclid) |
14 (HTTPS FITS URL or local MER cutout + PNG preview; EUCLID_CACHE_DIR / EUCLID_OUTPUT_DIR; optional output_path into EUCLID_WRITE_ROOTS, e.g. a 021 project ResearchSpace) |
Services bind to 127.0.0.1 only. Behind an Ingress (https://astro.example.com/<sdk>/...) the services accept the
path both with and without the /<sdk> prefix.
Run
python -m venv venv && . venv/bin/activate && pip install -r requirements.txt
python tests/make_fixtures.py # test fixture files
PY=$(which python) ./run_all.sh # starts 9101..9105 ; ./run_all.sh stop to stop
API
GET /health, GET /tools
POST /invoke body {"function_name": "...", "arguments": {...}} -> {"ok":bool,"result":...,"error":...}
curl -s localhost:9101/invoke -H 'content-type: application/json' -d '{"function_name":"astropy_sky_coord_transform_to","arguments":{"_self":{"ra":10.684,"dec":41.269},"frame":"galactic"}}'
curl -s localhost:9101/invoke -H 'content-type: application/json' -d '{"function_name":"astropy_flat_lambda_cdm_luminosity_distance","arguments":{"_self":{"__call__":"astropy.cosmology.FlatLambdaCDM","kwargs":{"H0":70,"Om0":0.3}},"_args":[0.5]}}'
curl -s localhost:9102/invoke -H 'content-type: application/json' -d '{"function_name":"astroquery_simbad_query_object","arguments":{"object_name":"M31"}}'
Codec
{"value":1.5,"unit":"km"} Quantity; {"ra":..,"dec":..,"unit":"deg","frame":"icrs"} SkyCoord;
{"__type__":"Time","value":..}, ndarray, Table (rows), tuple, slice, Unit.
{"__call__":"pkg.path","args":[],"kwargs":{}} builds an object by calling a callable under an allow-listed
package prefix (astropy/numpy/scipy.ndimage + the service’s own SDK); private names are refused.
- Instance methods take the instance in
_self; positional-only parameters go in _args.
- Results: arrays -> lists, Table -> rows, Quantity/Time/SkyCoord -> dicts; other objects ->
{"__type__":"object","handle":"hN","repr":..}
(the handle can be passed back as {"__handle__":"hN"}).
Limits
30 s timeout per call (SIGALRM, main thread), 4 GB address-space limit per process. __call__ may read local files
via numpy.load / astropy.io.fits: do not expose publicly without sandboxing / auth.
Verification
cases/<sdk>.json hold one reproducible input per tool; python tests/run_cases.py <sdk> calls the running service
and writes results/<sdk>.json. tests/build_xlsx.py renders the tool table. Statuses are recorded as observed.
Astroquery network tools: upstream timeouts (e.g. SIMBAD/Sesame historically) are acceptable; NED/SDSS/IRSA/… are included and marked 未验证 when the upstream is unreachable.
Helm
helm/astro-sdk-services: by default (allInOne: true) one Deployment + Service astro-all (SDK=all) and an Ingress
routing /astropy, /astroquery, /photutils, /astroplan, /sunpy, /euclid to it (host astro.example.com, placeholder),
with an emptyDir (or PVC) at /data/euclid for the Euclid cache/outputs. Raw manifest: deploy/astro-all.yaml.
allInOne: false deploys one Deployment + Service per SDK instead. See docs/DEPLOY.md.
All-in-one (default)
The image defaults to SDK=all: one process serves all 6 services under /<sdk>/{health,tools,invoke,mcp}, plus / and
/health listing them. docker run -p 8000:8000 ghcr.io/aaronyang0628/astro-sdk-services:latest.
Deployment handoff (Chinese, incl. 021 connector table): docs/DEPLOY.md.
SDK=<name> still runs a single SDK.
Authentication
Auth is off by default. Set a non-empty env API_TOKEN (Helm: --set auth.secretName=<secret with key "token">) to require Authorization: Bearer <token> on every endpoint except /health.
Regression against a deployed instance: BASE_URL=https://astro.example.com API_TOKEN=... python tests/run_cases.py <sdk>.
MCP (Streamable HTTP)
Every SDK service also speaks MCP at /mcp (via Ingress: /<sdk>/mcp, e.g. https://astro.example.com/astropy/mcp).
Its whitelisted tools are registered as MCP tools with the same names; description is the tool description and inputSchema
is generated from the parameter list (str/int/float/bool/dict/list map to JSON Schema types, astro objects such as
SkyCoord/Time/Quantity accept the codec forms above, required params go into required, methods require _self).
Calls share the /invoke engine: same whitelist, timeout and encoding; the tool result is a JSON text
{"ok", "result", "error", "elapsed_s"} (isError=true on failure). The endpoint is stateless and returns JSON responses.
If API_TOKEN is set, the same Authorization: Bearer <token> is required (401 otherwise); without it, omit headers.
Cursor (~/.cursor/mcp.json) / Claude Code / other clients that support remote HTTP servers:
{
"mcpServers": {
"astropy": {"url": "https://astro.example.com/astropy/mcp", "headers": {"Authorization": "Bearer <YOUR_TOKEN>"}},
"astroquery": {"url": "https://astro.example.com/astroquery/mcp", "headers": {"Authorization": "Bearer <YOUR_TOKEN>"}},
"photutils": {"url": "https://astro.example.com/photutils/mcp", "headers": {"Authorization": "Bearer <YOUR_TOKEN>"}},
"astroplan": {"url": "https://astro.example.com/astroplan/mcp", "headers": {"Authorization": "Bearer <YOUR_TOKEN>"}},
"sunpy": {"url": "https://astro.example.com/sunpy/mcp", "headers": {"Authorization": "Bearer <YOUR_TOKEN>"}}
}
}
Claude Code CLI: claude mcp add --transport http astropy https://astro.example.com/astropy/mcp --header "Authorization: Bearer <YOUR_TOKEN>".
Clients that only speak stdio (e.g. Claude Desktop) can bridge with npx mcp-remote https://astro.example.com/astropy/mcp --header "Authorization: Bearer <YOUR_TOKEN>".
Smoke test: BASE=https://astro.example.com API_TOKEN=... [VERIFY_TLS=0] python tests/mcp_check.py (initialize, list_tools ≈ per-SDK counts above (total 257), two tool calls per SDK).
评论