mcp-golang-wasm-example
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-golang-wasm-examplewhat's the current time?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Go WASM Server
A Model Context Protocol (MCP) server implementation in Go that runs in the browser via WebAssembly. This project demonstrates how to build an MCP server that can be executed client-side using WASM, enabling streamable HTTP communication without external dependencies.
๐ Features
Pure Go Implementation: Built using Go's standard library with no external dependencies
WebAssembly Support: Runs entirely in the browser via WASM
MCP Protocol Compliant: Implements the Model Context Protocol specification (version 2024-11-05)
Go WASM Module: Compiles to WebAssembly and exposes JavaScript functions
JavaScript Bridge: Handles communication between the browser and WASM
JSON-RPC Protocol: Standard request/response pattern for tool invocation
MCP Compliance: Follows the Model Context Protocol specification
Related MCP server: MCP Playground
๐ Quick Start
Prerequisites
Go 1.21 or higher
Python 3 (for local HTTP server)
Modern web browser with WebAssembly support
Or use the included Dev Container for a pre-configured environment
Using Dev Container (Recommended)
This project includes a Dev Container configuration for VS Code. You do not need to install Go or Python locally.
Steps:
Open the project in VS Code.
If prompted, "Reopen in Container" (or use the Command Palette:
Dev Containers: Reopen in Container).The container will build with Go and Python pre-installed, and VS Code extensions for Go and Python enabled.
Use the integrated terminal to run
make buildandmake serveas described below.
This ensures a consistent development environment for all contributors.
Build and Run
# Build the WASM binary
make build
# Serve the application (builds automatically)
make serve
# Or combine both steps
make runThen open your browser to http://localhost:8080
Manual Build
# Build WASM
GOOS=js GOARCH=wasm go build -o main.wasm main.go
# Copy the Go WASM runtime
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .
# Serve with any HTTP server
python3 -m http.server 8080๐ Usage
Using the Web Interface
Initialize Server: Click "Initialize Server" to establish the MCP connection
List Tools: View all available tools and their schemas
Call Tool: Select a tool from the dropdown, enter parameters (space-separated), and execute the tool. For example, use
add 2 3to get the sum of 2 and 3, or selectgetCurrentTimewith no parameters.
Programmatic Usage
// Send a JSON-RPC request to the MCP server
const request = {
jsonrpc: "2.0",
id: 1,
method: "tools/call",
params: {
name: "add",
arguments: { a: 2, b: 3 }
}
};
const responseJSON = mcpHandleRequest(JSON.stringify(request));
const response = JSON.parse(responseJSON);
console.log(response.result);๐ ๏ธ MCP Protocol Implementation
Supported Methods
Method | Description |
| Initialize the MCP server connection |
| List all available tools |
| Execute a specific tool |
Example Tools
getCurrentTime
{
"name": "getCurrentTime",
"description": "Returns the current time in RFC3339 format",
"inputSchema": {
"type": "object",
"properties": {},
"required": []
}
}add
{
"name": "add",
"description": "Returns the sum of two numbers (a + b)",
"inputSchema": {
"type": "object",
"properties": {
"a": { "type": "number" },
"b": { "type": "number" }
},
"required": ["a", "b"]
}
}๐ง Adding New Tools
๐ง Adding or Using Tools
To use a tool, select it from the dropdown in the UI and enter its parameters (space-separated). For example:
For
add, enter:2 3(returns 5)For
getCurrentTime, no parameters are needed
To add a new tool to the server, define it in NewMCPServer() and implement its handler in handleToolCall(), then rebuild the WASM binary.
๐ Project Structure
.
โโโ main.go # MCP server implementation
โโโ index.html # Web interface
โโโ go.mod # Go module definition
โโโ Makefile # Build automation
โโโ README.md # This file๐จ Design Philosophy
This implementation prioritizes:
Simplicity: No external dependencies, pure Go standard library
Efficiency: Minimal overhead, direct JavaScript bridge
Idiomatic Go: Follows Go best practices and conventions
Browser-First: Designed specifically for WASM/browser environments
MCP Compliance: Adheres to the Model Context Protocol specification
๐ Technical Details
WASM Bridge
The Go code exposes a single function to JavaScript:
js.Global().Set("mcpHandleRequest", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
requestJSON := args[0].String()
response := server.HandleRequest(requestJSON)
return response
}))JSON-RPC 2.0
All communication follows the JSON-RPC 2.0 specification:
Request:
{ jsonrpc, id, method, params }Response:
{ jsonrpc, id, result }or{ jsonrpc, id, error }
Error Codes
Standard JSON-RPC error codes:
-32700: Parse error-32601: Method not found-32602: Invalid params
๐งช Testing
Test the server using the web interface or browser console:
// Initialize
mcpHandleRequest('{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}')
// List tools
mcpHandleRequest('{"jsonrpc":"2.0","id":2,"method":"tools/list"}')
// Call tool
mcpHandleRequest('{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"getCurrentTime"}}')๐ License
MIT License - feel free to use this in your own projects!
๐ค Contributing
Contributions are welcome! Feel free to:
Add new example tools
Improve the UI
Enhance error handling
Add tests
Improve documentation
๐ Resources
Built with โค๏ธ using Go and WebAssembly
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/carljmosca/mcp-golang-wasm-example'
If you have feedback or need assistance with the MCP directory API, please join our Discord server