
Running MCP-Based Agents (Clients & Servers) on AWS
Learn from Java code examples how to run Model Context Protocol (MCP) clients & servers on AWS, using Amazon Bedrock and Amazon ECS.
1
2
3
4
5
6
7
String scheduleDogAdoptionAppointment(
int id,
String name) {
... call private scheduling system and return available times
}
Building Agents with AWS - Complete Tutorial (Java, Spring AI, Amazon Bedrock, & MCP)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class SchedulingApplication {
public static void main(String[] args) {
SpringApplication.run(SchedulingApplication.class, args);
}
ToolCallbackProvider serviceToolCallbackProvider(
DogAdoptionAppointmentScheduler scheduler) {
return MethodToolCallbackProvider.builder()
.toolObjects(scheduler)
.build();
}
}
class DogAdoptionAppointmentScheduler {
String scheduleDogAdoptionAppointment(
int id,
String name) {
// demo scheduling response (but could use backing data / services on AWS)
var instant = Instant.now().plus(3, ChronoUnit.DAYS);
System.out.println("confirming the appointment: " + instant + " for dog " + id + " named " + name);
return instant.toString();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!-- the BOM for Spring AI -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>1.0.0-M6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- The Spring Webflux MCP Server -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-mcp-server-webflux-spring-boot-starter</artifactId>
</dependency>
</dependencies>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!-- the BOM for Spring AI -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>1.0.0-M6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- enable a REST server -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- MCP Client -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-mcp-client-spring-boot-starter</artifactId>
</dependency>
<!-- Amazon Bedrock Converse support in Spring AI -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bedrock-converse-spring-boot-starter</artifactId>
</dependency>
<!-- for an automatic health check URL -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
1
2
spring.ai.bedrock.converse.chat.options.model=amazon.nova-pro-v1:0
spring.ai.bedrock.converse.chat.enabled=true
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class ConversationalController {
private final ChatClient chatClient;
ConversationalController(
String schedulingUrl,
ChatClient.Builder builder) {
var mcpClient = McpClient
.sync(new HttpClientSseClientTransport(url))
.build();
mcpClient.initialize();
this.chatClient = builder
.defaultTools(new SyncMcpToolCallbackProvider(mcpClient))
.build();
}
String inquire( { String question)
return chatClient
.prompt()
.user(question)
.call()
.content();
}
}
1
2
3
curl -X POST --location "http://myecsserver/inquire" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'question=when can i schedule to adopt Prancer'
- Code samples: AWS-related MCP Samples including Java, Kotlin, Python, and TypeScript
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.