find_documents_by_content
Search RSpace documents by content terms using AND/OR operators, filter with exclusion terms, and sort results to locate research data matching specific criteria.
Instructions
Advanced content-based document search
Usage: Find documents containing specific content terms
Parameters:
content_terms: List of terms that should appear in document content
operator: "and" (all terms must appear) or "or" (any term can appear)
exclude_terms: Optional list of terms to exclude from results
order_by: Sort results by field
page_size: Number of results to return
Returns: Dictionary with search results
Example: find_documents_by_content(["DNA", "extraction"], operator="and")
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content_terms | Yes | ||
| exclude_terms | No | ||
| operator | No | and | |
| order_by | No | lastModified desc | |
| page_size | No |
Implementation Reference
- main.py:355-404 (handler)Core implementation of the 'find_documents_by_content' MCP tool. Includes @mcp.tool decorator for registration, type-annotated parameters serving as input schema, comprehensive docstring, and logic using AdvancedQueryBuilder for full-text search with client-side exclusion filtering.@mcp.tool(tags={"rspace", "search"}) def find_documents_by_content( content_terms: List[str], operator: Literal["and", "or"] = "and", exclude_terms: List[str] = None, order_by: str = "lastModified desc", page_size: int = 20 ) -> dict: """ Advanced content-based document search Usage: Find documents containing specific content terms Parameters: - content_terms: List of terms that should appear in document content - operator: "and" (all terms must appear) or "or" (any term can appear) - exclude_terms: Optional list of terms to exclude from results - order_by: Sort results by field - page_size: Number of results to return Returns: Dictionary with search results Example: find_documents_by_content(["DNA", "extraction"], operator="and") """ builder = AdvancedQueryBuilder(operator=operator) for term in content_terms: builder.add_term(term, AdvancedQueryBuilder.QueryType.FULL_TEXT) # Note: RSpace API doesn't directly support exclusion, but we can filter results advanced_query = builder.get_advanced_query() results = eln_cli.get_documents_advanced_query( advanced_query=advanced_query, order_by=order_by, page_number=0, page_size=page_size ) # Filter out documents containing excluded terms if specified if exclude_terms and 'documents' in results: filtered_docs = [] for doc in results['documents']: # Check if any exclude terms are in the document name or other available text doc_text = (doc.get('name', '') + ' ' + doc.get('tags', '')).lower() if not any(exclude_term.lower() in doc_text for exclude_term in exclude_terms): filtered_docs.append(doc) results['documents'] = filtered_docs results['totalHits'] = len(filtered_docs) return results
- main.py:355-355 (registration)MCP tool registration decorator that automatically registers the find_documents_by_content function with tags for 'rspace' and 'search' categories.@mcp.tool(tags={"rspace", "search"})
- main.py:356-362 (schema)Input schema defined by Python type hints and defaults, used by MCP framework for validation and tool description.def find_documents_by_content( content_terms: List[str], operator: Literal["and", "or"] = "and", exclude_terms: List[str] = None, order_by: str = "lastModified desc", page_size: int = 20 ) -> dict: