Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,20 @@
"evm:clean": "cd packages/enclave-contracts && pnpm clean:deployments",
"evm:coverage": "cd packages/enclave-contracts && pnpm coverage",
"evm:release": "cd packages/enclave-contracts && pnpm release",
"mcp:build": "cd packages/enclave-mcp && pnpm build",
"mcp:release": "cd packages/enclave-mcp && pnpm release",
"react:build": "cd packages/enclave-react && pnpm build",
"sdk:build": "cd packages/enclave-sdk && pnpm build",
"sdk:test": "cd packages/enclave-sdk && pnpm test",
"sdk:release": "cd packages/enclave-sdk && pnpm release",
"wasm:release": "cd crates/wasm && pnpm release",
"config:release": "cd packages/enclave-config && pnpm release",
"react:release": "cd packages/enclave-react && pnpm release",
"npm:release": "pnpm build && pnpm config:release && pnpm evm:release && pnpm wasm:release && pnpm sdk:release && pnpm react:release",
"npm:release": "pnpm build && pnpm config:release && pnpm evm:release && pnpm wasm:release && pnpm sdk:release && pnpm react:release && pnpm mcp:release",
"support:build": "cd crates/support && ./scripts/build.sh",
"build": "pnpm compile",
"wasm:build": "cd ./crates/wasm && pnpm build",
"build:ts": "pnpm evm:build && pnpm sdk:build && pnpm react:build",
"build:ts": "pnpm evm:build && pnpm sdk:build && pnpm react:build && pnpm mcp:build",
"template:build": "cd templates/default && pnpm compile",
"prepare-publish": "tsx .github/scripts/prepareForNpmPublishing.ts"
},
Expand Down
93 changes: 93 additions & 0 deletions packages/enclave-mcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# @enclave-e3/mcp

MCP server for [Enclave](https://enclave.gg) documentation. Allows AI assistants to answer questions about Enclave by fetching content directly from [docs.enclave.gg](https://docs.enclave.gg).

## Requirements

- Node.js **>=18.20.0** — required for ESM JSON import attributes, global `fetch`, and top-level await used by the `enclave-mcp` CLI.

## Tools

| Tool | Description |
|------|-------------|
| `list_docs` | List all available documentation pages |
| `read_doc` | Read a specific page by slug (e.g. `introduction`, `ciphernode-operators/running`) |
| `search_docs` | Search for a keyword across all pages |

## Integration

### Claude Desktop

Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):

```json
{
"mcpServers": {
"enclave-docs": {
"command": "npx",
"args": ["-y", "@enclave-e3/mcp"]
}
}
}
```

Restart Claude Desktop. The tools will be available automatically.

### VS Code (Continue)

Add a file `.continue/mcpServers/enclave.yaml` in your project:

```yaml
name: Enclave Docs
version: 0.1.0
schema: v1
mcpServers:
- name: enclave-docs
command: npx
args:
- -y
- "@enclave-e3/mcp"
```

### Cursor

Edit `~/.cursor/mcp.json`:

```json
{
"mcpServers": {
"enclave-docs": {
"command": "npx",
"args": ["-y", "@enclave-e3/mcp"]
}
}
}
```

### Windsurf

Edit `~/.codeium/windsurf/mcp_config.json`:

```json
{
"mcpServers": {
"enclave-docs": {
"command": "npx",
"args": ["-y", "@enclave-e3/mcp"]
}
}
}
```

## Usage

Once configured, ask your AI assistant questions like:

- *"What is an E3 in Enclave?"*
- *"How do I run a ciphernode?"*
- *"Explain the Enclave architecture"*
- *"Search the enclave docs for threshold encryption"*

## License

LGPL-3.0-only
39 changes: 39 additions & 0 deletions packages/enclave-mcp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@enclave-e3/mcp",
"version": "0.1.0",
"description": "MCP server for Enclave documentation",
"type": "module",
"bin": {
"enclave-mcp": "./dist/index.js"
},
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/gnosisguild/enclave.git",
"directory": "packages/enclave-mcp"
},
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"prerelease": "pnpm build",
"release": "pnpm publish --access=public"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.10.2",
"node-html-parser": "^7.0.1",
"zod": "^3.23.8"
},
"devDependencies": {
"tsup": "^8.5.0",
"typescript": "5.8.3"
},
"engines": {
"node": ">=18.20.0"
},
"license": "LGPL-3.0-only"
Comment thread
cedoor marked this conversation as resolved.
}
216 changes: 216 additions & 0 deletions packages/enclave-mcp/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
// SPDX-License-Identifier: LGPL-3.0-only
//
// This file is provided WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
import { parse } from 'node-html-parser'
import { z } from 'zod'
import pkg from '../package.json' with { type: 'json' }

const { version } = pkg

const BASE_URL = 'https://docs.enclave.gg'
const FETCH_TIMEOUT_MS = 10_000

interface DocPage {
slug: string
title: string
url: string
}

// Fallback corpus used when the sitemap cannot be fetched.
const STATIC_DOC_PAGES: DocPage[] = [
{ slug: 'introduction', title: 'Introduction', url: '/introduction' },
{ slug: 'what-is-e3', title: 'What is an E3?', url: '/what-is-e3' },
{ slug: 'architecture-overview', title: 'Architecture Overview', url: '/architecture-overview' },
{ slug: 'computation-flow', title: 'E3 Computation Flow', url: '/computation-flow' },
{ slug: 'use-cases', title: 'Use Cases', url: '/use-cases' },
{ slug: 'building-with-enclave', title: 'Building with Enclave', url: '/building-with-enclave' },
{ slug: 'best-practices', title: 'Best Practices', url: '/best-practices' },
{ slug: 'installation', title: 'Installation', url: '/installation' },
{ slug: 'quick-start', title: 'Quick Start', url: '/quick-start' },
{ slug: 'hello-world-tutorial', title: 'Hello World Tutorial', url: '/hello-world-tutorial' },
{ slug: 'project-template', title: 'Project Template', url: '/project-template' },
{ slug: 'sdk', title: 'Enclave SDK', url: '/sdk' },
{ slug: 'setting-up-server', title: 'Setting Up the Server', url: '/setting-up-server' },
{ slug: 'noir-circuits', title: 'Noir Circuits', url: '/noir-circuits' },
{ slug: 'getting-started', title: 'Getting Started (Build an E3)', url: '/getting-started' },
{ slug: 'write-secure-program', title: 'Writing the Secure Process', url: '/write-secure-program' },
{ slug: 'write-e3-contract', title: 'Writing the E3 Program Contract', url: '/write-e3-contract' },
{ slug: 'compute-provider', title: 'Compute Provider Setup', url: '/compute-provider' },
{ slug: 'putting-it-together', title: 'Putting It All Together', url: '/putting-it-together' },
{ slug: 'whitepaper', title: 'White Paper', url: '/whitepaper' },
{ slug: 'ciphernode-operators', title: 'Ciphernode Operators Overview', url: '/ciphernode-operators' },
{ slug: 'ciphernode-operators/running', title: 'Running a Ciphernode', url: '/ciphernode-operators/running' },
{ slug: 'ciphernode-operators/registration', title: 'Registration & Licensing', url: '/ciphernode-operators/registration' },
{ slug: 'ciphernode-operators/tickets-and-sortition', title: 'Tickets & Sortition', url: '/ciphernode-operators/tickets-and-sortition' },
{ slug: 'ciphernode-operators/exits-and-slashing', title: 'Exits, Rewards & Slashing', url: '/ciphernode-operators/exits-and-slashing' },
{ slug: 'CRISP/introduction', title: 'CRISP Introduction', url: '/CRISP/introduction' },
{ slug: 'CRISP/setup', title: 'CRISP Setup', url: '/CRISP/setup' },
{ slug: 'CRISP/running-e3', title: 'CRISP Running an E3 Program', url: '/CRISP/running-e3' },
]

function fetchWithTimeout(url: string): Promise<Response> {
const controller = new AbortController()
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS)
return fetch(url, { signal: controller.signal }).finally(() => clearTimeout(timer))
}

// Attempt to build the page corpus from the sitemap so it stays current
// without manual updates. Falls back to STATIC_DOC_PAGES on any failure.
async function loadDocPages(): Promise<DocPage[]> {
try {
const response = await fetchWithTimeout(`${BASE_URL}/sitemap.xml`)
if (!response.ok) return STATIC_DOC_PAGES
const xml = await response.text()
const root = parse(xml)
const locs = root.querySelectorAll('loc').map((el) => el.text.trim())
if (locs.length === 0) return STATIC_DOC_PAGES
return locs
.filter((loc) => loc.startsWith(BASE_URL))
.map((loc) => {
const path = loc.slice(BASE_URL.length) || '/'
const slug = path.replace(/^\//, '')
const known = STATIC_DOC_PAGES.find((p) => p.slug === slug)
const title =
known?.title ??
slug
.split('/')
.map((s) => s.replace(/-/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase()))
.join(' / ')
return { slug, title, url: path }
})
} catch {
return STATIC_DOC_PAGES
}
}

async function fetchDocPage(url: string): Promise<string> {
const fullUrl = `${BASE_URL}${url}`
const response = await fetchWithTimeout(fullUrl)
if (!response.ok) {
throw new Error(`Failed to fetch ${fullUrl}: ${response.status} ${response.statusText}`)
}
const html = await response.text()
const root = parse(html)

// Remove nav, header, footer, scripts, styles
root.querySelectorAll("nav, header, footer, script, style, [aria-hidden='true']").forEach((el) => el.remove())
Comment thread
cedoor marked this conversation as resolved.

// Try to get the main article content
const article = root.querySelector('article') ?? root.querySelector('main') ?? root.querySelector('.nextra-content')
const content = article ?? root

return content.text.replace(/\n{3,}/g, '\n\n').trim()
}
Comment thread
cedoor marked this conversation as resolved.

const DOC_PAGES = await loadDocPages()

const server = new McpServer({
name: 'enclave-docs',
version,
})

// Resource: list all doc pages
server.registerResource('docs-index', 'docs://index', { description: 'Index of all Enclave documentation pages' }, async () => ({
contents: [
{
uri: 'docs://index',
text: DOC_PAGES.map((p) => `- [${p.title}](docs://${p.slug})`).join('\n'),
mimeType: 'text/markdown',
},
],
}))

// Resource: individual doc pages
for (const page of DOC_PAGES) {
server.registerResource(page.slug, `docs://${page.slug}`, { description: page.title }, async () => {
const content = await fetchDocPage(page.url)
return {
contents: [{ uri: `docs://${page.slug}`, text: content, mimeType: 'text/plain' }],
}
})
}

// Tool: read a specific doc page
server.registerTool(
'read_doc',
{
description: 'Fetch and read a specific Enclave documentation page by slug',
inputSchema: z.object({ slug: z.string().describe("Page slug, e.g. 'introduction', 'ciphernode-operators/running'") }),
},
async ({ slug }) => {
const page = DOC_PAGES.find((p) => p.slug === slug)
if (!page) {
const available = DOC_PAGES.map((p) => p.slug).join(', ')
return { content: [{ type: 'text', text: `Page "${slug}" not found. Available: ${available}` }], isError: true }
}
const content = await fetchDocPage(page.url)
return { content: [{ type: 'text', text: `# ${page.title}\n\n${content}` }] }
Comment thread
cedoor marked this conversation as resolved.
},
)

// Tool: search across all docs
server.registerTool(
'search_docs',
{
description: 'Search for a keyword or phrase across all Enclave documentation pages',
inputSchema: z.object({ query: z.string().describe('Search query') }),
},
async ({ query }) => {
if (!query.trim()) {
return { content: [{ type: 'text', text: 'Query must not be empty.' }], isError: true }
}

const lower = query.toLowerCase()
const results: string[] = []
const failures: string[] = []

await Promise.all(
DOC_PAGES.map(async (page) => {
try {
const content = await fetchDocPage(page.url)
if (content.toLowerCase().includes(lower)) {
const idx = content.toLowerCase().indexOf(lower)
const start = Math.max(0, idx - 150)
const end = Math.min(content.length, idx + 300)
const snippet = content.slice(start, end).replace(/\n+/g, ' ').trim()
results.push(`## ${page.title}\nURL: ${BASE_URL}${page.url}\n\n...${snippet}...`)
}
} catch {
failures.push(`${page.title} (${page.url})`)
}
}),
)

const failureSummary = failures.length > 0 ? `\n\n---\n⚠️ Failed to load ${failures.length} page(s): ${failures.join(', ')}` : ''

if (results.length === 0 && failures.length === DOC_PAGES.length) {
return { content: [{ type: 'text', text: `All page fetches failed. Check network connectivity.${failureSummary}` }], isError: true }
}

if (results.length === 0) {
return { content: [{ type: 'text', text: `No results found for "${query}".${failureSummary}` }] }
}

return {
content: [
{
type: 'text',
text: `Found ${results.length} page(s) matching "${query}":\n\n${results.join('\n\n---\n\n')}${failureSummary}`,
},
],
}
},
)

// Tool: list all available doc pages
server.registerTool('list_docs', { description: 'List all available Enclave documentation pages' }, async () => {
const list = DOC_PAGES.map((p) => `- **${p.title}** → slug: \`${p.slug}\``).join('\n')
return { content: [{ type: 'text', text: `# Enclave Documentation Pages\n\n${list}` }] }
})

const transport = new StdioServerTransport()
await server.connect(transport)
12 changes: 12 additions & 0 deletions packages/enclave-mcp/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"outDir": "dist"
},
"include": ["src"]
}
Loading
Loading