-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add enclave mcp package #1390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()) | ||
|
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() | ||
| } | ||
|
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}` }] } | ||
|
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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.