Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

AWS Logo
Menu
Yet another MCP client for Bedrock

Yet another MCP client for Bedrock

Lo-fi Model Context Protocol client for Bedrock in Typescript

Dave Roberts
Amazon Employee
Published Apr 2, 2025
Last Modified Apr 3, 2025
Kia ora builders, are you using the Bedrock Converse API and need to use other resources or tools? The Model Context Protocol (MCP) is an open protocol you can use but you need to build a client to proxy requests between Bedrock and your MCP server.
This post shows how to build a MCP Client using the MCP Typescript SDK. Giuseppe Battista did a great job explaining the concept in Python, so I won't rehash the theory and just get down into the code.

Setup the project

Create and initiate the project:
Add the following to package.json
Create a tsconfig.json

MCP Converse Client code

Add the following to src/index.ts
You can build and run the code with the following:
Right now, it is a basic interface to talk to a Bedrock model. If you have an MCP server, then add it with await client.connectToMcpServer('/path/to/mcp/index.js') where indicated in the code.

Inspecting the code

Constructor

This creates a Bedrock Runtime Client to use Bedrock models and a MCP Client to interact with MCP servers.

MCP server connection

This will take a MCP server script path and connect to it using the MCP client over Stdio.
It then adds the MCP server to a list of tools which are available to Bedrock and supplied when we converse with it.

Converse

This is where the magic happens. When you use Converse, you supply a conversation of all the messages between the user and assistant.
So, we take a conversation of Bedrock Messages and send a ConverseCommand along with the tools (MCP servers) we have available to use (if any).
If Bedrock wants to use one of these tools, then the response will have a stopReason of tool_use. This is documented here. We then have to call the correct tool using client.mcp.callTool and return the response to Bedrock along with the toolUseId which was given by Bedrock in the tool_use request.

Lo-fi chat interface

We need an interface, so I've used Inquirer.js for this in a basic way. The code below takes input and maintains a conversation loop until the user exits (blank message). Nothing radical here.

Summary

It's still early days with MCP, but we can already see potential in such tools to make our AI agents more useful.
In this post, I showed how to implement a MCP Client in Typescript to proxy requests to MCP servers so that Bedrock Converse can be used with external tools.
Hopefully it's useful for someone, keep on rocking innovation and be the best builder you can be!
Cheers, Dave
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

1 Comment