HGraphPunks hedera mcp server

HGraphPunks hedera mcp server avatar

by HGraphPunks

Hedera MCP server

What is HGraphPunks hedera mcp server

Hedera MCP Server (ALPHA - INITIAL FUNCTIONALITY STILL BROKEN)

Overview

The Hedera MCP Server is a production-ready, modular Node.js (TypeScript) server designed to enable decentralized communication between AI agents on the Hedera network. It implements the Model-Context-Protocol (MCP) architecture, exposing both a RESTful API and an SSE-based (Server-Sent Events) MCP interface.

Using the Hedera Agent Kit alongside the Standards Agent Kit, the server supports multiple Hedera Consensus Service (HCS) standards:

  • HCS-1 (File/Data Management)
  • HCS-2 (Registry for Agent Discovery)
  • HCS-3 (Large Message Handling and Recursion)
  • HCS-10 (Agent Communication Protocol)
  • HCS-11 (Decentralized Identity/Profile Management)

This server is especially aimed at hackathon participants and developers building AI-integrated decentralized applications on Hedera. It is also compatible with tools like Cursor for autonomous agent interactions.


Folder Structure

hedera-mcp-server/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ””โ”€โ”€ config.ts             # Configuration loader (environment variables, Hedera client)
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”œโ”€โ”€ agentService.ts       # Agent registration & profile management (HCS-10/HCS-11)
โ”‚   โ”‚   โ”œโ”€โ”€ connectionService.ts  # Connection request, acceptance & messaging (HCS-10)
โ”‚   โ”‚   โ”œโ”€โ”€ fileService.ts        # File storage for large messages (HCS-1 & HCS-3)
โ”‚   โ”‚   โ”œโ”€โ”€ logger.ts             # Logging utility
โ”‚   โ”‚   โ””โ”€โ”€ profileUtil.ts        # Helper for serializing agent profiles
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”œโ”€โ”€ agentRoutes.ts        # API endpoints for agent registration & query
โ”‚   โ”‚   โ”œโ”€โ”€ connectionRoutes.ts   # API endpoints for connection and messaging
โ”‚   โ”‚   โ””โ”€โ”€ index.ts              # Route aggregator for the REST API
โ”‚   โ”œโ”€โ”€ mcp/
โ”‚   โ”‚   โ””โ”€โ”€ mcpServer.ts          # MCP server (SSE interface) definition using FastMCP and Zod
โ”‚   โ””โ”€โ”€ index.ts                  # Main entry point to initialize Express and MCP servers
โ”œโ”€โ”€ test/
โ”‚   โ”œโ”€โ”€ unit/
โ”‚   โ”‚   โ”œโ”€โ”€ agentService.test.ts       # Unit tests for agent logic and profile serialization
โ”‚   โ”‚   โ”œโ”€โ”€ connectionService.test.ts  # Unit tests for connection and message formatting
โ”‚   โ”‚   โ””โ”€โ”€ fileService.test.ts        # Unit tests for file chunking and file storage
โ”‚   โ”œโ”€โ”€ integration/
โ”‚   โ”‚   โ””โ”€โ”€ apiEndpoints.test.ts       # Integration tests for REST API endpoints
โ”‚   โ””โ”€โ”€ e2e/
โ”‚       โ””โ”€โ”€ agentCommunication.e2e.ts  # End-to-end tests simulating agent registration, connection, and messaging
โ”œโ”€โ”€ Dockerfile                   # Docker configuration for building the server image
โ”œโ”€โ”€ docker-compose.yml           # One-command deployment configuration for Docker
โ”œโ”€โ”€ package.json                 # Project metadata and scripts
โ””โ”€โ”€ README.md                    # This file

Features

  • Agent Registration & Profiles (HCS-11):
    Create new Hedera accounts (or import existing ones) for AI agents. Automatically set up inbound/outbound topics and on-chain profiles.

  • Agent Discovery (HCS-2):
    Register agents in a centralized registry topic. Discover agents by name or capability using the provided search API.

  • Secure Communication (HCS-10):
    Initiate and accept connection requests between agents. Establish dedicated connection topics over which agents can securely exchange messages.

  • Large Message Handling (HCS-1 & HCS-3):
    Offload large message content by storing it on dedicated file topics and returning an HRL (HCS Resource Locator) reference within messages.

  • MCP Interface via SSE:
    Expose an MCP-compliant SSE endpoint (via FastMCP) that lets AI tools like Cursor directly invoke server โ€œtoolsโ€ (e.g., register_agent, send_message).

  • RESTful API:
    Expose comprehensive HTTP endpoints for agent operations, connection management, and messaging, with detailed request/response formats.

  • Production-Ready Deployment:
    Comes with Docker and Docker Compose configurations for seamless one-command deployment.


Requirements

  • Node.js โ‰ฅ 18 (LTS recommended)
  • npm (comes with Node)
  • Docker and Docker Compose (for container deployment)
  • A Hedera Testnet (or Mainnet) account with sufficient funds for transactions
    (Set the following environment variables: HEDERA_OPERATOR_ID and HEDERA_OPERATOR_KEY.)

Getting Started

1. Clone the Repository

git clone https://github.com/hgraphpunks/hedera-mcp-server.git
cd hedera-mcp-server

2. Install Dependencies

npm install

3. Configure Environment Variables

Create a .env file in the project root with the following content (adjust with your actual credentials):

# .env
HEDERA_NETWORK=testnet
HEDERA_OPERATOR_ID=0.0.12345
HEDERA_OPERATOR_KEY=302e0201...
REGISTRY_TOPIC_ID=        # (optional โ€“ if not provided, a new registry topic will be created)
PORT=3000
SSE_PORT=3001

4. Build the Project

Compile the TypeScript code into JavaScript:

npm run build

5. Run the Server Locally

Start the REST API and MCP SSE servers:

npm start

You should see logs indicating that:

  • The REST API is listening on http://localhost:3000
  • The MCP SSE server is available at http://localhost:3001/sse

6. Development Mode

For rapid development with automatic rebuilds, use:

npm run dev

API Documentation

Agent Endpoints

  • POST /api/agents/register
    Registers a new agent.
    Request Body:

    {
      "name": "AliceAgent",
      "accountId": "0.0.ABCDE",         // optional โ€“ leave empty to generate a new account
      "privateKey": "302e0201...",       // optional โ€“ required if accountId is provided
      "capabilities": [0, 4],
      "model": "gpt-4",
      "creator": "Alice"
    }
    

    Response (201 Created):

    {
      "accountId": "0.0.789123",
      "privateKey": "302e0201... (if new)",
      "profile": {
        "name": "AliceAgent",
        "inboundTopicId": "0.0.444444",
        "outboundTopicId": "0.0.444445",
        "type": 1,
        "capabilities": [0, 4],
        "model": "gpt-4",
        "creator": "Alice"
      }
    }
    
  • GET /api/agents/{accountId}
    Retrieves the profile of an agent by account ID.
    Response (200 OK):

    {
      "name": "AliceAgent",
      "inboundTopicId": "0.0.444444",
      "outboundTopicId": "0.0.444445",
      "type": 1,
      "capabilities": [0, 4],
      "model": "gpt-4",
      "creator": "Alice"
    }
    
  • GET /api/agents?name=Alice&capability=0
    Search for agents by name and/or capability.
    Response (200 OK):

    [
      {
        "name": "AliceAgent",
        "inboundTopicId": "0.0.444444",
        "outboundTopicId": "0.0.444445",
        "type": 1,
        "capabilities": [0, 4],
        "model": "gpt-4",
        "creator": "Alice"
      }
    ]
    

Connection Endpoints

  • POST /api/connections/request
    Initiates a connection request to another agent.
    Request Body:

    {
      "fromAccount": "0.0.AAAAA",
      "fromPrivateKey": "302e0201...",
      "toAccount": "0.0.BBBBB"
    }
    

    Response (200 OK):

    { "requestSequenceNumber": 42 }
    
  • POST /api/connections/accept
    Accepts a connection request and creates a dedicated connection topic.
    Request Body:

    {
      "fromAccount": "0.0.BBBBB",
      "fromPrivateKey": "302e0201...",
      "requesterAccount": "0.0.AAAAA"
    }
    

    Response (200 OK):

    { "connectionTopicId": "0.0.CCCCC" }
    
  • GET /api/connections?accountId=0.0.AAAAA
    Lists all active connections for a given agent.
    Response (200 OK):

    [
      { "peer": "0.0.BBBBB", "connectionTopicId": "0.0.CCCCC" }
    ]
    

Messaging Endpoints

  • POST /api/messages/send
    Sends a message over an established connection.
    Request Body:

    {
      "senderAccount": "0.0.AAAAA",
      "senderKey": "302e0201...",
      "connectionTopicId": "0.0.CCCCC",
      "message": "Hello, AgentB!"
    }
    

    Response (200 OK):

    { "sequenceNumber": 7 }
    
  • GET /api/messages?connectionTopicId=0.0.CCCCC&limit=10
    Retrieves recent messages from a connection topic.
    Response (200 OK):

    {
      "messages": [
        "{\"p\":\"hcs-10\",\"op\":\"message\",\"operator_id\":\"[email protected]\",\"data\":\"Hello, AgentB!\",\"m\":\"Message from agent.\"}"
      ]
    }
    

MCP SSE Interface

The server exposes an MCP interface over SSE (Server-Sent Events) powered by FastMCP. This interface is available at:

http://localhost:3001/sse

Integration with Cursor

  1. Run the Server:
    Ensure the MCP SSE server is running (default on port 3001). Use npm start or Docker as described below.

  2. Configure in Cursor:
    In Cursorโ€™s MCP settings, add a new MCP server with the URL:

    http://localhost:3001/sse
    

    Cursor will automatically retrieve the list of available tools (e.g., register_agent, request_connection, send_message, etc.).

  3. Usage:
    You can instruct Cursorโ€™s AI to perform actions using these tools. For example, prompt:

    "Register a new agent named AliceAgent and connect me to BobAgent."
    Cursor will call the respective MCP tools defined in the SSE interface.


Docker Deployment

The project comes with a Dockerfile and a docker-compose.yml file for easy one-command deployment.

Using Docker Compose

  1. Ensure Environment Variables:
    Set your environment variables in a .env file in the project root (as shown above).

  2. Build and Run:

    docker-compose up --build -d
    

    This command builds the Docker image and starts the containers in detached mode. The REST API will be accessible on port 3000 and the MCP SSE server on port 3001.

  3. Verify Deployment:
    Open your browser or use curl to check:

    • Health Check: http://localhost:3000/
    • MCP SSE Endpoint: http://localhost:3001/sse

Testing

Running the Test Suite

The project uses Jest for testing. Tests are organized into unit, integration, and end-to-end suites.

Run all tests with:

npm test

Tests include:

  • Unit Tests: Validate logic in individual services (e.g., file chunking in fileService.test.ts).
  • Integration Tests: Test REST API endpoints using Supertest to ensure proper responses.
  • End-to-End Tests: Simulate a full agent communication flow (agent registration, connection, and messaging) on Hedera Testnet.

Note: Tests will execute live operations on Hedera Testnet. Ensure your test environment has sufficient funds and that you are aware of minimal HBAR consumption.


Maintenance & Optimization

  • Logging & Monitoring:
    The server includes a basic logger. In production, consider integrating a more robust logging solution (e.g., Winston or Pino) and setting up log rotation and monitoring dashboards.

  • Caching:
    Agent profiles and connection lists are cached in memory. For high-load scenarios, consider replacing these with a persistent store (e.g., Redis or a database).

  • Scaling:
    The server is stateless aside from in-memory caches. It can be horizontally scaled behind a load balancer. For multiple instances, ensure they share the same registry configuration so that all agents appear in the global registry.

  • Security Considerations:

    • Secure the .env file and never expose private keys.
    • For production, implement proper authentication/authorization for API endpoints.
    • Consider using HTTPS and other secure communication practices.
  • Standards Compliance Updates:
    Keep an eye on updates to the Hedera Agent Kit and Standards Agent Kit. Upgrading dependencies may require minimal adjustments if new fields or protocols are introduced.


Contributing

Contributions are welcome! Please fork the repository and open pull requests with your improvements. For major changes, please open an issue first to discuss what you would like to change.


License

This project is licensed under the MIT License.

Leave a Comment

Frequently Asked Questions

What is MCP?

MCP (Model Context Protocol) is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications, providing a standardized way to connect AI models to different data sources and tools.

What are MCP Servers?

MCP Servers are lightweight programs that expose specific capabilities through the standardized Model Context Protocol. They act as bridges between LLMs like Claude and various data sources or services, allowing secure access to files, databases, APIs, and other resources.

How do MCP Servers work?

MCP Servers follow a client-server architecture where a host application (like Claude Desktop) connects to multiple servers. Each server provides specific functionality through standardized endpoints and protocols, enabling Claude to access data and perform actions through the standardized protocol.

Are MCP Servers secure?

Yes, MCP Servers are designed with security in mind. They run locally with explicit configuration and permissions, require user approval for actions, and include built-in security features to prevent unauthorized access and ensure data privacy.

Related MCP Servers

chrisdoc hevy mcp avatar

chrisdoc hevy mcp

mcp
sylphlab pdf reader mcp avatar

sylphlab pdf reader mcp

An MCP server built with Node.js/TypeScript that allows AI agents to securely read PDF files (local or URL) and extract text, metadata, or page counts. Uses pdf-parse.

pdf-parsetypescriptnodejs
aashari mcp server atlassian bitbucket avatar

aashari mcp server atlassian bitbucket

Node.js/TypeScript MCP server for Atlassian Bitbucket. Enables AI systems (LLMs) to interact with workspaces, repositories, and pull requests via tools (list, get, comment, search). Connects AI directly to version control workflows through the standard MCP interface.

atlassianrepositorymcp
aashari mcp server atlassian confluence avatar

aashari mcp server atlassian confluence

Node.js/TypeScript MCP server for Atlassian Confluence. Provides tools enabling AI systems (LLMs) to list/get spaces & pages (content formatted as Markdown) and search via CQL. Connects AI seamlessly to Confluence knowledge bases using the standard MCP interface.

atlassianmcpconfluence
prisma prisma avatar

prisma prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB

cockroachdbgomcp
Zzzccs123 mcp sentry avatar

Zzzccs123 mcp sentry

mcp sentry for typescript sdk

mcptypescript
zhuzhoulin dify mcp server avatar

zhuzhoulin dify mcp server

mcp
zhongmingyuan mcp my mac avatar

zhongmingyuan mcp my mac

mcp
zhixiaoqiang desktop image manager mcp avatar

zhixiaoqiang desktop image manager mcp

MCP ๆœๅŠกๅ™จ๏ผŒ็”จไบŽ็ฎก็†ๆกŒ้ขๅ›พ็‰‡ใ€ๆŸฅ็œ‹่ฏฆๆƒ…ใ€ๅŽ‹็ผฉใ€็งปๅŠจ็ญ‰๏ผˆๅฎŒๅ…จ่ฎฉTraeๅฎž็Žฐ๏ผ‰

mcp
zhixiaoqiang antd components mcp avatar

zhixiaoqiang antd components mcp

An MCP service for Ant Design components query | ไธ€ไธชๅ‡ๅฐ‘ Ant Design ็ป„ไปถไปฃ็ ็”Ÿๆˆๅนป่ง‰็š„ MCP ๆœๅŠก๏ผŒๅŒ…ๅซ็ณป็ปŸๆ็คบ่ฏใ€็ป„ไปถๆ–‡ๆกฃใ€API ๆ–‡ๆกฃใ€ไปฃ็ ็คบไพ‹ๅ’Œๆ›ดๆ–ฐๆ—ฅๅฟ—ๆŸฅ่ฏข

designantdapi

Submit Your MCP Server

Share your MCP server with the community

Submit Now