Skip to content

Commit

Permalink
Merge pull request #7 from wesen/task/refactor-transports
Browse files Browse the repository at this point in the history
Refactor transport layer with clean interfaces and improved error handling
  • Loading branch information
wesen authored Feb 22, 2025
2 parents f91982b + da5d146 commit 1b4975b
Show file tree
Hide file tree
Showing 70 changed files with 4,062 additions and 2,834 deletions.
10 changes: 5 additions & 5 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: 2
project_name: go-go-mcp
project_name: mcp

before:
hooks:
Expand All @@ -11,7 +11,7 @@ builds:
- env:
- CGO_ENABLED=0
main: ./cmd/go-go-mcp
binary: go-go-mcp
binary: mcp
goos:
- linux
# I am not able to test windows at the time
Expand All @@ -34,8 +34,8 @@ signs:
args: [ "--batch", "-u", "{{ .Env.GPG_FINGERPRINT }}", "--output", "${signature}", "--detach-sign", "${artifact}" ]

brews:
- name: go-go-mcp
description: "go-go-mcp is a tool to serve and run MCPs"
- name: mcp
description: "mcp is a tool to serve and run MCPs"
homepage: "https://github.com/go-go-golems/go-go-mcp"
repository:
owner: go-go-golems
Expand All @@ -51,7 +51,7 @@ nfpms:
maintainer: Manuel Odendahl <wesen@ruinwesen.com>

description: |-
go-go-mcp is a tool to serve and run MCPs
mcp is a tool to serve and run MCPs
license: MIT

Expand Down
20 changes: 19 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/go-go-mcp",
"args": ["start", "--transport", "sse", "--profile", "html-extraction", "--log-level", "debug", "--port", "3000"],
"args": ["server", "start", "--profile", "all", "--log-level", "debug"],
"cwd": "${workspaceFolder}"
},
{
"name": "Launch MCP Server (sse)",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/go-go-mcp",
"args": ["server", "start", "--transport", "sse", "--profile", "html-extraction", "--log-level", "debug", "--port", "3000"],
"cwd": "${workspaceFolder}"
},
{
Expand All @@ -28,6 +37,15 @@
"program": "${workspaceFolder}/cmd/go-go-mcp",
"args": ["config", "add-tool", "html-extraction", "--dir", "~/code/wesen/corporate-headquarters/go-go-mcp/examples/html-extract"],
"cwd": "${workspaceFolder}"
},
{
"name": "Launch UI Server",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/ui-server",
"args": ["examples/pages"],
"cwd": "${workspaceFolder}"
}
]
}
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bump-glazed:
go get github.com/go-go-golems/parka@latest
go mod tidy

go-go-mcp_BINARY=$(shell which go-go-mcp)
mcp_BINARY=$(shell which mcp)
install:
go build -o ./dist/go-go-mcp ./cmd/go-go-mcp && \
cp ./dist/go-go-mcp $(go-go-mcp_BINARY)
go build -o ./dist/mcp ./cmd/go-go-mcp && \
cp ./dist/mcp $(mcp_BINARY)
79 changes: 74 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ Start the server with either stdio or SSE transport:

```bash
# Start with stdio transport (default)
go-go-mcp start --transport stdio
go-go-mcp server start --transport stdio

# Start with SSE transport
go-go-mcp start --transport sse --port 3001
go-go-mcp server start --transport sse --port 3001
```

The server automatically watches configured repositories and files for changes, reloading tools when:
Expand Down Expand Up @@ -142,7 +142,7 @@ go-go-mcp server tools list --profile data
Use the client subcommand to interact with an MCP server:

```bash
# List available prompts (uses default server: go-go-mcp start --transport stdio)
# List available prompts (uses default server: go-go-mcp server start --transport stdio)
go-go-mcp client prompts list

# List available tools
Expand Down Expand Up @@ -171,7 +171,7 @@ go-go-mcp can be used as a bridge to expose an SSE server as a stdio server. Thi

```bash
# Start an SSE server on port 3000
go-go-mcp start --transport sse --port 3000
go-go-mcp server start --transport sse --port 3000

# In another terminal, start the bridge to expose the SSE server as stdio
go-go-mcp bridge --sse-url http://localhost:3000 --log-level debug
Expand All @@ -186,7 +186,7 @@ This is particularly useful when integrating with tools that only support stdio
Add the `--debug` flag to enable detailed logging:

```bash
go-go-mcp start --debug
go-go-mcp server start --debug
```

### Version Information
Expand Down Expand Up @@ -345,3 +345,72 @@ go-go-mcp help <topic>
# Show examples for a topic
go-go-mcp help <topic> --example
```

# UI DSL

A simple YAML-based Domain Specific Language for defining user interfaces.

## Components

The DSL supports the following basic components:

### Button
- `text`: Button label
- `type`: primary, secondary, danger, success
- `onclick`: JavaScript event handler

### Title
- `content`: Heading text content

### Text
- `content`: Text content

### Input
- `type`: text, email, password, number, tel
- `placeholder`: Placeholder text
- `value`: Default value
- `required`: Boolean

### Textarea
- `placeholder`: Placeholder text
- `rows`: Number of rows
- `cols`: Number of columns
- `value`: Default value

### Checkbox
- `label`: Checkbox label
- `checked`: Boolean
- `required`: Boolean
- `name`: Form field name

### List
- `type`: ul or ol
- `items`: Array of items or nested components

## Common Attributes

All components support these common attributes:
- `id`: Unique identifier
- `style`: Inline CSS
- `disabled`: Boolean
- `data`: Map of data attributes

## Example

```yaml
form:
id: signup-form
components:
- title:
content: Sign Up
- text:
content: Please fill in your details below.
- input:
type: email
placeholder: Email address
- button:
text: Submit
type: primary
```
See `ui-dsl.yaml` for more comprehensive examples.
123 changes: 122 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -1047,4 +1047,125 @@ Added server-side tool management commands for direct interaction with tool prov

- Added `server tools list` command to list available tools directly from tool provider
- Added `server tools call` command to call tools directly without starting the server
- Reused server layer for configuration consistency
- Reused server layer for configuration consistency

## Add Minimal Glazed Command Layer

Added a minimal version of the Glazed command layer (NewGlazedMinimalCommandLayer) that contains just the most commonly used parameters: print-yaml, print-parsed-parameters, load-parameters-from-file, and print-schema. This provides a simpler interface for basic command configuration.

- Added GlazedMinimalCommandSlug constant
- Added NewGlazedMinimalCommandLayer function

## Enhanced Glazed Command Layer Handling

Updated cobra command handling to support both full and minimal Glazed command layers:

- Added support for GlazedMinimalCommandLayer in cobra command processing
- Unified handling of common flags (print-yaml, print-parsed-parameters, etc.) between both layers
- Maintained backward compatibility with full GlazedCommandLayer features
- Added placeholder for schema printing functionality

# Transport Layer Refactoring

Implemented new transport layer architecture as described in RFC-01. This change:
- Creates a clean interface for different transport mechanisms
- Separates transport concerns from business logic
- Provides consistent error handling across transports
- Adds support for transport-specific options and capabilities

- Created new transport package with core interfaces and types
- Implemented SSE transport using new architecture
- Added transport options system
- Added standardized error handling

# Transport Layer Implementation

Added stdio transport implementation using new transport layer architecture:
- Implemented stdio transport with proper signal handling and graceful shutdown
- Added support for configurable buffer sizes and logging
- Added proper error handling and JSON-RPC message processing
- Added context-based cancellation and cleanup

# Server Layer Updates

Updated server implementation to use new transport layer:
- Refactored Server struct to use transport interface
- Added RequestHandler to implement transport.RequestHandler interface
- Updated server command to support multiple transport types
- Improved error handling and logging throughout server layer

# Enhanced SSE Transport

Added support for integrating SSE transport with existing HTTP servers:
- Added standalone and integrated modes for SSE transport
- Added GetHandlers method to get SSE endpoint handlers
- Added RegisterHandlers method for router integration
- Added support for path prefixes and middleware
- Improved configuration options for HTTP server integration

# Transport Interface Refactoring

Simplified transport interface to use protocol types directly instead of custom types.
- Removed duplicate type definitions from transport package
- Use protocol.Request/Response/Notification types directly
- Improved type safety by removing interface{} usage

# Transport Request ID Handling

Added proper request ID handling to transport package:
- Added IsNotification helper to check for empty/null request IDs
- Improved notification detection for JSON-RPC messages
- Consistent handling of request IDs across transports

# Transport ID Type Conversion

Added helper functions for converting between string and JSON-RPC ID types:
- Added StringToID to convert string to json.RawMessage
- Added IDToString to convert json.RawMessage to string
- Improved type safety in ID handling across transports

# Simplified UI DSL

Simplified the UI DSL by removing class attributes and creating distinct title and text elements:
- Removed class attributes from all components
- Added dedicated title element for headings
- Simplified text element to be just for paragraphs
- Updated documentation to reflect changes

# UI DSL Implementation

Created a YAML-based UI DSL for defining simple user interfaces. The DSL supports common UI components like buttons, text, inputs, textareas, checkboxes, and lists with a clean and intuitive syntax.

- Added `ui-dsl.yaml` with component definitions and examples
- Added documentation in `README.md`
- Included support for common attributes across all components
- Added nested component support for complex layouts

# UI Server Implementation
Added a new UI server that can render YAML UI definitions using HTMX and Bootstrap:
- Created a new command `ui-server` that serves UI definitions from YAML files
- Implemented templ templates for rendering UI components
- Added support for various UI components like buttons, inputs, forms, etc.
- Used HTMX for dynamic interactions and Bootstrap for styling

# Halloween-themed UI Examples
Added a collection of Halloween-themed example pages using the UI DSL:
- Created welcome page with spooky navigation
- Added haunted house tour booking form
- Created costume contest voting interface
- Added Halloween party RSVP form with fun options
- Created trick-or-treat checklist for safety

# UI DSL Structure Update
Updated the UI DSL to use a top-level components list for better sequence handling:
- Changed UIDefinition to use a list of components instead of a map
- Updated all example pages to use the new structure
- Modified templates to handle the new component list format
- Improved component rendering to handle nested components

# SSE Transport Port Configuration

Improved port configuration handling in SSE transport by properly parsing the provided address.

- Added proper port parsing from SSE options address
- Ensures port configuration is correctly propagated from command line to transport
4 changes: 2 additions & 2 deletions cmd/go-go-mcp/cmds/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/go-go-golems/go-go-mcp/pkg/server/transports/stdio"
"github.com/go-go-golems/go-go-mcp/pkg/server"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
)
Expand All @@ -22,7 +22,7 @@ This is useful when you want to connect a stdio client to a remote SSE server.`,
return fmt.Errorf("SSE URL is required")
}

server := stdio.NewSSEBridgeServer(logger, sseURL)
server := server.NewSSEBridgeServer(logger, sseURL)
return server.Start(context.Background())
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/go-go-mcp/cmds/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *SchemaCommand) RunIntoWriter(
}

// Convert to JSON schema
schema, err := mcp_cmds.ToJsonSchema(shellCmd.Description())
schema, err := shellCmd.Description().ToJsonSchema()
if err != nil {
return fmt.Errorf("could not convert to JSON schema: %w", err)
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/go-go-mcp/cmds/server/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package server

import (
"github.com/go-go-golems/glazed/pkg/cli"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)

Expand All @@ -13,4 +15,11 @@ var ServerCmd = &cobra.Command{

func init() {
ServerCmd.AddCommand(ToolsCmd)
startCmd, err := NewStartCommand()
if err != nil {
log.Fatal().Err(err).Msg("failed to create start command")
}
cobraStartCmd, err := cli.BuildCobraCommandFromBareCommand(startCmd)
cobra.CheckErr(err)
ServerCmd.AddCommand(cobraStartCmd)
}
Loading

0 comments on commit 1b4975b

Please sign in to comment.