AWSWSA-MCP
by mirecekd
README.md
<img src="https://capsule-render.vercel.app/api?type=waving&height=200&color=0:202323,55:303635,100:e7ac80&text=AWSWSA-MCP&fontColor=f1d6b4&fontSize=58&fontAlignY=38&desc=AWS%20Web%20Search%20API%20MCP%20%E2%80%94%20a%20complement%20to%20Tavily&descSize=20&descColor=f1d6b4&descAlignY=60" width="100%" alt="" />
<div align="center">
[](https://www.python.org/)
[](https://modelcontextprotocol.io/)
[](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/web-search-api.html)
[](https://github.com/mirecekd/awswsa-mcp/pkgs/container/awswsa-mcp)
[](LICENSE)
[](https://github.com/mirecekd/awswsa-mcp/actions)
[](https://github.com/mirecekd/awswsa-mcp/releases)
[](https://buymeacoffee.com/mirecekd) [](https://www.paypal.me/mirecekd)
</div>
## ๐ What is AWSWSA-MCP?
A small MCP server with one tool, `aws_web_search`, that wraps the Amazon Bedrock AgentCore **Web Search API** (`InvokeWebSearch`). Your agent gets ranked web results with a text extract, the source URL and the publication date, and the query is served from an Amazon-operated web index inside AWS.
It is meant as a **complement to a basic web search such as Tavily**, not a replacement. It only searches. It does not fetch whole pages, map or crawl a site, or run multi-step research. Keep Tavily (or any fetch tool) for that and add this server as a second, independent source.
## ๐ง How it works?
### 1. Listen
- An MCP client (Claude, pi, MCPHub, LiteLLM, any streamable-HTTP client) connects to `/mcp`. Optional bearer authentication protects the endpoint; `/health` is always open.
### 2. Think
- The tool validates the request (query 1-200 characters, 1-25 results, optional domain include/exclude lists, optional date range, optional country) before anything is sent to AWS.
### 3. Search
- `InvokeWebSearch` is called with the default boto3 credential chain, so the server needs **no API key of its own**: an EC2 instance profile is enough.
### 4. Show
- The result is a numbered markdown list with title, URL, publication date and a text extract, ending with a reminder to cite the sources (required by the AWS acceptable-use terms).
## โจ Features
- One tool, `aws_web_search`: query, `max_results`, `include_domains`, `exclude_domains`, `published_after`, `published_before`, `country`
- No third-party search key: IAM only, queries stay inside AWS
- Works with an **EC2 instance profile**, environment keys, session tokens, `*_FILE` secrets or a shared profile
- Optional bearer token, constant-time comparison, `/health` for container checks
- Small multi-arch Docker image, runs as a non-root user
- Fast: about 0.5 s per search in our tests, results carry a publication date
## ๐ ๏ธ Technology Stack
| Layer | Technology |
| --- | --- |
| Language | Python 3.13 |
| MCP | official `mcp` SDK, FastMCP, streamable HTTP |
| AWS | `boto3` (Amazon Bedrock AgentCore data plane) |
| Server | `uvicorn` / Starlette |
| Container | Docker, `linux/amd64` and `linux/arm64` |
## ๐๏ธ Architecture
```mermaid
flowchart LR
A[Agent / MCP client] -->|POST /mcp, Bearer| B[awswsa-mcp]
B -->|InvokeWebSearch, SigV4| C[AgentCore Web Search]
C --> D[(Amazon web index)]
E[Instance profile / keys] -.credentials.-> B
```
```text
client --MCP--> awswsa-mcp --boto3--> bedrock-agentcore: InvokeWebSearch
```
## ๐ฆ Get the image
```bash
docker pull ghcr.io/mirecekd/awswsa-mcp:latest
```
Or build it yourself:
```bash
docker build -t awswsa-mcp .
```
## โ๏ธ Setup
### 1. Allow the call in IAM
The caller needs one action on one resource, nothing else:
```json
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "bedrock-agentcore:InvokeWebSearch",
"Resource": "arn:aws:bedrock-agentcore:*:aws:tool/web-search.v1"
}]
}
```
Attach it to the EC2 instance role, or to the IAM user whose keys you pass in.
### 2. Run it
On EC2 with the policy above, **no keys are needed**:
```bash
docker run -d --name awswsa-mcp -p 127.0.0.1:8080:8080 \
-e AWS_REGION=eu-west-1 \
-e AWSWSA_BEARER_TOKEN="$(openssl rand -hex 24)" \
ghcr.io/mirecekd/awswsa-mcp:latest
```
With keys instead (any of these, in this order of precedence):
```bash
# environment, including temporary session credentials
docker run ... -e AWS_ACCESS_KEY_ID=... -e AWS_SECRET_ACCESS_KEY=... -e AWS_SESSION_TOKEN=... ...
# files (Docker or Compose secrets), nothing visible in `docker inspect`
docker run ... -v ./secrets:/run/secrets:ro \
-e AWS_ACCESS_KEY_ID_FILE=/run/secrets/access_key \
-e AWS_SECRET_ACCESS_KEY_FILE=/run/secrets/secret_key ...
# a shared profile
docker run ... -v ./aws-config:/app/aws:ro -e AWS_CONFIG_FILE=/app/aws/config -e AWS_SHARED_CREDENTIALS_FILE=/app/aws/credentials -e AWS_PROFILE=my-profile ...
```
When none of them is set, boto3 falls back to the EC2 instance profile. On a plain Docker host the instance metadata endpoint must be reachable from the container (IMDSv2 hop limit of 2).
### 3. Connect a client
The MCP endpoint is `http://<host>:8080/mcp` with the header `Authorization: Bearer <token>`. In MCPHub add a `streamable-http` server with that URL and header.
## ๐ง Configuration
| Variable | Default | Meaning |
| --- | --- | --- |
| `AWSWSA_HOST` | `0.0.0.0` | Listen address |
| `AWSWSA_PORT` | `8080` | Listen port |
| `AWSWSA_BEARER_TOKEN` | empty | When set, `/mcp` requires `Authorization: Bearer <token>`. When empty there is no authentication and a warning is logged |
| `AWSWSA_ALLOWED_HOSTS` | empty | Comma list of accepted `Host` headers; empty disables the DNS-rebinding check (use behind a reverse proxy) |
| `AWS_REGION` / `AWS_DEFAULT_REGION` | `eu-west-1` | Region of the Web Search API |
| `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN` | unset | Static or temporary credentials |
| `AWS_ACCESS_KEY_ID_FILE`, `AWS_SECRET_ACCESS_KEY_FILE`, `AWS_SESSION_TOKEN_FILE` | unset | Read the value from a file when the plain variable is not set |
| `AWS_PROFILE` | unset | Shared credentials profile |
## ๐งช When to use it, and when not
We ran the same nine queries (English, Czech, news; five results each) through this server and through Tavily Search (default settings, no topic or date options) on 2026-12-01. It is a small, informal comparison, not a benchmark.
| | AWS Web Search | Tavily |
| --- | --- | --- |
| Latency | about 0.5 s | about 1.6 s |
| Publication date in the result | 41 of 45 | 0 of 45 in the default (general) mode |
| English queries | good | good |
| News | good, recent sources | usable, age unknown |
| Czech queries | weak | good |
| Tools | search only | search, extract, map, crawl, research |
- **Use it** for English queries and news, when you want the publication date, when queries must not leave AWS, or as a second source (the two returned almost completely different domains: 4 shared of about 44).
- **Do not use it** for Czech or other small-language queries. It returned German, French and Dutch pages for Czech questions, with or without diacritics and with `country` set. Tavily returned Czech sources.
- **Do not expect** page extraction, site mapping or crawling. Pair it with a fetch tool.
## ๐ Security
- No default credentials in the image. The server uses what you give it, or the instance profile.
- Least privilege: one IAM action on one resource (see Setup).
- Secrets are never logged. The `*_FILE` variables keep keys out of `docker inspect`.
- Set `AWSWSA_BEARER_TOKEN` and do not publish the port. Without a token anyone who can reach the port can spend your search quota.
- The container runs as a non-root user.
## ๐ฐ Cost and limits
- The first 5,000 queries per month are free, then about 7 USD per 1,000 queries. Check the [AgentCore pricing](https://aws.amazon.com/bedrock/agentcore/pricing/) for current numbers.
- Default quota: 10 requests per second per Region.
- Available Regions: us-east-1, us-east-2, us-west-2, eu-west-1, ap-southeast-2, ap-northeast-1.
- Acceptable use: keep and show the source citation for every result you surface, and do not bulk-extract content or build a competing index.
## ๐งญ Versioning and releases
Versions are `YYYYMMDD.X`, the build day and the counter of that day. A push to `main` runs the tests, computes the next version with `scripts/release.py`, tags it, creates a GitHub release and publishes `ghcr.io/mirecekd/awswsa-mcp:<version>` and `:latest` for `linux/amd64` and `linux/arm64`. See `CHANGELOG.md`.
## ๐งช Development
```bash
python3 -m venv .venv && . .venv/bin/activate
pip install -r requirements.txt -r requirements-dev.txt
ruff check .
pytest -q tests scripts
python3 scripts/privacy_scan.py --tree
bash scripts/install-hooks.sh # refuses private files and key-like strings on commit
```
The tests need no network and no AWS account.
## โ Support
<div align="center">
[](https://www.buymeacoffee.com/mirecekd) [](https://www.paypal.com/donate/?business=LJ5ZF7Q9KMTRW&no_recurring=0¤cy_code=USD)
</div>
## ๐ License
MIT License - see the `LICENSE` file for details.
## ๐ค Author
Miroslav Dvorak - mirecekd@gmail.com
<img src="https://capsule-render.vercel.app/api?type=waving&height=110§ion=footer&color=0:e7ac80,55:303635,100:202323" width="100%" alt="" />
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues