Skip to main content

A Python-based MCP server for MarkLogic database operations

Project description

MarkLogic MCP Server

A Python-based MCP (Model-Controller-Processor) server for MarkLogic database operations. This server provides CRUD operations and search functionality for MarkLogic documents through a standardized interface using the MarkLogic REST API.

Features

  • Document CRUD operations (Create, Read, Update, Delete)
  • Document search with string and structured queries
  • Collection management
  • Database information retrieval
  • TOML-based configuration
  • Comprehensive logging
  • Full REST API support

Prerequisites

  • Python 3.7+
  • MarkLogic Server (installed and running)
  • Access to a MarkLogic database with appropriate permissions
  • REST API instance configured on MarkLogic server

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/marklogic-mcp.git
cd marklogic-mcp
  1. Install dependencies:
pip install -r requirements.txt
  1. Configure your server:
cp pyproject.toml.example pyproject.toml

Edit the pyproject.toml file with your MarkLogic connection details:

[tool.marklogic]
host = "localhost"
port = 8000
user = "your-username"
password = "your-password"

[tool.marklogic.logging]
level = "INFO"
format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"

Usage

  1. Start the MCP server:
python marklogic_mcp_server.py
  1. The server provides the following operations:

Create Document

create_document(uri: str, content: dict, collections: list = None)

Read Document

read_document(uri: str)

Update Document

update_document(uri: str, content: dict, collections: list = None)

Delete Document

delete_document(uri: str)

Search Documents

search_documents(
    query: str = None,           # String query (e.g., "marklogic and python")
    structured_query: dict = None,  # Structured query in JSON format
    start: int = 1,             # Starting position
    page_length: int = 10       # Number of results per page
)

Get Database Information

get_database_info()

Example Usage

# Create a document
response = create_document(
    uri="/documents/example.json",
    content={"title": "Example", "content": "This is a test"},
    collections=["test-collection"]
)

# Search using string query
response = search_documents(
    query="marklogic and python",
    start=1,
    page_length=10
)

# Search using structured query
response = search_documents(
    structured_query={
        "query": {
            "term-query": {
                "text": ["marklogic"]
            }
        }
    },
    start=1,
    page_length=10
)

Configuration

The server is configured using pyproject.toml. Here are the available configuration options:

[tool.marklogic]
host = "localhost"      # MarkLogic server host
port = 8000            # MarkLogic server port
user = "admin"         # MarkLogic username
password = "admin"     # MarkLogic password

[tool.marklogic.logging]
level = "INFO"         # Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"  # Log format

Response Format

All operations return a dictionary with a status field indicating success or failure:

# Success response
{
    "status": "success",
    "message": "Operation result message",
    "content": "Document content (for read operations)",
    "total": "Total results (for search operations)",
    "results": "Search results array",
    "facets": "Search facets (if available)"
}

# Error response
{
    "status": "error",
    "message": "Error message"
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

marklogic_mcp-0.1.0.dev1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

marklogic_mcp-0.1.0.dev1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file marklogic_mcp-0.1.0.dev1.tar.gz.

File metadata

  • Download URL: marklogic_mcp-0.1.0.dev1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for marklogic_mcp-0.1.0.dev1.tar.gz
Algorithm Hash digest
SHA256 f19299ad0b2fa18304f71cec15bc8314cb4e5cfebae96c009fae822166b4e4d8
MD5 fe87e73b29d82a39871addcb34266199
BLAKE2b-256 b3edc9d60fb0202061129d0018ac9839a9f3909c8e75b17b5b5b3d5230179ffc

See more details on using hashes here.

File details

Details for the file marklogic_mcp-0.1.0.dev1-py3-none-any.whl.

File metadata

File hashes

Hashes for marklogic_mcp-0.1.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 09743c3342160b63601cd15ea695833e03f068e5dbc53383714a1b7e4f327a6e
MD5 4932de0fd1566e02fd4c7f24d4528019
BLAKE2b-256 3a20fc381a683ce2ada2a1c0055a847bb57508e404ce4e6e5dd9b4a843088637

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page