nasa-images-mcp-server

nasa-images-mcp-server

Enables searching NASA's image library and navigating results with an interactive UI, supporting both stdio and HTTP transports.

Category
访问服务器

README

NASA Images MCP Server

A project to search NASA's image library using an MCP server and display images in an interactive UI.

🌟 Features:

  • Dual Transport Support: Supports both stdio and Streamable HTTP transport
  • Image Search: Search by keywords using NASA's Images API
  • Interactive UI: Beautiful image viewer using MCP Apps Pattern
  • Image Navigation: Display search results sequentially
  • Session Management: Stateful session management

screenshot

Requirements

  • Node.js 18 or higher
  • npm or yarn
  • NASA API Key (get free at nasa.gov/api)

Installation

  1. Clone the repository:
cd nasa-images-mcp-server
  1. Install dependencies:
npm install
  1. Set up environment variables:
cp .env.example .env

Edit the .env file to configure your NASA API key:

NASA_API_KEY=your_api_key_here
PORT=3000
  1. Build:
npm run build

Getting a NASA API Key

  1. Visit https://api.nasa.gov/
  2. Enter your name and email address in the form
  3. The API key will be sent to your email immediately
  4. Add it to your .env file

Rate Limits:

  • DEMO_KEY: 30 requests/hour, 50 requests/day
  • Registered key: 1000 requests/hour

Usage

stdio Mode (Recommended for MCP Clients like Claude Desktop)

In stdio mode, the server communicates via stdin/stdout — no HTTP server is started. Logs are written to stderr.

Run with npx (no installation required)

npx @kaitoy/nasa-images-mcp-server --stdio

Run from local build

Pass the --stdio flag to use stdio transport:

node build/index.js --stdio

Claude Desktop Configuration

Using npx (recommended):

{
  "mcpServers": {
    "nasa-images": {
      "command": "npx",
      "args": ["-y", "@kaitoy/nasa-images-mcp-server", "--stdio"],
      "env": {
        "NASA_API_KEY": "your_api_key_here"
      }
    }
  }
}

Using local build:

{
  "mcpServers": {
    "nasa-images": {
      "command": "node",
      "args": ["/path/to/nasa-images-mcp-server/build/index.js", "--stdio"],
      "env": {
        "NASA_API_KEY": "your_api_key_here"
      }
    }
  }
}

HTTP Server Mode

npm start

The server will start at http://localhost:3000.

Start on a Different Port

PORT=3001 npm start

About Transports

stdio Transport

Suitable for local MCP clients (e.g., Claude Desktop) that launch the server as a subprocess.

  • Communicates via stdin/stdout
  • Single session per process
  • No network configuration required

Streamable HTTP Transport

The latest MCP HTTP transport protocol, suitable for remote or multi-client scenarios.

Key Features:

  • ✅ Stateful Sessions: Issues a unique session ID for each client
  • ✅ SSE Support: Supports push notifications from the server via Server-Sent Events
  • ✅ JSON-RPC over HTTP: Communication via standard HTTP request/response
  • ✅ Session Management: Automatic session lifecycle management

Integration with MCP Clients

Connecting with MCP Inspector (HTTP mode)

You can test the server using MCP Inspector:

npx @modelcontextprotocol/inspector http://localhost:3000/mcp

Connecting with MCP Inspector (stdio mode)

npx @modelcontextprotocol/inspector node /path/to/nasa-images-mcp-server/build/index.js --stdio

Using with Custom MCP Clients

Steps to connect from a custom client:

  1. Initialize Request (POST /mcp):
curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "initialize",
    "params": {
      "protocolVersion": "2024-11-05",
      "capabilities": {},
      "clientInfo": {
        "name": "my-client",
        "version": "1.0.0"
      }
    }
  }'

The response headers will include mcp-session-id.

  1. Subsequent Requests:
curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "mcp-session-id: <your-session-id>" \
  -d '{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "tools/list"
  }'
  1. SSE Stream (GET /mcp):
curl -X GET "http://localhost:3000/mcp" \
  -H "mcp-session-id: <your-session-id>" \
  -H "Accept: text/event-stream"

Endpoints

Endpoint Method Description
/ GET Server information and endpoint list
/health GET Health check (includes active session count)
/mcp POST JSON-RPC requests (initialization, tool calls, etc.)
/mcp GET SSE stream (for server notifications)
/mcp DELETE Close session

Available Tools

1. search_nasa_images

Search NASA's image library.

Parameters:

  • query (string, required): Search query (e.g., "apollo 11", "mars rover")

Usage Example (JSON-RPC):

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "search_nasa_images",
    "arguments": {
      "query": "apollo 11 moon landing"
    }
  }
}

2. get_next_image

Display the next image from the current search results.

Parameters: None

Usage Example (JSON-RPC):

{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "tools/call",
  "params": {
    "name": "get_next_image",
    "arguments": {}
  }
}

Available Resources

nasa-image://current

Get the URL of the currently displayed image.

MIME Type: text/uri-list

ui://nasa-images/viewer

HTML UI resource for the image viewer.

MIME Type: text/html;profile=mcp-app

Architecture

stdio Mode

┌─────────────────────────────────────────────┐
│     MCP Client (Claude Desktop, etc.)       │
│                   ↕ stdin/stdout            │
└───────────────────┼─────────────────────────┘
                    │
┌───────────────────┼─────────────────────────┐
│  NASA Images MCP Server                     │
│  ┌────────────────┴──────────────────────┐  │
│  │  StdioServerTransport                 │  │
│  └───────────────────────────────────────┘  │
│  ┌───────────────────────────────────────┐  │
│  │  McpServer (MCP Apps Pattern)         │  │
│  │  - registerAppTool(search_nasa...)    │  │
│  │  - registerAppTool(get_next_image)    │  │
│  │  - registerAppResource(viewer UI)     │  │
│  │  - registerResource(image URL)        │  │
│  └───────────────────────────────────────┘  │
│  ┌───────────────────────────────────────┐  │
│  │  Session Manager                      │  │
│  │  - Manage search state per user       │  │
│  └───────────────────────────────────────┘  │
│  ┌───────────────────────────────────────┐  │
│  │  NASA API Client                      │  │
│  │  - Image search                       │  │
│  │  - Image URL retrieval                │  │
│  └───────────────────────────────────────┘  │
└───────────────────┼─────────────────────────┘
                    │ HTTPS
┌───────────────────┼─────────────────────────┐
│         NASA Images API                     │
│  https://images-api.nasa.gov/search         │
└─────────────────────────────────────────────┘

HTTP Mode

┌─────────────────────────────────────────────┐
│     MCP Client (Inspector, Custom App)      │
│                                             │
│  ┌────────────────────────────────────────┐ │
│  │  HTTP Client                           │ │
│  │  - POST /mcp (JSON-RPC requests)       │ │
│  │  - GET /mcp (SSE stream)               │ │
│  └────────────────────────────────────────┘ │
│                   ↕                         │
└───────────────────┼─────────────────────────┘
                    │ HTTP/SSE
┌───────────────────┼─────────────────────────┐
│  NASA Images MCP Server (Express)           │
│  ┌────────────────┴──────────────────────┐  │
│  │  StreamableHTTPServerTransport        │  │
│  │  - Session management                 │  │
│  │  - JSON-RPC over HTTP                 │  │
│  │  - SSE for notifications              │  │
│  └───────────────────────────────────────┘  │
│  ┌───────────────────────────────────────┐  │
│  │  McpServer (MCP Apps Pattern)         │  │
│  │  - registerAppTool(search_nasa...)    │  │
│  │  - registerAppTool(get_next_image)    │  │
│  │  - registerAppResource(viewer UI)     │  │
│  │  - registerResource(image URL)        │  │
│  └───────────────────────────────────────┘  │
│  ┌───────────────────────────────────────┐  │
│  │  Session Manager                      │  │
│  │  - Manage search state per user       │  │
│  └───────────────────────────────────────┘  │
│  ┌───────────────────────────────────────┐  │
│  │  NASA API Client                      │  │
│  │  - Image search                       │  │
│  │  - Image URL retrieval                │  │
│  └───────────────────────────────────────┘  │
└───────────────────┼─────────────────────────┘
                    │ HTTPS
┌───────────────────┼─────────────────────────┐
│         NASA Images API                     │
│  https://images-api.nasa.gov/search         │
└─────────────────────────────────────────────┘

Main Components

  • src/index.ts: Express server and transport management
  • src/mcp-server.ts: MCP server logic (tool and resource registration)
  • src/session-manager.ts: Session management (search state persistence)
  • src/nasa-api.ts: NASA API client
  • src/types.ts: TypeScript type definitions

Development

Watch Mode

npm run watch

Automatically rebuilds when files change.

Development Mode

npm run dev

Builds and immediately starts the server.

Troubleshooting

Port Already in Use

Error: listen EADDRINUSE: address already in use

Solution: Specify a different port:

PORT=3001 npm start

"Cannot find module" Error

Run:

npm run build

to compile TypeScript.

API Rate Limit Error

  • If using DEMO_KEY, obtain your own API key from api.nasa.gov
  • Limited to 30 requests per hour

"Not Acceptable" Error

The client must accept both MIME types:

  • application/json
  • text/event-stream
curl -H "Accept: application/json, text/event-stream" ...

Session Not Found

Save the mcp-session-id header returned after the initialization request and send it as the mcp-session-id header in subsequent requests.

Security Notes

  • This server has CORS enabled (for development)
  • In production, implement proper CORS settings and rate limiting
  • Manage NASA API keys via environment variables; do not hardcode them

License

MIT

References

Contributing

Pull requests are welcome! Bug reports and feature requests are accepted via Issues.

Support

If you encounter issues, please create an Issue or refer to the NASA API support page.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选