Skip to content

Golem CLI: add mcp server#1976

Closed
BenraouaneSoufiane wants to merge 19 commits intogolemcloud:mainfrom
BenraouaneSoufiane:mcp-server
Closed

Golem CLI: add mcp server#1976
BenraouaneSoufiane wants to merge 19 commits intogolemcloud:mainfrom
BenraouaneSoufiane:mcp-server

Conversation

@BenraouaneSoufiane
Copy link
Copy Markdown

@BenraouaneSoufiane BenraouaneSoufiane commented Aug 20, 2025

Add MCP Server Mode to golem-cli

Summary of Changes

This PR introduces an MCP (Model Context Protocol) server mode to golem-cli, allowing external tools (e.g. IDEs, LLMs, or orchestrators) to interact with golem via a standardized JSON-RPC 2.0 API over HTTP.


🔨 Implementation Details

  • Added --serve and --serve-port flags to launch golem-cli as an MCP server.
  • Confirmed successful release build with no warnings.

📡 MCP Endpoints Implemented

  • initialize — handshake and capability negotiation.
  • tools/list — exposes available CLI tools (golem.run).
  • tools/call — runs commands like golem version or golem profile list, with:
    • Streaming of stdout / stderr into logs array.
    • exitCode and final output in structured JSON.
    • Safety check: blocks disallowed top-level subcommands (e.g. system, exec).
  • resources/list — enumerates manifest files in current dir, ancestors, and immediate children.
  • resources/read — returns file contents by file:// URI.

🔬 Validation / Testing

A test plan was executed using curl against the MCP endpoint:

  • initialize returns protocol version & capabilities.
  • tools/list shows golem.run.
  • tools/call:
    • ✅ Happy path (golem version) returns logs + result.
    • ✅ Error path blocks disallowed commands (system exec).
    • ✅ Supports cwd argument for working directory override.
  • resources/list returns expected manifests.
  • resources/read fetches file contents.
  • Verified error handling for:
    • Unknown methods (-32601).
    • Wrong tool name (-32602).
    • Invalid URIs (clear error message).

🏁 Result

  • golem-cli can now be run as a long-lived MCP server:
    ./target/release/golem-cli --serve --serve-port 1232
    

▶️ Live demo

https://youtu.be/BxJBLJkkV8Q

🤔 How to

1- Build/compile:

cd golem/cli/golem-cli
cargo build --release

2- Run:

cd ../..
RUST_LOG=debug ./target/release/golem-cli --serve --serve-port 1232

Expected:

INFO golem_cli::serve: golem-cli: MCP HTTP server listening on http://127.0.0.1:1232

Then (if using) VSCode port forwading pop up

3- Test first request in other terminal run:

curl -sS http://127.0.0.1:1232/mcp   -H 'content-type: application/json'   -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | jq

Expected:

{ "jsonrpc": "2.0", "id": 1, "result": { "protocolVersion": "...", "serverInfo": {"..."}, "capabilities": {"..."} } }

See full implimented/available commands: https://github.com/BenraouaneSoufiane/golem/tree/mcp-server/cli/golem-cli

Algora.io

/claim #1926

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

@vigoo Hello, can you take a look if not busy

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

@jdegoes Any updates?

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

Hello @vigoo @noise64 can someone review my PR?

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

@vigoo Any updates on this?

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

Hello @mschuwalow can you review this?

@noise64
Copy link
Copy Markdown
Contributor

noise64 commented Sep 17, 2025

This PR is obviously AI generated for many parts, which is not a problem, but it is not cleaned up at all or reviewed properly before it was submitted, which is a problem, some examples:

  • the hooks / golem server feature got deleted, why? "Keep it empty to avoid trait lifetime churn."? what does this mean?
  • it randomly reimplements a sloppy version of command line parsing, that should be properly integrated with clap, or like how it is done for fallback parsing in the repo
  • droped the real main entry point of the app (or at least the tokio runtime parts...)
  • the allowed_subcommands are not even matching the real commands available, ideally this should be derived from clap meta, and then have a disallow list
  • the "discover manifest" randomly reimplements how manifest should be discovered and how it is done in other parts of the app
  • the server should not use hardcoded json literals, it should have a clean model
  • random comments in cargo.toml

and so on.

Even the description / implementation "details" in the PR description are making no sense:

Implemented main_async to replace duplicate main definitions (fixing fn main duplication errors).
Fixed ownership/move issues in serve.rs by restructuring mpsc::UnboundedReceiver and logs handling.
Cleaned up compiler warnings (unused_mut, dead_code).

Benraouane Soufiane and others added 5 commits September 18, 2025 06:35
…registry

- Gate the HTTP server behind the `mcp-server` Cargo feature
- Add graceful error when `--serve` is used without the feature
- Keep server code isolated in `serve.rs` behind cfg(feature = "mcp-server")
- Implement clean JSON-RPC response model (`RpcResponse`, `RpcError`) instead of raw literals
- Wire `tools/list` directly to the central registry of tools
- Restrict `tools/call` to only allowed/registered tools with typed input schema
- Align manifest discovery with repo’s canonical algorithm (`golem.yaml` walk-up)
@BenraouaneSoufiane
Copy link
Copy Markdown
Author

BenraouaneSoufiane commented Sep 24, 2025

Hello again @noise64
I've tried to resolve mentioned issues.

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

Hello again @vigoo can you take a look at this???

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

Hello @mschuwalow @afsalthaj can someone provide feedbacks on this?

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

Hello again @noise64 @vigoo @mschuwalow, any updates on this?

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

@vigoo any updates on this?

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

@noise64 I know you're busy, I've tried to fix mentioned issues, can you take a look?

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

@mschuwalow can you review this?

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

@afsalthaj can you review this?

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

@noise64 I think the body/description looks good now.

@BenraouaneSoufiane
Copy link
Copy Markdown
Author

Can someone approve the workflows?

@noise64
Copy link
Copy Markdown
Contributor

noise64 commented Oct 16, 2025

This is still full of random unreviewed AI generated things, and most of the things were not corrected or done properly.
Please stop pinging us with this.
I'm closing this PR now.

@noise64 noise64 closed this Oct 16, 2025
@BenraouaneSoufiane
Copy link
Copy Markdown
Author

BenraouaneSoufiane commented Oct 16, 2025

This is still full of random unreviewed AI generated things, and most of the things were not corrected or done properly. Please stop pinging us with this. I'm closing this PR now.

I've tried to built it locally & works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants