SAI MCP Server in WebAssembly Go

SAI MCP Server in WebAssembly Go

Sai Mcp Server

example42

Developer Tools
Visit Server

README

SAI MCP Server in WebAssembly Go

This project implements a Management Control Protocol (MCP) server in WebAssembly Go that executes the "sai" command and handles its output and exit code. The implementation is compatible with the wpcli framework.

Overview

The SAI MCP Server is a WebAssembly module that provides an interface for executing the SAI command line tool from JavaScript. It handles:

  1. Executing the "sai" command with provided arguments
  2. Capturing stdout, stderr, and exit code separately
  3. Parsing output formats (YAML, JSON, or plain text)
  4. Returning structured results to the JavaScript environment

Project Structure

sai_mcp/
├── cmd/
│   └── main/
│       ├── main.go           # WebAssembly entry point and JavaScript interface
│       ├── sai_executor.go   # SAI command execution logic
│       ├── parser.go         # Output format parsing (YAML, JSON)
│       └── main_test.go      # Test cases for the implementation
└── go.mod                    # Go module definition

Implementation Details

WebAssembly Interface

The WebAssembly module exposes a JavaScript function executeSai that takes command arguments and returns an object with the following properties:

  • stdout: Standard output from the command
  • stderr: Standard error output from the command
  • exitCode: Exit code (0 for success, non-zero for errors)
  • parsedOutput: (Optional) Parsed output if format is recognized
  • format: (Optional) Detected format of the output (json, yaml, text)

SAI Command Execution

The SaiExecutor component handles the actual execution of the SAI command:

  • Creates a new process for the SAI command
  • Captures stdout and stderr separately
  • Extracts the exit code from the process
  • Handles execution errors appropriately

Output Parsing

The implementation includes parsers for different output formats:

  • JSON: Parses JSON output into a structured object
  • YAML: Parses YAML output into a structured object
  • Text: Returns plain text as-is

The format is automatically detected based on the command and output content.

Building the WebAssembly Module

To build the WebAssembly module:

GOOS=js GOARCH=wasm go build -o sai_mcp.wasm ./cmd/main

This will produce a WebAssembly file (sai_mcp.wasm) that can be loaded by the wpcli framework.

Integration with wpcli

To integrate with the wpcli framework:

  1. Place the WebAssembly module in the appropriate plugin directory
  2. Create a configuration file that defines the available commands
  3. Register the plugin with the wpcli framework

Example configuration:

name: sai
description: SAI command line tool integration
uuid: sai-plugin-uuid
versions:
  - version: 1.0.0
    wasm: sai_mcp.wasm
    conf: sai_config.yaml
commands:
  - name: install
    description: Install software
    usage: install <software> [options]
    args:
      - name: software
        type: string
        description: The name of the software to install
        required: true
  # Additional commands...

Usage Examples

From JavaScript:

// Execute a SAI command
const result = executeSai("install", "nginx");

// Check the result
console.log("Exit code:", result.exitCode);
console.log("Output:", result.stdout);
if (result.stderr) {
  console.error("Error:", result.stderr);
}

// Access parsed output if available
if (result.parsedOutput) {
  console.log("Parsed output:", result.parsedOutput);
}

Error Handling

The implementation handles various error scenarios:

  • Command not found: Returns appropriate error in stderr and non-zero exit code
  • Command execution failure: Captures error message in stderr and returns the actual exit code
  • Output parsing errors: Falls back to returning raw output if parsing fails

Testing

The implementation includes comprehensive tests that verify:

  • Basic command execution
  • Output format detection and parsing
  • Error handling
  • Exit code propagation

To run the tests (requires native Go environment, not WebAssembly):

go test ./cmd/main -v

Limitations and Future Improvements

  • The current implementation assumes the SAI command is available in the PATH
  • Output format detection is based on simple heuristics and could be improved
  • More sophisticated parsing could be added for specific SAI commands
  • WebAssembly has limitations regarding file system access and process execution

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
MCP Package Docs Server

MCP Package Docs Server

Facilitates LLMs to efficiently access and fetch structured documentation for packages in Go, Python, and NPM, enhancing software development with multi-language support and performance optimization.

Featured
Local
TypeScript
Claude Code MCP

Claude Code MCP

An implementation of Claude Code as a Model Context Protocol server that enables using Claude's software engineering capabilities (code generation, editing, reviewing, and file operations) through the standardized MCP interface.

Featured
Local
JavaScript
@kazuph/mcp-taskmanager

@kazuph/mcp-taskmanager

Model Context Protocol server for Task Management. This allows Claude Desktop (or any MCP client) to manage and execute tasks in a queue-based system.

Featured
Local
JavaScript
Linear MCP Server

Linear MCP Server

Enables interaction with Linear's API for managing issues, teams, and projects programmatically through the Model Context Protocol.

Featured
JavaScript
mermaid-mcp-server

mermaid-mcp-server

A Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images.

Featured
JavaScript
Jira-Context-MCP

Jira-Context-MCP

MCP server to provide Jira Tickets information to AI coding agents like Cursor

Featured
TypeScript
Linear MCP Server

Linear MCP Server

A Model Context Protocol server that integrates with Linear's issue tracking system, allowing LLMs to create, update, search, and comment on Linear issues through natural language interactions.

Featured
JavaScript
Sequential Thinking MCP Server

Sequential Thinking MCP Server

This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.

Featured
Python