Skip to content

Commit dadb750

Browse files
feat(new MCP client Sample): Sample Implementation for MCP Integration with Nova Canvas (#189)
* Sample Implementation for MCP Integration with Nova Canvas * Fixing Pre-commit findings * Bug fix for forcing user to enter mandatory negative prompt to align with MCP Spec. * chore(build): fix pre commit --------- Co-authored-by: Alain Krok <[email protected]>
1 parent 90e64c8 commit dadb750

File tree

8 files changed

+2246
-0
lines changed

8 files changed

+2246
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,4 @@ dist
555555

556556

557557
# End of https://www.toptal.com/developers/gitignore/api/jetbrains+all,pycharm+all,node
558+
samples/mcp-integration-with-nova-canvas/output/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
AWS_PROFILE=<your-aws-profile>
2+
AWS_REGION=<your-aws-region>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# MCP Integration with Amazon Nova Canvas
2+
3+
This repository outlines a basic implementation of the [Model Context Protocol](https://modelcontextprotocol.io/) integration with Amazon Nova Canvas for image generation
4+
5+
## Overview
6+
7+
There are two parts to this implementation:
8+
9+
1. The `user_interfaces/image_generator_st.py` file, which handles the Streamlit/User Interface for the image generator
10+
2. The `client_server.py` file, which handles the MCP client and server implementation
11+
12+
The exact MCP server code leveraged can be found in the [src/nova-canvas-mcp-server](../../src/nova-canvas-mcp-server/) folder.
13+
14+
### Architecture
15+
16+
The implementation follows this flow:
17+
1. A Streamlit UI provides the user interface for image generation
18+
2. The UI communicates with a FastAPI server
19+
3. The FastAPI server uses the MCP client to communicate with the Nova Canvas MCP server
20+
4. The Nova Canvas MCP server interacts with Amazon Bedrock to generate images
21+
5. The generated images are returned to the UI for display
22+
23+
## Setup
24+
25+
### Prerequisites
26+
27+
- The [uv](https://docs.astral.sh/uv/getting-started/installation/) package manager
28+
- AWS Account with Bedrock access and proper IAM permissions - [Getting Started with Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started.html)
29+
- Access to the Amazon Nova Canvas and Amazon Nova Micro model (optional for prompt improvement) in Bedrock
30+
31+
### Installation
32+
33+
1. Clone the repository.
34+
35+
```bash
36+
git clone https://github.com/awslabs/mcp.git
37+
```
38+
39+
2. Navigate to the sample directory and copy the .env.example file to .env and add your AWS credentials.
40+
41+
```bash
42+
cd mcp/samples/mcp-integration-with-nova-canvas
43+
cp .env.example .env
44+
```
45+
46+
3. Open two different terminals and install the dependencies in each.
47+
48+
```bash
49+
uv sync
50+
```
51+
52+
then activate the virtual environment
53+
54+
```bash
55+
source .venv/bin/activate
56+
```
57+
4. In one of the terminals, run the FastAPI server
58+
59+
```bash
60+
uvicorn clients.client_server:app --reload
61+
```
62+
63+
5. In the other terminal, run the Streamlit app
64+
65+
```bash
66+
streamlit run user_interfaces/image_generator_st.py
67+
```
68+
69+
6. The image generator should now be running on [http://localhost:8501/](http://localhost:8501/)
70+
71+
## Usage
72+
73+
1. Enter a text prompt describing the image you want to generate
74+
2. Optionally, add a negative prompt to specify what you don't want in the image
75+
3. Customize image parameters (dimensions, quality, etc.)
76+
4. For color-guided generation, select colors from the color picker
77+
5. Click "Generate Image" to create your image
78+
6. View the generated image and save it if desired
79+
80+
## Troubleshooting
81+
82+
Logs are available in the terminal where you ran the FastAPI server, outlining various steps and actions taken by the server.
83+
84+
If you see an error about `boto3` or `streamlit` not being found, it is likely because you did not activate the virtual environment:
85+
86+
```bash
87+
uv sync
88+
source .venv/bin/activate

0 commit comments

Comments
 (0)