Extend the Amazon Q Developer CLI with Model Context Protocol (MCP) for Richer Context

Earlier today, Amazon Q Developer unveiled its support for the Model Context Protocol (MCP) within the command line interface (CLI). This enhancement allows developers to seamlessly connect external data sources to the Q Developer CLI, resulting in more context-aware responses. By incorporating MCP tools and prompts, users gain access to a wide array of pre-built integrations or any MCP servers that support stdio. This added context empowers Q Developer to produce more accurate code, comprehend data structures, generate suitable unit tests, create detailed database documentation, and execute precise queries—all without the need for custom integration code. The introduction of MCP tools and prompts significantly accelerates development tasks, enhancing the overall developer experience.

Understanding Model Context Protocol

As a developer, I am always on the lookout for tools that can enhance my workflow and unlock new capabilities. The recent addition of MCP support in the Amazon Q Developer CLI has certainly piqued my interest. MCP serves as an open protocol that standardizes the integration of applications with large language models (LLMs), facilitating a common method for sharing context, accessing data sources, and enabling robust AI-driven functionalities. For a deeper dive into MCP, you can refer to this introduction.

Previously, Q Developer had the capability to utilize various tools. I had previously discussed the ability to run CLI commands and describe AWS resources. With the new MCP support, I can now add additional tools to the Q Developer CLI. For instance, while I could describe my AWS resources, I also need to detail database schemas, message formats, and more to build a comprehensive application. Let’s explore how to configure MCP to provide this essential context.

In this exploration, I will set up an MCP server to supply Q Developer with the database schema for a Learning Management System (LMS) I am developing. Although Q Developer excels at writing SQL, it lacks knowledge of my database schema, which is stored within the database and not in the project’s source code. Therefore, I will utilize an MCP server capable of querying the database schema, specifically employing the official PostgreSQL reference implementation to connect to my Amazon Relational Database Service (RDS). Let’s proceed with the configuration.

Before Model Context Protocol

Prior to the introduction of MCP support, the Q Developer CLI offered a suite of native tools, including the ability to execute bash commands, interact with files and the file system, and make calls to AWS services. However, its capabilities for querying databases were somewhat limited.

For example, before configuring the MCP server, I tasked Q Developer with “Writing a query that lists the students and the number of credits each student is taking.” The result was a generic SQL query, as Q Developer lacked specific knowledge of my LMS database schema.

This was a promising start, yet I knew that Q Developer could achieve so much more with an understanding of the database schema.

Configuring Model Context Protocol

The introduction of MCP support in the Q Developer CLI simplifies the configuration of MCP servers. I can define one or more MCP servers in a file named mcp.json. This configuration can be stored in my home directory (e.g., ~/.aws/amazonq/mcp.json) for application across all projects on my machine, or in the workspace root (e.g., .amazonq/mcp.json) for sharing among project members. Below is an example configuration for the PostgreSQL MCP server:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://USERNAME:PASSWORD@HOST:5432/DBNAME"
      ]
    }
  }
}

With the MCP server configured, I am eager to see how Amazon Q Developer enhances my experience.

After Model Context Protocol

Upon starting a new Q Developer session, the benefits of MCP support become immediately apparent. In addition to the existing tools, Q Developer now has access to PostgreSQL, enabling me to explore my database schema, understand table structures, and execute complex SQL queries—all without the need for additional integration code.

To test the MCP server, I prompted Q Developer to “List the database tables.” The response demonstrated that Q Developer now recognized my request concerning the PostgreSQL database, successfully listing my three tables: students, courses, and enrollment.

Returning to my earlier example, when I asked Q Developer to “Write a query that lists the students and the number of credits each student is taking,” the response was no longer generic. Instead, Q Developer accurately described the relevant tables in my database, generated the appropriate SQL query, and executed it, providing the desired results.

Beyond writing queries, Q Developer can leverage the MCP server to generate Java code that interacts with the database, create unit tests for the data layer, document the database, and much more. For instance, when I requested Q Developer to “Create an entity-relationship (ER) diagram using Mermaid syntax,” it produced a visual representation of the database schema, enhancing my understanding of the relationships among various entities.

The integration of MCP into the Q Developer CLI has significantly streamlined my workflow, allowing me to incorporate additional tools as needed.

Tech Optimizer
Extend the Amazon Q Developer CLI with Model Context Protocol (MCP) for Richer Context