generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 80
feat: add MCP tools for SOP discovery and retrieval #29
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
Open
konippi
wants to merge
4
commits into
strands-agents:main
Choose a base branch
from
konippi:add-mcp-tools-for-sop-discovery-and-retrieval
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9fb664d
feat: add MCP tools for SOP discovery and retrieval
konippi fad2646
chore: fix conflict with main
konippi c134079
Merge branch 'main' into add-mcp-tools-for-sop-discovery-and-retrieval
jlhood 32b6934
refactor(mcp): consolidate MCP server and simplify SOP tools
konippi 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
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
| """MCP server implementation for Agent SOPs.""" | ||
|
|
||
| from .server import AgentSOPMCPServer | ||
|
|
||
| __all__ = ["AgentSOPMCPServer"] |
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,48 @@ | ||
| """MCP prompts for SOP execution.""" | ||
|
|
||
| import logging | ||
|
|
||
| from mcp.server.fastmcp import FastMCP | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def register_sop_prompts(mcp: FastMCP, sops: list[dict]) -> None: | ||
konippi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Register SOP prompts with MCP server. | ||
|
|
||
| Args: | ||
| mcp: FastMCP server instance | ||
| sops: List of SOP dictionaries with name, description, and content | ||
| """ | ||
| for sop in sops: | ||
| try: | ||
| handler = create_prompt_handler(sop["name"], sop["content"]) | ||
| mcp.prompt(name=sop["name"], description=sop["description"])(handler) | ||
| except Exception as e: | ||
| logger.error(f"Error registering prompt for SOP '{sop['name']}': {e}") | ||
| continue | ||
|
|
||
|
|
||
| def create_prompt_handler(sop_name: str, sop_content: str): | ||
| """Create a prompt handler for a specific SOP. | ||
|
|
||
| Args: | ||
| sop_name: Name of the SOP | ||
| sop_content: Content of the SOP | ||
|
|
||
| Returns: | ||
| Prompt handler function | ||
| """ | ||
|
|
||
| def get_prompt(user_input: str = "") -> str: | ||
| return f"""Run this SOP: | ||
| <agent-sop name="{sop_name}"> | ||
| <content> | ||
| {sop_content} | ||
| </content> | ||
| <user-input> | ||
| {user_input} | ||
| </user-input> | ||
| </agent-sop>""" | ||
|
|
||
| return get_prompt | ||
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,35 @@ | ||
| """MCP server orchestrator for Agent SOPs.""" | ||
|
|
||
| import logging | ||
|
|
||
| from mcp.server.fastmcp import FastMCP | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class AgentSOPMCPServer: | ||
| """MCP server for serving Agent SOPs as prompts and tools.""" | ||
|
|
||
| def __init__(self, sop_paths: str | None = None): | ||
| """Initialize the MCP server. | ||
|
|
||
| Args: | ||
| sop_paths: Optional colon-separated string of external SOP directory paths | ||
| """ | ||
| self.sop_paths = sop_paths | ||
| self.mcp = FastMCP("agent-sop-prompt-server") | ||
|
|
||
| def setup(self) -> None: | ||
|
||
| """Setup the MCP server by loading SOPs and registering prompts/tools.""" | ||
| from ..utils import get_all_sops | ||
| from .prompts import register_sop_prompts | ||
| from .tools import register_sop_tools | ||
konippi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| sops = get_all_sops(self.sop_paths) | ||
| register_sop_prompts(self.mcp, sops) | ||
| register_sop_tools(self.mcp, sops) | ||
|
|
||
| def run(self) -> None: | ||
| """Start the MCP server.""" | ||
| self.setup() | ||
| self.mcp.run() | ||
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,55 @@ | ||
| """MCP tools for SOP management.""" | ||
|
|
||
| from mcp.server.fastmcp import FastMCP | ||
|
|
||
| from ..utils import create_sop_metadata | ||
|
|
||
|
|
||
| def register_sop_tools(mcp: FastMCP, sops: list[dict]) -> None: | ||
konippi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Register SOP management tools with MCP server. | ||
|
|
||
| Args: | ||
| mcp: FastMCP server instance | ||
| sops: List of SOP dictionaries with name, description, and content | ||
| """ | ||
|
|
||
| @mcp.tool() | ||
| def list_agent_sops() -> list[dict]: | ||
| """List all available agent SOPs with metadata. | ||
|
|
||
| Returns: | ||
| List of SOP metadata dictionaries containing name, description, and parameters | ||
| """ | ||
| result = [] | ||
| for sop in sops: | ||
| metadata = create_sop_metadata(name=sop["name"], content=sop["content"]) | ||
| result.append( | ||
| { | ||
| "name": metadata["name"], | ||
| "description": metadata["description"], | ||
| "parameters": metadata["parameters"], | ||
| } | ||
| ) | ||
| return sorted(result, key=lambda x: x["name"]) | ||
|
|
||
| @mcp.tool() | ||
| def get_agent_sop(sop_name: str) -> dict: | ||
| """Get the full content and metadata of a specific SOP. | ||
|
|
||
| Args: | ||
| sop_name: Name of the SOP to retrieve | ||
|
|
||
| Returns: | ||
| Complete SOP metadata including content, parameters, examples, troubleshooting | ||
|
|
||
| Raises: | ||
| ValueError: If SOP name is not found | ||
| """ | ||
| for sop in sops: | ||
| if sop["name"] == sop_name: | ||
| return create_sop_metadata(name=sop["name"], content=sop["content"]) | ||
|
|
||
| available_sops = [sop["name"] for sop in sops] | ||
| raise ValueError( | ||
| f"SOP '{sop_name}' not found. Available SOPs: {available_sops}" | ||
| ) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These dont exist anymore