Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/aws-documentation-mcp-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ FROM public.ecr.aws/amazonlinux/amazonlinux@sha256:50a58a006d3381e38160fc5bb4bbe

# Place executables in the environment at the front of the path and include other binaries
ENV PATH="/app/.venv/bin:$PATH:/usr/sbin" \
PYTHONUNBUFFERED=1
PYTHONUNBUFFERED=1 \
FASTMCP_HOST=0.0.0.0

# Install other tools as needed for the MCP server
# Add non-root user and ability to change directory into /root
Expand Down
53 changes: 53 additions & 0 deletions src/aws-documentation-mcp-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,64 @@ or docker after a successful `docker build -t mcp/aws-documentation .`:
}
```

### HTTP Transport Mode (for ECS/Container Deployments)

The server supports `streamable-http` transport mode for containerized deployments on platforms like Amazon ECS, Kubernetes, or behind load balancers.

**Environment Variables for HTTP Mode:**

| Variable | Description | Default |
|----------|-------------|---------|
| `FASTMCP_TRANSPORT` | Transport mode (`stdio` or `streamable-http`) | `stdio` |
| `FASTMCP_HOST` | Host to bind HTTP server | `127.0.0.1` |
| `FASTMCP_PORT` | Port for HTTP server | `8000` |

**Docker Example with HTTP Mode:**

```bash
docker run -d \
-p 8000:8000 \
-e FASTMCP_TRANSPORT=streamable-http \
-e FASTMCP_HOST=0.0.0.0 \
-e FASTMCP_PORT=8000 \
-e AWS_DOCUMENTATION_PARTITION=aws \
mcp/aws-documentation:latest
```

**MCP Client Configuration for HTTP Mode:**

```json
{
"mcpServers": {
"aws-doc-remote": {
"url": "https://your-domain.com/mcp",
"headers": {
"Accept": "application/json, text/event-stream",
"Content-Type": "application/json"
},
"autoApprove": ["read_documentation", "get_available_services"]
}
}
}
```

**Testing HTTP Endpoint:**

```bash
curl -X POST http://localhost:8000/mcp \
-H "Accept: application/json, text/event-stream" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}},"id":1}'
```

## Environment Variables

| Variable | Description | Default |
|----------|-------------|----------|
| `FASTMCP_LOG_LEVEL` | Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) | `WARNING` |
| `FASTMCP_TRANSPORT` | Transport mode (`stdio` or `streamable-http`) | `stdio` |
| `FASTMCP_HOST` | Host to bind HTTP server (HTTP mode only) | `127.0.0.1` |
| `FASTMCP_PORT` | Port for HTTP server (HTTP mode only) | `8000` |
| `AWS_DOCUMENTATION_PARTITION` | AWS partition (`aws` or `aws-cn`) | `aws` |
| `MCP_USER_AGENT` | Custom User-Agent string for HTTP requests | Chrome-based default |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import httpx
import json
import os
import re
import uuid

Expand Down Expand Up @@ -55,9 +56,14 @@
}
]

# Read FastMCP settings from environment variables
FASTMCP_HOST = os.getenv('FASTMCP_HOST', '127.0.0.1')
FASTMCP_PORT = int(os.getenv('FASTMCP_PORT', '8000'))

mcp = FastMCP(
'awslabs.aws-documentation-mcp-server',
host=FASTMCP_HOST,
port=FASTMCP_PORT,
instructions="""
# AWS Documentation MCP Server

Expand Down Expand Up @@ -447,8 +453,12 @@ async def recommend(

def main():
"""Run the MCP server with CLI argument support."""
logger.info('Starting AWS Documentation MCP Server')
mcp.run()
import os

transport = os.getenv('FASTMCP_TRANSPORT', 'stdio')
logger.info(f'Starting AWS Documentation MCP Server with {transport} transport')

mcp.run(transport=transport)


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
from mcp.server.fastmcp import Context, FastMCP
from pydantic import AnyUrl, Field
from typing import Union
import os


SESSION_UUID = str(uuid.uuid4())

# Read FastMCP settings from environment variables
FASTMCP_HOST = os.getenv('FASTMCP_HOST', '127.0.0.1')
FASTMCP_PORT = int(os.getenv('FASTMCP_PORT', '8000'))

mcp = FastMCP(
'awslabs.aws-documentation-mcp-server',
host=FASTMCP_HOST,
port=FASTMCP_PORT,
instructions="""
# AWS China Documentation MCP Server

Expand Down Expand Up @@ -241,10 +248,12 @@ async def get_available_services(

def main():
"""Run the MCP server with CLI argument support."""
# Log startup information
logger.info('Starting AWS China Documentation MCP Server')

mcp.run()
import os

transport = os.getenv('FASTMCP_TRANSPORT', 'stdio')
logger.info(f'Starting AWS China Documentation MCP Server with {transport} transport')

mcp.run(transport=transport)


if __name__ == '__main__':
Expand Down
37 changes: 29 additions & 8 deletions src/aws-documentation-mcp-server/docker-healthcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,32 @@

SERVER="aws-documentation-mcp-server"

# Check if the server process is running
if pgrep -P 0 -a -l -x -f "/app/.venv/bin/python3? /app/.venv/bin/awslabs.$SERVER" > /dev/null; then
echo -n "$SERVER is running";
exit 0;
fi;

# Unhealthy
exit 1;
# Check if HTTP transport is enabled
if [ "$FASTMCP_TRANSPORT" = "streamable-http" ]; then
# Check HTTP endpoint - 406 is acceptable (means server is running but needs proper headers)
PORT="${FASTMCP_PORT:-8000}"
if python3 -c "
import urllib.request
try:
urllib.request.urlopen('http://localhost:$PORT/mcp', timeout=5)
exit(0)
except urllib.error.HTTPError as e:
# 406 Not Acceptable means server is running
exit(0 if e.code == 406 else 1)
except Exception:
exit(1)
" 2>/dev/null; then
echo "$SERVER HTTP is healthy"
exit 0
fi
echo "$SERVER HTTP is unhealthy"
exit 1
else
# Original stdio check
if pgrep -P 0 -a -l -x -f "/app/.venv/bin/python3? /app/.venv/bin/awslabs.$SERVER" > /dev/null; then
echo "$SERVER is running"
exit 0
fi
echo "$SERVER is not running"
exit 1
fi