From b906cd489f1ae112c747f4c8a8cf5d9066a1cf6b Mon Sep 17 00:00:00 2001 From: meghanmurphy1 Date: Tue, 4 Mar 2025 17:03:57 -0500 Subject: [PATCH 1/2] searching as a tool instead --- server.py | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/server.py b/server.py index 00a0c7e..778f6d2 100644 --- a/server.py +++ b/server.py @@ -13,7 +13,7 @@ @mcp.resource( - "elasticsearch://indices", + uri="elasticsearch://indices", name="Elasticsearch Indices", description="Retrieve all Elasticsearch indices.", ) @@ -23,7 +23,7 @@ def fetch_indices() -> list[dict]: @mcp.resource( - "elasticsearch://indices/{index}", + uri="elasticsearch://indices/{index}", name="Index Details", description="Retrieve details of a specific Elasticsearch index.", ) @@ -33,7 +33,7 @@ def fetch_index_details(index: str) -> dict[str, any]: @mcp.resource( - "docs://search/{query}", + uri="docs://search/{query}", name="Elasticsearch Documentation", description="Perform a semantic search across Elastic documentation for a given query.", ) @@ -46,11 +46,14 @@ def search_elastic_documentation(query: str) -> dict[str, any]: return es_client.search_crawler_resource("search-elastic-docs", query) -@mcp.resource( - "search_labs://search/{query}", - name="Elasticsearch Labs Blogs", - description="Perform a semantic search across Elastic search labs blogs for a given query.", -) +# ------------------- MCP Tools (Actions Users Can Trigger) ------------------- + + +# IMO the search tools (semantic search) should be actually resources +# +# TODO: define actual tools + +@mcp.tool() def search_elastic_search_labs_blogs(query: str) -> dict[str, any]: """ Perform a semantic search across Elastic search labs blogs for a given query. The @@ -60,12 +63,6 @@ def search_elastic_search_labs_blogs(query: str) -> dict[str, any]: return es_client.search_crawler_resource("search-blog-search-labs", query) -# ------------------- MCP Tools (Actions Users Can Trigger) ------------------- - - -# IMO the search tools (semantic search) should be actually resources -# TODO: define actual tools - # ------------------- MCP Prompts (Predefined Interactions with the Assistant) ------------------- @@ -114,17 +111,36 @@ def analyze_salesforce_data(index: str) -> list[Message]: # ------------------- DEBUG: Print Registered Resources ------------------- - def debug_registered_resources(): """Print all registered MCP resources for debugging.""" print("\nšŸ” Registered MCP Resources:") for resource in mcp._resource_manager.list_resources(): - print(f" - {resource}") + print(f" - {resource.name}") + for resource in mcp._resource_manager.list_templates(): + print(f" - {resource.name}") + +# ------------------- DEBUG: Print Registered Tools ------------------- + +def debug_registered_tools(): + """Print all registered MCP tools for debugging.""" + print("\nšŸ” Registered MCP Tools:") + for tool in mcp._tool_manager.list_tools(): + print(f" - {tool.name}") + +# ------------------- DEBUG: Print Registered Prompts ------------------- + +def debug_registered_prompts(): + """Print all registered MCP prompts for debugging.""" + print("\nšŸ” Registered MCP Prompts:") + for prompt in mcp._prompt_manager.list_prompts(): + print(f" - {prompt.name}") # ------------------- MCP Server Execution ------------------- if __name__ == "__main__": debug_registered_resources() - print(f"MCP server '{mcp.name}' is running...") + debug_registered_prompts() + debug_registered_tools() + print(f"\n MCP server '{mcp.name}' is running...") mcp.run() From 879c7b43c50cad1bb3bd443bde401b6934544acb Mon Sep 17 00:00:00 2001 From: meghanmurphy1 Date: Tue, 4 Mar 2025 17:15:37 -0500 Subject: [PATCH 2/2] add search docs --- server.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/server.py b/server.py index 778f6d2..ded11f6 100644 --- a/server.py +++ b/server.py @@ -32,11 +32,14 @@ def fetch_index_details(index: str) -> dict[str, any]: return es_client.get_index_details(index) -@mcp.resource( - uri="docs://search/{query}", - name="Elasticsearch Documentation", - description="Perform a semantic search across Elastic documentation for a given query.", -) +# ------------------- MCP Tools (Actions Users Can Trigger) ------------------- + + +# IMO the search tools (semantic search) should be actually resources +# +# TODO: define actual tools + +@mcp.tool() def search_elastic_documentation(query: str) -> dict[str, any]: """ Perform a semantic search across Elastic documentation for a given query. The @@ -45,14 +48,6 @@ def search_elastic_documentation(query: str) -> dict[str, any]: """ return es_client.search_crawler_resource("search-elastic-docs", query) - -# ------------------- MCP Tools (Actions Users Can Trigger) ------------------- - - -# IMO the search tools (semantic search) should be actually resources -# -# TODO: define actual tools - @mcp.tool() def search_elastic_search_labs_blogs(query: str) -> dict[str, any]: """