HY

Hyperledger Fabric Agent Suite MCP Server

Manage Fabric test networks and chaincode lifecycle with the MCP server in the Hyperledger Fabric Agent Suite.

Overview

The MCP (Model Context Protocol) server in the Hyperledger Fabric Agent Suite provides a lightweight HTTP API and orchestration layer to manage Fabric test networks and to automate chaincode lifecycle tasks. It is designed for developers who need repeatable, scriptable control over local or CI-based Fabric deployments — creating peers and orderers, creating channels, installing and committing chaincode, and retrieving deployment status through a consistent API.

Using the MCP server helps standardize how tools and automation scripts interact with Fabric test networks. Instead of embedding Fabric CLI sequences in many different places, teams can call the MCP server to perform lifecycle operations, making CI pipelines, local developer tooling, and teaching labs simpler and less error-prone.

Features

  • REST API to manage Fabric test networks (create, start, stop, destroy)
  • Chaincode lifecycle automation: package, install, approve, commit, invoke, query
  • Channel management: create channel, join peers to channels, update anchors
  • Environment configuration via JSON files or environment variables
  • Suitable for local development, CI pipelines, and sandbox environments
  • Basic status and logging endpoints for integration and troubleshooting
  • Extensible architecture for adding custom runtime steps or integrations

Installation / Configuration

Prerequisites: Node.js (12+), Docker (for fabric containers), Fabric binaries or Docker images available locally.

Clone and install:

git clone https://github.com/padmarajkore/hlf-fabric-agent.git
cd hlf-fabric-agent
npm install

Create a minimal configuration file (config.json):

{
  "port": 8080,
  "fabric": {
    "dockerNetwork": "fabric_testnet",
    "fabricToolsPath": "/opt/fabric/bin",
    "ordererOrg": "OrdererOrg",
    "peerOrgs": [
      {"name": "Org1", "domain": "org1.example.com", "peers": 2}
    ]
  },
  "chaincode": {
    "language": "golang",
    "chaincodePath": "./chaincode",
    "packageOutput": "./packages"
  }
}

Run the server locally:

export MCP_CONFIG=./config.json
npm start
# or
node server.js --config ./config.json

Common environment variables:

  • MCP_CONFIG — path to server config JSON
  • PORT — HTTP port override (default 8080)
  • FABRIC_TOOLS_PATH — path to peer/orderer binaries (if needed)
  • DOCKER_HOST — if using remote Docker engine

If you prefer Docker:

docker build -t hlf-mcp .
docker run -p 8080:8080 -v $(pwd)/config.json:/app/config.json hlf-mcp

Available Resources

  • GitHub repository: https://github.com/padmarajkore/hlf-fabric-agent
  • REST API root: GET /health (returns server and Fabric tooling status)
  • Logging: GET /logs or stream via websocket (if enabled)
  • Static config: /config (read-only view of effective configuration)

API endpoints (typical set):

EndpointVerbDescription
/healthGETServer and tooling health
/networksPOSTCreate/start a test network
/networks/{id}GETGet network status
/networks/{id}DELETETeardown a network
/channelsPOSTCreate a channel
/peers/{peerId}/joinPOSTJoin peer to channel
/chaincodesPOSTPackage & install chaincode
/chaincodes/{cc}/approvePOSTApprove chaincode for org
/chaincodes/{cc}/commitPOSTCommit chaincode to channel
/chaincodes/{cc}/invokePOSTInvoke chaincode transaction
/chaincodes/{cc}/queryGETQuery chaincode state

Note: Exact paths may vary by release; consult the repo docs or /help endpoint.

Use Cases

  1. CI/CD chaincode validation

    • In a pipeline job, call POST /networks to provision a fresh test network, POST /chaincodes to install and approve a candidate chaincode package, then POST /chaincodes/{cc}/invoke and /query to run unit tests. After tests finish, call DELETE /networks/{id} to free resources.

    Example (simplified):

    curl -X POST http://localhost:8080/networks -H "Content-Type: application/json" -d '{"name":"ci-net","profile":"test","orgs":1}'
    curl -X POST http://localhost:8080/chaincodes -F "[email protected]" -F "label=mycc_v1"
    curl -X POST http://localhost:8080/chaincodes/mycc_v1/commit -d '{"channel":"mychannel"}'
    
  2. Local developer sandbox

    • Developers spin up a reproducible network with one command, deploy chaincode, and iterate on smart contracts without manually running peer and orderer containers. Use the server to snapshot and restore test states.
  3. Teaching and workshops

    • Course instructors provision identical networks for each lab, provide simple HTTP-based tasks to students (e.g., “POST /chaincodes to deploy this example”), and automate teardown between sessions.
  4. Integration testing for off-chain services

    • Services that need to test Fabric interactions can use the MCP server to create deterministic environments and assert on ledger state via /chaincodes/{cc}/query.

Tips and Next Steps

  • Keep chaincode packages in a shared build artifact store or reference by label when automating.
  • Use the health and logs endpoints to diagnose permissions or binary-version mismatches.
  • Extend the server by adding custom handlers for non-standard lifecycle steps (e.g., private data collection setup or custom endorsement flows).

For detailed API shapes and example payloads, check the repository README and the server’s /help or OpenAPI endpoint in the running instance.