Skip to content

Add MCP Server for Safe Outputs with TypeScript Compilation, Go Embedding, NPM Dependency Management, and Organized Project Structure - #710

Closed
pelikhan with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-3bdd1e39-dace-4b2d-b8d1-c51469111465
Closed

pelikhan with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-3bdd1e39-dace-4b2d-b8d1-c51469111465

Conversation

Copilot AI commented Sep 10, 2025 •

Copy link
Copy Markdown
Contributor
  • Add MCP Server for Safe Outputs with TypeScript Compilation, Go Embedding, NPM Dependency Management, and Organized Project Structure
  • Fix environment variable syntax to use ${{ env.VAR_NAME }} format in all three engine files
  • Create minimal package.json and package-lock.json for MCP server dependencies
  • Add automatic npm dependency installation and temp directory management
  • Add make mcp-install task for updating MCP server npm dependencies
  • Move MCP safe outputs server sources to separate folder (pkg/workflow/mcp-safe-outputs)
  • Add cwd parameter to MCP server configurations to ensure Node.js dependencies are resolved from correct directory

Key Changes

1. TypeScript MCP Server Implementation

  • Created safe_outputs_mcp_server.ts implementing all 10 safe output types as MCP tools
  • Tools are dynamically filtered based on GITHUB_AW_SAFE_OUTPUTS_CONFIG environment variable
  • MCP tool invocations write JSONL entries to the safe output file

2. Go Embedding and Compilation Pipeline

  • Added TypeScript compilation process using npm run compile
  • Embedded compiled JavaScript in Go binary using go:embed
  • Used base64 encoding to safely embed JavaScript in workflow YAML generation
  • Created SafeOutputsMCPServerScript() function to access embedded content

3. NPM Dependency Management

  • Created minimal mcp_package.json with only @modelcontextprotocol/sdk dependency
  • Generated and embedded mcp_package-lock.json for reproducible builds
  • Modified WriteSafeOutputsMCPServerToTemp() to automatically install npm dependencies using npm ci in temp directory
  • MCP server now runs from temp folder where node_modules is properly resolved
  • Added make mcp-install task for updating MCP server dependencies

4. MCP SDK Upgrade and Integration

  • Updated github.com/modelcontextprotocol/go-sdk from v0.2.0 to v0.4.0
  • Fixed deprecated API usage for CommandTransport and StreamableClientTransport
  • Added comprehensive Go tests using the MCP Go SDK for tool listing and invocation

5. Workflow Engine Integration

  • Extended all three engines (Claude, Codex, Custom) to support safe-outputs MCP server
  • Added renderSafeOutputsClaudeMCPConfig(), renderSafeOutputsCodexMCPConfig(), and renderSafeOutputsMCPConfig() methods
  • MCP server automatically starts when mcp: true is set in safe-outputs configuration
  • Fixed environment variable syntax to use ${{ env.VAR_NAME }} format for proper GitHub Actions expansion
  • Added cwd parameter to all MCP server configurations to ensure Node.js dependencies are resolved from the correct temp directory

6. Schema and Configuration Updates

  • Added mcp field to SafeOutputsConfig struct with proper YAML marshaling
  • Updated main_workflow_schema.json to allow the mcp boolean field
  • Enhanced extractSafeOutputsConfig() to parse the MCP flag from frontmatter

7. Organized Project Structure

  • Moved all MCP safe outputs server sources to dedicated pkg/workflow/mcp-safe-outputs/ directory
  • Organized TypeScript and JavaScript source files in clean subdirectory structure
  • Updated Go embed paths to reference the new organized structure
  • Updated Makefile tasks and TypeScript configuration for new file locations
  • Maintained full backward compatibility while improving code organization

8. Backward Compatibility

  • Existing workflows continue to work without changes
  • MCP mode is opt-in via mcp: true flag
  • Traditional JSONL safe outputs remain the default behavior

Usage Example

Workflows can now use MCP-based safe outputs:

---
on: workflow_dispatch

safe-outputs:
  mcp: true
  create-issue:
    title-prefix: "[MCP] "
    max: 1
  add-issue-comment:
    max: 1

engine: claude
---

# MCP Safe Outputs Workflow
Create an issue and add a comment using MCP tools instead of direct JSONL writing.

Testing

  • Added comprehensive test suite in safe_outputs_mcp_test.go
  • Tests cover embedded JavaScript retrieval, MCP flag parsing, and Go SDK integration
  • Created test workflow test-mcp-safe-outputs.md demonstrating the functionality
  • All existing tests pass, ensuring no regressions

This implementation provides a more structured and protocol-compliant approach to safe outputs while maintaining full backward compatibility with existing workflows. The MCP server is fully self-contained with automatic dependency management, organized project structure, and proper working directory configuration, ensuring reliable execution in GitHub Actions environments.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits September 11, 2025 00:03
…ementation

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
… Go embedding

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…, and working test workflow

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add a MCP server that implements the safe output as tools. - self contained javascript-based MCP server that implements each safe output as tools and write tool invocations into the safe output JSONL log file. - see previous implementation attempt a... Add MCP Server for Safe Outputs with TypeScript Compilation and Go Embedding Sep 11, 2025
Copilot AI requested a review from pelikhan September 11, 2025 00:35

@pelikhan pelikhan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot the server relies on the MCP typescript sdk which needs to be installed in the temp folder

  • create a package.json that only contains the MCP server dependencies, run install to compute the package.lock file
  • package the package.json and lock file as go embed resources
  • save the package.json and package.lock in the temp MCP server folder and run "npm ci"
  • run the MCP server starting from the temp folder so that the packages are correctly resolved.

Comment thread pkg/workflow/claude_engine.go Outdated
yaml.WriteString(" \"command\": \"node\",\n")
yaml.WriteString(" \"args\": [\"/tmp/safe-outputs-mcp/safe_outputs_mcp_server.js\"],\n")
yaml.WriteString(" \"env\": {\n")
yaml.WriteString(" \"GITHUB_AW_SAFE_OUTPUTS\": \"$GITHUB_AW_SAFE_OUTPUTS\",\n")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot use the ${{ env.VAR_NAME }} syntax to set the variable value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the environment variable syntax to use ${{ env.VAR_NAME }} format in all three engine files (claude_engine.go, codex_engine.go, custom_engine.go) as requested.

Changes made in commit a0a1ac3.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Sep 11, 2025 •

Copy link
Copy Markdown
Contributor Author

@copilot the server relies on the MCP typescript sdk which needs to be installed in the temp folder

  • create a package.json that only contains the MCP server dependencies, run install to compute the ...

I've implemented the npm dependency management as requested. The MCP server now:

  • Uses a minimal package.json with only the @modelcontextprotocol/sdk dependency
  • Includes an embedded package-lock.json for reproducible builds
  • Automatically runs npm ci in the temp directory to install dependencies
  • Runs from the temp folder where node_modules is properly resolved

Changes made in commit a0a1ac3.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.contoso.com
    • Triggering command: /tmp/go-build4046239486/b279/cli.test -test.testlogfile=/tmp/go-build4046239486/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)
    • Triggering command: /tmp/go-build3098302341/b279/cli.test -test.testlogfile=/tmp/go-build3098302341/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add MCP Server for Safe Outputs with TypeScript Compilation and Go Embedding Add MCP Server for Safe Outputs with TypeScript Compilation, Go Embedding, and NPM Dependency Management Sep 11, 2025
Copilot AI requested a review from pelikhan September 11, 2025 00:52
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot add a task in the makefile for running "npm install" for new package. Make sure that the lock file is added to the repo

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Sep 11, 2025

Copy link
Copy Markdown
Contributor Author

@copilot add a task in the makefile for running "npm install" for new package. Make sure that the lock file is added to the repo

Added make mcp-install Makefile task that creates a temporary directory, copies the MCP package.json, runs npm install to regenerate the lock file, and copies it back to pkg/workflow/mcp_package-lock.json. The lock file is tracked in the repository and the task includes a reminder to commit any changes.

Usage: make mcp-install

Changes made in commit b37895e.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot move safe output server sources to a separate folder (pkg/workflow/mcp-safe-outputs)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Sep 11, 2025 •

Copy link
Copy Markdown
Contributor Author

@copilot move safe output server sources to a separate folder (pkg/workflow/mcp-safe-outputs)

Moved all MCP safe outputs server sources to the separate folder pkg/workflow/mcp-safe-outputs/. This includes:

  • TypeScript and JavaScript source files
  • NPM package.json and lock files
  • Updated Go embed paths and Makefile references
  • Updated tsconfig.json compilation settings
  • Recompiled TypeScript for proper embedding

All tests pass and the build works correctly with the new organization.

Changes made in commit 7055257.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.contoso.com
    • Triggering command: /tmp/go-build1469106478/b279/cli.test -test.testlogfile=/tmp/go-build1469106478/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add MCP Server for Safe Outputs with TypeScript Compilation, Go Embedding, and NPM Dependency Management Add MCP Server for Safe Outputs with TypeScript Compilation, Go Embedding, NPM Dependency Management, and Organized Project Structure Sep 11, 2025
Comment thread pkg/workflow/claude_engine.go Resolved
…endency resolution

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Sep 11, 2025

Copy link
Copy Markdown
Contributor Author

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.contoso.com
    • Triggering command: /tmp/go-build1976770350/b279/cli.test -test.testlogfile=/tmp/go-build1976770350/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from pelikhan September 11, 2025 05:09
@pelikhan pelikhan closed this Sep 11, 2025
@pelikhan
pelikhan deleted the copilot/fix-3bdd1e39-dace-4b2d-b8d1-c51469111465 branch September 11, 2025 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants