Developer Integration

MindCP provides a flexible and strong framework for Developer Integration that makes it simple for developers to design, modify, and expand AI agents. Whether you want to build new agents, connect external services, or integrate MindCP’s AI capabilities into your own applications, this framework provides all the tools and APIs needed for smooth development.


Key Features

Feature
Description

API Access

RESTful and WebSocket APIs for interacting with AI agents and system components

SDKs

Software Development Kits available for popular programming languages like Python and JavaScript

Custom Agent Creation

Tools and templates to build agents tailored to specific tasks or industries

Event Hooks

Define custom event listeners to trigger actions based on agent activity or user interaction

Context Integration

Seamless access to decentralized context data within your custom applications

Security Controls

Robust authentication and permission systems to protect user data and control access


SDK Installation

Install the official MindCP SDK from npm:

npm install @mindcp/sdk

Set your API key in a .env file:

MindCP_API_KEY="YOUR_MINDCP_API_KEY_HERE"

Example: Verifying AI Model Output

Below is a full implementation example for verifying AI outputs using the MindCP SDK:

// Import the MindCP SDK – your gateway to decentralized AI verification
import { MindCP } from '@MindCP/sdk';

// Initialize the MindCP client with your API key
// Ensure your MindCP_API_KEY is set in your environment variables for production use.
const mcp = new MindCP({
  apiKey: process.env.MindCP_API_KEY,
  environment: 'production' // Use 'production' for live deployments
});

/**
 * Verifies the output of an AI model using MindCP's decentralized attestation network.
 * This process ensures trust and transparency for AI-generated content or decisions.
 *
 * @param {string} modelId - The identifier of the AI model (e.g., 'gpt-4o', 'custom-financial-predictor').
 * @param {string} input - The prompt or input given to the AI model.
 * @param {string} output - The exact output generated by the AI model.
 * @returns {Promise<object|null>} The verification details if successful, otherwise null.
 */
async function verifyAIModelOutput(modelId, input, output) {
  console.log(`\n--- Starting Verification for Model: ${modelId} ---`);
  console.log('Input:', input);
  console.log('Output:', output);

  try {
    // Step 1: Create an Attestation
    console.log('Requesting attestation from MindCP...');
    const attestation = await mcp.createAttestation({
      modelId,
      input,
      output,
      options: {
        includeProof: true,
        storagePolicy: 'persistent'
      }
    });

    console.log(`Attestation created successfully! Attestation ID: ${attestation.id}`);

    // Step 2: Verify the Attestation
    console.log('Verifying the attestation...');
    const verification = await mcp.verifyAttestation(attestation.id);
    
    if (verification.isValid) {
      console.log('✅ AI Output Verified Successfully!');
      console.log(`Verification ID: ${verification.id}`);
      return verification;
    } else {
      console.error('❌ Verification Failed!');
      console.error(`Reason: ${verification.reason}`);
      return null;
    }
  } catch (error) {
    console.error('An error occurred during the verification process:');
    if (error.response) {
        console.error('API Error Status:', error.response.status);
        console.error('API Error Data:', error.response.data);
    } else if (error.request) {
        console.error('Network Error: No response received from MindCP API.');
    } else {
        console.error('General Error Message:', error.message);
    }
    throw error;
  } finally {
    console.log('--- Verification Process Complete ---');
  }
}

// --- Example Usage ---

verifyAIModelOutput(
  'gpt-4o',
  'What is the capital of France?',
  'The capital of France is Paris.'
).then(result => {
    if (result) {
        console.log('Factual AI response check passed.');
    } else {
        console.log('Factual AI response check failed.');
    }
});

verifyAIModelOutput(
  'content-moderator-v1',
  'Review the following text for hate speech: "I love sunny days!"',
  'Classification: Clean. No hate speech detected.'
).then(result => {
    if (result) {
        console.log('Content moderation AI output check passed.');
    } else {
        console.log('Content moderation AI output check failed.');
    }
}).catch(err => {
    console.error("Content moderation example encountered an error:", err);
});

Last updated