Model Context Protocol Ontology

tl;dr : Model Context Protocol expressed in RDF because WWW.

This is a first pass, most of the heavy lifting done by Claude, so while it looks plausible, it might not be. I've not had a play yet.

There would be more but Message limit reached for Claude 3.5 Sonnet until 9 PM.

Get your Linked Data on!

Source Repo (GitHub)

Abstract

The Model Context Protocol (MCP) Ontology provides a formal vocabulary for describing interactions between AI language models and external context providers. It defines core concepts for resources, tools, prompts and messaging that enable structured communication between AI systems and domain-specific data sources.

Files

Namespace

http://purl.org/stuff/mcp/

Preferred prefix: mcp

Overview

This ontology models the key components of the Model Context Protocol ecosystem:

Servers
Implementations that provide resources, tools and prompts to clients
Clients
Applications that connect to servers and facilitate interaction with language models
Resources
Contextual information made available to language models
Tools
Executable functions that allow models to perform actions
Prompts
Templates that structure interactions with language models

Classes

mcp:Server
An MCP server implementation
mcp:Client
An MCP client implementation
mcp:Resource
A resource accessible via MCP
mcp:Tool
A tool callable via MCP
mcp:Prompt
A prompt template
mcp:Message
A message in an MCP conversation
mcp:Content
Content of an MCP message
mcp:TextContent
Text content in a message
mcp:ImageContent
Image content in a message
mcp:Role
Role of a participant in communication
mcp:Capability
A supported capability

Properties

mcp:hasCapability
Links implementations to their capabilities
mcp:providesResource
Links servers to their resources
mcp:providesTool
Links servers to their tools
mcp:providesPrompt
Links servers to their prompts
mcp:hasContent
Links messages to their content
mcp:hasRole
Links messages to sender roles

RAG Integration Patterns

The MCP ontology supports Retrieval-Augmented Generation (RAG) through structured access to context resources. Here are key integration patterns:

Resource Discovery

PREFIX mcp: <http://purl.org/stuff/mcp/>

SELECT ?resource ?name ?type WHERE {
  ?server a mcp:Server ;
          mcp:providesResource ?resource .
  ?resource mcp:name ?name ;
           mcp:mimeType ?type .
}

Tool Discovery

PREFIX mcp: <http://purl.org/stuff/mcp/>

SELECT ?tool ?desc WHERE {
  ?server mcp:providesTool ?tool .
  ?tool mcp:description ?desc .
  FILTER(CONTAINS(LCASE(?desc), "text analysis"))
}

Hybrid Search Implementation

Combining vector similarity with graph traversal:

from rdflib import Graph, Namespace
from sentence_transformers import SentenceTransformer

MCP = Namespace("http://purl.org/stuff/mcp/")
g = Graph()
g.parse("mcp-store.ttl")
encoder = SentenceTransformer('all-MiniLM-L6-v2')

# Index resources
resources = []
for s,p,o in g.triples((None, MCP.text, None)):
    resources.append({
        'id': str(s),
        'text': str(o),
        'embedding': encoder.encode(str(o))
    })

# Query with RAG
def query_with_context(question):
    q_embedding = encoder.encode(question)
    relevant = find_similar(q_embedding, resources)

    context = []
    for r in relevant:
        # Get metadata
        meta = g.query("""
            SELECT ?name ?type WHERE {
                ?res mcp:name ?name ;
                     mcp:mimeType ?type .
                FILTER(?res = <%s>)
            }""" % r['id'])
        context.append({
            'text': r['text'],
            'metadata': list(meta)[0]
        })

    return build_prompt(question, context)

Best Practices

  • Use SPARQL property paths to traverse related resources
  • Maintain vector indices for text content
  • Cache frequent query patterns
  • Implement real-time updates through change notifications
  • Track resource versions in the graph