Skip to main content
The Neural Mesh Protocol (NMP) provides the @nekzus/neural-mesh, designed as a powerful yet highly familiar SDK. If you have previously built servers for MCP, transitioning to NMP architecture is almost effortless. In this guide, we’ll build a basic NMP Server that exposes a tool, and a Client that invokes it.
Under the hood, NMP is compiling your logic to WebAssembly and injecting it via P2P. However, the SDK abstracts this entirely, letting you focus on writing pure business logic.

1. Installation

Install the official SDK in your Node.js or TypeScript project.
npm install @nekzus/neural-mesh zod

2. Create an NMP Server (Data Node)

An NMP Server acts as a Data Node. It connects to the mesh and listens for incoming injected logic from remote agents. It exposes secure tools and resources. Create a file named server.ts:
server.ts
import { NmpServer } from '@nekzus/neural-mesh';
import { z } from 'zod';

// Initialize the Server with identity and capabilities
const server = new NmpServer({
  name: "MyLocalDataNode",
  version: "1.0.0"
});

// Expose a tool. 
// Note: In NMP, the async logic provided here is dynamically converted 
// into an isolated Capability for incoming WASM Agents.
server.tool(
  "query_database",
  "Analyzes giant tables exactly at the origin. Pass a SQL-like string.",
  { query: z.string() },
  async ({ query }) => {
    console.log(`[Server] Executing Logic-on-Origin for query: ${query}`);
    
    // Imagine processing 5GB of local data here.
    // Only the final result leaves the server.
    return {
      content: [{ type: "text", text: `Processed query results for: ${query}` }]
    };
  }
);

// Start the server and announce it to the Kademlia DHT Mesh
async function main() {
  await server.connect();
  console.log("NMP Server is listening on the Mesh...");
}

main().catch(console.error);

3. Create an NMP Client (Agent Node)

An NMP Client acts as the Intelligence. It discovers servers on the mesh and pushes compiled requests (intent) to them. Create a file named client.ts:
client.ts
import { NmpClient } from '@nekzus/neural-mesh';

async function main() {
  // Initialize the Client
  const client = new NmpClient({
    name: "AI_Research_Agent",
    version: "2.5.1"
  });

  await client.connect();
  console.log("Joined Neural Mesh Protocol...");

  // Discover the server and inject logic
  try {
    const result = await client.callTool("MyLocalDataNode", "query_database", {
      query: "SELECT * FROM massive_table WHERE anomaly = true"
    });

    console.log("Received mathematically-verified result:");
    console.log(result.content[0].text);
  } catch (err) {
    console.error("Agent execution failed:", err);
  }
}

main().catch(console.error);

4. Run your Mesh

First, start your isolated Server:
npx tsx server.ts
# Output: NMP Server is listening on the Mesh...
In a separate terminal, unleash your Agent:
npx tsx client.ts
# Output: Joined Neural Mesh Protocol...
# Output: Received mathematically-verified result:
# Output: Processed query results for: SELECT * FROM massive_table WHERE anomaly = true

What just happened?

Unlike legacy REST APIs or MCP strings parsing:
  1. Your Client discovered the Server instantly via a P2P Kademlia Routing Table.
  2. A Post-Quantum Kyber Handshake secured the intent.
  3. The query was serialized into an ultra-compact Protobuf Binary.
  4. The execution happened inside a microscopic WASI Sandbox on the server, safely isolated from your physical host.

Next Steps

Now that you’ve run your first Mesh execution, dive deeper into the core architecture to understand how to leverage advanced capabilities like Continuous Watchdogs and Zero-Knowledge Proofs.

Core Architecture

Learn how the Data Layer and Transport Layer synergize in NMP.