File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed
Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 1+ from fastmcp import FastMCP
2+
3+
4+ def register_prompt (mcp : FastMCP ):
5+ """
6+ Register Openstack MCP prompts.
7+ """
8+
9+ @mcp .prompt ()
10+ def get_instances_by_security_group (security_group_name : str ) -> str :
11+ """
12+ Get instances associated with a specific security group.
13+
14+ :param security_group_name: The name of the security group to filter instances by.
15+ """
16+ return (
17+ f"Find all compute instances that have the security group "
18+ f"'{ security_group_name } ' attached.\n \n "
19+ f"Steps:\n "
20+ f"1. Call get_servers to list all servers.\n "
21+ f"2. Check each server's security_groups field.\n "
22+ f"3. Return only the servers where security_groups contains "
23+ f"an entry with name '{ security_group_name } '.\n "
24+ f"4. For each matching server, show the server name, ID, "
25+ f"status, and the full list of its security groups."
26+ )
Original file line number Diff line number Diff line change 22from fastmcp .server .middleware .error_handling import ErrorHandlingMiddleware
33from fastmcp .server .middleware .logging import LoggingMiddleware
44
5+ from openstack_mcp_server .prompts import register_prompt
56from openstack_mcp_server .tools import register_tool
67
78
@@ -13,7 +14,7 @@ def serve(transport: str, **kwargs):
1314
1415 register_tool (mcp )
1516 # resister_resources(mcp)
16- # register_prompt(mcp)
17+ register_prompt (mcp )
1718
1819 # Add middlewares
1920 mcp .add_middleware (ErrorHandlingMiddleware ())
Original file line number Diff line number Diff line change 1+ from openstack_mcp_server .prompts import register_prompt
2+
3+
4+ def test_get_instances_by_security_group_prompt_registered ():
5+ """Test that the prompt is registered with the MCP instance."""
6+ from unittest .mock import MagicMock
7+
8+ mcp = MagicMock ()
9+ register_prompt (mcp )
10+ mcp .prompt .assert_called ()
11+
12+
13+ def test_get_instances_by_security_group_prompt_content ():
14+ """Test that the prompt returns expected content."""
15+ from fastmcp import FastMCP
16+
17+ mcp = FastMCP ("test" )
18+ register_prompt (mcp )
19+
20+ prompts = mcp ._prompt_manager ._prompts
21+ assert "get_instances_by_security_group" in prompts
22+
23+ prompt_obj = prompts ["get_instances_by_security_group" ]
24+ assert prompt_obj .fn is not None
25+
26+ result = prompt_obj .fn (security_group_name = "my-sg" )
27+ assert "my-sg" in result
28+ assert "get_servers" in result
29+ assert "security_groups" in result
You can’t perform that action at this time.
0 commit comments