Skip to main content
Glama
DHLAB MCP Server

DHLAB MCP Server

by marksverdhei

dhlab-mcp

MCP server providing access to DHLAB (National Library of Norway Digital Humanities Lab) functionality through the Model Context Protocol.

Overview

This server exposes tools for:

  • Text search: Search the National Library's digital text collection

  • NGram analysis: Analyze word frequency trends over time

  • Concordance: Find word contexts in documents

  • Collocations: Discover words that appear together

  • Word lookup: Look up Norwegian word forms and lemmas

  • Image search: Search for images in the digital collection

  • Corpus statistics: Get information about document collections

Related MCP server: gallica-mcp

Installation

This project uses uv, which can be installed with:

# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh

Clone and install:

git clone https://github.com/marksverdhei/dhlab-mcp.git
cd dhlab-mcp
uv sync --dev

Or install directly:

pip install git+https://github.com/marksverdhei/dhlab-mcp.git

Usage

Configuring in Claude Code CLI

Add the MCP server to your Claude Code configuration:

# inside the repo directory:
claude mcp add --transport stdio dhlab -- uv --directory $PWD run dhlab-mcp

or under user scope:

claude mcp add --scope user --transport stdio dhlab -- uv --directory $PWD run dhlab-mcp

Verify the server is added:

claude mcp list

The DHLAB tools will then be available in your Claude Code sessions.

Running the MCP Server Standalone

You can also run the server directly for testing:

dhlab-mcp

Or in development mode:

uv run dhlab-mcp

Running as a Local HTTP API

To run the MCP server as a local HTTP API on a custom port:

# Run on default port 8000
dhlab-mcp --transport http

# Run on a custom port
dhlab-mcp --transport http --port 9000

# Run on a specific host and port
dhlab-mcp --transport http --host 0.0.0.0 --port 8080

The server supports the following transport options:

  • stdio (default): Standard input/output for CLI integration

  • http: Streamable HTTP transport (recommended for network access)

  • sse: Server-Sent Events transport (legacy, for backward compatibility)

Once running, the HTTP server will be available at http://<host>:<port>/mcp/.

Available Tools

1. search_texts

Search for texts in the digital collection.

{
  "query": "ibsen",
  "limit": 10,
  "from_year": 1900,
  "to_year": 1950,
  "media_type": "aviser"  # or "bøker", "tidsskrift"
}

2. ngram_frequencies

Get word frequency trends over time.

{
  "words": ["frihet", "demokrati"],
  "corpus": "bok",  # or "avis"
  "from_year": 1810,
  "to_year": 2020
}

3. find_concordances

Find word contexts in a document (returns HTML-formatted text).

{
  "urn": "URN:NBN:no-nb_digibok_2008051404065",
  "word": "Norge",
  "window": 25
}

Output format: HTML-formatted concordance with <b> tags highlighting matches.

4. word_concordance

Find word contexts with structured output (no HTML formatting).

{
  "urn": "URN:NBN:no-nb_digibok_2008051404065",
  "word": "Norge",
  "window": 12
}

Output format: Clean structured data with separate fields:

  • dhlabid: Document identifier

  • before: Text before the matched word

  • target: The matched word itself

  • after: Text after the matched word

Use cases:

  • Use find_concordances for display/UI (HTML-formatted)

  • Use word_concordance for analysis/processing (structured data)

5. find_collocations

Find words that appear near the target word.

{
  "urn": "URN:NBN:no-nb_digibok_2008051404065",
  "word": "frihet",
  "window": 5
}

6. lookup_word_forms

Look up different forms of a Norwegian word.

{
  "word": "løpe"
}

7. lookup_word_lemma

Look up the lemma (base form) of a word.

{
  "word": "løper"
}

8. search_images

Search for images in the collection.

{
  "query": "Oslo",
  "limit": 10,
  "from_year": 1900,
  "to_year": 1950
}

9. get_corpus_statistics

Get statistics about a set of documents.

{
  "urns": ["URN:NBN:no-nb_digibok_2008051404065"]
}

Development

For development, install with:

uv sync --dev

Run tests:

pytest

Format code:

ruff format src/ tests/

About DHLAB

DHLAB is a Python library for qualitative and quantitative analyses of digital texts from the National Library of Norway's collection. For more information, visit:

License

See LICENSE file.

Available Tools

9 tools
find_collocationsB

Find collocations (words that appear near the target word) in a document.

Args: urn: URN identifier for the document word: Target word to find collocations for window: Size of context window (default: 5) limit: Maximum number of collocations to return (default: 100)

Returns: JSON string containing collocation statistics

Inputs: urn (required), word (required), window, limit. Returns: result

find_concordancesC

Find concordances (contexts) for a word in a specific document.

Args: urn: URN identifier for the document word: Word to find concordances for window: Number of words before and after the match (default: 25) limit: Maximum number of concordances to return (default: 100)

Returns: JSON string containing concordance results

Inputs: urn (required), word (required), window, limit. Returns: result

get_corpus_statisticsC

Get statistical information about a corpus of documents.

Args: urns: List of URN identifiers for documents

Returns: JSON string containing corpus statistics

Inputs: urns (required). Returns: result

lookup_word_formsC

Look up different forms of a Norwegian word.

Args: word: The word to look up

Returns: JSON string containing different word forms

Inputs: word (required). Returns: result

lookup_word_lemmaC

Look up the lemma (base form) of a Norwegian word.

Args: word: The word to look up

Returns: JSON string containing lemma information

Inputs: word (required). Returns: result

ngram_frequenciesB

Get word frequency trends over time using NGram analysis.

Args: words: List of words to analyze corpus: Corpus type. Options: 'bok' (books), 'avis' (newspapers). Default: 'bok' from_year: Start year (default: 1810) to_year: End year (default: 2020) smooth: Smoothing parameter for the frequency curve (default: 1)

Returns: JSON string containing frequency data over time

Inputs: words (required), corpus, from_year, to_year, +1 more. Returns: result

search_imagesB

Search for images in the National Library's digital collection.

Args: query: Search query string limit: Maximum number of results (default: 10) from_year: Start year (optional) to_year: End year (optional)

Returns: JSON string containing image search results with URLs

Inputs: query (required), limit, from_year, to_year. Returns: result

search_textsA

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

Inputs: query (required), limit, from_year, to_year, +1 more. Returns: result

word_concordanceA

Find concordances with structured output (no HTML formatting).

Returns clean format with separate before/target/after fields instead of HTML-formatted text. This is useful for programmatic analysis where you need the matched word separated from context.

Args: urn: URN identifier for the document word: Word to find concordances for window: Number of words before and after the match (default: 12, max: 24) limit: Maximum number of concordances to return (default: 100)

Returns: JSON string containing structured concordance results with fields: - dhlabid: Document identifier - before: Text before the matched word - target: The matched word itself - after: Text after the matched word

Inputs: urn (required), word (required), window, limit. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 9 tools

    Disambiguation4/5

    Most tools have distinct purposes, but find_concordances and word_concordance have significant overlap as both find concordances for words in documents, differing mainly in output format. This could cause confusion for an agent deciding which to use. Other tools like find_collocations, ngram_frequencies, and search functions are clearly differentiated.

    Naming Consistency5/5

    All tool names follow a consistent snake_case pattern with clear verb_noun structure (e.g., find_collocations, lookup_word_forms, search_images). The naming is predictable and readable throughout the set, with no mixing of conventions or styles.

    Tool Count5/5

    With 9 tools, this server is well-scoped for digital humanities text analysis. The count is appropriate, covering key operations like searching, concordancing, collocation analysis, and statistical queries without being overwhelming or too sparse for the domain.

    Completeness4/5

    The toolset covers core digital humanities workflows including text search, image search, concordancing, collocation analysis, and corpus statistics. Minor gaps exist, such as no direct document retrieval or metadata lookup tools, but agents can likely work around these using the provided search and analysis functions.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides access to Sweden's National Library (Kungliga biblioteket) open APIs, enabling search and retrieval of 20M+ bibliographic records, 10M+ cultural heritage objects, 2M+ research publications, and linked data through 52 tools across 10 endpoints.
      3
      -
    • A
      license
      A
      quality
      C
      maintenance
      Enables searching and accessing OCR text from millions of digitized documents in Gallica, the digital library of the Bibliothèque nationale de France, through MCP tools for text search, snippet retrieval, and full-text download.
      3
      1
      Apache 2.0
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables full-text search and retrieval of Kansallisarkisto's machine-transcribed archival corpora, including medieval charters from Diplomatarium Fennicum, with filters and stemming support.
      Apache 2.0
    • A
      license
      A
      quality
      C
      maintenance
      Provides AI assistants with programmatic access to the National Library of Sweden's digitized historical newspapers, enabling full-text search, filtering, timelines, and image retrieval across over 2.2 million pages.
      5
      1
      MIT