Overview
Superset uses the Model Context Protocol (MCP) to provide AI agents with tools and resources for interacting with the desktop app, managing workspaces, and automating workflows. Packages:packages/mcp- Superset cloud MCP server (workspace/device management)packages/desktop-mcp- Desktop automation MCP server (UI testing, browser control)
MCP Protocol Basics
MCP servers expose tools and resources that AI agents can invoke:- Tools: Functions the agent can call (e.g.,
create_workspace,click,navigate) - Resources: Data the agent can read (e.g., workspace details, app context)
- Prompts: Pre-configured prompts for common tasks
Server Initialization
MCP servers are created using@modelcontextprotocol/sdk:
Tool Registration
Tools are registered with Zod schemas for input validation:Desktop MCP Server
Package:@superset/desktop-mcp
Source: packages/desktop-mcp/src/mcp/mcp-server.ts:5
Provides browser automation and UI testing tools.
Server Setup
Available Tools
Source:packages/desktop-mcp/src/mcp/tools/index.ts:20
All tools defined in packages/desktop-mcp/src/mcp/tools/:
take_screenshot- Capture app screenshotsinspect_dom- Inspect DOM elementsclick- Click UI elementstype_text- Type text into inputssend_keys- Send keyboard shortcutsget_console_logs- Retrieve console logsevaluate_js- Execute JavaScript in appnavigate- Navigate to URLsget_window_info- Get window metadata
Tool Example: click
Source: packages/desktop-mcp/src/mcp/tools/click/click.ts:43
Usage Example
Agents invoke desktop MCP tools via the protocol:Superset MCP Server
Package:@superset/mcp
Source: packages/mcp/src/server.ts:4
Provides workspace, device, and task management tools.
Server Setup
Available Tools
Source:packages/mcp/src/tools/index.ts:20
All tools organized by category:
Device Tools
list_devices- List registered deviceslist_workspaces- List workspaces on a devicecreate_workspace- Create new workspace(s)switch_workspace- Switch active workspacedelete_workspace- Delete workspaceupdate_workspace- Update workspace configlist_projects- List projectsget_app_context- Get current app stateget_workspace_details- Get workspace metadatastart_agent_session- Start agent session on device
Task Tools
create_task- Create taskupdate_task- Update tasklist_tasks- List tasksget_task- Get task detailsdelete_task- Delete tasklist_task_statuses- List available statuses
Organization Tools
list_members- List organization members
Tool Example: create_workspace
Source: packages/mcp/src/tools/devices/create-workspace/create-workspace.ts:20
Authentication Context
MCP tools use a context pattern for authentication:Building Custom MCP Servers
1. Create Server Structure
2. Define Tools
src/tools/my-tool.ts:3. Register Tools
src/tools/index.ts:4. Create Server
src/server.ts:5. Create CLI Entry Point
src/bin.ts:6. Build and Test
MCP Server Configuration
Add your MCP server to.mcp.json:
Server Lifecycle
Initialization
- Server process starts via stdio transport
- MCP SDK establishes connection
- Tools are registered
- Server sends
initializednotification
Tool Invocation
- Client sends
tools/callrequest - Server validates input with Zod schema
- Tool handler executes
- Server returns result or error
Shutdown
- Client closes connection
- Server cleanup handlers run
- Process exits
Testing MCP Servers
Unit Testing Tools
Integration Testing
Use@modelcontextprotocol/inspector for manual testing:
Error Handling
Return Errors from Tools
Throw Errors for Server Issues
Best Practices
1. Tool Naming
- Use
snake_casefor tool names - Be descriptive:
create_workspacenotcreate - Prefix with category:
github_create_issue
2. Input Validation
- Always use Zod schemas
- Provide clear descriptions for each parameter
- Set reasonable defaults
- Mark optional parameters explicitly
3. Error Messages
- Return user-friendly error messages
- Include context: what failed and why
- Suggest fixes when possible
4. Tool Descriptions
- Start with action verb: “Create”, “List”, “Update”
- Explain what the tool does in plain language
- Include use cases in description
5. Response Format
- Always return
{ content: [...] } - Use
type: "text"for messages - Set
isError: truefor user-facing errors
Example: Full Custom MCP Server
src/server.ts:Next Steps
Desktop API
Electron IPC APIs for local operations
tRPC Endpoints
Cloud tRPC API reference
MCP SDK Docs
Official MCP documentation
Example MCP Servers
Reference implementations