search_texts
Search the National Library of Norway's digital collection for texts in newspapers, books, or journals using query terms, date ranges, and media type filters.
Instructions
Search for texts in the National Library's digital collection.
Args: query: Search query string limit: Maximum number of results to return (default: 10) from_year: Start year for search period (optional) to_year: End year for search period (optional) media_type: Type of media to search. Options: 'digavis' (newspapers), 'digibok' (books), 'digitidsskrift' (journals). Default: 'digavis'
Returns: JSON string containing search results with metadata
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| limit | No | ||
| from_year | No | ||
| to_year | No | ||
| media_type | No | digavis |
Implementation Reference
- src/dhlab_mcp/server.py:10-51 (handler)The search_texts tool handler, decorated with @mcp.tool() for registration. It searches texts using dhlab.Corpus based on query parameters and returns JSON results.@mcp.tool() def search_texts( query: str, limit: int = 10, from_year: int | None = None, to_year: int | None = None, media_type: str = "digavis", ) -> str: """Search for texts in the National Library's digital collection. Args: query: Search query string limit: Maximum number of results to return (default: 10) from_year: Start year for search period (optional) to_year: End year for search period (optional) media_type: Type of media to search. Options: 'digavis' (newspapers), 'digibok' (books), 'digitidsskrift' (journals). Default: 'digavis' Returns: JSON string containing search results with metadata """ try: # Build search parameters using correct Corpus API params = { "fulltext": query, "limit": limit, "doctype": media_type } if from_year: params["from_year"] = from_year if to_year: params["to_year"] = to_year # Perform search using dhlab corpus = dhlab.Corpus(**params) # Return corpus information if hasattr(corpus, 'corpus') and corpus.corpus is not None: return corpus.corpus.to_json(orient='records', force_ascii=False) return "No results found" except Exception as e: return f"Error searching texts: {str(e)}"