Mind Chain API

CMD API Documentation

The CMD API is a Node.js server that integrates with Supabase for agent data management. This API allows you to check for existing agents, retrieve agent data, and store new agent details.


Prerequisites

Before setting up the CMD API, make sure you have the following:

  • Node.js (v14 or higher)

  • npm or yarn

  • A Supabase account and a project created


Setup

Clone the Repository

First, clone the repository to your local machine:

bashCopygit clone <repository_url>

Install Dependencies

Navigate into the project folder and install the dependencies:

bashCopynpm install

Copy the Environment Variables Template

Next, copy the environment variables template file:

bashCopycp .env.example .env

Update the .env File

Update the .env file with your Supabase credentials:

plaintextCopyPORT=3000
SUPABASE_URL=your_supabase_project_url
SUPABASE_ANON_KEY=your_supabase_anon_key

Replace your_supabase_project_url and your_supabase_anon_key with the actual credentials from your Supabase project.

Set Up Your Supabase Database

Run the following SQL command to set up the required schema in your Supabase database:

sqlCopycreate table agents (
  id uuid default uuid_generate_v4() primary key,
  name text unique not null,
  personality text,
  created_at timestamp with time zone default timezone('utc'::text, now()) not null,
  updated_at timestamp with time zone default timezone('utc'::text, now()) not null
);

This will create a table for storing agent data, including the agent's name, personality, and timestamps for creation and updates.


Development

To run the development server:

bashCopynpm run dev

This will start the API server on the specified port (3000 by default).


Production

To build and start the production server, run the following commands:

bashCopynpm run build
npm start

This will optimize the application for production and start the server.


API Endpoints

Check if Agent Exists

To check if an agent exists by its name:

GET /exists/:agentName

  • Parameters:

    • agentName: The name of the agent you want to check for.

  • Response:

    • 200: If the agent exists.

    • 404: If the agent does not exist.


Get Agent Data

To retrieve the data of an agent by its name:

GET /agent/:agentName

  • Parameters:

    • agentName: The name of the agent whose data you want to retrieve.

  • Response:

    • 200: Returns the agent's data (name, personality, etc.).

    • 404: If the agent does not exist.


Store Agent

To store an agent's details:

POST /store-agent

  • Body:

jsonCopy{
  "agentName": "string",
  "agentDetails": {
    "personality": "string"
  }
}
  • Response:

    • 200: If the agent was successfully stored.

    • 400: Bad Request if the data is incorrect or missing.

    • 500: Internal Server Error if something goes wrong with the database.


Error Handling

The API includes proper error handling, and it will return appropriate HTTP status codes:

  • 200: Success

  • 400: Bad Request

  • 404: Not Found

  • 500: Internal Server Error

Make sure to check for the response status code to handle errors accordingly.


Conclusion

The CMD API provides simple integration with Supabase to manage agent data. You can check if an agent exists, get agent data, and store new agents easily using the endpoints provided.

Make sure to update your .env file with the correct Supabase credentials and configure the database schema as instructed for smooth operation.

Last updated