awslabs / awslabs/agentcore-samples

mcp-server-agentcore-runtime (Terraform): deployed runtime crashes with ModuleNotFoundError: No module named 'mcp.server.fastmcp'

Open Beginner friendly
#1,938 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
3.4k
Forks
1.3k
Avg merge
1d 22h
Merged PRs (30d)
30

Description

### Description

Deploying `04-infrastructure-as-code/terraform/mcp-server-agentcore-runtime` and testing it via `test_mcp_server.py` fails during MCP session initialization:

```
mcp.shared.exceptions.McpError: An error occurred when starting the runtime. Please check your CloudWatch logs for more information.
```

The runtime's CloudWatch log group (`/aws/bedrock-agentcore/runtimes/-DEFAULT`) shows the actual crash:

```
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/app/mcp_server.py", line 1, in
from mcp.server.fastmcp import FastMCP
ModuleNotFoundError: No module named 'mcp.server.fastmcp'
```

### Root cause

`mcp-server-code/requirements.txt` declares:

```
mcp>=1.10.0
```

with no upper bound. The official `mcp` PyPI package released `2.0.0`, which renamed `mcp.server.fastmcp` to `mcp.server.mcpserver`. CodeBuild resolves the unpinned constraint to `2.0.0` when building the container image, so the deployed server crashes on import at container startup — every fresh deploy of this sample is currently broken.

This is the same unpinned-dependency pattern already fixed for the gateway tutorials in #[link to 1926] ("fix(gateway): Pin fastmcp..."), but it also affects this Terraform sample's own `mcp-server-code/requirements.txt`, and additionally affects the local test client's dependency (`test_mcp_server.py` imports `streamablehttp_client`, which `mcp==2.0.0` renamed to `streamable_http_client`).

### Steps to reproduce

1. `terraform apply` (build/deploy succeeds — CodeBuild doesn't fail, since the crash is at container runtime, not build time)
2. `terraform output -raw get_token_command | bash` and export the JWT
3. Run `test_mcp_server.py $JWT_TOKEN `
4. Observe `McpError: An error occurred when starting the runtime`
5. Check the runtime's CloudWatch log group — see `ModuleNotFoundError: No module named 'mcp.server.fastmcp'`

### Expected behavior

A fresh deploy of this sample should produce a working MCP server that responds to `test_mcp_server.py`.

### Suggested fix

Pin `mcp` in `mcp-server-code/requirements.txt` to `>=1.10.0,<2.0.0`. I have a fix ready and will open a PR referencing this issue.

Contributor guide

Open the contributing guide

Research direction

Start with 04-infrastructure-as-code/terraform/mcp-server-agentcore-runtime/mcp-server-code/requirements.txt and test_mcp_server.py, checking how each imports the MCP package. Deploy with terraform apply, run the test client, and verify the runtime starts without the CloudWatch ModuleNotFoundError and responds successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, terraform
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.