
Extending AI Capabilities with On-the-Fly Context Using Amazon Q Developer CLI
Discover how Amazon Q Developer CLI transcends traditional AI knowledge boundaries by leveraging on-the-fly context from code repositories and external documents. Master techniques for providing just-in-time information from entire codebases, specific files, or documentation, empowering AI to craft solutions based on patterns outside its training data—delivering expert results even for cutting-edge technologies and specialized implementations.
AI models have inherent knowledge limitations based on their training data. When you need expertise on recent frameworks or specialized implementations, these models often fall short. But what if you could provide that missing context on the fly—what some call just-in-time context?
The Challenge: AI Knowledge Boundaries
AI models are trained on finite datasets with cutoff dates, meaning they can't know about:
- Recently released libraries or frameworks
- Your organization's internal tools and patterns
- The latest versions of rapidly evolving codebases
The Solution: On-the-Fly Context
Amazon Q Developer CLI enables a powerful approach: providing on-the-fly context from code repositories and documentation. Here's how it works:
- Identify a repository containing patterns similar to what you want to build
- Use Amazon Q Developer to analyze these materials in real-time
- Ask Amazon Q Developer to help you build a similar solution based on this context
- Iterate on the implementation with the Q Developer's guidance
What makes this approach powerful is Amazon Q Developer CLI's ability to access repositories directly from your local machine, including internal codebases and proprietary frameworks.
How On-the-Fly Context Works
text
+-------------+ +-----------------+ +----------------+| Repository |---->| Amazon Q |---->| AI-Generated || or Docs | | Developer CLI | | Solution |+-------------+ | | | || Real-time | +----------------+| On-the-fly | || Context Analysis| |+-----------------+ |^ || || v+----------------+ +----------------+| User Feedback |<----| Implementation || & Refinement | | & Testing |+----------------+ +----------------+
Context Sources Beyond Repositories
Amazon Q Developer CLI can analyze various materials accessible from your machine:
- Documentation pages and API references
- Architecture diagrams
- Configuration files
- Custom frameworks and libraries
Real-World Example: Dialog with Amazon Q Developer CLI
For this example, I used the following prompt:
Prompt
text
Please analyze the code structure and implementation of theAWS Documentation MCP Server athttps://github.com/awslabs/mcp/tree/main/src/aws-documentation-mcp-server/awslabs/aws_documentation_mcp_server,and then help me build a similar MCP server for the Open Weather API.Include the necessary files, code structure, API endpoints,authentication handling, data processing, and any othercomponents needed to create a functional Open Weather APIserver following the same architectural patterns.Provide complete code examples with explanations for each component.
Below is an excerpt from an actual conversation with Amazon Q Developer CLI, showing exactly how it analyzes an external GitHub repository in real-time and uses that context to build a similar implementation.
Bash
> Please analyze the code structure and implementation of the AWS Documentation MCP Server at https://github.com/awslabs/mcp/tree/main/src/aws-documentation-mcp-server/awslabs/aws_documentation_mcp_server,and then help me build a similar MCP server for the Open Weather API. Include the necessary files, code structure, API endpoints, authentication handling, data processing, and any other components needed tocreate a functional Open Weather API server following the same architectural patterns. Provide complete code examples with explanations for each component.I'll help you analyze the AWS Documentation MCP Server and then build a similar server for the Open Weather API. Let's start by examining the structure and implementation of the MCP server.Execute shell command▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔I will run the following shell command:git clone https://github.com/awslabs/mcp.git /tmp/mcp && ls -la /tmp/mcp/src/aws-documentation-mcp-server/awslabs/aws_documentation_mcp_serverEnter y to run this tool, otherwise continue chatting.> yExecuting `git clone https://github.com/awslabs/mcp.git /tmp/mcp && ls -la /tmp/mcp/src/aws-documentation-mcp-server/awslabs/aws_documentation_mcp_server`...▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔Cloning into '/tmp/mcp'...total 72drwxr-xr-x@ 6 user wheel 192 Apr 9 14:34 .drwxr-xr-x@ 4 user wheel 128 Apr 9 14:34 ..-rw-r--r--@ 1 user wheel 624 Apr 9 14:34 __init__.py-rw-r--r--@ 1 user wheel 1001 Apr 9 14:34 models.py-rw-r--r--@ 1 user wheel 15461 Apr 9 14:34 server.py-rw-r--r--@ 1 user wheel 8636 Apr 9 14:34 util.py🟢 Completed in 1.299sLet's examine each file to understand the structure and implementation:Read from filesystem▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔Reading file: /tmp/mcp/src/aws-documentation-mcp-server/awslabs/aws_documentation_mcp_server/__init__.py, all linesReading from filesystem...▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔Reading: /tmp/mcp/src/aws-documentation-mcp-server/awslabs/aws_documentation_mcp_server/__init__.py🟢 Completed in 0.1s[Amazon Q Developer CLI continues reading and analyzing each file]Now that I've analyzed the AWS Documentation MCP Server, I'll help you build a similar server for the Open Weather API. Let's create the necessary files and structure.First, let's create a directory structure for our Open Weather API MCP Server:Execute shell command▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔I will run the following shell command:mkdir -p ~/project/openweather_mcp_server/openweather_mcp_serverEnter y to run this tool, otherwise continue chatting.> yExecuting `mkdir -p ~/project/openweather_mcp_server/openweather_mcp_server`...▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🟢 Completed in 0.46sWrite to filesystem▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔Path: /Users/user/project/openweather_mcp_server/openweather_mcp_server/__init__.py+ 1: """openweather_mcp_server - MCP Server for Open Weather API."""+ 2:+ 3: __version__ = '0.0.1'Enter y to run this tool, otherwise continue chatting.> yWriting to filesystem...▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔Creating: /Users/user/project/openweather_mcp_server/openweather_mcp_server/__init__.py🟢 Completed in 0.3s
This is just the beginning of the conversation. Amazon Q Developer CLI continues by:
- Creating the
models.pyfile with Pydantic models for weather data
- Implementing
util.pywith formatting functions
- Building
server.pywith API endpoints for weather data
- Creating
setup.py,README.md, and other project files
Throughout the process, Amazon Q Developer CLI:
- Shows you exactly what it's doing (cloning repos, reading files, creating new files)
- Asks for permission before executing commands
- Provides real-time feedback on command execution
- Explains its implementation choices based on the analyzed repository
This authentic dialog demonstrates how Amazon Q Developer CLI leverages on-the-fly context from repositories to build solutions that follow specific patterns, even if those patterns weren't part of its original training data.
Generated Project Structure
Amazon Q Developer CLI created a well-organized project structure following the patterns from the reference repository:
Bash
openweather-mcp-server/├── pyproject.toml├── README.md├── openweather_mcp_server/│ ├── __init__.py│ ├── models.py # Weather data models (similar to original models.py)│ ├── server.py # MCP server implementation (similar to original server.py)│ └── util.py # Utility functions for MCP operations (similar to original util.py)└── tests/└── test_server.py # Tests for the MCP endpoints
This structure mirrors the architectural patterns of the reference implementation while adapting them specifically for weather data and the Open Weather API's requirements.
Alternative Approaches to Providing Context
While you can point to an entire repository, you can also be more specific about which files to analyze without cloning the entire repository. Here's an alternative prompt that accomplishes this:
Prompt
text
Please read and analyze the code files in the AWS Documentation MCP Server athttps://github.com/awslabs/mcp/tree/main/src/aws-documentation-mcp-server/awslabs/aws_documentation_mcp_serverwithout cloning the repository.Specifically, examine the __init__.py, models.py, server.py, and util.py filesto understand their structure and implementation patterns.After analyzing these files, help me build a MCP similar server for theOpen Weather API. Create all necessary files with complete code examples,following the same architectural patterns but adapted for weather data.Include:1. Project structure with appropriate files2. Data models for weather API responses3. Server implementation with API endpoints4. Utility functions for formatting and processing5. Authentication handling for API keys6. Error handling and logging7. Documentation for each componentPlease explain your implementation choices and how they relate to theoriginal MCP server patterns.
This more targeted approach offers several advantages:
- Efficiency: Only the necessary files are analyzed, saving time and resources
- Focus: The AI's attention is directed to the most relevant components
- Specificity: You can explicitly request analysis of particular patterns or features
- Control: You determine exactly which files contribute to the context
By being specific about which files to analyze and what aspects to focus on, you can guide Amazon Q Developer CLI to provide more tailored assistance based on the exact context you need.
Real-World Example: Alternative Approach in Action
When I used this alternative prompt with Amazon Q Developer CLI, here's how the interaction began:
Bash
> Please read and analyze the code files in the AWS Documentation MCP Server at https://github.com/awslabs/mcp/tree/main/src/aws-documentation-mcp-server/awslabs/aws_documentation_mcp_server without cloning the repository. Specifically, examine the __init__.py, models.py, server.py, and util.py files to understand their structure and implementation patterns.After analyzing these files, help me build a similar MCP server for the Open Weather API. Create all necessary files with complete code examples, following the same architectural patterns but adapted for weather data. Include:1. Project structure with appropriate files2. Data models for weather API responses3. Server implementation with API endpoints4. Utility functions for formatting and processing5. Authentication handling for API keys6. Error handling and logging7. Documentation for each componentPlease explain your implementation choices and how they relate to the original MCP server patterns.I'll help you build a similar MCP server for the Open Weather API based on the AWS Documentation MCP Server architecture. Let's start by examining the original repository structure and then create our implementation.Let's first look at the repository structure to understand the components:Execute shell command▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔I will run the following shell command: mkdir -p mcp-weatherEnter y to run this tool, otherwise continue chatting.> yExecuting `mkdir -p mcp-weather`...▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🟢 Completed in 0.31sLet's analyze the key files from the AWS Documentation MCP Server repository:Execute shell command▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔I will run the following shell command:curl -s https://raw.githubusercontent.com/awslabs/mcp/main/src/aws-documentation-mcp-server/awslabs/aws_documentation_mcp_server/__init__.pyEnter y to run this tool, otherwise continue chatting.> yExecuting `curl -s https://raw.githubusercontent.com/awslabs/mcp/main/src/aws-documentation-mcp-server/awslabs/aws_documentation_mcp_server/__init__.py`...▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.## Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance# with the License. A copy of the License is located at## http://www.apache.org/licenses/LICENSE-2.0## or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions# and limitations under the License."""awslabs.aws-documentation-mcp-server"""__version__ = '0.0.1'🟢 Completed in 0.287s
Notice how Amazon Q Developer CLI directly fetches the files from GitHub using
curl instead of cloning the entire repository. It then proceeds to analyze each file individually and build the implementation based on that analysis.This approach is more efficient and focused, allowing Amazon Q Developer CLI to get exactly the information it needs without downloading unnecessary files or directories.
When to Use This Technique
This approach is particularly valuable when:
- Working with cutting-edge technologies
- Building with organization-specific patterns
- Dealing with complex or specialized systems
- Maintaining consistency across microservices
- Onboarding new team members to existing codebases
- Modernizing legacy systems
Key Benefits
- Breaking Knowledge Boundaries: Extend the AI's capabilities beyond its training data
- Learning from Real Implementations: Analyze tested and refined code patterns
- Maintaining Consistency: Ensure new code aligns with established patterns
- Accelerating Development: Build on existing patterns rather than starting from scratch
- Filling Documentation Gaps: Gain insights when documentation is sparse or outdated
How to Apply This Technique
- Identify Context Sources: Find repositories with similar functionality and clear structure
- Craft Specific Prompts: Include repository paths and clearly state what you want to build
- Analyze and Generate: Let Amazon Q Developer CLI explore the codebase and generate solutions
- Iterate and Refine: Ask for clarifications and request modifications as needed
- Test Thoroughly: Validate the generated code against your requirements
Amazon Q Developer CLI also offers helpful commands like
/context for managing contextual information and /profile for switching between different project profiles, making it even easier to work with different context scenarios.Limitations to Consider
- Respect copyright and licensing terms
- Review generated code for security issues
- Adapt code to your specific requirements
- Understand the code before implementing it
- Be aware of performance impacts with large repositories
Conclusion
Providing on-the-fly context through Amazon Q Developer CLI represents a powerful technique for extending AI capabilities in your development workflow. Rather than being limited by what the AI was trained on months or years ago, you can provide just-in-time context for your specific task.
Next time you're building something and find your AI assistant lacking knowledge about a specific implementation, consider providing that context on the fly. You might be surprised by how effectively it can help you build something similar, even if the original code wasn't part of its original training data.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article