generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(ecs-mcp-server): add AWS Knowledge MCP Server proxy integration #1332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
src/ecs-mcp-server/awslabs/ecs_mcp_server/modules/aws_knowledge_proxy.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| # 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. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """ | ||
| AWS Knowledge Proxy module for ECS MCP Server. | ||
| This module handles the setup and configuration of the AWS Knowledge MCP Server proxy integration. | ||
| """ | ||
|
|
||
| import logging | ||
| from typing import Optional | ||
|
|
||
| from fastmcp import FastMCP | ||
| from fastmcp.server.proxy import ProxyClient | ||
| from fastmcp.tools.tool_transform import ToolTransformConfig | ||
|
|
||
| # Guidance to append to tool descriptions | ||
| # ruff: noqa: E501 | ||
| ECS_TOOL_GUIDANCE = """ | ||
|
|
||
| ## ECS DOCUMENTATION GUIDANCE: | ||
| This tool provides up-to-date ECS documentation and implementation guidance, including new ECS features beyond standard LLM training data. | ||
|
|
||
| New ECS features include: | ||
| - ECS Native Blue-Green Deployments (different from CodeDeploy blue-green, launched 2025) | ||
| """ | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def register_proxy(mcp: FastMCP) -> Optional[bool]: | ||
| """ | ||
| Sets up the AWS Knowledge MCP Server proxy integration. | ||
|
|
||
| Args: | ||
| mcp: The FastMCP server instance to mount the proxy on | ||
|
|
||
| Returns: | ||
| bool: True if setup was successful, False otherwise | ||
| """ | ||
| try: | ||
| logger.info("Setting up AWS Knowledge MCP Server proxy") | ||
| proxy_config = { | ||
| "mcpServers": { | ||
| "aws-knowledge-mcp-server": { | ||
| "command": "uvx", | ||
| "args": [ | ||
| "mcp-proxy", | ||
| "--transport", | ||
| "streamablehttp", | ||
matthewgoodman13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "https://knowledge-mcp.global.api.aws", | ||
| ], | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # Create and mount the proxy | ||
| aws_knowledge_proxy = FastMCP.as_proxy(ProxyClient(proxy_config)) | ||
| mcp.mount(aws_knowledge_proxy, prefix="aws_knowledge") | ||
|
|
||
| # Add prompt patterns for blue-green deployments | ||
| register_ecs_prompts(mcp) | ||
|
|
||
| logger.info("Successfully mounted AWS Knowledge MCP Server") | ||
| return True | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Failed to setup AWS Knowledge MCP Server proxy: {e}") | ||
| return False | ||
|
|
||
|
|
||
| async def apply_tool_transformations(mcp: FastMCP) -> None: | ||
| """ | ||
| Apply tool transformations to the AWS Knowledge proxy tools. | ||
|
|
||
| Args: | ||
| mcp: The FastMCP server instance to apply transformations to | ||
| """ | ||
| logger.info("Applying tool transformations...") | ||
| await _add_ecs_guidance_to_knowledge_tools(mcp) | ||
|
|
||
|
|
||
| async def _add_ecs_guidance_to_knowledge_tools(mcp: FastMCP) -> None: | ||
| """Add ECS documentation guidance to specific tools if they exist.""" | ||
| try: | ||
| tools = await mcp.get_tools() | ||
|
|
||
| knowledge_tools = [ | ||
| "aws_knowledge_aws___search_documentation", | ||
| "aws_knowledge_aws___read_documentation", | ||
| "aws_knowledge_aws___recommend", | ||
| ] | ||
|
|
||
| for tool_name in knowledge_tools: | ||
| if tool_name not in tools: | ||
| logger.warning(f"Tool {tool_name} not found in MCP tools") | ||
| continue | ||
|
|
||
| original_desc = tools[tool_name].description or "" | ||
| config = ToolTransformConfig( | ||
| name=tool_name, description=original_desc + ECS_TOOL_GUIDANCE | ||
| ) | ||
| mcp.add_tool_transformation(tool_name, config) | ||
|
|
||
| logger.debug("Added ECS guidance to AWS Knowledge tools") | ||
| except Exception as e: | ||
| logger.error(f"Error applying tool transformations: {e}") | ||
| raise | ||
|
|
||
|
|
||
| def register_ecs_prompts(mcp: FastMCP) -> None: | ||
| """ | ||
| Register ECS-related prompt patterns with AWS Knowledge proxy tools. | ||
|
|
||
| Covers blue-green deployments, new ECS features, and comparisons based on ECS_TOOL_GUIDANCE. | ||
|
|
||
| Args: | ||
| mcp: The FastMCP server instance to register prompts with | ||
| """ | ||
|
|
||
| prompts = [ | ||
| { | ||
| "patterns": [ | ||
matthewgoodman13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "what are blue green deployments", | ||
| "what are b/g deployments", | ||
| "native ecs blue green", | ||
| "native ecs b/g", | ||
| "ecs native blue green deployments", | ||
| "difference between codedeploy and native blue green", | ||
| "how to setup blue green", | ||
| "setup ecs blue green", | ||
| "configure ecs blue green deployments", | ||
| "configure blue green", | ||
| "configure b/g", | ||
| "create blue green deployment", | ||
| ], | ||
| "response": [ | ||
| { | ||
| "name": "aws_knowledge_aws___search_documentation", | ||
| } | ||
| ], | ||
| }, | ||
| { | ||
| "patterns": [ | ||
| "ecs best practices", | ||
| "ecs implementation guide", | ||
| "ecs guidance", | ||
| "ecs recommendations", | ||
| "how to use ecs effectively", | ||
| "new ecs feature", | ||
| "latest ecs feature", | ||
| ], | ||
| "response": [ | ||
| { | ||
| "name": "aws_knowledge_aws___search_documentation", | ||
| } | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| # Register all prompt patterns using loops | ||
| total_patterns = 0 | ||
| for prompt_group in prompts: | ||
| patterns = prompt_group["patterns"] | ||
| response = prompt_group["response"] | ||
|
|
||
| for pattern in patterns: | ||
|
|
||
| def create_prompt_handler(response_data): | ||
| def prompt_handler(): | ||
| return response_data | ||
|
|
||
| return prompt_handler | ||
|
|
||
| handler = create_prompt_handler(response) | ||
| mcp.prompt(pattern)(handler) | ||
| total_patterns += 1 | ||
|
|
||
| logger.info( | ||
| f"Registered {total_patterns} ECS-related prompt patterns with AWS Knowledge proxy tools" | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.