Apache Jena SPARQL MCP server

Provides a bridge between AI agents and Apache Jena for executing SPARQL queries, performing updates, and accessing RDF data stored in Jena Fuseki servers with secure API key authentication.
Back to servers
Provider
ramuzes
Release date
Mar 19, 2025
Language
TypeScript

The MCP Server for Apache Jena provides a connection between AI agents and Apache Jena, enabling SPARQL query capabilities for RDF data. This server implements the Model Context Protocol, allowing AI agents like Cursor or Claude to access and query semantic data stored in Jena Fuseki.

Prerequisites

  • Node.js (v16 or later)
  • Apache Jena Fuseki server with your RDF data loaded
  • An AI agent that supports the Model Context Protocol

Installation

Standard Installation

  1. Clone the repository:

    git clone https://github.com/ramuzes/mcp-jena.git
    cd mcp-jena
    
  2. Install dependencies:

    npm install
    
  3. Build the TypeScript code:

    npm run build
    

Docker Installation

  1. Build the Docker image:

    docker build -t mcp-jena .
    
  2. Run with Docker:

    docker run -e JENA_FUSEKI_URL=http://your-jena-server:3030 -e DEFAULT_DATASET=your_dataset mcp-jena
    

Usage

Starting the Server

Run with default settings (localhost:3030 for Jena, 'ds' for dataset):

npm start

Use custom Jena endpoint, dataset, and authentication:

npm start -- --endpoint http://your-jena-server:3030 --dataset your_dataset --username your_username --password your_password

With short flags:

npm start -- -e http://your-jena-server:3030 -d your_dataset -u your_username -p your_password

Configuration

You can configure the server using environment variables:

  • JENA_FUSEKI_URL: URL of your Jena Fuseki server (default: http://localhost:3030)
  • DEFAULT_DATASET: Default dataset name (default: ds)
  • JENA_USERNAME: Username for HTTP Basic authentication
  • JENA_PASSWORD: Password for HTTP Basic authentication
  • PORT: Port for the MCP server (default: 8080)
  • API_KEY: API key for MCP server authentication

Available Tools

The MCP server provides these tools for interacting with Jena:

1. Execute SPARQL Query

Use execute_sparql_query to run SPARQL queries against the Jena dataset.

Example query:

SELECT ?subject ?predicate ?object
WHERE {
  ?subject ?predicate ?object
}
LIMIT 10

2. Execute SPARQL Update

Use execute_sparql_update to modify RDF data in the dataset.

Example update:

PREFIX ex: <http://example.org/>
INSERT DATA {
  ex:subject1 ex:predicate1 "object1" .
  ex:subject2 ex:predicate2 42 .
}

3. List Graphs

Use list_graphs to see all available named graphs in the dataset.

4. SPARQL Query Templates

Use sparql_query_templates to get pre-built templates for various purposes:

  • exploration: Basic data discovery
  • property-paths: Graph navigation patterns
  • statistics: Knowledge graph metrics
  • validation: Data quality checks
  • schema: Structure discovery

Example Queries

Query a Specific Named Graph

SELECT ?subject ?predicate ?object
FROM NAMED <http://example.org/graph1>
WHERE {
  GRAPH <http://example.org/graph1> {
    ?subject ?predicate ?object
  }
}
LIMIT 10

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later