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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ build-ui:
build-go:
go build -o server ./cmd/server

# Build MCP server binary
build-mcp:
go build -o workflow-mcp-server ./cmd/mcp

# Run all tests with race detection
test:
go test -race ./...
Expand Down
39 changes: 39 additions & 0 deletions cmd/mcp/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Command mcp starts the workflow MCP (Model Context Protocol) server.
//
// The server runs over stdio by default, making it compatible with any
// MCP-capable AI client. It exposes workflow engine tools (validate,
// list types, generate schemas) and resources (documentation, examples).
//
// Usage:
//
// workflow-mcp-server [options]
//
// Options:
//
// -plugin-dir string Plugin data directory (default "data/plugins")
package main

import (
"flag"
"fmt"
"os"

workflowmcp "github.com/GoCodeAlone/workflow/mcp"
)

func main() {
pluginDir := flag.String("plugin-dir", "data/plugins", "Plugin data directory")
showVersion := flag.Bool("version", false, "Show version and exit")
flag.Parse()

if *showVersion {
fmt.Printf("workflow-mcp-server %s\n", workflowmcp.Version)
os.Exit(0)
}

srv := workflowmcp.NewServer(*pluginDir)
if err := srv.ServeStdio(); err != nil {
fmt.Fprintf(os.Stderr, "MCP server error: %v\n", err)
os.Exit(1)
}
}
164 changes: 164 additions & 0 deletions docs/mcp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# MCP Server for Workflow Engine

The workflow engine includes a built-in [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server that exposes engine functionality to AI assistants and tools.

## Features

The MCP server provides:

### Tools

| Tool | Description |
|------|-------------|
| `list_module_types` | List all available module types for workflow YAML configs |
| `list_step_types` | List all pipeline step types |
| `list_trigger_types` | List all trigger types (http, schedule, event, eventbus) |
| `list_workflow_types` | List all workflow handler types |
| `generate_schema` | Generate JSON Schema for workflow config files |
| `validate_config` | Validate a workflow YAML configuration string |
| `inspect_config` | Inspect a config and get structured summary of modules, workflows, triggers |
| `list_plugins` | List installed external plugins |
| `get_config_skeleton` | Generate a skeleton YAML config for given module types |

### Resources

| Resource | Description |
|----------|-------------|
| `workflow://docs/overview` | Engine overview documentation |
| `workflow://docs/yaml-syntax` | YAML configuration syntax guide |
| `workflow://docs/module-reference` | Dynamic module type reference |

## Building

```bash
# Build the MCP server binary
make build-mcp

# Or directly with Go
go build -o workflow-mcp-server ./cmd/mcp
```

## Installation

### Claude Desktop

Add the following to your Claude Desktop configuration file:

**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
**Windows**: `%APPDATA%\Claude\claude_desktop_config.json`

```json
{
"mcpServers": {
"workflow": {
"command": "/path/to/workflow-mcp-server",
"args": ["-plugin-dir", "/path/to/data/plugins"]
}
}
}
```

### VS Code with GitHub Copilot

Add to your VS Code `settings.json`:

```json
{
"github.copilot.chat.mcpServers": {
"workflow": {
"command": "/path/to/workflow-mcp-server",
"args": ["-plugin-dir", "/path/to/data/plugins"]
}
}
}
```

### Cursor

Add to your Cursor MCP configuration (`.cursor/mcp.json`):

```json
{
"mcpServers": {
"workflow": {
"command": "/path/to/workflow-mcp-server",
"args": ["-plugin-dir", "/path/to/data/plugins"]
}
}
}
```

### Generic MCP Client

The server communicates over **stdio** using JSON-RPC 2.0. Any MCP-compatible client can connect:

```bash
./workflow-mcp-server -plugin-dir ./data/plugins
```

## Usage Examples

Once connected, the AI assistant can use the tools to:

### List available module types
```
Use the list_module_types tool to see what modules are available.
```

### Validate a configuration
```
Validate this workflow config:
modules:
- name: webServer
type: http.server
config:
address: ":8080"
```

### Generate a config skeleton
```
Generate a skeleton config with http.server, http.router, and http.handler modules.
```

### Inspect a configuration
```
Inspect this config and show me the dependency graph...
```

## Command Line Options

```
Usage: workflow-mcp-server [options]

Options:
-plugin-dir string Plugin data directory (default "data/plugins")
-version Show version and exit
```

## Dynamic Updates

The MCP server dynamically reflects the current state of the engine:

- **Module types** are read from the schema registry, which includes both built-in types and any dynamically registered plugin types
- **Plugin list** scans the configured plugin directory at query time
- **Schema generation** uses the current module schema registry
- **Validation** uses the same validation logic as `wfctl validate`

This means the MCP server automatically picks up new module types and plugins without requiring a restart.

## Running Tests

```bash
go test -v ./mcp/
```

## Architecture

```
cmd/mcp/main.go → Entry point (stdio transport)
mcp/server.go → MCP server setup, tool handlers, resource handlers
mcp/docs.go → Embedded documentation content
mcp/server_test.go → Unit tests
```

The server uses the [mcp-go](https://github.com/mark3labs/mcp-go) library for MCP protocol implementation over stdio transport.
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ require (
github.com/jackc/pgx/v5 v5.7.5
github.com/launchdarkly/go-sdk-common/v3 v3.5.0
github.com/launchdarkly/go-server-sdk/v7 v7.14.5
github.com/mark3labs/mcp-go v0.27.0
github.com/nats-io/nats.go v1.48.0
github.com/prometheus/client_golang v1.19.1
github.com/redis/go-redis/v9 v9.18.0
Expand All @@ -54,6 +55,8 @@ require (
go.opentelemetry.io/otel/trace v1.40.0
golang.org/x/crypto v0.48.0
golang.org/x/oauth2 v0.35.0
golang.org/x/sync v0.19.0
golang.org/x/text v0.34.0
golang.org/x/time v0.14.0
google.golang.org/api v0.265.0
google.golang.org/grpc v1.79.1
Expand Down Expand Up @@ -186,7 +189,9 @@ require (
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spiffe/go-spiffe/v2 v2.6.0 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
github.com/yuin/gopher-lua v1.1.1 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.39.0 // indirect
Expand All @@ -200,9 +205,7 @@ require (
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
golang.org/x/net v0.50.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
google.golang.org/genproto v0.0.0-20260128011058-8636f8732409 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260203192932-546029d2fa20 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260217215200-42d3e9bedb6d // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/github/copilot-sdk/go v0.1.23 h1:uExtO/inZQndCZMiSAA1hvXINiz9tqo/MZgQzFzurxw=
Expand Down Expand Up @@ -354,6 +356,8 @@ github.com/launchdarkly/go-test-helpers/v3 v3.1.0 h1:E3bxJMzMoA+cJSF3xxtk2/chr1z
github.com/launchdarkly/go-test-helpers/v3 v3.1.0/go.mod h1:Ake5+hZFS/DmIGKx/cizhn5W9pGA7pplcR7xCxWiLIo=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mark3labs/mcp-go v0.27.0 h1:iok9kU4DUIU2/XVLgFS2Q9biIDqstC0jY4EQTK2Erzc=
github.com/mark3labs/mcp-go v0.27.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
Expand Down Expand Up @@ -439,6 +443,8 @@ github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIH
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M=
github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spiffe/go-spiffe/v2 v2.6.0 h1:l+DolpxNWYgruGQVV0xsfeya3CsC7m8iBzDnMpsbLuo=
Expand All @@ -465,6 +471,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/wsxiaoys/terminal v0.0.0-20160513160801-0940f3fc43a0 h1:3UeQBvD0TFrlVjOeLOBz+CPAI8dnbqNSVwUwRrkp7vQ=
github.com/wsxiaoys/terminal v0.0.0-20160513160801-0940f3fc43a0/go.mod h1:IXCdmsXIht47RaVFLEdVnh1t+pgYtTAhQGj73kz+2DM=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
Expand Down
Loading
Loading