meta_mcp.tools._search#
Attributes#
Functions#
|
Returns the input schema for a given tool, to know how to call it. |
|
Lists all (or just the filtered) MCP servers and their descriptions, offering a wide range of tools for biomedical (analysis) tasks to choose from. |
|
Returns a list of all (or just the filtered) tools for a given MCP server. |
|
Returns top-n most fitting strings from candidates list. |
|
Perform string matching search using specified method. |
|
Create a dynamic Pydantic model for LLM search output. |
|
Create a system prompt template for LLM search. |
|
Perform LLM-based search using structured outputs. |
|
Prepare candidates for semantic search by combining with descriptions. |
|
Compute cosine similarity between query and candidates, return top-n indices. |
|
Perform semantic search using embeddings. |
|
Perform semantic search using direct model initialization. |
|
Perform semantic search using HTTP embedding server. |
Module Contents#
- async meta_mcp.tools._search.get_tool_info(server_name: Annotated[str, The name of the server that provides the tool], tool_name: Annotated[str, The name of the tool to get information about]) str#
Returns the input schema for a given tool, to know how to call it.
- async meta_mcp.tools._search.list_servers(query: Annotated[str | None, Optional query to filter the servers by]=None) str#
Lists all (or just the filtered) MCP servers and their descriptions, offering a wide range of tools for biomedical (analysis) tasks to choose from.
- async meta_mcp.tools._search.list_server_tools(server_name: Annotated[str, The name of the MCP server to list tools for], query: Annotated[str | None, Optional query to filter the tools by] = None) str#
Returns a list of all (or just the filtered) tools for a given MCP server.
- meta_mcp.tools._search.general_search(query: str, candidates: list[str], top_n: int = 5, mode: Literal['string_match', 'llm', 'semantic'] = 'string_match', string_match_method: Literal['fuzzy', 'substring'] = 'fuzzy', descriptions: list[str | None] | None = None, reasoning: bool = True, **kwargs) list[str]#
Returns top-n most fitting strings from candidates list.
- Parameters:
query (str) – The search query string.
candidates (list[str]) – List of candidate strings to search through.
top_n (int) – Number of top results to return (default: 5).
mode (str) – Search mode: “string_match”, “llm”, or “semantic” (default: “string_match”).
string_match_method (str) – String matching method: “fuzzy” or “substring” (default: “fuzzy”).
descriptions (list[str | None] | None) – Optional list of descriptions for candidates. Must match length of candidates. Used in both “llm” and “semantic” search modes. In “llm” mode, descriptions are formatted as CSV in the system prompt. In “semantic” mode, descriptions are combined with candidates as “candidate (description)” for embedding computation.
**kwargs (dict) – Mode-specific keyword arguments. “llm” mode keys: model (str), temperature (float), reasoning (bool). “semantic” mode keys: backend (str), model (str), http_url (str).
- Returns:
List of top-n matching strings, ordered by relevance (best match first).
- Return type:
- Raises:
ValueError – If invalid mode or string_match_method is provided, or if descriptions length doesn’t match candidates length.
RuntimeError – If LLM search fails (when mode is “llm”).
- meta_mcp.tools._search._string_match_search(query: str, candidates: list[str], top_n: int, method: Literal['fuzzy', 'substring']) list[str]#
Perform string matching search using specified method.
- Parameters:
- Returns:
List of top-n matching strings, ordered by relevance.
- Return type:
- meta_mcp.tools._search._create_search_output_model(candidates: list[str], reasoning: bool = True) type[pydantic.BaseModel]#
Create a dynamic Pydantic model for LLM search output.
- Parameters:
- Returns:
Dynamically created Pydantic model with selected_strings field and optionally reasoning field.
- Return type:
- meta_mcp.tools._search._create_search_system_prompt(candidates: list[str], top_n: int, descriptions: list[str | None] | None = None, reasoning: bool = True) str#
Create a system prompt template for LLM search.
- Parameters:
candidates (list[str]) – List of candidate strings to search through.
top_n (int) – Number of top results to return.
descriptions (list[str | None] | None) – Optional list of descriptions for candidates. If provided and not all None, formats candidates and descriptions as CSV table. Otherwise uses numbered list format.
reasoning (bool) – Whether to include reasoning instructions in the prompt (default: True).
- Returns:
System prompt string with candidates list and instructions.
- Return type:
- meta_mcp.tools._search._llm_search(query: str, candidates: list[str], top_n: int, model: str = 'openai/gpt-5-nano', temperature: float = 1.0, descriptions: list[str | None] | None = None, reasoning: bool = True, verbose: bool = False, **kwargs) list[str]#
Perform LLM-based search using structured outputs.
- Parameters:
query (str) – The search query string.
candidates (list[str]) – List of candidate strings to search through.
top_n (int) – Number of top results to return.
model (str) – Model name for LLM backend (default: “openai/gpt-5-nano”).
temperature (float) – Sampling temperature (default: 1.0).
descriptions (list[str | None] | None) – Optional list of descriptions for candidates. When provided, candidates and descriptions are formatted as CSV in the system prompt to help the LLM make better matches. The function still returns only the original candidates.
reasoning (bool) – Whether to include reasoning in LLM output and prompt (default: True).
**kwargs – Additional keyword arguments (unused, reserved for future use).
- Returns:
List of top-n matching strings, ordered by relevance (original candidates without descriptions).
- Return type:
- Raises:
ValueError – If the response contains invalid strings or parsing fails.
RuntimeError – If the LLM call fails.
- meta_mcp.tools._search._prepare_semantic_candidates(candidates: list[str], descriptions: list[str | None] | None) tuple[list[str], list[str]]#
Prepare candidates for semantic search by combining with descriptions.
- Parameters:
- Returns:
Tuple of (combined_strings_for_embedding, original_candidates). The combined strings are used for embedding, and original_candidates maintains the mapping back to original strings.
- Return type:
- meta_mcp.tools._search._compute_cosine_similarity_ranking(query_embedding: numpy.ndarray, candidate_embeddings: numpy.ndarray, top_n: int) numpy.ndarray#
Compute cosine similarity between query and candidates, return top-n indices.
- Parameters:
query_embedding (np.ndarray) – Query embedding vector.
candidate_embeddings (np.ndarray) – Candidate embedding vectors (2D array).
top_n (int) – Number of top results to return.
- Returns:
Indices of top-n candidates ordered by similarity (best first).
- Return type:
np.ndarray
- meta_mcp.tools._search._semantic_search(query: str, candidates: list[str], top_n: int, backend: Literal['direct', 'http'] = 'direct', model: str = 'all-MiniLM-L6-v2', http_url: str | None = None, descriptions: list[str | None] | None = None, **kwargs) list[str]#
Perform semantic search using embeddings.
- Parameters:
query (str) – The search query string.
candidates (list[str]) – List of candidate strings to search through.
top_n (int) – Number of top results to return.
backend (str) – Backend to use: “direct” or “http” (default: “direct”).
model (str) – Model name for direct backend (default: “all-MiniLM-L6-v2”).
http_url (str) – URL for HTTP backend (default: “http://127.0.0.1:8501/embed”). When unset, falls back to the META_MCP_EMBEDDING_HTTP_URL environment variable.
descriptions (list[str | None] | None) – Optional list of descriptions for candidates. Combined with candidates as “candidate (description)” for embedding computation.
**kwargs – Additional keyword arguments (unused, reserved for future use).
- Returns:
List of top-n matching strings, ordered by relevance (original candidates without descriptions).
- Return type:
- Raises:
ValueError – If invalid backend is provided.
- meta_mcp.tools._search._semantic_search_direct(query: str, combined_strings: list[str], original_candidates: list[str], top_n: int, model: str) list[str]#
Perform semantic search using direct model initialization.
- Parameters:
query (str) – The search query string.
combined_strings (list[str]) – List of combined candidate strings (with descriptions if provided) for embedding.
original_candidates (list[str]) – List of original candidate strings to return.
top_n (int) – Number of top results to return.
model (str) – Model name to use for embeddings.
- Returns:
List of top-n matching strings, ordered by relevance (original candidates).
- Return type:
- meta_mcp.tools._search._semantic_search_http(query: str, combined_strings: list[str], original_candidates: list[str], top_n: int, http_url: str) list[str]#
Perform semantic search using HTTP embedding server.
- Parameters:
query (str) – The search query string.
combined_strings (list[str]) – List of combined candidate strings (with descriptions if provided) for embedding.
original_candidates (list[str]) – List of original candidate strings to return.
top_n (int) – Number of top results to return.
http_url (str) – URL of the embedding server endpoint.
- Returns:
List of top-n matching strings, ordered by relevance (original candidates).
- Return type:
- Raises:
RuntimeError – If the HTTP request fails.
ValueError – If the server response is invalid.