Skip to main content

Quick Start

This guide will get you up and running with the MCMP JavaScript SDK in just a few minutes.

Prerequisites

Node.js 16+

Ensure you have Node.js 16 or higher installed

MCMP Account

Sign up for a free account at mcmp.app

Step 1: Install the SDK

Install the MCMP JavaScript SDK:
npm install @mcmp/sdk

Step 2: Get Your API Key

  1. Sign in to mcmp.app
  2. Go to SettingsAPI Keys
  3. Click Generate New Key
  4. Copy your API key

Step 3: Create Your First Server

import { McmpClient } from '@mcmp/sdk';

async function quickStart() {
  // Initialize the client
  const client = new McmpClient({
    apiKey: 'your-api-key-here'
  });
  
  try {
    // Create a new server
    const server = await client.servers.create({
      name: 'My First Server',
      type: 'PAPER',
      version: '1.21.1'
    });
    
    console.log('Created server:', server.id);
    
    // Start the server
    await client.servers.start(server.id);
    console.log('Server started!');
    
    // Check server status
    const status = await client.servers.getStatus(server.id);
    console.log('Server status:', status.state);
    
  } catch (error) {
    console.error('Error:', error.message);
  }
}

quickStart();

Step 4: Run Your Code

Run your JavaScript application:
node quickstart.js

What’s Next?

Common Examples

List All Servers

// List all your servers
const servers = await client.servers.list();

servers.forEach(server => {
  console.log('Server:', server.name);
  console.log('ID:', server.id);
  console.log('Status:', server.status);
  console.log('---');
});

Execute Server Commands

// Execute a command on your server
const result = await client.servers.executeCommand(server.id, 'list');
console.log('Online players:', result);

Monitor Server Performance

// Get server performance metrics
const metrics = await client.servers.getMetrics(server.id);

console.log('CPU Usage:', metrics.cpuUsage + '%');
console.log('Memory Usage:', metrics.memoryUsage + 'MB');
console.log('Players Online:', metrics.playerCount);

TypeScript Support

The SDK includes full TypeScript support:
import { McmpClient, Server, ServerType, ServerVersion } from '@mcmp/sdk';

const client = new McmpClient({
  apiKey: process.env.MCMP_API_KEY!
});

const server: Server = await client.servers.create({
  name: 'TypeScript Server',
  type: ServerType.PAPER,
  version: ServerVersion.V1_21_1
});

React Integration

For React applications, use the React-specific package:
npm install @mcmp/sdk @mcmp/sdk-react
import { McmpProvider, useMcmpClient } from '@mcmp/sdk-react';

function App() {
  return (
    <McmpProvider apiKey="your-api-key">
      <ServerList />
    </McmpProvider>
  );
}

function ServerList() {
  const client = useMcmpClient();
  const [servers, setServers] = useState([]);
  
  useEffect(() => {
    client.servers.list().then(setServers);
  }, [client]);
  
  return (
    <div>
      {servers.map(server => (
        <div key={server.id}>{server.name}</div>
      ))}
    </div>
  );
}

Vue.js Integration

For Vue.js applications:
npm install @mcmp/sdk @mcmp/sdk-vue
<template>
  <div>
    <h1>My Servers</h1>
    <div v-for="server in servers" :key="server.id">
      {{ server.name }} - {{ server.status }}
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useMcmpClient } from '@mcmp/sdk-vue';

const client = useMcmpClient();
const servers = ref([]);

onMounted(async () => {
  servers.value = await client.servers.list();
});
</script>

Error Handling

Handle errors gracefully:
import { McmpClient, AuthenticationError, ServerError } from '@mcmp/sdk';

async function handleErrors() {
  try {
    const client = new McmpClient({ apiKey: 'invalid-key' });
    await client.servers.list();
  } catch (error) {
    if (error instanceof AuthenticationError) {
      console.error('Authentication failed:', error.message);
    } else if (error instanceof ServerError) {
      console.error('Server error:', error.message);
    } else {
      console.error('Unexpected error:', error.message);
    }
  }
}

Environment Variables

Use environment variables for configuration:
# .env
MCMP_API_KEY=your-api-key-here
import { McmpClient } from '@mcmp/sdk';

const client = new McmpClient({
  apiKey: process.env.MCMP_API_KEY
});

Troubleshooting

Make sure your API key is correct and has the necessary permissions.
Check that you have sufficient resources and the server type/version is supported.
Verify your network connection and that the MCMP API is accessible.
Ensure you have TypeScript installed and your tsconfig.json is configured properly.

Next Steps

1

Authentication

Learn about different authentication methods
2

Server Management

Master server lifecycle management
3

Real-time Events

Explore real-time server events