Caution
This is an experimental MCP server. This is only intended for educational purposes so use at your own risk.
A Model Context Protocol (MCP) server that connects to SpiceDB via its HTTP API for permission management. This server enables LLMs like Claude to interact with your SpiceDB instance to query, manage, and understand your permission system.
Note
Everything in this repo was almost entirely created by Claude 3.5 Sonnet. Any quirks, unusual patterns, or potential errors are direct artifacts of LLM-based generation.
-
Resources:
- Schema retrieval with associated object definition resources
- Relationship queries with interactive relationship resources
- Object definitions with detailed type information
-
Tools:
- Read schema with object definition resources
- Read relationships with relationship resources
- Check permissions with detailed authorization traces and explanations
- Look up resources by subject with permission context
- Look up subjects by resource with permission details
- Write relationships with validation
- Node.js 16+
- SpiceDB instance
- SpiceDB API key
-
Clone this repository:
git clone https://github.com/authzed/spicedb-mcp-server.git cd spicedb-mcp-server
-
Install dependencies:
npm install # or yarn install
-
Configure your environment:
Create a
.env
file with your SpiceDB connection details:# SpiceDB HTTP API endpoint (the default port for HTTP API is typically 8443) SPICEDB_ENDPOINT=http://localhost:8443 # or for TLS: https://spicedb.example.com SPICEDB_API_KEY=your-api-key-here SPICEDB_USE_TLS=false
-
Build the server:
npm run build # or yarn build
Run the server from the command line:
node build/index.js
# or
npm start
# or
yarn start
-
Edit your Claude for Desktop configuration file:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Windows:
%APPDATA%\Claude\claude_desktop_config.json
-
Add the SpiceDB MCP server to the
mcpServers
section:
{
"mcpServers": {
"spicedb": {
"command": "node",
"args": [
"/path/to/spicedb-mcp-server/build/index.js"
],
"env": {
"SPICEDB_ENDPOINT": "http://localhost:8443",
"SPICEDB_API_KEY": "your-api-key-here",
"SPICEDB_USE_TLS": "false"
}
}
}
}
-
Restart Claude for Desktop
-
View logs for Claude Desktop and SpiceDB MCP
macOS:
/Users/<your username>/Library/Logs/Claude/mcp-server-spicedb.log
and/Users/<your username>/Library/Logs/Claude/mcp.log
Note
A SpiceDB instance with a schema and relationship data should be running with the flag --http-enabled
"Does user:alice have the permission view on document:report1?"
"What documents can user:bob read?"
"Who has edit permission on project:website?"
"Can you explain the permission system schema?"
"Setup the following scenario by writing the appropriate relationships: there is a new role "auditor" and user jared has that role"
"The project pied_piper is now deprecated. Find all users who have some form of access to it and create a comprehensive list of users and their access"
spicedb://schema
- Get the current schema, returns both schema text and object definition resourcesspicedb://relationships/{resourceType?}/{resourceId?}/{relation?}/{subjectType?}/{subjectId?}/{subjectRelation?}
- Query relationships with optional filtersspicedb://definition/{objectType}
- Get detailed definition for a specific object type
read-schema
- Retrieves the current schema with object definition resourcesread-relationships
- Queries relationships based on filter parameters, returns both text output and relationship resourcescheck-permission
- Checks if a subject has a specific permission on a resource with debug tracing and explanations of the authorization decisionlookup-resources
- Finds resources where a subject has a specific permission, optimized for array response formatslookup-subjects
- Finds subjects with a specific permission on a resource, optimized for array response formatswrite-relationship
- Creates, updates, or deletes a relationship with validation
lookup-resources-for-subject
- Finds resources a subject can accesslookup-subjects-for-resource
- Finds subjects that can access a resourceexplain-permission-check
- Explains a permission check resultanalyze-schema
- Analyzes the current permission schema
Relationships in SpiceDB are formatted as:
resourceType:resourceId#relation@subjectType:subjectId[#subjectRelation]
This format combines:
- Resource:
resourceType:resourceId
(the object being accessed) - Relation:
#relation
(the relationship type) - Subject:
subjectType:subjectId
(the actor accessing the resource) - Optional subject relation:
#subjectRelation
(for computed subjects)
Examples:
document:report#viewer@user:alice
- User alice is a viewer of the report documentproject:website#admin@group:engineering#member
- Members of the engineering group are admins of the website projectresource:promserver#viewer@usergroup:engineering#member
- Members of the engineering user group are viewers of the promserver resource
The SpiceDB MCP server implements the full Model Context Protocol connection lifecycle:
-
Initialization Request: When a client connects, it sends an
initialize
request containing:- Protocol version
- Client information (name, version)
- Client capabilities
-
Server Response: The server responds with:
- Protocol version
- Server information (name, version)
- Server capabilities (resources, tools, prompts, etc.)
-
Initialization Confirmation: The client sends an
initialized
notification to confirm the connection. -
Message Exchange: Normal operation begins with the exchange of requests and responses.
-
Termination: When the client disconnects, the server cleans up resources.
The server logs details about this lifecycle to stderr, which you can observe when running the server directly.
This server provides the following capabilities:
- Resources: Exposes schema, relationships, and definitions as readable and navigable resources
- Tools: Provides tools for interacting with SpiceDB with rich responses including resources
- Prompts: Offers template prompts for common permission-related tasks and analysis
- Debug Tracing: Includes detailed authorization decision traces and explanations
- Response Formats: Support for both legacy and array-based SpiceDB API response formats
- Logging: Provides structured logging for troubleshooting and monitoring